source: source/ariba/utility/transport/tcpip/protlib/eclock_gettime.c@ 10073

Last change on this file since 10073 was 9991, checked in by Christoph Mayer, 13 years ago

-fixes on protlib for android

File size: 2.5 KB
RevLine 
[5284]1/// ----------------------------------------*- mode: C++; -*--
2/// @file eclock_gettime.c
3/// emulates a clock_gettime call for systems not having it
4/// ----------------------------------------------------------
5/// $Id: eclock_gettime.c 2549 2007-04-02 22:17:37Z bless $
6/// $HeadURL: https://svn.ipv6.tm.uka.de/nsis/protlib/trunk/fastqueue/eclock_gettime.c $
7// ===========================================================
8//
9// Copyright (C) 2005-2007, all rights reserved by
10// - Institute of Telematics, Universitaet Karlsruhe (TH)
11//
12// More information and contact:
13// https://projekte.tm.uka.de/trac/NSIS
14//
15// This program is free software; you can redistribute it and/or modify
16// it under the terms of the GNU General Public License as published by
17// the Free Software Foundation; version 2 of the License
18//
19// This program is distributed in the hope that it will be useful,
20// but WITHOUT ANY WARRANTY; without even the implied warranty of
21// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
22// GNU General Public License for more details.
23//
24// You should have received a copy of the GNU General Public License along
25// with this program; if not, write to the Free Software Foundation, Inc.,
26// 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
27//
28// ===========================================================
[9686]29/** @addtogroup protlib
[5284]30 * @{
31 */
32
33
34
35#include <sys/time.h>
36#include <unistd.h>
37
38/* struct timezone tz = { 0, DST_NONE }; */
39static struct timeval tv;
40
41/* syntax for clock_gettime:
42 int clock_gettime (clockid_t clock_id, struct timespec *tp);
43
44 to supply it include the following (because of speed):
45 extern int eclock_gettime(struct timespec *tp);
46 #define clock_gettime(clock_id, tspec) eclock_gettime(tspec)
47*/
48
49int eclock_gettime(struct timespec *tp)
50{
51 /* DESCRIPTION
52
53 The clock_gettime function returns the current time (in seconds and
54 nanoseconds) for the specified clock. The clock_settime function sets the
55 specified clock. The CLOCK_REALTIME clock measures the amount of time
56 elapsed since 00:00:00:00 January 1, 1970 Greenwich Mean Time (GMT), other-
57 wise known as the Epoch. Time values that fall between two non-negative
58 integer multiples of the resolution are truncated down to the smaller mul-
59 tiple of the resolution.
60
61 */
62 if (gettimeofday(&tv, 0) == 0)
63 {
64#ifdef DEBUG
65 if (tp)
66#endif
67 {
68 tp->tv_sec= tv.tv_sec;
69 tp->tv_nsec= tv.tv_usec*1000;
70 return 0;
71 }
72 }
73 else
74 return -1;
75}
76
77//@}
Note: See TracBrowser for help on using the repository browser.