git-svn-id: svn://svn.berlios.de/openocd/trunk@228 b42882b7-edfa-0310-969c-e2dbd0fdcd60
[openocd.git] / src / helper / replacements.c
1 /***************************************************************************
2 * Copyright (C) 2006 by Dominic Rath *
3 * Dominic.Rath@gmx.de *
4 * *
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. *
9 * *
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. *
14 * *
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 ***************************************************************************/
20 #ifdef HAVE_CONFIG_H
21 #include "config.h"
22 #endif
23
24 /* DANGER!!!! These must be defined *BEFORE* replacements.h and the malloc() macro!!!! */
25
26 #include <stdlib.h>
27 #include <strings.h>
28 /*
29 * clear_malloc
30 *
31 * will alloc memory and clear it
32 */
33 void *clear_malloc(size_t size)
34 {
35 void *t = malloc(size);
36 if (t!=NULL)
37 {
38 memset(t, 0x00, size);
39 }
40 return t;
41 }
42
43 void *fill_malloc(size_t size)
44 {
45 void *t = malloc(size);
46 if (t!=NULL)
47 {
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);
54 }
55 return t;
56 }
57
58 #include "replacements.h"
59
60 #include <stdio.h>
61
62 /* replacements for gettimeofday */
63 #ifndef HAVE_GETTIMEOFDAY
64
65 /* Windows */
66 #ifdef _WIN32
67
68 #ifndef __GNUC__
69 #define EPOCHFILETIME (116444736000000000i64)
70 #else
71 #define EPOCHFILETIME (116444736000000000LL)
72 #endif
73
74 int gettimeofday(struct timeval *tv, struct timezone *tz)
75 {
76 FILETIME ft;
77 LARGE_INTEGER li;
78 __int64 t;
79 static int tzflag;
80
81 if (tv)
82 {
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);
91 }
92
93 if (tz)
94 {
95 if (!tzflag)
96 {
97 _tzset();
98 tzflag++;
99 }
100 tz->tz_minuteswest = _timezone / 60;
101 tz->tz_dsttime = _daylight;
102 }
103
104 return 0;
105 }
106 #endif /* _WIN32 */
107
108 #endif /* HAVE_GETTIMEOFDAY */
109
110 #ifndef HAVE_STRNLEN
111 size_t strnlen(const char *s, size_t maxlen)
112 {
113 const char *end= (const char *)memchr(s, '\0', maxlen);
114 return end ? (size_t) (end - s) : maxlen;
115 }
116 #endif
117
118 #ifndef HAVE_STRNDUP
119 char* strndup(const char *s, size_t n)
120 {
121 size_t len = strnlen (s, n);
122 char *new = (char *) malloc (len + 1);
123
124 if (new == NULL)
125 return NULL;
126
127 new[len] = '\0';
128 return (char *) memcpy (new, s, len);
129 }
130 #endif

Linking to existing account procedure

If you already have an account and want to add another login method you MUST first sign in with your existing account and then change URL to read https://review.openocd.org/login/?link to get to this page again but this time it'll work for linking. Thank you.

SSH host keys fingerprints

1024 SHA256:YKx8b7u5ZWdcbp7/4AeXNaqElP49m6QrwfXaqQGJAOk gerrit-code-review@openocd.zylin.com (DSA)
384 SHA256:jHIbSQa4REvwCFG4cq5LBlBLxmxSqelQPem/EXIrxjk gerrit-code-review@openocd.org (ECDSA)
521 SHA256:UAOPYkU9Fjtcao0Ul/Rrlnj/OsQvt+pgdYSZ4jOYdgs gerrit-code-review@openocd.org (ECDSA)
256 SHA256:A13M5QlnozFOvTllybRZH6vm7iSt0XLxbA48yfc2yfY gerrit-code-review@openocd.org (ECDSA)
256 SHA256:spYMBqEYoAOtK7yZBrcwE8ZpYt6b68Cfh9yEVetvbXg gerrit-code-review@openocd.org (ED25519)
+--[ED25519 256]--+
|=..              |
|+o..   .         |
|*.o   . .        |
|+B . . .         |
|Bo. = o S        |
|Oo.+ + =         |
|oB=.* = . o      |
| =+=.+   + E     |
|. .=o   . o      |
+----[SHA256]-----+
2048 SHA256:0Onrb7/PHjpo6iVZ7xQX2riKN83FJ3KGU0TvI0TaFG4 gerrit-code-review@openocd.zylin.com (RSA)