source: trash/old-modules/transport/protlib/eclock_gettime.c@ 6796

Last change on this file since 6796 was 5641, checked in by Christoph Mayer, 15 years ago
File size: 2.5 KB
Line 
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// ===========================================================
29/** @addtogroup fastqueue Fast Queue
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;
40typedef int clockid_t;
41
42/* syntax for clock_gettime:
43 int clock_gettime (clockid_t clock_id, struct timespec *tp);
44
45 to supply it include the following (because of speed):
46 extern int eclock_gettime(struct timespec *tp);
47 #define clock_gettime(clock_id, tspec) eclock_gettime(tspec)
48*/
49
50int eclock_gettime(struct timespec *tp)
51{
52 /* DESCRIPTION
53
54 The clock_gettime function returns the current time (in seconds and
55 nanoseconds) for the specified clock. The clock_settime function sets the
56 specified clock. The CLOCK_REALTIME clock measures the amount of time
57 elapsed since 00:00:00:00 January 1, 1970 Greenwich Mean Time (GMT), other-
58 wise known as the Epoch. Time values that fall between two non-negative
59 integer multiples of the resolution are truncated down to the smaller mul-
60 tiple of the resolution.
61
62 */
63 if (gettimeofday(&tv, 0) == 0)
64 {
65#ifdef DEBUG
66 if (tp)
67#endif
68 {
69 tp->tv_sec= tv.tv_sec;
70 tp->tv_nsec= tv.tv_usec*1000;
71 return 0;
72 }
73 }
74 else
75 return -1;
76}
77
78//@}
Note: See TracBrowser for help on using the repository browser.