Debian Codegraph @

src/compat/gettimeofday.cpp

raw symbols SCIP
1 /*
2 * Copyright (C) 2000 Ross Combs ([email protected])
3 *
4 * This program is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU General Public License
6 * as published by the Free Software Foundation; either version 2
7 * of the License, or (at your option) any later version.
8 *
9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
13 *
14 * You should have received a copy of the GNU General Public License
15 * along with this program; if not, write to the Free Software
16 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
17 */
18 #include "common/setup_before.h"
19 #ifndef HAVE_GETTIMEOFDAY
20
21 #include "gettimeofday.h"
22 #include <cerrno>
23 #include <ctime>
24
25 #ifdef HAVE_SYS_TIMEB_H
26 # include <sys/timeb.h>
27 #endif
28
29
30
31 #include "common/setup_after.h"
32
33 namespace pvpgn
34 {
35
36 extern int gettimeofday(struct timeval * tv, struct timezone * tz)
37 {
38 #ifdef HAVE_FTIME
39 struct timeb tb;
40 #endif
41
42 if (!tv)
43 {
44 errno = EFAULT;
45 return -1;
46 }
47
48 #ifdef HAVE_FTIME
49 tb.millitm = 0; /* apparently the MS CRT version of this doesn't set this member */
50 /* FIXME: what would be a more appropriate function for that platform? */
51 ftime(&tb); /* FIXME: some versions are void return others int */
52
53 tv->tv_sec = tb.time;
54 tv->tv_usec = ((long)tb.millitm) * 1000;
55 if (tz)
56 {
57 tz->tz_minuteswest = 0;
58 tz->tz_dsttime = 0;
59 }
60
61 return 0;
62 #else
63 # error "This program requires either gettimeofday() or ftime()"
64 #endif
65 }
66
67 }
68
69 #else
70 typedef int filenotempty; /* make ISO standard happy */
71 #endif