1 /**\file oscallsUnix.c
2 * \brief OS API calls wrapper for Unix.
3 *
4 * \author Rainer Gerhards <rgerhards@adiscon.com>
5 *
6 * \date 2003-09-02
7 * rgerhards: coding begun
8 *
9 * Copyright 2002-2014
10 * Rainer Gerhards and Adiscon GmbH. All Rights Reserved.
11 *
12 * Redistribution and use in source and binary forms, with or without
13 * modification, are permitted provided that the following conditions are
14 * met:
15 *
16 * * Redistributions of source code must retain the above copyright
17 * notice, this list of conditions and the following disclaimer.
18 *
19 * * Redistributions in binary form must reproduce the above copyright
20 * notice, this list of conditions and the following disclaimer in
21 * the documentation and/or other materials provided with the
22 * distribution.
23 *
24 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS
25 * IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
26 * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A
27 * PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER
28 * OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
29 * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
30 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
31 * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
32 * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
33 * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
34 * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
35 */
36
37 #include <sys/time.h>
38 #include <time.h>
39
40 /* ################################################################# */
41 /* private members */
42 /* ################################################################# */
43
44 /* As this is not a "real" object, there won't be any private
45 * members in this file.
46 */
47
48 /* ################################################################# */
49 /* public members */
50 /* ################################################################# */
51
52 /**
53 * Get the current date/time in the best resolution the operating
54 * system has to offer (well, actually at most down to the milli-
55 * second level.
56 *
57 * The date and time is returned in separate fields as this is
58 * most portable and removes the need for additional structures
59 * (but I have to admit it is somewhat "bulky";)).
60 *
61 * Obviously, all caller-provided pointers must not be NULL...
62 */
getCurrTime(int * year,int * month,int * day,int * hour,int * minute,int * second,int * secfrac,int * secfracPrecison,char * pcOffsetMode,int * pOffsetHour,int * pOffsetMinute)63 srRetVal getCurrTime(int* year, int* month, int* day, int *hour, int* minute, int *second,
64 int* secfrac, int *secfracPrecison, char* pcOffsetMode, int* pOffsetHour,
65 int* pOffsetMinute)
66 {
67 struct timeval tp;
68 struct tm *tm;
69 long lBias;
70
71 gettimeofday(&tp, NULL);
72 tm = localtime(&(tp.tv_sec));
73
74 *year = tm->tm_year + 1900;
75 *month = tm->tm_mon + 1;
76 *day = tm->tm_mday;
77 *hour = tm->tm_hour;
78 *minute = tm->tm_min;
79 *second = tm->tm_sec;
80 *secfrac = tp.tv_usec;
81 *secfracPrecison = 6;
82
83 #ifdef SROS_Solaris
84 /* Solaris uses a different method of exporting the time zone.
85 * It is UTC - localtime, which is opposite sign of min east of GMT.
86 */
87 lBias = -(daylight ? altzone : timezone);
88 #else
89 lBias = tm->tm_gmtoff;
90 #endif
91 if(lBias < 0)
92 {
93 *pcOffsetMode = '-';
94 lBias *= -1;
95 }
96 else
97 *pcOffsetMode = '+';
98
99 *pOffsetHour = lBias / 3600;
100 *pOffsetMinute = lBias % 3600;
101
102 return SR_RET_OK;
103 }
104
105