cosmopolitan/libc/fmt/strtol.internal.h
Justine Tunney e963d9c8e3 Add cpu / mem / fsz limits to build system
Thanks to all the refactorings we now have the ability to enforce
reasonable limitations on the amount of resources any individual
compile or test can consume. Those limits are currently:

- `-C 8` seconds of 3.1ghz CPU time
- `-M 256mebibytes` of virtual memory
- `-F 100megabyte` limit on file size

Only one file currently needs to exceed these limits:

    o/$(MODE)/third_party/python/Objects/unicodeobject.o: \
        QUOTA += -C16  # overrides cpu limit to 16 seconds

This change introduces a new sizetol() function to LIBC_FMT for parsing
byte or bit size strings with Si unit suffixes. Functions like atoi()
have been rewritten too.
2021-08-13 23:40:53 -07:00

35 lines
1.3 KiB
C

#ifndef COSMOPOLITAN_LIBC_FMT_STRTOL_H_
#define COSMOPOLITAN_LIBC_FMT_STRTOL_H_
#define CONSUME_SPACES(s, c) \
while (c == ' ' || c == '\t') c = *++s
#define GET_SIGN(s, c, d) \
d = c == '-' ? -1 : 1; \
if (c == '-' || c == '+') c = *++s
#define GET_RADIX(s, c, r) \
if (!(2 <= r && r <= 36)) { \
if (c == '0') { \
c = *++s; \
if (c == 'x' || c == 'X') { \
c = *++s; \
r = 16; \
} else if (c == 'b' || c == 'B') { \
c = *++s; \
r = 2; \
} else { \
r = 8; \
} \
} else { \
r = 10; \
} \
} else if (c == '0') { \
c = *++s; \
if ((r == 2 && (c == 'b' || c == 'B')) || \
(r == 16 && (c == 'x' || c == 'X'))) { \
c = *++s; \
} \
}
#endif /* COSMOPOLITAN_LIBC_FMT_STRTOL_H_ */