summaryrefslogtreecommitdiff
path: root/system
diff options
context:
space:
mode:
Diffstat (limited to 'system')
-rw-r--r--system/include/AL/al.h172
-rw-r--r--system/include/AL/alc.h84
-rw-r--r--system/include/emscripten/emscripten.h4
-rw-r--r--system/include/err.h95
-rw-r--r--system/include/libc/ctype.h23
-rw-r--r--system/include/libc/iso646.h43
-rw-r--r--system/include/libc/math.h27
-rw-r--r--system/include/stdbool.h3
-rw-r--r--system/lib/libc.symbols25
-rw-r--r--system/lib/libc/gen/err.c49
-rw-r--r--system/lib/libc/gen/errx.c49
-rw-r--r--system/lib/libc/gen/verr.c58
-rw-r--r--system/lib/libc/gen/verrx.c51
-rw-r--r--system/lib/libc/gen/vwarn.c55
-rw-r--r--system/lib/libc/gen/vwarnx.c48
-rw-r--r--system/lib/libc/gen/warn.c49
-rw-r--r--system/lib/libc/gen/warnx.c49
-rw-r--r--system/lib/libc/stdlib/getopt_long.c511
-rw-r--r--system/lib/libc/stdlib/strtod.c305
19 files changed, 1675 insertions, 25 deletions
diff --git a/system/include/AL/al.h b/system/include/AL/al.h
new file mode 100644
index 00000000..d7234e32
--- /dev/null
+++ b/system/include/AL/al.h
@@ -0,0 +1,172 @@
+#ifndef OPENAL_AL_H__
+#define OPENAL_AL_H__
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+#define AL_BITS 0x2002
+#define AL_BUFFER 0x1009
+#define AL_BUFFERS_PROCESSED 0x1016
+#define AL_BUFFERS_QUEUED 0x1015
+#define AL_BYTE_OFFSET 0x1026
+#define AL_CHANNELS 0x2003
+#define AL_CONE_INNER_ANGLE 0x1001
+#define AL_CONE_OUTER_ANGLE 0x1002
+#define AL_CONE_OUTER_GAIN 0x1022
+#define AL_DIRECTION 0x1005
+#define AL_DISTANCE_MODEL 0xD000
+#define AL_DOPPLER_FACTOR 0xC000
+#define AL_DOPPLER_VELOCITY 0xC001
+#define AL_EXPONENT_DISTANCE 0xD005
+#define AL_EXPONENT_DISTANCE_CLAMPED 0xD006
+#define AL_EXTENSIONS 0xB004
+#define AL_FALSE 0
+#define AL_FORMAT_MONO16 0x1101
+#define AL_FORMAT_MONO8 0x1100
+#define AL_FORMAT_STEREO16 0x1103
+#define AL_FORMAT_STEREO8 0x1102
+#define AL_FREQUENCY 0x2001
+#define AL_GAIN 0x100A
+#define AL_ILLEGAL_COMMAND AL_INVALID_OPERATION
+#define AL_ILLEGAL_ENUM AL_INVALID_ENUM
+#define AL_INITIAL 0x1011
+#define AL_INVALID (-1)
+#define AL_INVALID_ENUM 0xA002
+#define AL_INVALID_NAME 0xA001
+#define AL_INVALID_OPERATION 0xA004
+#define AL_INVALID_VALUE 0xA003
+#define AL_INVERSE_DISTANCE 0xD001
+#define AL_INVERSE_DISTANCE_CLAMPED 0xD002
+#define AL_LINEAR_DISTANCE 0xD003
+#define AL_LINEAR_DISTANCE_CLAMPED 0xD004
+#define AL_LOOPING 0x1007
+#define AL_MAX_DISTANCE 0x1023
+#define AL_MAX_GAIN 0x100E
+#define AL_MIN_GAIN 0x100D
+#define AL_NONE 0
+#define AL_NO_ERROR 0
+#define AL_ORIENTATION 0x100F
+#define AL_OUT_OF_MEMORY 0xA005
+#define AL_PAUSED 0x1013
+#define AL_PENDING 0x2011
+#define AL_PITCH 0x1003
+#define AL_PLAYING 0x1012
+#define AL_POSITION 0x1004
+#define AL_PROCESSED 0x2012
+#define AL_REFERENCE_DISTANCE 0x1020
+#define AL_RENDERER 0xB003
+#define AL_ROLLOFF_FACTOR 0x1021
+#define AL_SAMPLE_OFFSET 0x1025
+#define AL_SEC_OFFSET 0x1024
+#define AL_SIZE 0x2004
+#define AL_SOURCE_RELATIVE 0x202
+#define AL_SOURCE_STATE 0x1010
+#define AL_SOURCE_TYPE 0x1027
+#define AL_SPEED_OF_SOUND 0xC003
+#define AL_STATIC 0x1028
+#define AL_STOPPED 0x1014
+#define AL_STREAMING 0x1029
+#define AL_TRUE 1
+#define AL_UNDETERMINED 0x1030
+#define AL_UNUSED 0x2010
+#define AL_VELOCITY 0x1006
+#define AL_VENDOR 0xB001
+#define AL_VERSION 0xB002
+#define AL_VERSION_1_0
+#define AL_VERSION_1_1
+#define OPENAL
+
+typedef char ALboolean;
+typedef char ALchar;
+typedef double ALdouble;
+typedef float ALfloat;
+typedef int ALenum;
+typedef int ALint;
+typedef int ALsizei;
+typedef short ALshort;
+typedef signed char ALbyte;
+typedef unsigned char ALubyte;
+typedef unsigned int ALuint;
+typedef unsigned short ALushort;
+typedef void ALvoid;
+
+extern ALboolean alGetBoolean(ALenum param);
+extern ALboolean alIsBuffer(ALuint buffer);
+extern ALboolean alIsEnabled(ALenum capability);
+extern ALboolean alIsExtensionPresent(const ALchar *extname);
+extern ALboolean alIsSource(ALuint source);
+extern ALdouble alGetDouble(ALenum param);
+extern ALenum alGetEnumValue(const ALchar *ename);
+extern ALenum alGetError();
+extern ALfloat alGetFloat(ALenum param);
+extern ALint alGetInteger(ALenum param);
+extern const ALchar *alGetString(ALenum param);
+extern void *alGetProcAddress(const ALchar *fname);
+extern void alBuffer3f(ALuint buffer, ALenum param, ALfloat value1, ALfloat value2, ALfloat value3);
+extern void alBuffer3i(ALuint buffer, ALenum param, ALint value1, ALint value2, ALint value3);
+extern void alBufferData(ALuint buffer, ALenum format, const ALvoid *data, ALsizei size, ALsizei freq);
+extern void alBufferf(ALuint buffer, ALenum param, ALfloat value);
+extern void alBufferfv(ALuint buffer, ALenum param, const ALfloat *values);
+extern void alBufferi(ALuint buffer, ALenum param, ALint value);
+extern void alBufferiv(ALuint buffer, ALenum param, const ALint *values);
+extern void alDeleteBuffers(ALsizei n, const ALuint *buffers);
+extern void alDeleteSources(ALsizei n, const ALuint *sources);
+extern void alDisable(ALenum capability);
+extern void alDistanceModel(ALenum distanceModel);
+extern void alDopplerFactor(ALfloat value);
+extern void alDopplerVelocity(ALfloat value);
+extern void alEnable(ALenum capability);
+extern void alGenBuffers(ALsizei n, ALuint *buffers);
+extern void alGenSources(ALsizei n, ALuint *sources);
+extern void alGetBooleanv(ALenum param, ALboolean *values);
+extern void alGetBuffer3f(ALuint buffer, ALenum param, ALfloat *value1, ALfloat *value2, ALfloat *value3);
+extern void alGetBuffer3i(ALuint buffer, ALenum param, ALint *value1, ALint *value2, ALint *value3);
+extern void alGetBufferf(ALuint buffer, ALenum param, ALfloat *value);
+extern void alGetBufferfv(ALuint buffer, ALenum param, ALfloat *values);
+extern void alGetBufferi(ALuint buffer, ALenum param, ALint *value);
+extern void alGetBufferiv(ALuint buffer, ALenum param, ALint *values);
+extern void alGetDoublev(ALenum param, ALdouble *values);
+extern void alGetFloatv(ALenum param, ALfloat *values);
+extern void alGetIntegerv(ALenum param, ALint *values);
+extern void alGetListener3f(ALenum param, ALfloat *value1, ALfloat *value2, ALfloat *value3);
+extern void alGetListener3i(ALenum param, ALint *value1, ALint *value2, ALint *value3);
+extern void alGetListenerf(ALenum param, ALfloat *value);
+extern void alGetListenerfv(ALenum param, ALfloat *values);
+extern void alGetListeneri(ALenum param, ALint *value);
+extern void alGetListeneriv(ALenum param, ALint *values);
+extern void alGetSource3f(ALuint source, ALenum param, ALfloat *value1, ALfloat *value2, ALfloat *value3);
+extern void alGetSource3i(ALuint source, ALenum param, ALint *value1, ALint *value2, ALint *value3);
+extern void alGetSourcef(ALuint source, ALenum param, ALfloat *value);
+extern void alGetSourcefv(ALuint source, ALenum param, ALfloat *values);
+extern void alGetSourcei(ALuint source, ALenum param, ALint *value);
+extern void alGetSourceiv(ALuint source, ALenum param, ALint *values);
+extern void alListener3f(ALenum param, ALfloat value1, ALfloat value2, ALfloat value3);
+extern void alListener3i(ALenum param, ALint value1, ALint value2, ALint value3);
+extern void alListenerf(ALenum param, ALfloat value);
+extern void alListenerfv(ALenum param, const ALfloat *values);
+extern void alListeneri(ALenum param, ALint value);
+extern void alListeneriv(ALenum param, const ALint *values);
+extern void alSource3f(ALuint source, ALenum param, ALfloat value1, ALfloat value2, ALfloat value3);
+extern void alSource3i(ALuint source, ALenum param, ALint value1, ALint value2, ALint value3);
+extern void alSourcePause(ALuint source);
+extern void alSourcePausev(ALsizei n, const ALuint *sources);
+extern void alSourcePlay(ALuint source);
+extern void alSourcePlayv(ALsizei n, const ALuint *sources);
+extern void alSourceQueueBuffers(ALuint source, ALsizei nb, const ALuint *buffers);
+extern void alSourceRewind(ALuint source);
+extern void alSourceRewindv(ALsizei n, const ALuint *sources);
+extern void alSourceStop(ALuint source);
+extern void alSourceStopv(ALsizei n, const ALuint *sources);
+extern void alSourceUnqueueBuffers(ALuint source, ALsizei nb, ALuint *buffers);
+extern void alSourcef(ALuint source, ALenum param, ALfloat value);
+extern void alSourcefv(ALuint source, ALenum param, const ALfloat *values);
+extern void alSourcei(ALuint source, ALenum param, ALint value);
+extern void alSourceiv(ALuint source, ALenum param, const ALint *values);
+extern void alSpeedOfSound(ALfloat value);
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif
diff --git a/system/include/AL/alc.h b/system/include/AL/alc.h
new file mode 100644
index 00000000..6ff7cb9b
--- /dev/null
+++ b/system/include/AL/alc.h
@@ -0,0 +1,84 @@
+#ifndef OPENAL_ALC_H__
+#define OPENAL_ALC_H__
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+#define ALCAPI ALC_API
+#define ALCAPIENTRY ALC_APIENTRY
+#define ALC_ALL_ATTRIBUTES 0x1003
+#define ALC_ALL_DEVICES_SPECIFIER 0x1013
+#define ALC_ATTRIBUTES_SIZE 0x1002
+#define ALC_CAPTURE_DEFAULT_DEVICE_SPECIFIER 0x311
+#define ALC_CAPTURE_DEVICE_SPECIFIER 0x310
+#define ALC_CAPTURE_SAMPLES 0x312
+#define ALC_DEFAULT_ALL_DEVICES_SPECIFIER 0x1012
+#define ALC_DEFAULT_DEVICE_SPECIFIER 0x1004
+#define ALC_DEVICE_SPECIFIER 0x1005
+#define ALC_ENUMERATE_ALL_EXT 1
+#define ALC_EXTENSIONS 0x1006
+#define ALC_EXT_CAPTURE 1
+#define ALC_FALSE 0
+#define ALC_FREQUENCY 0x1007
+#define ALC_INVALID 0
+#define ALC_INVALID_CONTEXT 0xA002
+#define ALC_INVALID_DEVICE 0xA001
+#define ALC_INVALID_ENUM 0xA003
+#define ALC_INVALID_VALUE 0xA004
+#define ALC_MAJOR_VERSION 0x1000
+#define ALC_MINOR_VERSION 0x1001
+#define ALC_MONO_SOURCES 0x1010
+#define ALC_NO_ERROR 0
+#define ALC_OUT_OF_MEMORY 0xA005
+#define ALC_REFRESH 0x1008
+#define ALC_STEREO_SOURCES 0x1011
+#define ALC_SYNC 0x1009
+#define ALC_TRUE 1
+#define ALC_VERSION_0_1 1
+#define AL_ALC_H
+
+struct ALCcontext_struct;
+struct ALCdevice_struct;
+typedef char ALCboolean;
+typedef char ALCchar;
+typedef double ALCdouble;
+typedef float ALCfloat;
+typedef int ALCenum;
+typedef int ALCint;
+typedef int ALCsizei;
+typedef short ALCshort;
+typedef signed char ALCbyte;
+typedef struct ALCcontext_struct ALCcontext;
+typedef struct ALCdevice_struct ALCdevice;
+typedef unsigned char ALCubyte;
+typedef unsigned int ALCuint;
+typedef unsigned short ALCushort;
+typedef void ALCvoid;
+
+extern ALCboolean alcCaptureCloseDevice(ALCdevice *device);
+extern ALCboolean alcCloseDevice(ALCdevice *device);
+extern ALCboolean alcIsExtensionPresent(ALCdevice *device, const ALCchar *extname);
+extern ALCboolean alcMakeContextCurrent(ALCcontext *context);
+extern ALCcontext *alcCreateContext(ALCdevice *device, const ALCint *attrlist);
+extern ALCcontext *alcGetCurrentContext();
+extern ALCdevice *alcCaptureOpenDevice(const ALCchar *devicename, ALCuint frequency, ALCenum format, ALCsizei buffersize);
+extern ALCdevice *alcGetContextsDevice(ALCcontext *context);
+extern ALCdevice *alcOpenDevice(const ALCchar *devicename);
+extern ALCenum alcGetEnumValue(ALCdevice *device, const ALCchar *enumname);
+extern ALCenum alcGetError(ALCdevice *device);
+extern const ALCchar *alcGetString(ALCdevice *device, ALCenum param);
+extern void *alcGetProcAddress(ALCdevice *device, const ALCchar *funcname);
+extern void alcCaptureSamples(ALCdevice *device, ALCvoid *buffer, ALCsizei samples);
+extern void alcCaptureStart(ALCdevice *device);
+extern void alcCaptureStop(ALCdevice *device);
+extern void alcDestroyContext(ALCcontext *context);
+extern void alcGetIntegerv(ALCdevice *device, ALCenum param, ALCsizei size, ALCint *values);
+extern void alcProcessContext(ALCcontext *context);
+extern void alcSuspendContext(ALCcontext *context);
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif
diff --git a/system/include/emscripten/emscripten.h b/system/include/emscripten/emscripten.h
index 427dda0c..61634b0e 100644
--- a/system/include/emscripten/emscripten.h
+++ b/system/include/emscripten/emscripten.h
@@ -60,7 +60,7 @@ extern void emscripten_async_run_script(const char *script, int millis);
* that execution continues normally. Note that in both cases
* we do not run global destructors, atexit, etc., since we
* know the main loop will still be running, but if we do
- * not simulate an infinite loop then the stack will be unwinded.
+ * not simulate an infinite loop then the stack will be unwound.
* That means that if simulate_infinite_loop is false, and
* you created an object on the stack, it will be cleaned up
* before the main loop will be called the first time.
@@ -215,7 +215,7 @@ void emscripten_async_wget_data(const char* url, void *arg, void (*onload)(void*
* More feature-complete version of emscripten_async_wget. Note:
* this version is experimental.
*
- * The requestype is 'GET' or 'POST',
+ * The requesttype is 'GET' or 'POST',
* If is post request, param is the post parameter
* like key=value&key2=value2.
* The param 'arg' is a pointer will be pass to the callback
diff --git a/system/include/err.h b/system/include/err.h
new file mode 100644
index 00000000..a9b92ee6
--- /dev/null
+++ b/system/include/err.h
@@ -0,0 +1,95 @@
+/* $OpenBSD: err.h,v 1.10 2006/01/06 18:53:04 millert Exp $ */
+/* $NetBSD: err.h,v 1.11 1994/10/26 00:55:52 cgd Exp $ */
+
+/*-
+ * Copyright (c) 1993
+ * The Regents of the University of California. All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ * 3. Neither the name of the University nor the names of its contributors
+ * may be used to endorse or promote products derived from this software
+ * without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
+ * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
+ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ *
+ * @(#)err.h 8.1 (Berkeley) 6/2/93
+ */
+
+#ifndef _ERR_H_
+#define _ERR_H_
+
+/*
+ * Don't use va_list in the err/warn prototypes. Va_list is typedef'd in two
+ * places (<machine/varargs.h> and <machine/stdarg.h>), so if we include one
+ * of them here we may collide with the utility's includes. It's unreasonable
+ * for utilities to have to include one of them to include err.h, so we get
+ * va_list from <machine/_types.h> and use it.
+ */
+#include <sys/cdefs.h>
+//#include <machine/_types.h>
+#include <stdarg.h>
+
+#define __dead __attribute__((__noreturn__))
+
+__BEGIN_DECLS
+
+__dead void err(int, const char *, ...)
+ __attribute__((__format__ (printf, 2, 3)));
+__dead void verr(int, const char *, va_list)
+ __attribute__((__format__ (printf, 2, 0)));
+__dead void errx(int, const char *, ...)
+ __attribute__((__format__ (printf, 2, 3)));
+__dead void verrx(int, const char *, va_list)
+ __attribute__((__format__ (printf, 2, 0)));
+void warn(const char *, ...)
+ __attribute__((__format__ (printf, 1, 2)));
+void vwarn(const char *, va_list)
+ __attribute__((__format__ (printf, 1, 0)));
+void warnx(const char *, ...)
+ __attribute__((__format__ (printf, 1, 2)));
+void vwarnx(const char *, va_list)
+ __attribute__((__format__ (printf, 1, 0)));
+
+/*
+ * The _* versions are for use in library functions so user-defined
+ * versions of err*,warn* do not get used.
+ */
+__dead void _err(int, const char *, ...)
+ __attribute__((__format__ (printf, 2, 3)));
+__dead void _verr(int, const char *, va_list)
+ __attribute__((__format__ (printf, 2, 0)));
+__dead void _errx(int, const char *, ...)
+ __attribute__((__format__ (printf, 2, 3)));
+__dead void _verrx(int, const char *, va_list)
+ __attribute__((__format__ (printf, 2, 0)));
+void _warn(const char *, ...)
+ __attribute__((__format__ (printf, 1, 2)));
+void _vwarn(const char *, va_list)
+ __attribute__((__format__ (printf, 1, 0)));
+void _warnx(const char *, ...)
+ __attribute__((__format__ (printf, 1, 2)));
+void _vwarnx(const char *, va_list)
+ __attribute__((__format__ (printf, 1, 0)));
+
+#undef __dead
+
+__END_DECLS
+
+#endif /* !_ERR_H_ */
diff --git a/system/include/libc/ctype.h b/system/include/libc/ctype.h
index 26d3c6ce..383a8db1 100644
--- a/system/include/libc/ctype.h
+++ b/system/include/libc/ctype.h
@@ -72,11 +72,14 @@ _CONST
#define isgraph(__c) (__ctype_lookup(__c)&(CTYPE__P|CTYPE__U|CTYPE__L|CTYPE__N))
#define iscntrl(__c) (__ctype_lookup(__c)&CTYPE__C)
+/* XXX: EMSCRIPTEN: We alter the names of __typeof__ declarations to
+ reduce the chance of them conflicting when expanded */
+
#if defined(__GNUC__) && \
(!defined(__STRICT_ANSI__) || __STDC_VERSION__ >= 199901L)
#define isblank(__c) \
- __extension__ ({ __typeof__ (__c) __x = (__c); \
- (__ctype_lookup(__x)&_B) || (int) (__x) == '\t';})
+ __extension__ ({ __typeof__ (__c) __ctb_x = (__c); \
+ (__ctype_lookup(__ctb_x)&_B) || (int) (__ctb_x) == '\t';})
#endif
@@ -86,20 +89,20 @@ _CONST
# if defined(__GNUC__)
# if !defined (_MB_EXTENDED_CHARSETS_ISO) && !defined (_MB_EXTENDED_CHARSETS_WINDOWS)
# define toupper(__c) \
- __extension__ ({ __typeof__ (__c) __x = (__c); \
- islower (__x) ? (int) __x - 'a' + 'A' : (int) __x;})
+ __extension__ ({ __typeof__ (__c) __cttu_x = (__c); \
+ islower (__cttu_x) ? (int) __cttu_x - 'a' + 'A' : (int) __cttu_x;})
# define tolower(__c) \
- __extension__ ({ __typeof__ (__c) __x = (__c); \
- isupper (__x) ? (int) __x - 'A' + 'a' : (int) __x;})
+ __extension__ ({ __typeof__ (__c) __cttl_x = (__c); \
+ isupper (__cttl_x) ? (int) __cttl_x - 'A' + 'a' : (int) __cttl_x;})
# else /* _MB_EXTENDED_CHARSETS* */
/* Allow a gcc warning if the user passed 'char', but defer to the
function. */
# define toupper(__c) \
- __extension__ ({ __typeof__ (__c) __x = (__c); \
- (void) __ctype_ptr__[__x]; (toupper) (__x);})
+ __extension__ ({ __typeof__ (__c) __cttu_x = (__c); \
+ (void) __ctype_ptr__[__cttu_x]; (toupper) (__cttu_x);})
# define tolower(__c) \
- __extension__ ({ __typeof__ (__c) __x = (__c); \
- (void) __ctype_ptr__[__x]; (tolower) (__x);})
+ __extension__ ({ __typeof__ (__c) __cttl_x = (__c); \
+ (void) __ctype_ptr__[__cttl_x]; (tolower) (__cttl_x);})
# endif /* _MB_EXTENDED_CHARSETS* */
# endif /* __GNUC__ */
#endif /* !__cplusplus */
diff --git a/system/include/libc/iso646.h b/system/include/libc/iso646.h
new file mode 100644
index 00000000..dca13c5b
--- /dev/null
+++ b/system/include/libc/iso646.h
@@ -0,0 +1,43 @@
+/*===---- iso646.h - Standard header for alternate spellings of operators---===
+ *
+ * Copyright (c) 2008 Eli Friedman
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
+ * of this software and associated documentation files (the "Software"), to deal
+ * in the Software without restriction, including without limitation the rights
+ * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+ * copies of the Software, and to permit persons to whom the Software is
+ * furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be included in
+ * all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
+ * THE SOFTWARE.
+ *
+ *===-----------------------------------------------------------------------===
+ */
+
+#ifndef __ISO646_H
+#define __ISO646_H
+
+#ifndef __cplusplus
+#define and &&
+#define and_eq &=
+#define bitand &
+#define bitor |
+#define compl ~
+#define not !
+#define not_eq !=
+#define or ||
+#define or_eq |=
+#define xor ^
+#define xor_eq ^=
+#endif
+
+#endif /* __ISO646_H */
diff --git a/system/include/libc/math.h b/system/include/libc/math.h
index d963c6c8..e2f8cdef 100644
--- a/system/include/libc/math.h
+++ b/system/include/libc/math.h
@@ -210,25 +210,28 @@ extern int __signbitd (double x);
((sizeof(__x) == sizeof(float)) ? __signbitf(__x) : \
__signbitd(__x))
+/* XXX: EMSCRIPTEN: We alter the names of __typeof__ declarations to
+ reduce the chance of them conflicting when expanded */
+
#define isgreater(x,y) \
- (__extension__ ({__typeof__(x) __x = (x); __typeof__(y) __y = (y); \
- !isunordered(__x,__y) && (__x > __y);}))
+ (__extension__ ({__typeof__(x) __isg_x = (x); __typeof__(y) __isg_y = (y); \
+ !isunordered(__isg_x,__isg_y) && (__isg_x > __isg_y);}))
#define isgreaterequal(x,y) \
- (__extension__ ({__typeof__(x) __x = (x); __typeof__(y) __y = (y); \
- !isunordered(__x,__y) && (__x >= __y);}))
+ (__extension__ ({__typeof__(x) __isge_x = (x); __typeof__(y) __isge_y = (y); \
+ !isunordered(__isge_x,__isge_y) && (__isge_x >= __isge_y);}))
#define isless(x,y) \
- (__extension__ ({__typeof__(x) __x = (x); __typeof__(y) __y = (y); \
- !isunordered(__x,__y) && (__x < __y);}))
+ (__extension__ ({__typeof__(x) __isl_x = (x); __typeof__(y) __isl_y = (y); \
+ !isunordered(__isl_x,__isl_y) && (__isl_x < __isl_y);}))
#define islessequal(x,y) \
- (__extension__ ({__typeof__(x) __x = (x); __typeof__(y) __y = (y); \
- !isunordered(__x,__y) && (__x <= __y);}))
+ (__extension__ ({__typeof__(x) __isle_x = (x); __typeof__(y) __isle_y = (y); \
+ !isunordered(__isle_x,__isle_y) && (__isle_x <= __isle_y);}))
#define islessgreater(x,y) \
- (__extension__ ({__typeof__(x) __x = (x); __typeof__(y) __y = (y); \
- !isunordered(__x,__y) && (__x < __y || __x > __y);}))
+ (__extension__ ({__typeof__(x) __islg_x = (x); __typeof__(y) __islg_y = (y); \
+ !isunordered(__islg_x,__islg_y) && (__islg_x < __islg_y || __islg_x > __islg_y);}))
#define isunordered(a,b) \
- (__extension__ ({__typeof__(a) __a = (a); __typeof__(b) __b = (b); \
- fpclassify(__a) == FP_NAN || fpclassify(__b) == FP_NAN;}))
+ (__extension__ ({__typeof__(a) __isu_a = (a); __typeof__(b) __isu_b = (b); \
+ fpclassify(__isu_a) == FP_NAN || fpclassify(__isu_b) == FP_NAN;}))
/* Non ANSI double precision functions. */
diff --git a/system/include/stdbool.h b/system/include/stdbool.h
index f970ade8..561eed3f 100644
--- a/system/include/stdbool.h
+++ b/system/include/stdbool.h
@@ -2,12 +2,13 @@
#ifndef __stdbool_h__
#define __stdbool_h__
+#define __bool_true_false_are_defined 1
+
#ifndef __cplusplus
#define bool _Bool
#define true 1
#define false 0
-#define __bool_true_false_are_defined 1
#endif
diff --git a/system/lib/libc.symbols b/system/lib/libc.symbols
index d41f4140..1342d938 100644
--- a/system/lib/libc.symbols
+++ b/system/lib/libc.symbols
@@ -1,3 +1,6 @@
+getopt
+getopt_long
+getopt_long_only
malloc
free
calloc
@@ -48,3 +51,25 @@ _ZNSt20bad_array_new_lengthC2Ev
_ZNSt20bad_array_new_lengthD0Ev
_ZNSt20bad_array_new_lengthD1Ev
_ZNSt20bad_array_new_lengthD2Ev
+warn
+warnx
+err
+errx
+_warn
+_warnx
+_err
+_errx
+vwarn
+vwarnx
+verr
+verrx
+_vwarn
+_vwarnx
+_verr
+_verrx
+strtod
+strtold
+strtof
+strtod_l
+strtold_l
+atof
diff --git a/system/lib/libc/gen/err.c b/system/lib/libc/gen/err.c
new file mode 100644
index 00000000..218a3bfc
--- /dev/null
+++ b/system/lib/libc/gen/err.c
@@ -0,0 +1,49 @@
+/* $OpenBSD: err.c,v 1.11 2012/12/05 23:19:59 deraadt Exp $ */
+/*-
+ * Copyright (c) 1993
+ * The Regents of the University of California. All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ * 3. Neither the name of the University nor the names of its contributors
+ * may be used to endorse or promote products derived from this software
+ * without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
+ * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
+ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ */
+
+#include <err.h>
+#include <stdarg.h>
+
+#define __dead __attribute__((__noreturn__))
+
+/* PRINTFLIKE2 */
+__dead void
+_err(int eval, const char *fmt, ...)
+{
+ va_list ap;
+
+ va_start(ap, fmt);
+ _verr(eval, fmt, ap);
+ va_end(ap);
+}
+
+/* PRINTFLIKE2 */
+__dead void
+err(int eval, const char *fmt, ...) __attribute__((weak, alias("_err")));
diff --git a/system/lib/libc/gen/errx.c b/system/lib/libc/gen/errx.c
new file mode 100644
index 00000000..a16643c7
--- /dev/null
+++ b/system/lib/libc/gen/errx.c
@@ -0,0 +1,49 @@
+/* $OpenBSD: errx.c,v 1.10 2012/12/05 23:19:59 deraadt Exp $ */
+/*-
+ * Copyright (c) 1993
+ * The Regents of the University of California. All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ * 3. Neither the name of the University nor the names of its contributors
+ * may be used to endorse or promote products derived from this software
+ * without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
+ * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
+ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ */
+
+#include <err.h>
+#include <stdarg.h>
+
+#define __dead __attribute__((__noreturn__))
+
+/* PRINTFLIKE2 */
+__dead void
+_errx(int eval, const char *fmt, ...)
+{
+ va_list ap;
+
+ va_start(ap, fmt);
+ _verrx(eval, fmt, ap);
+ va_end(ap);
+}
+
+/* PRINTFLIKE2 */
+__dead void
+errx(int eval, const char *fmt, ...) __attribute__((weak, alias("_errx")));
diff --git a/system/lib/libc/gen/verr.c b/system/lib/libc/gen/verr.c
new file mode 100644
index 00000000..90f5870f
--- /dev/null
+++ b/system/lib/libc/gen/verr.c
@@ -0,0 +1,58 @@
+/* $OpenBSD: verr.c,v 1.9 2012/12/05 23:20:00 deraadt Exp $ */
+/*-
+ * Copyright (c) 1993
+ * The Regents of the University of California. All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ * 3. Neither the name of the University nor the names of its contributors
+ * may be used to endorse or promote products derived from this software
+ * without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
+ * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
+ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ */
+
+#include <err.h>
+#include <errno.h>
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+#include <stdarg.h>
+
+extern char *__progname; /* Program name, from crt0. */
+
+#define __dead __attribute__((__noreturn__))
+
+__dead void
+_verr(int eval, const char *fmt, va_list ap)
+{
+ int sverrno;
+
+ sverrno = errno;
+ (void)fprintf(stderr, "%s: ", __progname);
+ if (fmt != NULL) {
+ (void)vfprintf(stderr, fmt, ap);
+ (void)fprintf(stderr, ": ");
+ }
+ (void)fprintf(stderr, "%s\n", strerror(sverrno));
+ exit(eval);
+}
+
+__dead void
+verr(int eval, const char *fmt, va_list ap) __attribute__((weak, alias("_verr")));
diff --git a/system/lib/libc/gen/verrx.c b/system/lib/libc/gen/verrx.c
new file mode 100644
index 00000000..b712c65c
--- /dev/null
+++ b/system/lib/libc/gen/verrx.c
@@ -0,0 +1,51 @@
+/* $OpenBSD: verrx.c,v 1.9 2012/12/05 23:20:00 deraadt Exp $ */
+/*-
+ * Copyright (c) 1993
+ * The Regents of the University of California. All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ * 3. Neither the name of the University nor the names of its contributors
+ * may be used to endorse or promote products derived from this software
+ * without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
+ * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
+ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ */
+
+#include <err.h>
+#include <stdio.h>
+#include <stdlib.h>
+#include <stdarg.h>
+
+extern char *__progname; /* Program name, from crt0. */
+
+#define __dead __attribute__((__noreturn__))
+
+__dead void
+_verrx(int eval, const char *fmt, va_list ap)
+{
+ (void)fprintf(stderr, "%s: ", __progname);
+ if (fmt != NULL)
+ (void)vfprintf(stderr, fmt, ap);
+ (void)fprintf(stderr, "\n");
+ exit(eval);
+}
+
+__dead void
+verrx(int eval, const char *fmt, va_list ap) __attribute__((weak, alias("_verrx")));
diff --git a/system/lib/libc/gen/vwarn.c b/system/lib/libc/gen/vwarn.c
new file mode 100644
index 00000000..37acef35
--- /dev/null
+++ b/system/lib/libc/gen/vwarn.c
@@ -0,0 +1,55 @@
+/* $OpenBSD: vwarn.c,v 1.9 2012/12/05 23:20:00 deraadt Exp $ */
+/*-
+ * Copyright (c) 1993
+ * The Regents of the University of California. All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ * 3. Neither the name of the University nor the names of its contributors
+ * may be used to endorse or promote products derived from this software
+ * without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
+ * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
+ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ */
+
+#include <err.h>
+#include <errno.h>
+#include <stdio.h>
+#include <string.h>
+#include <stdarg.h>
+
+extern char *__progname; /* Program name, from crt0. */
+
+void
+_vwarn(const char *fmt, va_list ap)
+{
+ int sverrno;
+
+ sverrno = errno;
+ (void)fprintf(stderr, "%s: ", __progname);
+ if (fmt != NULL) {
+ (void)vfprintf(stderr, fmt, ap);
+ (void)fprintf(stderr, ": ");
+ }
+ (void)fprintf(stderr, "%s\n", strerror(sverrno));
+}
+
+void
+vwarn(const char *fmt, va_list ap) __attribute__((weak, alias("_vwarn")));
+
diff --git a/system/lib/libc/gen/vwarnx.c b/system/lib/libc/gen/vwarnx.c
new file mode 100644
index 00000000..a81a5a0d
--- /dev/null
+++ b/system/lib/libc/gen/vwarnx.c
@@ -0,0 +1,48 @@
+/* $OpenBSD: vwarnx.c,v 1.9 2012/12/05 23:20:00 deraadt Exp $ */
+/*-
+ * Copyright (c) 1993
+ * The Regents of the University of California. All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ * 3. Neither the name of the University nor the names of its contributors
+ * may be used to endorse or promote products derived from this software
+ * without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
+ * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
+ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ */
+
+#include <err.h>
+#include <stdio.h>
+#include <stdarg.h>
+
+extern char *__progname; /* Program name, from crt0. */
+
+void
+_vwarnx(const char *fmt, va_list ap)
+{
+ (void)fprintf(stderr, "%s: ", __progname);
+ if (fmt != NULL)
+ (void)vfprintf(stderr, fmt, ap);
+ (void)fprintf(stderr, "\n");
+}
+
+void
+vwarnx(const char *fmt, va_list ap) __attribute__((weak, alias("_vwarnx")));
+
diff --git a/system/lib/libc/gen/warn.c b/system/lib/libc/gen/warn.c
new file mode 100644
index 00000000..c0803ab9
--- /dev/null
+++ b/system/lib/libc/gen/warn.c
@@ -0,0 +1,49 @@
+/* $OpenBSD: warn.c,v 1.10 2012/12/05 23:20:00 deraadt Exp $ */
+/*-
+ * Copyright (c) 1993
+ * The Regents of the University of California. All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ * 3. Neither the name of the University nor the names of its contributors
+ * may be used to endorse or promote products derived from this software
+ * without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
+ * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
+ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ */
+
+#include <err.h>
+#include <stdarg.h>
+
+#define __dead __attribute__((__noreturn__))
+
+/* PRINTFLIKE1 */
+void
+_warn(const char *fmt, ...)
+{
+ va_list ap;
+
+ va_start(ap, fmt);
+ _vwarn(fmt, ap);
+ va_end(ap);
+}
+
+/* PRINTFLIKE1 */
+void
+warn(const char *fmt, ...) __attribute__((weak, alias("warn")));
diff --git a/system/lib/libc/gen/warnx.c b/system/lib/libc/gen/warnx.c
new file mode 100644
index 00000000..7909cf2c
--- /dev/null
+++ b/system/lib/libc/gen/warnx.c
@@ -0,0 +1,49 @@
+/* $OpenBSD: warnx.c,v 1.9 2012/12/05 23:20:00 deraadt Exp $ */
+/*-
+ * Copyright (c) 1993
+ * The Regents of the University of California. All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ * 3. Neither the name of the University nor the names of its contributors
+ * may be used to endorse or promote products derived from this software
+ * without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
+ * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
+ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ */
+
+#include <err.h>
+#include <stdarg.h>
+
+#define __dead __attribute__((__noreturn__))
+
+/* PRINTFLIKE1 */
+void
+_warnx(const char *fmt, ...)
+{
+ va_list ap;
+
+ va_start(ap, fmt);
+ _vwarnx(fmt, ap);
+ va_end(ap);
+}
+
+/* PRINTFLIKE1 */
+void
+warnx(const char *fmt, ...) __attribute__((weak, alias("_warnx")));
diff --git a/system/lib/libc/stdlib/getopt_long.c b/system/lib/libc/stdlib/getopt_long.c
new file mode 100644
index 00000000..e149fe0a
--- /dev/null
+++ b/system/lib/libc/stdlib/getopt_long.c
@@ -0,0 +1,511 @@
+/* $OpenBSD: getopt_long.c,v 1.25 2011/03/05 22:10:11 guenther Exp $ */
+/* $NetBSD: getopt_long.c,v 1.15 2002/01/31 22:43:40 tv Exp $ */
+
+/*
+ * Copyright (c) 2002 Todd C. Miller <Todd.Miller@courtesan.com>
+ *
+ * Permission to use, copy, modify, and distribute this software for any
+ * purpose with or without fee is hereby granted, provided that the above
+ * copyright notice and this permission notice appear in all copies.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
+ * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
+ * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
+ * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
+ * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
+ * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
+ * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
+ *
+ * Sponsored in part by the Defense Advanced Research Projects
+ * Agency (DARPA) and Air Force Research Laboratory, Air Force
+ * Materiel Command, USAF, under agreement number F39502-99-1-0512.
+ */
+/*-
+ * Copyright (c) 2000 The NetBSD Foundation, Inc.
+ * All rights reserved.
+ *
+ * This code is derived from software contributed to The NetBSD Foundation
+ * by Dieter Baron and Thomas Klausner.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
+ * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
+ * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+ * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
+ * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+ * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+ * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
+ * POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#include <err.h>
+#include <errno.h>
+#include <getopt.h>
+#include <stdlib.h>
+#include <string.h>
+
+int opterr = 1; /* if error message should be printed */
+int optind = 1; /* index into parent argv vector */
+int optopt = '?'; /* character checked for validity */
+int optreset; /* reset getopt */
+char *optarg; /* argument associated with option */
+
+#define PRINT_ERROR ((opterr) && (*options != ':'))
+
+#define FLAG_PERMUTE 0x01 /* permute non-options to the end of argv */
+#define FLAG_ALLARGS 0x02 /* treat non-options as args to option "-1" */
+#define FLAG_LONGONLY 0x04 /* operate as getopt_long_only */
+
+/* return values */
+#define BADCH (int)'?'
+#define BADARG ((*options == ':') ? (int)':' : (int)'?')
+#define INORDER (int)1
+
+#define EMSG ""
+
+static int getopt_internal(int, char * const *, const char *,
+ const struct option *, int *, int);
+static int parse_long_options(char * const *, const char *,
+ const struct option *, int *, int);
+static int gcd(int, int);
+static void permute_args(int, int, int, char * const *);
+
+static char *place = EMSG; /* option letter processing */
+
+/* XXX: set optreset to 1 rather than these two */
+static int nonopt_start = -1; /* first non option argument (for permute) */
+static int nonopt_end = -1; /* first option after non options (for permute) */
+
+/* Error messages */
+static const char recargchar[] = "option requires an argument -- %c";
+static const char recargstring[] = "option requires an argument -- %s";
+static const char ambig[] = "ambiguous option -- %.*s";
+static const char noarg[] = "option doesn't take an argument -- %.*s";
+static const char illoptchar[] = "unknown option -- %c";
+static const char illoptstring[] = "unknown option -- %s";
+
+/*
+ * Compute the greatest common divisor of a and b.
+ */
+static int
+gcd(int a, int b)
+{
+ int c;
+
+ c = a % b;
+ while (c != 0) {
+ a = b;
+ b = c;
+ c = a % b;
+ }
+
+ return (b);
+}
+
+/*
+ * Exchange the block from nonopt_start to nonopt_end with the block
+ * from nonopt_end to opt_end (keeping the same order of arguments
+ * in each block).
+ */
+static void
+permute_args(int panonopt_start, int panonopt_end, int opt_end,
+ char * const *nargv)
+{
+ int cstart, cyclelen, i, j, ncycle, nnonopts, nopts, pos;
+ char *swap;
+
+ /*
+ * compute lengths of blocks and number and size of cycles
+ */
+ nnonopts = panonopt_end - panonopt_start;
+ nopts = opt_end - panonopt_end;
+ ncycle = gcd(nnonopts, nopts);
+ cyclelen = (opt_end - panonopt_start) / ncycle;
+
+ for (i = 0; i < ncycle; i++) {
+ cstart = panonopt_end+i;
+ pos = cstart;
+ for (j = 0; j < cyclelen; j++) {
+ if (pos >= panonopt_end)
+ pos -= nnonopts;
+ else
+ pos += nopts;
+ swap = nargv[pos];
+ /* LINTED const cast */
+ ((char **) nargv)[pos] = nargv[cstart];
+ /* LINTED const cast */
+ ((char **)nargv)[cstart] = swap;
+ }
+ }
+}
+
+/*
+ * parse_long_options --
+ * Parse long options in argc/argv argument vector.
+ * Returns -1 if short_too is set and the option does not match long_options.
+ */
+static int
+parse_long_options(char * const *nargv, const char *options,
+ const struct option *long_options, int *idx, int short_too)
+{
+ char *current_argv, *has_equal;
+ size_t current_argv_len;
+ int i, match;
+
+ current_argv = place;
+ match = -1;
+
+ optind++;
+
+ if ((has_equal = strchr(current_argv, '=')) != NULL) {
+ /* argument found (--option=arg) */
+ current_argv_len = has_equal - current_argv;
+ has_equal++;
+ } else
+ current_argv_len = strlen(current_argv);
+
+ for (i = 0; long_options[i].name; i++) {
+ /* find matching long option */
+ if (strncmp(current_argv, long_options[i].name,
+ current_argv_len))
+ continue;
+
+ if (strlen(long_options[i].name) == current_argv_len) {
+ /* exact match */
+ match = i;
+ break;
+ }
+ /*
+ * If this is a known short option, don't allow
+ * a partial match of a single character.
+ */
+ if (short_too && current_argv_len == 1)
+ continue;
+
+ if (match == -1) /* partial match */
+ match = i;
+ else {
+ /* ambiguous abbreviation */
+ if (PRINT_ERROR)
+ warnx(ambig, (int)current_argv_len,
+ current_argv);
+ optopt = 0;
+ return (BADCH);
+ }
+ }
+ if (match != -1) { /* option found */
+ if (long_options[match].has_arg == no_argument
+ && has_equal) {
+ if (PRINT_ERROR)
+ warnx(noarg, (int)current_argv_len,
+ current_argv);
+ /*
+ * XXX: GNU sets optopt to val regardless of flag
+ */
+ if (long_options[match].flag == NULL)
+ optopt = long_options[match].val;
+ else
+ optopt = 0;
+ return (BADARG);
+ }
+ if (long_options[match].has_arg == required_argument ||
+ long_options[match].has_arg == optional_argument) {
+ if (has_equal)
+ optarg = has_equal;
+ else if (long_options[match].has_arg ==
+ required_argument) {
+ /*
+ * optional argument doesn't use next nargv
+ */
+ optarg = nargv[optind++];
+ }
+ }
+ if ((long_options[match].has_arg == required_argument)
+ && (optarg == NULL)) {
+ /*
+ * Missing argument; leading ':' indicates no error
+ * should be generated.
+ */
+ if (PRINT_ERROR)
+ warnx(recargstring,
+ current_argv);
+ /*
+ * XXX: GNU sets optopt to val regardless of flag
+ */
+ if (long_options[match].flag == NULL)
+ optopt = long_options[match].val;
+ else
+ optopt = 0;
+ --optind;
+ return (BADARG);
+ }
+ } else { /* unknown option */
+ if (short_too) {
+ --optind;
+ return (-1);
+ }
+ if (PRINT_ERROR)
+ warnx(illoptstring, current_argv);
+ optopt = 0;
+ return (BADCH);
+ }
+ if (idx)
+ *idx = match;
+ if (long_options[match].flag) {
+ *long_options[match].flag = long_options[match].val;
+ return (0);
+ } else
+ return (long_options[match].val);
+}
+
+/*
+ * getopt_internal --
+ * Parse argc/argv argument vector. Called by user level routines.
+ */
+static int
+getopt_internal(int nargc, char * const *nargv, const char *options,
+ const struct option *long_options, int *idx, int flags)
+{
+ char *oli; /* option letter list index */
+ int optchar, short_too;
+ static int posixly_correct = -1;
+
+ if (options == NULL)
+ return (-1);
+
+ /*
+ * XXX Some GNU programs (like cvs) set optind to 0 instead of
+ * XXX using optreset. Work around this braindamage.
+ */
+ if (optind == 0)
+ optind = optreset = 1;
+
+ /*
+ * Disable GNU extensions if POSIXLY_CORRECT is set or options
+ * string begins with a '+'.
+ */
+ if (posixly_correct == -1 || optreset)
+ posixly_correct = (getenv("POSIXLY_CORRECT") != NULL);
+ if (*options == '-')
+ flags |= FLAG_ALLARGS;
+ else if (posixly_correct || *options == '+')
+ flags &= ~FLAG_PERMUTE;
+ if (*options == '+' || *options == '-')
+ options++;
+
+ optarg = NULL;
+ if (optreset)
+ nonopt_start = nonopt_end = -1;
+start:
+ if (optreset || !*place) { /* update scanning pointer */
+ optreset = 0;
+ if (optind >= nargc) { /* end of argument vector */
+ place = EMSG;
+ if (nonopt_end != -1) {
+ /* do permutation, if we have to */
+ permute_args(nonopt_start, nonopt_end,
+ optind, nargv);
+ optind -= nonopt_end - nonopt_start;
+ }
+ else if (nonopt_start != -1) {
+ /*
+ * If we skipped non-options, set optind
+ * to the first of them.
+ */
+ optind = nonopt_start;
+ }
+ nonopt_start = nonopt_end = -1;
+ return (-1);
+ }
+ if (*(place = nargv[optind]) != '-' ||
+ (place[1] == '\0' && strchr(options, '-') == NULL)) {
+ place = EMSG; /* found non-option */
+ if (flags & FLAG_ALLARGS) {
+ /*
+ * GNU extension:
+ * return non-option as argument to option 1
+ */
+ optarg = nargv[optind++];
+ return (INORDER);
+ }
+ if (!(flags & FLAG_PERMUTE)) {
+ /*
+ * If no permutation wanted, stop parsing
+ * at first non-option.
+ */
+ return (-1);
+ }
+ /* do permutation */
+ if (nonopt_start == -1)
+ nonopt_start = optind;
+ else if (nonopt_end != -1) {
+ permute_args(nonopt_start, nonopt_end,
+ optind, nargv);
+ nonopt_start = optind -
+ (nonopt_end - nonopt_start);
+ nonopt_end = -1;
+ }
+ optind++;
+ /* process next argument */
+ goto start;
+ }
+ if (nonopt_start != -1 && nonopt_end == -1)
+ nonopt_end = optind;
+
+ /*
+ * If we have "-" do nothing, if "--" we are done.
+ */
+ if (place[1] != '\0' && *++place == '-' && place[1] == '\0') {
+ optind++;
+ place = EMSG;
+ /*
+ * We found an option (--), so if we skipped
+ * non-options, we have to permute.
+ */
+ if (nonopt_end != -1) {
+ permute_args(nonopt_start, nonopt_end,
+ optind, nargv);
+ optind -= nonopt_end - nonopt_start;
+ }
+ nonopt_start = nonopt_end = -1;
+ return (-1);
+ }
+ }
+
+ /*
+ * Check long options if:
+ * 1) we were passed some
+ * 2) the arg is not just "-"
+ * 3) either the arg starts with -- we are getopt_long_only()
+ */
+ if (long_options != NULL && place != nargv[optind] &&
+ (*place == '-' || (flags & FLAG_LONGONLY))) {
+ short_too = 0;
+ if (*place == '-')
+ place++; /* --foo long option */
+ else if (*place != ':' && strchr(options, *place) != NULL)
+ short_too = 1; /* could be short option too */
+
+ optchar = parse_long_options(nargv, options, long_options,
+ idx, short_too);
+ if (optchar != -1) {
+ place = EMSG;
+ return (optchar);
+ }
+ }
+
+ if ((optchar = (int)*place++) == (int)':' ||
+ (optchar == (int)'-' && *place != '\0') ||
+ (oli = strchr(options, optchar)) == NULL) {
+ /*
+ * If the user specified "-" and '-' isn't listed in
+ * options, return -1 (non-option) as per POSIX.
+ * Otherwise, it is an unknown option character (or ':').
+ */
+ if (optchar == (int)'-' && *place == '\0')
+ return (-1);
+ if (!*place)
+ ++optind;
+ if (PRINT_ERROR)
+ warnx(illoptchar, optchar);
+ optopt = optchar;
+ return (BADCH);
+ }
+ if (long_options != NULL && optchar == 'W' && oli[1] == ';') {
+ /* -W long-option */
+ if (*place) /* no space */
+ /* NOTHING */;
+ else if (++optind >= nargc) { /* no arg */
+ place = EMSG;
+ if (PRINT_ERROR)
+ warnx(recargchar, optchar);
+ optopt = optchar;
+ return (BADARG);
+ } else /* white space */
+ place = nargv[optind];
+ optchar = parse_long_options(nargv, options, long_options,
+ idx, 0);
+ place = EMSG;
+ return (optchar);
+ }
+ if (*++oli != ':') { /* doesn't take argument */
+ if (!*place)
+ ++optind;
+ } else { /* takes (optional) argument */
+ optarg = NULL;
+ if (*place) /* no white space */
+ optarg = place;
+ else if (oli[1] != ':') { /* arg not optional */
+ if (++optind >= nargc) { /* no arg */
+ place = EMSG;
+ if (PRINT_ERROR)
+ warnx(recargchar, optchar);
+ optopt = optchar;
+ return (BADARG);
+ } else
+ optarg = nargv[optind];
+ }
+ place = EMSG;
+ ++optind;
+ }
+ /* dump back option letter */
+ return (optchar);
+}
+
+/*
+ * getopt --
+ * Parse argc/argv argument vector.
+ *
+ * [eventually this will replace the BSD getopt]
+ */
+int
+getopt(int nargc, char * const *nargv, const char *options)
+{
+
+ /*
+ * We don't pass FLAG_PERMUTE to getopt_internal() since
+ * the BSD getopt(3) (unlike GNU) has never done this.
+ *
+ * Furthermore, since many privileged programs call getopt()
+ * before dropping privileges it makes sense to keep things
+ * as simple (and bug-free) as possible.
+ */
+ return (getopt_internal(nargc, nargv, options, NULL, NULL, 0));
+}
+
+/*
+ * getopt_long --
+ * Parse argc/argv argument vector.
+ */
+int
+getopt_long(int nargc, char * const *nargv, const char *options,
+ const struct option *long_options, int *idx)
+{
+
+ return (getopt_internal(nargc, nargv, options, long_options, idx,
+ FLAG_PERMUTE));
+}
+
+/*
+ * getopt_long_only --
+ * Parse argc/argv argument vector.
+ */
+int
+getopt_long_only(int nargc, char * const *nargv, const char *options,
+ const struct option *long_options, int *idx)
+{
+
+ return (getopt_internal(nargc, nargv, options, long_options, idx,
+ FLAG_PERMUTE|FLAG_LONGONLY));
+}
diff --git a/system/lib/libc/stdlib/strtod.c b/system/lib/libc/stdlib/strtod.c
new file mode 100644
index 00000000..53191337
--- /dev/null
+++ b/system/lib/libc/stdlib/strtod.c
@@ -0,0 +1,305 @@
+/*
+ * strtod.c --
+ *
+ * Source code for the "strtod" library procedure.
+ *
+ * Copyright (c) 1988-1993 The Regents of the University of California.
+ * Copyright (c) 1994 Sun Microsystems, Inc.
+ *
+ * Permission to use, copy, modify, and distribute this
+ * software and its documentation for any purpose and without
+ * fee is hereby granted, provided that the above copyright
+ * notice appear in all copies. The University of California
+ * makes no representations about the suitability of this
+ * software for any purpose. It is provided "as is" without
+ * express or implied warranty.
+ *
+ * RCS: @(#) $Id$
+ *
+ * Taken from http://svn.ruby-lang.org/repos/ruby/branches/ruby_1_8/missing/strtod.c
+ */
+
+#include <stdlib.h>
+#include <ctype.h>
+#include <errno.h>
+#include <locale.h>
+extern int errno;
+
+#ifndef __STDC__
+# ifdef __GNUC__
+# define const __const__
+# else
+# define const
+# endif
+#endif
+
+#ifndef TRUE
+#define TRUE 1
+#define FALSE 0
+#endif
+#ifndef NULL
+#define NULL 0
+#endif
+
+static int maxExponent = 511; /* Largest possible base 10 exponent. Any
+ * exponent larger than this will already
+ * produce underflow or overflow, so there's
+ * no need to worry about additional digits.
+ */
+static double powersOf10[] = { /* Table giving binary powers of 10. Entry */
+ 10., /* is 10^2^i. Used to convert decimal */
+ 100., /* exponents into floating-point numbers. */
+ 1.0e4,
+ 1.0e8,
+ 1.0e16,
+ 1.0e32,
+ 1.0e64,
+ 1.0e128,
+ 1.0e256
+};
+
+/*
+ *----------------------------------------------------------------------
+ *
+ * strtod --
+ *
+ * This procedure converts a floating-point number from an ASCII
+ * decimal representation to internal double-precision format.
+ *
+ * Results:
+ * The return value is the double-precision floating-point
+ * representation of the characters in string. If endPtr isn't
+ * NULL, then *endPtr is filled in with the address of the
+ * next character after the last one that was part of the
+ * floating-point number.
+ *
+ * Side effects:
+ * None.
+ *
+ *----------------------------------------------------------------------
+ */
+
+double
+strtod(string, endPtr)
+ const char *string; /* A decimal ASCII floating-point number,
+ * optionally preceded by white space.
+ * Must have form "-I.FE-X", where I is the
+ * integer part of the mantissa, F is the
+ * fractional part of the mantissa, and X
+ * is the exponent. Either of the signs
+ * may be "+", "-", or omitted. Either I
+ * or F may be omitted, or both. The decimal
+ * point isn't necessary unless F is present.
+ * The "E" may actually be an "e". E and X
+ * may both be omitted (but not just one).
+ */
+ char **endPtr; /* If non-NULL, store terminating character's
+ * address here. */
+{
+ int sign, expSign = FALSE;
+ double fraction, dblExp, *d;
+ register const char *p;
+ register int c;
+ int exp = 0; /* Exponent read from "EX" field. */
+ int fracExp = 0; /* Exponent that derives from the fractional
+ * part. Under normal circumstatnces, it is
+ * the negative of the number of digits in F.
+ * However, if I is very long, the last digits
+ * of I get dropped (otherwise a long I with a
+ * large negative exponent could cause an
+ * unnecessary overflow on I alone). In this
+ * case, fracExp is incremented one for each
+ * dropped digit. */
+ int mantSize; /* Number of digits in mantissa. */
+ int decPt; /* Number of mantissa digits BEFORE decimal
+ * point. */
+ const char *pExp; /* Temporarily holds location of exponent
+ * in string. */
+
+ /*
+ * Strip off leading blanks and check for a sign.
+ */
+
+ p = string;
+ while (isspace(*p)) {
+ p += 1;
+ }
+ if (*p == '-') {
+ sign = TRUE;
+ p += 1;
+ } else {
+ if (*p == '+') {
+ p += 1;
+ }
+ sign = FALSE;
+ }
+
+ /*
+ * Count the number of digits in the mantissa (including the decimal
+ * point), and also locate the decimal point.
+ */
+
+ decPt = -1;
+ for (mantSize = 0; ; mantSize += 1)
+ {
+ c = *p;
+ if (!isdigit(c)) {
+ if ((c != '.') || (decPt >= 0)) {
+ break;
+ }
+ decPt = mantSize;
+ }
+ p += 1;
+ }
+
+ /*
+ * Now suck up the digits in the mantissa. Use two integers to
+ * collect 9 digits each (this is faster than using floating-point).
+ * If the mantissa has more than 18 digits, ignore the extras, since
+ * they can't affect the value anyway.
+ */
+
+ pExp = p;
+ p -= mantSize;
+ if (decPt < 0) {
+ decPt = mantSize;
+ } else {
+ mantSize -= 1; /* One of the digits was the point. */
+ }
+ if (mantSize > 18) {
+ fracExp = decPt - 18;
+ mantSize = 18;
+ } else {
+ fracExp = decPt - mantSize;
+ }
+ if (mantSize == 0) {
+ fraction = 0.0;
+ p = string;
+ goto done;
+ } else {
+ int frac1, frac2;
+ frac1 = 0;
+ for ( ; mantSize > 9; mantSize -= 1)
+ {
+ c = *p;
+ p += 1;
+ if (c == '.') {
+ c = *p;
+ p += 1;
+ }
+ frac1 = 10*frac1 + (c - '0');
+ }
+ frac2 = 0;
+ for (; mantSize > 0; mantSize -= 1)
+ {
+ c = *p;
+ p += 1;
+ if (c == '.') {
+ c = *p;
+ p += 1;
+ }
+ frac2 = 10*frac2 + (c - '0');
+ }
+ fraction = (1.0e9 * frac1) + frac2;
+ }
+
+ /*
+ * Skim off the exponent.
+ */
+
+ p = pExp;
+ if ((*p == 'E') || (*p == 'e')) {
+ p += 1;
+ if (*p == '-') {
+ expSign = TRUE;
+ p += 1;
+ } else {
+ if (*p == '+') {
+ p += 1;
+ }
+ expSign = FALSE;
+ }
+ while (isdigit(*p)) {
+ exp = exp * 10 + (*p - '0');
+ p += 1;
+ }
+ }
+ if (expSign) {
+ exp = fracExp - exp;
+ } else {
+ exp = fracExp + exp;
+ }
+
+ /*
+ * Generate a floating-point number that represents the exponent.
+ * Do this by processing the exponent one bit at a time to combine
+ * many powers of 2 of 10. Then combine the exponent with the
+ * fraction.
+ */
+
+ if (exp < 0) {
+ expSign = TRUE;
+ exp = -exp;
+ } else {
+ expSign = FALSE;
+ }
+ if (exp > maxExponent) {
+ exp = maxExponent;
+ errno = ERANGE;
+ }
+ dblExp = 1.0;
+ for (d = powersOf10; exp != 0; exp >>= 1, d += 1) {
+ if (exp & 01) {
+ dblExp *= *d;
+ }
+ }
+ if (expSign) {
+ fraction /= dblExp;
+ } else {
+ fraction *= dblExp;
+ }
+
+done:
+ if (endPtr != NULL) {
+ *endPtr = (char *) p;
+ }
+
+ if (sign) {
+ return -fraction;
+ }
+ return fraction;
+}
+
+/*
+ * Implementations added for emscripten.
+ */
+// XXX add real support for long double
+long double
+strtold(const char* nptr, char **endptr)
+{
+ return (long double) strtod(nptr, endptr);
+}
+
+// use stdtod to handle strtof
+float
+strtof(const char* nptr, char **endptr)
+{
+ return (float) strtof(nptr, endptr);
+}
+
+// XXX no locale support yet
+double
+strtod_l(const char* nptr, char **endptr, locale_t loc)
+{
+ return strtod(nptr, endptr);
+}
+long double
+strtold_l(const char* nptr, char **endptr, locale_t loc)
+{
+ return strtold(nptr, endptr);
+}
+
+double atof(const char* str)
+{
+ return strtod(str, (char **) NULL);
+}