1 /***************************************************************************
2 * Copyright (C) 2006 by Dominic Rath *
3 * Dominic.Rath@gmx.de *
5 * This program is free software; you can redistribute it and/or modify *
6 * it under the terms of the GNU General Public License as published by *
7 * the Free Software Foundation; either version 2 of the License, or *
8 * (at your option) any later version. *
10 * This program is distributed in the hope that it will be useful, *
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of *
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
13 * GNU General Public License for more details. *
15 * You should have received a copy of the GNU General Public License *
16 * along with this program; if not, write to the *
17 * Free Software Foundation, Inc., *
18 * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. *
19 ***************************************************************************/
24 #include "replacements.h"
28 /* replacements for gettimeofday */
29 #ifndef HAVE_GETTIMEOFDAY
35 #define EPOCHFILETIME (116444736000000000i64)
37 #define EPOCHFILETIME (116444736000000000LL)
40 int gettimeofday(struct timeval *tv, struct timezone *tz)
49 GetSystemTimeAsFileTime(&ft);
50 li.LowPart = ft.dwLowDateTime;
51 li.HighPart = ft.dwHighDateTime;
52 t = li.QuadPart; /* In 100-nanosecond intervals */
53 t -= EPOCHFILETIME; /* Offset to the Epoch time */
54 t /= 10; /* In microseconds */
55 tv->tv_sec = (long)(t / 1000000);
56 tv->tv_usec = (long)(t % 1000000);
66 tz->tz_minuteswest = _timezone / 60;
67 tz->tz_dsttime = _daylight;
74 #endif /* HAVE_GETTIMEOFDAY */
77 size_t strnlen(const char *s, size_t maxlen)
79 const char *end= (const char *)memchr(s, '\0', maxlen);
80 return end ? (size_t) (end - s) : maxlen;
85 char* strndup(const char *s, size_t n)
87 size_t len = strnlen (s, n);
88 char *new = (char *) malloc (len + 1);
94 return (char *) memcpy (new, s, len);