Skip to content

Commit 63abb5c

Browse files
committed
dtoa.c: make compilable independently
Except for `-Dxmalloc=malloc -Dxfree=free`.
1 parent 01aa036 commit 63abb5c

File tree

1 file changed

+18
-6
lines changed

1 file changed

+18
-6
lines changed

missing/dtoa.c

Lines changed: 18 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -183,12 +183,16 @@
183183
#undef Long
184184
#undef ULong
185185

186-
#if SIZEOF_INT == 4
186+
#include <limits.h>
187+
188+
#if (INT_MAX >> 30) && !(INT_MAX >> 31)
187189
#define Long int
188190
#define ULong unsigned int
189-
#elif SIZEOF_LONG == 4
191+
#elif (LONG_MAX >> 30) && !(LONG_MAX >> 31)
190192
#define Long long int
191193
#define ULong unsigned long int
194+
#else
195+
#error No 32bit integer
192196
#endif
193197

194198
#if HAVE_LONG_LONG
@@ -202,6 +206,11 @@
202206
#define Bug(x) {fprintf(stderr, "%s\n", (x)); exit(EXIT_FAILURE);}
203207
#endif
204208

209+
#ifndef ISDIGIT
210+
#include <ctype.h>
211+
#define ISDIGIT(c) isdigit(c)
212+
#endif
213+
#include <errno.h>
205214
#include <stdlib.h>
206215
#include <string.h>
207216

@@ -219,6 +228,9 @@ extern void FREE(void*);
219228
#else
220229
#define FREE xfree
221230
#endif
231+
#ifndef NO_SANITIZE
232+
#define NO_SANITIZE(x, y) y
233+
#endif
222234

223235
#ifndef Omit_Private_Memory
224236
#ifndef PRIVATE_MEM
@@ -280,7 +292,7 @@ extern "C" {
280292
#endif
281293

282294
#ifndef hexdigit
283-
static const char hexdigits[] = "0123456789abcdef0123456789ABCDEF";
295+
static const char hexdigit[] = "0123456789abcdef0123456789ABCDEF";
284296
#endif
285297

286298
#if defined(IEEE_LITTLE_ENDIAN) + defined(IEEE_BIG_ENDIAN) + defined(VAX) + defined(IBM) != 1
@@ -2520,10 +2532,10 @@ static char *dtoa_result;
25202532
static char *
25212533
rv_alloc(int i)
25222534
{
2523-
return dtoa_result = xmalloc(i);
2535+
return dtoa_result = MALLOC(i);
25242536
}
25252537
#else
2526-
#define rv_alloc(i) xmalloc(i)
2538+
#define rv_alloc(i) MALLOC(i)
25272539
#endif
25282540

25292541
static char *
@@ -2550,7 +2562,7 @@ nrv_alloc(const char *s, char **rve, size_t n)
25502562
static void
25512563
freedtoa(char *s)
25522564
{
2553-
xfree(s);
2565+
FREE(s);
25542566
}
25552567
#endif
25562568

0 commit comments

Comments
 (0)