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!!!! */
32 * will alloc memory and clear it
34 void *clear_malloc(size_t size)
36 void *t = malloc(size);
39 memset(t, 0x00, size);
44 void *fill_malloc(size_t size)
46 void *t = malloc(size);
49 /* We want to initialize memory to some known bad state. */
50 /* 0 and 0xff yields 0 and -1 as integers, which often */
51 /* have meaningful values. 0x5555... is not often a valid */
52 /* integer and is quite easily spotted in the debugger */
53 /* also it is almost certainly an invalid address */
54 memset(t, 0x55, size);
59 #include "replacements.h"
63 /* replacements for gettimeofday */
64 #ifndef HAVE_GETTIMEOFDAY
70 #define EPOCHFILETIME (116444736000000000i64)
72 #define EPOCHFILETIME (116444736000000000LL)
75 int gettimeofday(struct timeval *tv, struct timezone *tz)
84 GetSystemTimeAsFileTime(&ft);
85 li.LowPart = ft.dwLowDateTime;
86 li.HighPart = ft.dwHighDateTime;
87 t = li.QuadPart; /* In 100-nanosecond intervals */
88 t -= EPOCHFILETIME; /* Offset to the Epoch time */
89 t /= 10; /* In microseconds */
90 tv->tv_sec = (long)(t / 1000000);
91 tv->tv_usec = (long)(t % 1000000);
101 tz->tz_minuteswest = _timezone / 60;
102 tz->tz_dsttime = _daylight;
109 #endif /* HAVE_GETTIMEOFDAY */
112 size_t strnlen(const char *s, size_t maxlen)
114 const char *end= (const char *)memchr(s, '\0', maxlen);
115 return end ? (size_t) (end - s) : maxlen;
120 char* strndup(const char *s, size_t n)
122 size_t len = strnlen (s, n);
123 char *new = (char *) malloc (len + 1);
129 return (char *) memcpy (new, s, len);