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 /* DANGER!!!! These must be defined *BEFORE* replacements.h and the malloc() macro!!!! */
31 * will alloc memory and clear it
33 void *clear_malloc(size_t size)
35 void *t = malloc(size);
38 memset(t, 0x00, size);
43 void *fill_malloc(size_t size)
45 void *t = malloc(size);
48 /* We want to initialize memory to some known bad state. */
49 /* 0 and 0xff yields 0 and -1 as integers, which often */
50 /* have meaningful values. 0x5555... is not often a valid */
51 /* integer and is quite easily spotted in the debugger */
52 /* also it is almost certainly an invalid address */
53 memset(t, 0x55, size);
58 #include "replacements.h"
62 /* replacements for gettimeofday */
63 #ifndef HAVE_GETTIMEOFDAY
69 #define EPOCHFILETIME (116444736000000000i64)
71 #define EPOCHFILETIME (116444736000000000LL)
74 int gettimeofday(struct timeval *tv, struct timezone *tz)
83 GetSystemTimeAsFileTime(&ft);
84 li.LowPart = ft.dwLowDateTime;
85 li.HighPart = ft.dwHighDateTime;
86 t = li.QuadPart; /* In 100-nanosecond intervals */
87 t -= EPOCHFILETIME; /* Offset to the Epoch time */
88 t /= 10; /* In microseconds */
89 tv->tv_sec = (long)(t / 1000000);
90 tv->tv_usec = (long)(t % 1000000);
100 tz->tz_minuteswest = _timezone / 60;
101 tz->tz_dsttime = _daylight;
108 #endif /* HAVE_GETTIMEOFDAY */
111 size_t strnlen(const char *s, size_t maxlen)
113 const char *end= (const char *)memchr(s, '\0', maxlen);
114 return end ? (size_t) (end - s) : maxlen;
119 char* strndup(const char *s, size_t n)
121 size_t len = strnlen (s, n);
122 char *new = (char *) malloc (len + 1);
128 return (char *) memcpy (new, s, len);