WvStreams
utils.cc
1// utils.cpp : Defines the entry point for the DLL application.
2//
3
4#include "wvwin32-sanitize.h"
5
6#define EPOCHFILETIME (116444736000000000LL)
7
8int gettimeofday(struct timeval *tv, struct timezone *tz)
9{
10 FILETIME ft;
11 LARGE_INTEGER li;
12 __int64 t;
13 static int tzflag;
14
15 if (tv)
16 {
17 GetSystemTimeAsFileTime(&ft);
18 li.LowPart = ft.dwLowDateTime;
19 li.HighPart = ft.dwHighDateTime;
20 t = li.QuadPart; /* In 100-nanosecond intervals */
21 t -= EPOCHFILETIME; /* Offset to the Epoch time */
22 t /= 10; /* In microseconds */
23 tv->tv_sec = (long)(t / 1000000);
24 tv->tv_usec = (long)(t % 1000000);
25 }
26
27#if 0
28 if (tz)
29 {
30 if (!tzflag)
31 {
32 _tzset();
33 tzflag++;
34 }
35 tz->tz_minuteswest = _timezone / 60;
36 tz->tz_dsttime = _daylight;
37 }
38#endif
39 return 0;
40}
41
42
43pid_t getpid()
44{
45 return GetCurrentThreadId();
46}
47
48
49unsigned int sleep(unsigned int secs)
50{
51 Sleep(secs*1000);
52 return 0;
53}
54
55
56// FIXME: this makes alarms silently fail. They should probably fail more
57// nicely, or (better still) actually work...
58unsigned int alarm(unsigned int t)
59{
60 return 0;
61}
62
63
64// This is the same as what Python uses, apparently
65int fsync(int fd)
66{
67 return _commit(fd);
68}