GSI Object Oriented Online Offline (Go4) GO4-6.4.0
Loading...
Searching...
No Matches
f_ut_time.c
Go to the documentation of this file.
1// $Id$
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 _MSC_VER
59
60#include <windows.h>
61#include <sysinfoapi.h>
62
63#define DELTA_EPOCH_IN_MICROSECS 11644473600000000Ui64
64
65int clock_gettime(int clockid, struct timespec *tp)
66{
67 FILETIME ft;
68 unsigned __int64 tmpres = 0;
69
70 tp->tv_sec = 0;
71 tp->tv_nsec = 0;
72
73 GetSystemTimeAsFileTime(&ft);
74
75 tmpres |= ft.dwHighDateTime;
76 tmpres <<= 32;
77 tmpres |= ft.dwLowDateTime;
78
79 /*converting file time to unix epoch*/
80 tmpres /= 10; /*convert into microseconds*/
81 tmpres -= DELTA_EPOCH_IN_MICROSECS;
82 tp->tv_sec = (long)(tmpres / 1000000UL);
83 tp->tv_nsec = (long)(tmpres % 1000000UL) * 1000;
84
85 return 0;
86}
87
88#endif
89
91{
92 struct timespec tp;
93 struct tm st_time;
94#ifndef _MSC_VER
95 struct tm buf_time;
96#endif
97
98 clock_gettime(CLOCK_REALTIME, &tp);
99
100#ifdef _MSC_VER
101 st_time = *localtime(&tp.tv_sec);
102#else
103 st_time = *localtime_r(&tp.tv_sec, &buf_time);
104#endif
105
106 strftime(pc_time,30,"%d-%h-%y %T",&st_time);
107 return ((CHARS *) pc_time);
108}
CHARS * f_ut_time(CHARS *pc_time)
Definition f_ut_time.c:90
char CHARS
Definition typedefs.h:21