GSI Object Oriented Online Offline (Go4)  GO4-6.1.4
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros
f_ut_time.c
Go to the documentation of this file.
1 // $Id: f_ut_time.c 2866 2020-05-18 16:23:47Z linev $
2 //-----------------------------------------------------------------------
3 // The GSI Online Offline Object Oriented (Go4) Project
4 // Experiment Data Processing at EE department, GSI
5 //-----------------------------------------------------------------------
6 // Copyright (C) 2000- GSI Helmholtzzentrum fuer Schwerionenforschung GmbH
7 // Planckstr. 1, 64291 Darmstadt, Germany
8 // Contact: http://go4.gsi.de
9 //-----------------------------------------------------------------------
10 // This software can be used under the license agreements as stated
11 // in Go4License.txt file which is part of the distribution.
12 //-----------------------------------------------------------------------
13 
14 #include "typedefs.h"
15 /*****************+***********+****************************************/
16 /* */
17 /* GSI, Gesellschaft fuer Schwerionenforschung mbH */
18 /* Postfach 11 05 52 */
19 /* D-64220 Darmstadt */
20 /* */
21 /*1+ C Procedure *************+****************************************/
22 /* */
23 /*+ Module : f_ut_time */
24 /* */
25 /*--------------------------------------------------------------------*/
26 /*+ CALLING : CHARS * = f_ut_time(CHARS *) */
27 /*--------------------------------------------------------------------*/
28 /* */
29 /*+ PURPOSE : Returns date/time string in format */
30 /* day-month-year hours:min:sec */
31 /* must be linked on Lynx with -X (=posix library) */
32 /* because of the time correction done. */
33 /* On VMS with /PREF=ALL */
34 /* */
35 /*3+Function******+***********+****************************************/
36 /* */
37 /* Length of returned string is 17. No \n. */
38 /* */
39 /*3+Examples******+***********+****************************************/
40 /* Description */
41 /*2+Implementation************+****************************************/
42 /*+ Utility : util */
43 /*+ File name : f_ut_time.c */
44 /*+ Home direct.: path */
45 /*+ Declaration : CHARS *f_ut_time(CHARS *); */
46 /*+ Version : 1.01 */
47 /*+ Author : H.G.Essel */
48 /*+ Created : 24-Mar-1994 */
49 /*+ Object libr.: */
50 /*+ Updates : Date Purpose */
51 /*- : 03-apr-97 : support VMS, AIX, DECunix, Lynx */
52 /*1- C Procedure *************+****************************************/
53 
54 #include "f_ut_time.h"
55 
56 #include <stdio.h>
57 
58 #ifdef WIN32
59 
60 #include <sysinfoapi.h>
61 
62 #if defined(_MSC_VER) || defined(_MSC_EXTENSIONS)
63  #define DELTA_EPOCH_IN_MICROSECS 11644473600000000Ui64
64 #else
65  #define DELTA_EPOCH_IN_MICROSECS 11644473600000000ULL
66 #endif
67 
68 int clock_gettime(int clockid, struct timespec *tp)
69 {
70  FILETIME ft;
71  unsigned __int64 tmpres = 0;
72 
73  tp->tv_sec = 0;
74  tp->tv_nsec = 0;
75 
76  GetSystemTimeAsFileTime(&ft);
77 
78  tmpres |= ft.dwHighDateTime;
79  tmpres <<= 32;
80  tmpres |= ft.dwLowDateTime;
81 
82  /*converting file time to unix epoch*/
83  tmpres /= 10; /*convert into microseconds*/
84  tmpres -= DELTA_EPOCH_IN_MICROSECS;
85  tp->tv_sec = (long)(tmpres / 1000000UL);
86  tp->tv_nsec = (long)(tmpres % 1000000UL) * 1000;
87 
88  return 0;
89 }
90 
91 #endif
92 
93 CHARS *f_ut_time (CHARS *pc_time)
94 {
95  struct timespec tp;
96  struct tm st_time;
97 #ifndef WIN32
98  struct tm buf_time;
99 #endif
100 
101  clock_gettime(CLOCK_REALTIME, &tp);
102 
103 #ifdef WIN32
104  st_time = *localtime(&tp.tv_sec);
105 #else
106  st_time = *localtime_r(&tp.tv_sec, &buf_time);
107 #endif
108 
109  strftime(pc_time,30,"%d-%h-%y %T",&st_time);
110  return ((CHARS *) pc_time);
111 }
CHARS * f_ut_time(CHARS *pc_time)
Definition: f_ut_time.c:93
char CHARS
Definition: typedefs.h:21