From cabcfc4bb3dc6a2c2edf5aa5875f2f2e2667d2fa Mon Sep 17 00:00:00 2001 From: "Sergey Semyonov (Serge)" Date: Tue, 26 Jan 2016 02:29:46 +0000 Subject: [PATCH] newlib: update git-svn-id: svn://kolibrios.org@6099 a494cfbc-eb01-0410-851d-a64ba20cac60 --- contrib/sdk/sources/newlib/libc/Makefile | 25 +- contrib/sdk/sources/newlib/libc/Tupfile.lua | 26 +- .../sdk/sources/newlib/libc/ctype/iswalpha.c | 2 +- contrib/sdk/sources/newlib/libc/ctype/jp2uc.c | 1 + .../sdk/sources/newlib/libc/include/_ansi.h | 8 +- .../sdk/sources/newlib/libc/include/complex.h | 5 +- .../sdk/sources/newlib/libc/include/ctype.h | 3 +- contrib/sdk/sources/newlib/libc/include/grp.h | 1 + .../sdk/sources/newlib/libc/include/ieeefp.h | 73 +- .../sources/newlib/libc/include/inttypes.h | 285 ++-- .../sources/newlib/libc/include/kos32sys.h | 266 ++-- .../sdk/sources/newlib/libc/include/libgen.h | 16 +- .../sdk/sources/newlib/libc/include/libsync.h | 14 +- .../libc/include/machine/_default_types.h | 38 +- .../newlib/libc/include/machine/_types.h | 2 +- .../newlib/libc/include/machine/ieeefp.h | 14 +- .../newlib/libc/include/machine/setjmp.h | 48 +- .../newlib/libc/include/machine/time.h | 12 +- .../newlib/libc/include/machine/types.h | 2 + .../sdk/sources/newlib/libc/include/math.h | 41 +- .../sdk/sources/newlib/libc/include/newlib.h | 2 +- .../sdk/sources/newlib/libc/include/pthread.h | 4 +- contrib/sdk/sources/newlib/libc/include/pwd.h | 13 +- .../sdk/sources/newlib/libc/include/reent.h | 22 +- .../sdk/sources/newlib/libc/include/sched.h | 2 +- .../sdk/sources/newlib/libc/include/setjmp.h | 5 + .../sdk/sources/newlib/libc/include/stdint.h | 223 ++-- .../sdk/sources/newlib/libc/include/stdio.h | 67 +- .../sources/newlib/libc/include/stdio_ext.h | 36 +- .../sdk/sources/newlib/libc/include/stdlib.h | 86 +- .../sdk/sources/newlib/libc/include/string.h | 116 +- .../newlib/libc/include/sys/_default_fcntl.h | 19 +- .../sources/newlib/libc/include/sys/_intsup.h | 209 +++ .../sources/newlib/libc/include/sys/_sigset.h | 43 + .../sources/newlib/libc/include/sys/_stdint.h | 49 + .../newlib/libc/include/sys/_timespec.h | 49 + .../newlib/libc/include/sys/_timeval.h | 88 ++ .../sources/newlib/libc/include/sys/cdefs.h | 246 +++- .../sources/newlib/libc/include/sys/config.h | 8 + .../sources/newlib/libc/include/sys/errno.h | 38 +- .../newlib/libc/include/sys/features.h | 10 +- .../sources/newlib/libc/include/sys/param.h | 7 + .../sources/newlib/libc/include/sys/queue.h | 40 +- .../sources/newlib/libc/include/sys/reent.h | 15 +- .../newlib/libc/include/sys/resource.h | 2 + .../sources/newlib/libc/include/sys/sched.h | 6 +- .../sources/newlib/libc/include/sys/select.h | 86 ++ .../sources/newlib/libc/include/sys/signal.h | 66 +- .../sources/newlib/libc/include/sys/stat.h | 14 +- .../sources/newlib/libc/include/sys/time.h | 487 ++++++- .../newlib/libc/include/sys/timespec.h | 63 + .../sources/newlib/libc/include/sys/tree.h | 801 ++++++++++++ .../sources/newlib/libc/include/sys/types.h | 75 +- .../sources/newlib/libc/include/sys/unistd.h | 40 +- .../sources/newlib/libc/include/sys/wait.h | 2 +- .../sdk/sources/newlib/libc/include/threads.h | 93 ++ .../sdk/sources/newlib/libc/include/time.h | 7 + .../sdk/sources/newlib/libc/include/wchar.h | 36 +- .../sdk/sources/newlib/libc/locale/ldpart.c | 3 +- .../sdk/sources/newlib/libc/locale/locale.c | 26 +- .../sdk/sources/newlib/libc/reent/closer.c | 2 +- .../sdk/sources/newlib/libc/reent/fstatr.c | 2 +- .../sdk/sources/newlib/libc/reent/isattyr.c | 2 +- .../sdk/sources/newlib/libc/reent/lseekr.c | 2 +- contrib/sdk/sources/newlib/libc/reent/openr.c | 2 +- contrib/sdk/sources/newlib/libc/reent/readr.c | 2 +- .../sdk/sources/newlib/libc/reent/writer.c | 2 +- .../sdk/sources/newlib/libc/search/qsort.c | 100 +- .../sdk/sources/newlib/libc/stdio/asnprintf.c | 11 + .../sdk/sources/newlib/libc/stdio/asprintf.c | 11 + .../sdk/sources/newlib/libc/stdio/clearerr.c | 23 +- .../sdk/sources/newlib/libc/stdio/dprintf.c | 11 + .../sdk/sources/newlib/libc/stdio/fclose.c | 22 +- contrib/sdk/sources/newlib/libc/stdio/feof.c | 24 +- .../sdk/sources/newlib/libc/stdio/ferror.c | 24 +- .../sdk/sources/newlib/libc/stdio/fflush.c | 53 +- contrib/sdk/sources/newlib/libc/stdio/fgetc.c | 42 +- contrib/sdk/sources/newlib/libc/stdio/fgets.c | 49 +- .../sdk/sources/newlib/libc/stdio/fileno.c | 26 +- .../sdk/sources/newlib/libc/stdio/findfp.c | 28 +- contrib/sdk/sources/newlib/libc/stdio/flags.c | 6 +- .../sdk/sources/newlib/libc/stdio/fprintf.c | 11 + contrib/sdk/sources/newlib/libc/stdio/fputc.c | 41 +- contrib/sdk/sources/newlib/libc/stdio/fputs.c | 46 +- .../sdk/sources/newlib/libc/stdio/fputwc.c | 83 +- contrib/sdk/sources/newlib/libc/stdio/fread.c | 51 +- .../sdk/sources/newlib/libc/stdio/freopen.c | 17 +- .../sdk/sources/newlib/libc/stdio/fscanf.c | 11 + contrib/sdk/sources/newlib/libc/stdio/fseek.c | 16 +- .../sdk/sources/newlib/libc/stdio/fvwrite.c | 2 +- contrib/sdk/sources/newlib/libc/stdio/fwalk.c | 11 +- .../sdk/sources/newlib/libc/stdio/fwrite.c | 51 +- contrib/sdk/sources/newlib/libc/stdio/local.h | 72 +- .../sdk/sources/newlib/libc/stdio/printf.c | 11 + contrib/sdk/sources/newlib/libc/stdio/puts.c | 2 + .../sdk/sources/newlib/libc/stdio/refill.c | 2 +- .../sdk/sources/newlib/libc/stdio/siscanf.c | 188 +++ .../sdk/sources/newlib/libc/stdio/snprintf.c | 11 + .../sdk/sources/newlib/libc/stdio/sprintf.c | 64 +- .../sdk/sources/newlib/libc/stdio/sscanf.c | 184 ++- .../sources/newlib/libc/stdio/vasnprintf.c | 12 + .../sdk/sources/newlib/libc/stdio/vdprintf.c | 11 + .../sdk/sources/newlib/libc/stdio/vfprintf.c | 46 +- .../sdk/sources/newlib/libc/stdio/vfscanf.c | 6 +- .../sdk/sources/newlib/libc/stdio/vscanf.c | 10 + .../sdk/sources/newlib/libc/stdio/vsnprintf.c | 12 + .../sdk/sources/newlib/libc/stdio/vsprintf.c | 12 + .../sdk/sources/newlib/libc/stdio/vsscanf.c | 12 + contrib/sdk/sources/newlib/libc/stdio/wbuf.c | 2 +- .../sdk/sources/newlib/libc/stdio/wsetup.c | 4 +- .../sdk/sources/newlib/libc/stdlib/__atexit.c | 26 +- contrib/sdk/sources/newlib/libc/stdlib/exit.c | 2 +- .../sdk/sources/newlib/libc/stdlib/gd_qnan.h | 20 + .../sources/newlib/libc/stdlib/gdtoa-hexnan.c | 18 + .../sdk/sources/newlib/libc/stdlib/gdtoa.h | 2 + .../sdk/sources/newlib/libc/stdlib/getenv_r.c | 105 ++ .../sdk/sources/newlib/libc/stdlib/mallocr.c | 18 +- .../sdk/sources/newlib/libc/stdlib/mprec.h | 7 + .../sdk/sources/newlib/libc/stdlib/strtod.c | 45 +- .../sdk/sources/newlib/libc/stdlib/strtodg.c | 1147 +++++++++++++++++ .../sdk/sources/newlib/libc/stdlib/strtold.c | 44 +- .../sdk/sources/newlib/libc/stdlib/strtorx.c | 129 ++ .../sdk/sources/newlib/libc/stdlib/wctomb_r.c | 2 +- .../sdk/sources/newlib/libc/string/local.h | 48 +- .../sdk/sources/newlib/libc/string/memchr.c | 2 +- .../sdk/sources/newlib/libc/string/memset.c | 2 +- .../sources/newlib/libc/string/str-two-way.h | 2 +- .../sources/newlib/libc/string/strcasestr.c | 5 +- .../sdk/sources/newlib/libc/string/strdup_r.c | 2 +- .../sdk/sources/newlib/libc/string/strerror.c | 93 +- .../sdk/sources/newlib/libc/string/strtok.c | 12 +- .../sdk/sources/newlib/libc/string/u_strerr.c | 5 + contrib/sdk/sources/newlib/libc/time/clock.c | 2 +- .../sdk/sources/newlib/libc/time/gmtime_r.c | 91 +- .../sdk/sources/newlib/libc/time/lcltime_r.c | 113 +- contrib/sdk/sources/newlib/libc/time/local.h | 76 +- contrib/sdk/sources/newlib/libc/time/mktime.c | 8 +- contrib/sdk/sources/newlib/libc/time/mktm_r.c | 259 ---- .../sources/newlib/libc/time/month_lengths.c | 14 + .../sdk/sources/newlib/libc/time/strftime.c | 216 +++- .../sources/newlib/libc/time/tzcalc_limits.c | 77 ++ contrib/sdk/sources/newlib/libc/time/tzset.c | 82 ++ .../sdk/sources/newlib/libc/time/tzset_r.c | 193 +++ contrib/sdk/sources/newlib/libc/time/tzvars.c | 20 +- 144 files changed, 6873 insertions(+), 1545 deletions(-) create mode 100644 contrib/sdk/sources/newlib/libc/include/sys/_intsup.h create mode 100644 contrib/sdk/sources/newlib/libc/include/sys/_sigset.h create mode 100644 contrib/sdk/sources/newlib/libc/include/sys/_stdint.h create mode 100644 contrib/sdk/sources/newlib/libc/include/sys/_timespec.h create mode 100644 contrib/sdk/sources/newlib/libc/include/sys/_timeval.h create mode 100644 contrib/sdk/sources/newlib/libc/include/sys/select.h create mode 100644 contrib/sdk/sources/newlib/libc/include/sys/timespec.h create mode 100644 contrib/sdk/sources/newlib/libc/include/sys/tree.h create mode 100644 contrib/sdk/sources/newlib/libc/include/threads.h create mode 100644 contrib/sdk/sources/newlib/libc/stdio/siscanf.c create mode 100644 contrib/sdk/sources/newlib/libc/stdlib/getenv_r.c create mode 100644 contrib/sdk/sources/newlib/libc/stdlib/strtodg.c create mode 100644 contrib/sdk/sources/newlib/libc/stdlib/strtorx.c delete mode 100644 contrib/sdk/sources/newlib/libc/time/mktm_r.c create mode 100644 contrib/sdk/sources/newlib/libc/time/month_lengths.c create mode 100644 contrib/sdk/sources/newlib/libc/time/tzcalc_limits.c create mode 100644 contrib/sdk/sources/newlib/libc/time/tzset.c create mode 100644 contrib/sdk/sources/newlib/libc/time/tzset_r.c diff --git a/contrib/sdk/sources/newlib/libc/Makefile b/contrib/sdk/sources/newlib/libc/Makefile index 2ae1568d90..e05101c272 100644 --- a/contrib/sdk/sources/newlib/libc/Makefile +++ b/contrib/sdk/sources/newlib/libc/Makefile @@ -149,13 +149,16 @@ CORE_SRCS:= \ time/gmtime.c \ time/gmtime_r.c \ time/mktime.c \ - time/mktm_r.c \ + time/month_lengths.c \ time/lcltime.c \ time/lcltime_r.c \ time/strftime.c \ time/time.c \ + time/tzcalc_limits.c \ time/timelocal.c \ time/tzlock.c \ + time/tzset.c \ + time/tzset_r.c \ time/tzvars.c @@ -176,6 +179,7 @@ STDLIB_SRCS= \ gdtoa-gethex.c \ gdtoa-hexnan.c \ getenv.c \ + getenv_r.c \ mprec.c \ mbtowc.c \ mbtowc_r.c \ @@ -191,10 +195,12 @@ STDLIB_SRCS= \ seed48.c \ srand48.c \ strtod.c \ + strtodg.c \ strtol.c \ strtold.c \ strtoll.c \ strtoll_r.c \ + strtorx.c \ strtoul.c \ strtoull.c \ strtoull_r.c \ @@ -279,11 +285,18 @@ STDIO_SRCS= \ putc.c \ puts.c \ refill.c \ - rget.c \ remove.c \ rename.c \ rewind.c \ + rget.c \ + sccl.c \ setvbuf.c \ + siprintf.c \ + siscanf.c \ + sniprintf.c \ + snprintf.c \ + sprintf.c \ + sscanf.c \ stdio.c \ tmpfile.c \ tmpnam.c \ @@ -297,13 +310,7 @@ STDIO_SRCS= \ vsnprintf.c \ vsscanf.c \ wsetup.c \ - wbuf.c \ - sccl.c \ - siprintf.c \ - sniprintf.c \ - snprintf.c \ - sprintf.c \ - sscanf.c + wbuf.c MATH_SRCS = e_acos.c e_acosh.c e_asin.c e_atan2.c e_atanh.c e_cosh.c e_exp.c e_fmod.c \ diff --git a/contrib/sdk/sources/newlib/libc/Tupfile.lua b/contrib/sdk/sources/newlib/libc/Tupfile.lua index 9f774bc365..81380804ae 100644 --- a/contrib/sdk/sources/newlib/libc/Tupfile.lua +++ b/contrib/sdk/sources/newlib/libc/Tupfile.lua @@ -53,18 +53,19 @@ CORE_SRCS = { "sys/_rename.c", "sys/stat.c", "sys/unlink.c", "sys/write.c", "sys/io_alloc.S", "time/asctime.c", "time/asctime_r.c", "time/clock.c", "time/ctime.c", "time/ctime_r.c", "time/difftime.c", "time/gettzinfo.c", "time/gmtime.c", - "time/gmtime_r.c", "time/mktime.c", "time/mktm_r.c", "time/lcltime.c", - "time/lcltime_r.c", "time/strftime.c", "time/time.c", "time/timelocal.c", - "time/tzlock.c", "time/tzvars.c" + "time/gmtime_r.c", "time/mktime.c", "time/month_lengths.c", "time/lcltime.c", + "time/lcltime_r.c", "time/strftime.c", "time/time.c", "time/tzcalc_limits.c", + "time/timelocal.c", "time/tzlock.c", "time/tzset.c", "time/tzset_r.c", "time/tzvars.c" } STDLIB_SRCS = { "__atexit.c", "__call_atexit.c", "abort.c", "abs.c", "assert.c", "atexit.c", "atof.c", "atoi.c", "atol.c", "div.c", "dtoa.c", "dtoastub.c", "exit.c", - "gdtoa-gethex.c", "gdtoa-hexnan.c", "getenv.c", "mprec.c", "mbtowc.c", + "gdtoa-gethex.c", "gdtoa-hexnan.c", "getenv.c", "getenv_r.c","mprec.c", "mbtowc.c", "mbtowc_r.c", "mbrtowc.c", "mlock.c", "calloc.c", "malloc.c", "mallocr.c", "rand.c", "rand_r.c", "rand48.c", "realloc.c", "seed48.c", "srand48.c", - "strtod.c", "strtol.c", "strtold.c", "strtoll.c", "strtoll_r.c", "strtoul.c", - "strtoull.c", "strtoull_r.c", "system.c", "wcrtomb.c", "wctomb_r.c" + "strtod.c", "strtodg.c", "strtol.c", "strtold.c", "strtoll.c", "strtoll_r.c", + "strtorx.c","strtoul.c", "strtoull.c", "strtoull_r.c", "system.c", "wcrtomb.c", + "wctomb_r.c" } STRING_SRCS = { "memcpy.c", "memcmp.c", "memmove.c", "memset.c", "memchr.c", "stpcpy.c", @@ -80,14 +81,15 @@ STDIO_SRCS = { "clearerr.c", "diprintf.c", "dprintf.c", "printf.c", "putchar.c", "fgetc.c", "fgets.c", "fopen.c", "fclose.c", "fdopen.c", "fflush.c", "flags.c", "fileno.c", "findfp.c", "fiprintf.c", "fiscanf.c", "fprintf.c", "fputc.c", - "fputs.c", "fputwc.c", "fread.c", "freopen.c", "fscanf.c", "fseek.c", - "fseeko.c", "ftell.c", "ftello.c", "fwrite.c", "fvwrite.c", "fwalk.c", - "makebuf.c", "mbstowcs.c", "mktemp.c", "perror.c", "putc.c", "puts.c", - "refill.c", "rget.c", "remove.c", "rename.c", "setvbuf.c", "stdio.c", + "fputs.c", "fputwc.c", "fread.c", "freopen.c", "fscanf.c", "fseek.c", "fseeko.c", + "ftell.c", "ftello.c", "fwrite.c", "fvwrite.c", "fwalk.c", "makebuf.c", + "mbstowcs.c", "mktemp.c", "perror.c", "putc.c", "puts.c", "refill.c", "remove.c", + "rename.c", "rewind.c", "rget.c", "sccl.c", "setvbuf.c", "siprintf.c", + "siscanf.c", "sniprintf.c", "snprintf.c", "sprintf.c", "sscanf.c", "stdio.c", "tmpfile.c", "tmpnam.c", "ungetc.c", "vasniprintf.c", "vasnprintf.c", "vdprintf.c", "vdiprintf.c", "vscanf.c", "vsprintf.c", "vsnprintf.c", - "vsscanf.c", "wsetup.c", "wbuf.c", "sccl.c", "siprintf.c", "sniprintf.c", - "snprintf.c", "sprintf.c", "sscanf.c" + "vsscanf.c", "wsetup.c", "wbuf.c" + } MATH_SRCS = { diff --git a/contrib/sdk/sources/newlib/libc/ctype/iswalpha.c b/contrib/sdk/sources/newlib/libc/ctype/iswalpha.c index 6051a27f1f..c95c0de9ec 100644 --- a/contrib/sdk/sources/newlib/libc/ctype/iswalpha.c +++ b/contrib/sdk/sources/newlib/libc/ctype/iswalpha.c @@ -415,7 +415,7 @@ _DEFUN(iswalpha,(c), wint_t c) /* otherwise c > *ptr */ /* look for 0x0 as next element which indicates a range */ ++ptr; - if (*ptr == 0x0) + if (ptr < table + size - 1 && *ptr == 0x0) { /* we have a range..see if c falls within range */ ++ptr; diff --git a/contrib/sdk/sources/newlib/libc/ctype/jp2uc.c b/contrib/sdk/sources/newlib/libc/ctype/jp2uc.c index 0b0085f15b..40d777add9 100644 --- a/contrib/sdk/sources/newlib/libc/ctype/jp2uc.c +++ b/contrib/sdk/sources/newlib/libc/ctype/jp2uc.c @@ -37,6 +37,7 @@ #ifndef __CYGWIN__ #include <_ansi.h> +#include #include #include "local.h" #include "jp2uc.h" diff --git a/contrib/sdk/sources/newlib/libc/include/_ansi.h b/contrib/sdk/sources/newlib/libc/include/_ansi.h index cd2b8c177b..2056c4f849 100644 --- a/contrib/sdk/sources/newlib/libc/include/_ansi.h +++ b/contrib/sdk/sources/newlib/libc/include/_ansi.h @@ -35,7 +35,7 @@ #define _END_STD_C } #endif #if __GNUC_PREREQ (3, 3) -#define _NOTHROW __attribute__ ((nothrow)) +#define _NOTHROW __attribute__ ((__nothrow__)) #else #define _NOTHROW throw() #endif @@ -72,9 +72,6 @@ #ifndef _LONG_DOUBLE #define _LONG_DOUBLE long double #endif -#ifndef _LONG_LONG_TYPE -#define _LONG_LONG_TYPE long long -#endif #ifndef _PARAMS #define _PARAMS(paramlist) paramlist #endif @@ -93,7 +90,6 @@ #define _DEFUN_VOID(name) name() #define _CAST_VOID #define _LONG_DOUBLE double -#define _LONG_LONG_TYPE long #ifndef _PARAMS #define _PARAMS(paramlist) () #endif @@ -126,7 +122,7 @@ /* We're using GCC, but without the new C99-compatible behaviour. */ #define _ELIDABLE_INLINE extern __inline__ _ATTRIBUTE ((__always_inline__)) #else -/* We're using GCC in C99 mode, or an unknown compiler which +/* We're using GCC in C99 mode, or an unknown compiler which we just have to hope obeys the C99 semantics of inline. */ #define _ELIDABLE_INLINE static __inline__ #endif diff --git a/contrib/sdk/sources/newlib/libc/include/complex.h b/contrib/sdk/sources/newlib/libc/include/complex.h index 370938e2d5..ab35b5de11 100644 --- a/contrib/sdk/sources/newlib/libc/include/complex.h +++ b/contrib/sdk/sources/newlib/libc/include/complex.h @@ -83,6 +83,7 @@ float complex clogf(float complex); float cabsf(float complex) __RENAME(__c99_cabsf); #endif */ +long double cabsl(long double complex) ; double cabs(double complex) ; float cabsf(float complex) ; @@ -102,7 +103,7 @@ float cargf(float complex); /* 7.3.9.2 The cimag functions */ double cimag(double complex); float cimagf(float complex); -/*long double cimagl(long double complex); */ +long double cimagl(long double complex); /* 7.3.9.3 The conj functions */ double complex conj(double complex); @@ -117,7 +118,7 @@ float complex cprojf(float complex); /* 7.3.9.5 The creal functions */ double creal(double complex); float crealf(float complex); -/*long double creall(long double complex); */ +long double creall(long double complex); __END_DECLS diff --git a/contrib/sdk/sources/newlib/libc/include/ctype.h b/contrib/sdk/sources/newlib/libc/include/ctype.h index f5b153e392..969d3ef1f3 100644 --- a/contrib/sdk/sources/newlib/libc/include/ctype.h +++ b/contrib/sdk/sources/newlib/libc/include/ctype.h @@ -39,11 +39,10 @@ int _EXFUN(toascii, (int __c)); #define _X 0100 #define _B 0200 -extern #ifndef _MB_CAPABLE _CONST #endif -__IMPORT char *__ctype_ptr__; +extern __IMPORT char *__ctype_ptr__; #ifndef __cplusplus /* These macros are intentionally written in a manner that will trigger diff --git a/contrib/sdk/sources/newlib/libc/include/grp.h b/contrib/sdk/sources/newlib/libc/include/grp.h index c508fee47c..f241dd4214 100644 --- a/contrib/sdk/sources/newlib/libc/include/grp.h +++ b/contrib/sdk/sources/newlib/libc/include/grp.h @@ -43,6 +43,7 @@ #ifndef _GRP_H_ #define _GRP_H_ +#include #include #ifdef __CYGWIN__ #include diff --git a/contrib/sdk/sources/newlib/libc/include/ieeefp.h b/contrib/sdk/sources/newlib/libc/include/ieeefp.h index 2bbab3f234..35ee56563c 100644 --- a/contrib/sdk/sources/newlib/libc/include/ieeefp.h +++ b/contrib/sdk/sources/newlib/libc/include/ieeefp.h @@ -4,11 +4,12 @@ #include "_ansi.h" #include +#include _BEGIN_STD_C /* FIXME FIXME FIXME: - Neither of __ieee_{float,double}_shape_tape seem to be used anywhere + Neither of __ieee_{float,double}_shape_type seem to be used anywhere except in libm/test. If that is the case, please delete these from here. If that is not the case, please insert documentation here describing why they're needed. */ @@ -46,9 +47,7 @@ typedef union long aslong[2]; } __ieee_double_shape_type; -#endif - -#ifdef __IEEE_LITTLE_ENDIAN +#elif defined __IEEE_LITTLE_ENDIAN typedef union { @@ -92,7 +91,7 @@ typedef union } __ieee_double_shape_type; -#endif +#endif /* __IEEE_LITTLE_ENDIAN */ #ifdef __IEEE_BIG_ENDIAN @@ -118,9 +117,7 @@ typedef union } __ieee_float_shape_type; -#endif - -#ifdef __IEEE_LITTLE_ENDIAN +#elif defined __IEEE_LITTLE_ENDIAN typedef union { @@ -144,10 +141,70 @@ typedef union } __ieee_float_shape_type; +#endif /* __IEEE_LITTLE_ENDIAN */ + +#ifndef _LDBL_EQ_DBL + +#ifndef LDBL_MANT_DIG +#error "LDBL_MANT_DIG not defined - should be found in float.h" + +#elif LDBL_MANT_DIG == DBL_MANT_DIG +#error "double and long double are the same size but LDBL_EQ_DBL is not defined" + +#elif LDBL_MANT_DIG == 53 +/* This happens when doubles are 32-bits and long doubles are 64-bits. */ +#define EXT_EXPBITS 11 +#define EXT_FRACHBITS 20 +#define EXT_FRACLBITS 32 +#define __ieee_ext_field_type unsigned long + +#elif LDBL_MANT_DIG == 64 +#define EXT_EXPBITS 15 +#define EXT_FRACHBITS 32 +#define EXT_FRACLBITS 32 +#define __ieee_ext_field_type unsigned int + +#elif LDBL_MANT_DIG == 65 +#define EXT_EXPBITS 15 +#define EXT_FRACHBITS 32 +#define EXT_FRACLBITS 32 +#define __ieee_ext_field_type unsigned int + +#elif LDBL_MANT_DIG == 112 +#define EXT_EXPBITS 15 +#define EXT_FRACHBITS 48 +#define EXT_FRACLBITS 64 +#define __ieee_ext_field_type unsigned long long + +#elif LDBL_MANT_DIG == 113 +#define EXT_EXPBITS 15 +#define EXT_FRACHBITS 48 +#define EXT_FRACLBITS 64 +#define __ieee_ext_field_type unsigned long long + +#else +#error Unsupported value for LDBL_MANT_DIG #endif +#define EXT_EXP_INFNAN ((1 << EXT_EXPBITS) - 1) /* 32767 */ +#define EXT_EXP_BIAS ((1 << (EXT_EXPBITS - 1)) - 1) /* 16383 */ +#define EXT_FRACBITS (EXT_FRACLBITS + EXT_FRACHBITS) +typedef struct ieee_ext +{ + __ieee_ext_field_type ext_fracl : EXT_FRACLBITS; + __ieee_ext_field_type ext_frach : EXT_FRACHBITS; + __ieee_ext_field_type ext_exp : EXT_EXPBITS; + __ieee_ext_field_type ext_sign : 1; +} ieee_ext; +typedef union ieee_ext_u +{ + long double extu_ld; + struct ieee_ext extu_ext; +} ieee_ext_u; + +#endif /* ! _LDBL_EQ_DBL */ /* FLOATING ROUNDING */ diff --git a/contrib/sdk/sources/newlib/libc/include/inttypes.h b/contrib/sdk/sources/newlib/libc/include/inttypes.h index a78e9a6f14..8f42f878ed 100644 --- a/contrib/sdk/sources/newlib/libc/include/inttypes.h +++ b/contrib/sdk/sources/newlib/libc/include/inttypes.h @@ -13,25 +13,35 @@ #ifndef _INTTYPES_H #define _INTTYPES_H -#include +#include +#include +#include #include #define __need_wchar_t #include -/* Don't use __STDINT_EXP test since GCC's stdint.h provides different - macros than newlib's stdint.h. */ -#if __GNUC_PREREQ(3, 2) - #define __INTTYPES_EXP(x) __##x##__ -#else - #define __INTTYPES_EXP(x) x - #include -#endif - #define __STRINGIFY(a) #a /* 8-bit types */ -#define __PRI8(x) __STRINGIFY(x) -#define __SCN8(x) __STRINGIFY(hh##x) +#define __PRI8(x) __INT8 __STRINGIFY(x) +#define __PRI8LEAST(x) __LEAST8 __STRINGIFY(x) +#define __PRI8FAST(x) __FAST8 __STRINGIFY(x) + +/* NOTICE: scanning 8-bit types requires use of the hh specifier + * which is only supported on newlib platforms that + * are built with C99 I/O format support enabled. If the flag in + * newlib.h hasn't been set during configuration to indicate this, the 8-bit + * scanning format macros are disabled here as they result in undefined + * behaviour which can include memory overwrite. Overriding the flag after the + * library has been built is not recommended as it will expose the underlying + * undefined behaviour. + */ + +#if defined(_WANT_IO_C99_FORMATS) + #define __SCN8(x) __INT8 __STRINGIFY(x) + #define __SCN8LEAST(x) __LEAST8 __STRINGIFY(x) + #define __SCN8FAST(x) __FAST8 __STRINGIFY(x) +#endif /* _WANT_IO_C99_FORMATS */ #define PRId8 __PRI8(d) @@ -41,43 +51,61 @@ #define PRIx8 __PRI8(x) #define PRIX8 __PRI8(X) +/* Macros below are only enabled for a newlib built with C99 I/O format support. */ +#if defined(_WANT_IO_C99_FORMATS) + #define SCNd8 __SCN8(d) #define SCNi8 __SCN8(i) #define SCNo8 __SCN8(o) #define SCNu8 __SCN8(u) #define SCNx8 __SCN8(x) - -#define PRIdLEAST8 __PRI8(d) -#define PRIiLEAST8 __PRI8(i) -#define PRIoLEAST8 __PRI8(o) -#define PRIuLEAST8 __PRI8(u) -#define PRIxLEAST8 __PRI8(x) -#define PRIXLEAST8 __PRI8(X) - -#define SCNdLEAST8 __SCN8(d) -#define SCNiLEAST8 __SCN8(i) -#define SCNoLEAST8 __SCN8(o) -#define SCNuLEAST8 __SCN8(u) -#define SCNxLEAST8 __SCN8(x) +#endif /* _WANT_IO_C99_FORMATS */ -#define PRIdFAST8 __PRI8(d) -#define PRIiFAST8 __PRI8(i) -#define PRIoFAST8 __PRI8(o) -#define PRIuFAST8 __PRI8(u) -#define PRIxFAST8 __PRI8(x) -#define PRIXFAST8 __PRI8(X) +#define PRIdLEAST8 __PRI8LEAST(d) +#define PRIiLEAST8 __PRI8LEAST(i) +#define PRIoLEAST8 __PRI8LEAST(o) +#define PRIuLEAST8 __PRI8LEAST(u) +#define PRIxLEAST8 __PRI8LEAST(x) +#define PRIXLEAST8 __PRI8LEAST(X) -#define SCNdFAST8 __SCN8(d) -#define SCNiFAST8 __SCN8(i) -#define SCNoFAST8 __SCN8(o) -#define SCNuFAST8 __SCN8(u) -#define SCNxFAST8 __SCN8(x) +/* Macros below are only enabled for a newlib built with C99 I/O format support. */ +#if defined(_WANT_IO_C99_FORMATS) + + #define SCNdLEAST8 __SCN8LEAST(d) + #define SCNiLEAST8 __SCN8LEAST(i) + #define SCNoLEAST8 __SCN8LEAST(o) + #define SCNuLEAST8 __SCN8LEAST(u) + #define SCNxLEAST8 __SCN8LEAST(x) + +#endif /* _WANT_IO_C99_FORMATS */ + +#define PRIdFAST8 __PRI8FAST(d) +#define PRIiFAST8 __PRI8FAST(i) +#define PRIoFAST8 __PRI8FAST(o) +#define PRIuFAST8 __PRI8FAST(u) +#define PRIxFAST8 __PRI8FAST(x) +#define PRIXFAST8 __PRI8FAST(X) + +/* Macros below are only enabled for a newlib built with C99 I/O format support. */ +#if defined(_WANT_IO_C99_FORMATS) + + #define SCNdFAST8 __SCN8FAST(d) + #define SCNiFAST8 __SCN8FAST(i) + #define SCNoFAST8 __SCN8FAST(o) + #define SCNuFAST8 __SCN8FAST(u) + #define SCNxFAST8 __SCN8FAST(x) + +#endif /* _WANT_IO_C99_FORMATS */ /* 16-bit types */ -#define __PRI16(x) __STRINGIFY(x) -#define __SCN16(x) __STRINGIFY(h##x) +#define __PRI16(x) __INT16 __STRINGIFY(x) +#define __PRI16LEAST(x) __LEAST16 __STRINGIFY(x) +#define __PRI16FAST(x) __FAST16 __STRINGIFY(x) +#define __SCN16(x) __INT16 __STRINGIFY(x) +#define __SCN16LEAST(x) __LEAST16 __STRINGIFY(x) +#define __SCN16FAST(x) __FAST16 __STRINGIFY(x) #define PRId16 __PRI16(d) @@ -94,41 +122,40 @@ #define SCNx16 __SCN16(x) -#define PRIdLEAST16 __PRI16(d) -#define PRIiLEAST16 __PRI16(i) -#define PRIoLEAST16 __PRI16(o) -#define PRIuLEAST16 __PRI16(u) -#define PRIxLEAST16 __PRI16(x) -#define PRIXLEAST16 __PRI16(X) +#define PRIdLEAST16 __PRI16LEAST(d) +#define PRIiLEAST16 __PRI16LEAST(i) +#define PRIoLEAST16 __PRI16LEAST(o) +#define PRIuLEAST16 __PRI16LEAST(u) +#define PRIxLEAST16 __PRI16LEAST(x) +#define PRIXLEAST16 __PRI16LEAST(X) -#define SCNdLEAST16 __SCN16(d) -#define SCNiLEAST16 __SCN16(i) -#define SCNoLEAST16 __SCN16(o) -#define SCNuLEAST16 __SCN16(u) -#define SCNxLEAST16 __SCN16(x) +#define SCNdLEAST16 __SCN16LEAST(d) +#define SCNiLEAST16 __SCN16LEAST(i) +#define SCNoLEAST16 __SCN16LEAST(o) +#define SCNuLEAST16 __SCN16LEAST(u) +#define SCNxLEAST16 __SCN16LEAST(x) -#define PRIdFAST16 __PRI16(d) -#define PRIiFAST16 __PRI16(i) -#define PRIoFAST16 __PRI16(o) -#define PRIuFAST16 __PRI16(u) -#define PRIxFAST16 __PRI16(x) -#define PRIXFAST16 __PRI16(X) +#define PRIdFAST16 __PRI16FAST(d) +#define PRIiFAST16 __PRI16FAST(i) +#define PRIoFAST16 __PRI16FAST(o) +#define PRIuFAST16 __PRI16FAST(u) +#define PRIxFAST16 __PRI16FAST(x) +#define PRIXFAST16 __PRI16FAST(X) -#define SCNdFAST16 __SCN16(d) -#define SCNiFAST16 __SCN16(i) -#define SCNoFAST16 __SCN16(o) -#define SCNuFAST16 __SCN16(u) -#define SCNxFAST16 __SCN16(x) +#define SCNdFAST16 __SCN16FAST(d) +#define SCNiFAST16 __SCN16FAST(i) +#define SCNoFAST16 __SCN16FAST(o) +#define SCNuFAST16 __SCN16FAST(u) +#define SCNxFAST16 __SCN16FAST(x) /* 32-bit types */ -#if __have_long32 -#define __PRI32(x) __STRINGIFY(l##x) -#define __SCN32(x) __STRINGIFY(l##x) -#else -#define __PRI32(x) __STRINGIFY(x) -#define __SCN32(x) __STRINGIFY(x) -#endif +#define __PRI32(x) __INT32 __STRINGIFY(x) +#define __SCN32(x) __INT32 __STRINGIFY(x) +#define __PRI32LEAST(x) __LEAST32 __STRINGIFY(x) +#define __SCN32LEAST(x) __LEAST32 __STRINGIFY(x) +#define __PRI32FAST(x) __FAST32 __STRINGIFY(x) +#define __SCN32FAST(x) __FAST32 __STRINGIFY(x) #define PRId32 __PRI32(d) #define PRIi32 __PRI32(i) @@ -144,46 +171,44 @@ #define SCNx32 __SCN32(x) -#define PRIdLEAST32 __PRI32(d) -#define PRIiLEAST32 __PRI32(i) -#define PRIoLEAST32 __PRI32(o) -#define PRIuLEAST32 __PRI32(u) -#define PRIxLEAST32 __PRI32(x) -#define PRIXLEAST32 __PRI32(X) +#define PRIdLEAST32 __PRI32LEAST(d) +#define PRIiLEAST32 __PRI32LEAST(i) +#define PRIoLEAST32 __PRI32LEAST(o) +#define PRIuLEAST32 __PRI32LEAST(u) +#define PRIxLEAST32 __PRI32LEAST(x) +#define PRIXLEAST32 __PRI32LEAST(X) -#define SCNdLEAST32 __SCN32(d) -#define SCNiLEAST32 __SCN32(i) -#define SCNoLEAST32 __SCN32(o) -#define SCNuLEAST32 __SCN32(u) -#define SCNxLEAST32 __SCN32(x) +#define SCNdLEAST32 __SCN32LEAST(d) +#define SCNiLEAST32 __SCN32LEAST(i) +#define SCNoLEAST32 __SCN32LEAST(o) +#define SCNuLEAST32 __SCN32LEAST(u) +#define SCNxLEAST32 __SCN32LEAST(x) -#define PRIdFAST32 __PRI32(d) -#define PRIiFAST32 __PRI32(i) -#define PRIoFAST32 __PRI32(o) -#define PRIuFAST32 __PRI32(u) -#define PRIxFAST32 __PRI32(x) -#define PRIXFAST32 __PRI32(X) +#define PRIdFAST32 __PRI32FAST(d) +#define PRIiFAST32 __PRI32FAST(i) +#define PRIoFAST32 __PRI32FAST(o) +#define PRIuFAST32 __PRI32FAST(u) +#define PRIxFAST32 __PRI32FAST(x) +#define PRIXFAST32 __PRI32FAST(X) -#define SCNdFAST32 __SCN32(d) -#define SCNiFAST32 __SCN32(i) -#define SCNoFAST32 __SCN32(o) -#define SCNuFAST32 __SCN32(u) -#define SCNxFAST32 __SCN32(x) +#define SCNdFAST32 __SCN32FAST(d) +#define SCNiFAST32 __SCN32FAST(i) +#define SCNoFAST32 __SCN32FAST(o) +#define SCNuFAST32 __SCN32FAST(u) +#define SCNxFAST32 __SCN32FAST(x) /* 64-bit types */ -#if __have_long64 -#define __PRI64(x) __STRINGIFY(l##x) -#define __SCN64(x) __STRINGIFY(l##x) -#elif __have_longlong64 -#define __PRI64(x) __STRINGIFY(I64##x) -#define __SCN64(x) __STRINGIFY(I64##x) -#else -#define __PRI64(x) __STRINGIFY(x) -#define __SCN64(x) __STRINGIFY(x) -#endif +#define __PRI64(x) __INT64 __STRINGIFY(x) +#define __SCN64(x) __INT64 __STRINGIFY(x) +#define __PRI64LEAST(x) __LEAST64 __STRINGIFY(x) +#define __SCN64LEAST(x) __LEAST64 __STRINGIFY(x) +#define __PRI64FAST(x) __FAST64 __STRINGIFY(x) +#define __SCN64FAST(x) __FAST64 __STRINGIFY(x) + +#if __int64_t_defined #define PRId64 __PRI64(d) #define PRIi64 __PRI64(i) #define PRIo64 __PRI64(o) @@ -196,34 +221,36 @@ #define SCNo64 __SCN64(o) #define SCNu64 __SCN64(u) #define SCNx64 __SCN64(x) +#endif -#if __int64_t_defined -#define PRIdLEAST64 __PRI64(d) -#define PRIiLEAST64 __PRI64(i) -#define PRIoLEAST64 __PRI64(o) -#define PRIuLEAST64 __PRI64(u) -#define PRIxLEAST64 __PRI64(x) -#define PRIXLEAST64 __PRI64(X) +#if __int_least64_t_defined +#define PRIdLEAST64 __PRI64LEAST(d) +#define PRIiLEAST64 __PRI64LEAST(i) +#define PRIoLEAST64 __PRI64LEAST(o) +#define PRIuLEAST64 __PRI64LEAST(u) +#define PRIxLEAST64 __PRI64LEAST(x) +#define PRIXLEAST64 __PRI64LEAST(X) -#define SCNdLEAST64 __SCN64(d) -#define SCNiLEAST64 __SCN64(i) -#define SCNoLEAST64 __SCN64(o) -#define SCNuLEAST64 __SCN64(u) -#define SCNxLEAST64 __SCN64(x) +#define SCNdLEAST64 __SCN64LEAST(d) +#define SCNiLEAST64 __SCN64LEAST(i) +#define SCNoLEAST64 __SCN64LEAST(o) +#define SCNuLEAST64 __SCN64LEAST(u) +#define SCNxLEAST64 __SCN64LEAST(x) +#endif +#if __int_fast64_t_defined +#define PRIdFAST64 __PRI64FAST(d) +#define PRIiFAST64 __PRI64FAST(i) +#define PRIoFAST64 __PRI64FAST(o) +#define PRIuFAST64 __PRI64FAST(u) +#define PRIxFAST64 __PRI64FAST(x) +#define PRIXFAST64 __PRI64FAST(X) -#define PRIdFAST64 __PRI64(d) -#define PRIiFAST64 __PRI64(i) -#define PRIoFAST64 __PRI64(o) -#define PRIuFAST64 __PRI64(u) -#define PRIxFAST64 __PRI64(x) -#define PRIXFAST64 __PRI64(X) - -#define SCNdFAST64 __SCN64(d) -#define SCNiFAST64 __SCN64(i) -#define SCNoFAST64 __SCN64(o) -#define SCNuFAST64 __SCN64(u) -#define SCNxFAST64 __SCN64(x) +#define SCNdFAST64 __SCN64FAST(d) +#define SCNiFAST64 __SCN64FAST(i) +#define SCNoFAST64 __SCN64FAST(o) +#define SCNuFAST64 __SCN64FAST(u) +#define SCNxFAST64 __SCN64FAST(x) #endif /* max-bit types */ @@ -252,15 +279,15 @@ #define SCNxMAX __SCNMAX(x) /* ptr types */ -#if PTRDIFF_MAX <= __INTTYPES_EXP(INT_MAX) -# define __PRIPTR(x) __STRINGIFY(x) -# define __SCNPTR(x) __STRINGIFY(x) -#elif PTRDIFF_MAX <= __INTTYPES_EXP(LONG_MAX) || !defined(__have_longlong64) +#if defined (_INTPTR_EQ_LONGLONG) +# define __PRIPTR(x) __STRINGIFY(ll##x) +# define __SCNPTR(x) __STRINGIFY(ll##x) +#elif defined (_INTPTR_EQ_LONG) # define __PRIPTR(x) __STRINGIFY(l##x) # define __SCNPTR(x) __STRINGIFY(l##x) #else -# define __PRIPTR(x) __STRINGIFY(ll##x) -# define __SCNPTR(x) __STRINGIFY(ll##x) +# define __PRIPTR(x) __STRINGIFY(x) +# define __SCNPTR(x) __STRINGIFY(x) #endif #define PRIdPTR __PRIPTR(d) diff --git a/contrib/sdk/sources/newlib/libc/include/kos32sys.h b/contrib/sdk/sources/newlib/libc/include/kos32sys.h index b9b756f8f3..24eff7bc88 100644 --- a/contrib/sdk/sources/newlib/libc/include/kos32sys.h +++ b/contrib/sdk/sources/newlib/libc/include/kos32sys.h @@ -52,6 +52,32 @@ typedef struct int out_size; }ioctl_t; +static inline void begin_draw(void) +{ + __asm__ __volatile__( + "int $0x40" ::"a"(12),"b"(1)); +}; + +static inline +void end_draw(void) +{ + __asm__ __volatile__( + "int $0x40" ::"a"(12),"b"(2)); +}; + +static inline +void sys_create_window(int x, int y, int w, int h, const char *name, + color_t workcolor, uint32_t style) +{ + __asm__ __volatile__( + "int $0x40" + ::"a"(0), + "b"((x << 16) | ((w-1) & 0xFFFF)), + "c"((y << 16) | ((h-1) & 0xFFFF)), + "d"((style << 24) | (workcolor & 0xFFFFFF)), + "D"(name), + "S"(0) : "memory"); +}; static inline void define_button(uint32_t x_w, uint32_t y_h, uint32_t id, uint32_t color) @@ -64,7 +90,47 @@ void define_button(uint32_t x_w, uint32_t y_h, uint32_t id, uint32_t color) "d"(id), "S"(color)); }; -static inline void DefineButton(void) __attribute__ ((alias ("define_button"))); + +static inline +void draw_line(int xs, int ys, int xe, int ye, color_t color) +{ + __asm__ __volatile__( + "int $0x40" + ::"a"(38), "d"(color), + "b"((xs << 16) | xe), + "c"((ys << 16) | ye)); +} + +static inline +void draw_bar(int x, int y, int w, int h, color_t color) +{ + __asm__ __volatile__( + "int $0x40" + ::"a"(13), "d"(color), + "b"((x << 16) | w), + "c"((y << 16) | h)); +} + +static inline +void draw_bitmap(void *bitmap, int x, int y, int w, int h) +{ + __asm__ __volatile__( + "int $0x40" + ::"a"(7), "b"(bitmap), + "c"((w << 16) | h), + "d"((x << 16) | y)); +} + +static inline +void draw_text_sys(const char *text, int x, int y, int len, color_t color) +{ + __asm__ __volatile__( + "int $0x40" + ::"a"(4),"d"(text), + "b"((x << 16) | y), + "S"(len),"c"(color) + :"memory"); +} static inline uint32_t get_skin_height(void) @@ -77,35 +143,21 @@ uint32_t get_skin_height(void) :"a"(48),"b"(4)); return height; }; + +static inline void BeginDraw(void) __attribute__ ((alias ("begin_draw"))); +static inline void EndDraw(void) __attribute__ ((alias ("end_draw"))); +static inline void DrawWindow(int x, int y, int w, int h, const char *name, + color_t workcolor, uint32_t style) + __attribute__ ((alias ("sys_create_window"))); +static inline void DefineButton(void) __attribute__ ((alias ("define_button"))); +static inline void DrawLine(int xs, int ys, int xe, int ye, color_t color) + __attribute__ ((alias ("draw_line"))); +static inline void DrawBar(int x, int y, int w, int h, color_t color) + __attribute__ ((alias ("draw_bar"))); +static inline void DrawBitmap(void *bitmap, int x, int y, int w, int h) + __attribute__ ((alias ("draw_bitmap"))); static inline uint32_t GetSkinHeight(void) __attribute__ ((alias ("get_skin_height"))); -static inline -void BeginDraw(void) -{ - __asm__ __volatile__( - "int $0x40" ::"a"(12),"b"(1)); -}; - -static inline -void EndDraw(void) -{ - __asm__ __volatile__( - "int $0x40" ::"a"(12),"b"(2)); -}; - -static inline void DrawWindow(int x, int y, int w, int h, const char *name, - color_t workcolor, uint32_t style) -{ - - __asm__ __volatile__( - "int $0x40" - ::"a"(0), - "b"((x << 16) | ((w-1) & 0xFFFF)), - "c"((y << 16) | ((h-1) & 0xFFFF)), - "d"((style << 24) | (workcolor & 0xFFFFFF)), - "D"(name), - "S"(0) : "memory"); -}; #define POS_SCREEN 0 #define POS_WINDOW 1 @@ -122,7 +174,6 @@ pos_t get_mouse_pos(int origin) :"a"(37),"b"(origin)); return val; } -static inline pos_t GetMousePos(int origin) __attribute__ ((alias ("get_mouse_pos"))); static inline uint32_t get_mouse_buttons(void) @@ -135,7 +186,6 @@ uint32_t get_mouse_buttons(void) :"a"(37),"b"(2)); return val; }; -static inline uint32_t GetMouseButtons(void) __attribute__ ((alias ("get_mouse_buttons"))); static inline uint32_t get_mouse_wheels(void) @@ -148,8 +198,47 @@ uint32_t get_mouse_wheels(void) :"a"(37),"b"(7)); return val; }; + +static inline uint32_t load_cursor(void *path, uint32_t flags) +{ + uint32_t val; + __asm__ __volatile__( + "int $0x40" + :"=a"(val) + :"a"(37), "b"(4), "c"(path), "d"(flags)); + return val; +} + +static inline uint32_t set_cursor(uint32_t cursor) +{ + uint32_t old; + __asm__ __volatile__( + "int $0x40" + :"=a"(old) + :"a"(37), "b"(5), "c"(cursor)); + return old; +}; + +static inline int destroy_cursor(uint32_t cursor) +{ + int ret; + __asm__ __volatile__( + "int $0x40" + :"=a"(ret) + :"a"(37), "b"(6), "c"(cursor) + :"memory"); + return ret; +}; + +static inline pos_t GetMousePos(int origin) __attribute__ ((alias ("get_mouse_pos"))); +static inline uint32_t GetMouseButtons(void) __attribute__ ((alias ("get_mouse_buttons"))); static inline uint32_t GetMouseWheels(void) __attribute__ ((alias ("get_mouse_wheels"))); +static inline uint32_t LoadCursor(void *path, uint32_t flags) __attribute__ ((alias ("load_cursor"))); +static inline uint32_t SetCursor(uint32_t cursor) __attribute__ ((alias ("set_cursor"))); +static inline int DestroyCursor(uint32_t cursor) __attribute__ ((alias ("destroy_cursor"))); + + static inline uint32_t wait_for_event(uint32_t time) { @@ -252,49 +341,6 @@ static inline int call_service(ioctl_t *io) }; -static inline -void draw_line(int xs, int ys, int xe, int ye, color_t color) -{ - __asm__ __volatile__( - "int $0x40" - ::"a"(38), "d"(color), - "b"((xs << 16) | xe), - "c"((ys << 16) | ye)); -} - - - -static inline -void draw_bar(int x, int y, int w, int h, color_t color) -{ - __asm__ __volatile__( - "int $0x40" - ::"a"(13), "d"(color), - "b"((x << 16) | w), - "c"((y << 16) | h)); -} - -static inline -void draw_bitmap(void *bitmap, int x, int y, int w, int h) -{ - __asm__ __volatile__( - "int $0x40" - ::"a"(7), "b"(bitmap), - "c"((w << 16) | h), - "d"((x << 16) | y)); -} - -static inline -void draw_text_sys(const char *text, int x, int y, int len, color_t color) -{ - __asm__ __volatile__( - "int $0x40" - ::"a"(4),"d"(text), - "b"((x << 16) | y), - "S"(len),"c"(color) - :"memory"); -} - static inline void yield(void) { __asm__ __volatile__( @@ -320,7 +366,6 @@ void *user_alloc(size_t size) :"a"(68),"b"(12),"c"(size)); return val; } -static inline void *UserAlloc(size_t size) __attribute__ ((alias ("user_alloc"))); static inline int user_free(void *mem) @@ -332,7 +377,19 @@ int user_free(void *mem) :"a"(68),"b"(13),"c"(mem)); return val; } -static inline int UserFree(void *mem) __attribute__ ((alias ("user_free"))); + +static inline +void* user_realloc(void *mem, size_t size) +{ + void *val; + __asm__ __volatile__( + "int $0x40" + :"=a"(val) + :"a"(68),"b"(20),"c"(size),"d"(mem) + :"memory"); + + return val; +}; static inline int *user_unmap(void *base, size_t offset, size_t size) @@ -344,6 +401,10 @@ int *user_unmap(void *base, size_t offset, size_t size) :"a"(68),"b"(26),"c"(base),"d"(offset),"S"(size)); return val; }; + +static inline void *UserAlloc(size_t size) __attribute__ ((alias ("user_alloc"))); +static inline int UserFree(void *mem) __attribute__ ((alias ("user_free"))); +static inline void* UserRealloc(void *mem, size_t size) __attribute__ ((alias ("user_realloc"))); static inline int *UserUnmap(void *base, size_t offset, size_t size) __attribute__ ((alias ("user_unmap"))); typedef union @@ -356,7 +417,6 @@ typedef union unsigned long long raw; }ufile_t; - static inline ufile_t load_file(const char *path) { ufile_t uf; @@ -381,43 +441,6 @@ static inline int GetScreenSize() return retval; } -static inline -uint32_t load_cursor(void *path, uint32_t flags) -{ - uint32_t val; - __asm__ __volatile__( - "int $0x40" - :"=a"(val) - :"a"(37), "b"(4), "c"(path), "d"(flags)); - return val; -} -static inline -uint32_t LoadCursor(void *path, uint32_t flags) __attribute__ ((alias ("load_cursor"))); - -static inline -uint32_t set_cursor(uint32_t cursor) -{ - uint32_t old; - __asm__ __volatile__( - "int $0x40" - :"=a"(old) - :"a"(37), "b"(5), "c"(cursor)); - return old; -}; -static inline uint32_t SetCursor(uint32_t cursor) __attribute__ ((alias ("set_cursor"))); - -static inline -int destroy_cursor(uint32_t cursor) -{ - int ret; - __asm__ __volatile__( - "int $0x40" - :"=a"(ret) - :"a"(37), "b"(6), "c"(cursor) - :"memory"); - return ret; -}; -static inline int DestroyCursor(uint32_t cursor) __attribute__ ((alias ("destroy_cursor"))); static inline void get_proc_info(char *info) { @@ -429,21 +452,6 @@ static inline void get_proc_info(char *info) }; static inline void GetProcInfo(char *info) __attribute__ ((alias ("get_proc_info"))); -static inline -void* user_realloc(void *mem, size_t size) -{ - void *val; - __asm__ __volatile__( - "int $0x40" - :"=a"(val) - :"a"(68),"b"(20),"c"(size),"d"(mem) - :"memory"); - - return val; -}; -static inline void* UserRealloc(void *mem, size_t size) __attribute__ ((alias ("user_realloc"))); - -void *get_resource(void *data, uint32_t id); struct blit_call { @@ -483,6 +491,8 @@ static inline void Blit(void *bitmap, int dst_x, int dst_y, ::"a"(73),"b"(0),"c"(&bc.dstx)); }; +int create_thread(int (*proc)(void *param), void *param, int stack_size); + void* load_library(const char *name); void* get_proc_address(void *handle, const char *proc_name); diff --git a/contrib/sdk/sources/newlib/libc/include/libgen.h b/contrib/sdk/sources/newlib/libc/include/libgen.h index b619d90962..b3442ea3d8 100644 --- a/contrib/sdk/sources/newlib/libc/include/libgen.h +++ b/contrib/sdk/sources/newlib/libc/include/libgen.h @@ -6,13 +6,27 @@ #define _LIBGEN_H_ #include "_ansi.h" +#include #include #ifdef __cplusplus extern "C" { #endif -char *_EXFUN(basename, (char *)); +/* There are two common basename variants. If you do NOT #include + and you do + + #define _GNU_SOURCE + #include + + you get the GNU version. Otherwise you get the POSIX versionfor which you + should #include i for the function prototype. POSIX requires that + #undef basename will still let you invoke the underlying function. However, + this also implies that the POSIX version is used in this case. That's made + sure here. */ +#undef basename +#define basename __xpg_basename +char *_EXFUN(basename, (char *)) __asm__(__ASMNAME("basename")); char *_EXFUN(dirname, (char *)); #ifdef __cplusplus diff --git a/contrib/sdk/sources/newlib/libc/include/libsync.h b/contrib/sdk/sources/newlib/libc/include/libsync.h index 490ad6a5f5..87f72f9d48 100644 --- a/contrib/sdk/sources/newlib/libc/include/libsync.h +++ b/contrib/sdk/sources/newlib/libc/include/libsync.h @@ -56,19 +56,19 @@ static inline void mutex_lock(mutex_t *mutex) while (exchange_acquire (&mutex->lock, 2) != 0) { asm volatile( - "int $0x40\t" + "int $0x40\t\n" :"=a"(tmp) :"a"(77),"b"(FUTEX_WAIT), "c"(mutex->handle),"d"(2),"S"(0)); } }; -static inline void mutex_lock_timeout(mutex_t *mutex, int timeout) +static inline int mutex_lock_timeout(mutex_t *mutex, int timeout) { - int tmp; + int tmp = 0; if( __sync_fetch_and_add(&mutex->lock, 1) == 0) - return; + return 1; while (exchange_acquire (&mutex->lock, 2) != 0) { @@ -77,7 +77,11 @@ static inline void mutex_lock_timeout(mutex_t *mutex, int timeout) :"=a"(tmp) :"a"(77),"b"(FUTEX_WAIT), "c"(mutex->handle),"d"(2),"S"(timeout)); - } + + if(++tmp == 0) + break; + } + return tmp ; }; static inline int mutex_trylock (mutex_t *mutex) diff --git a/contrib/sdk/sources/newlib/libc/include/machine/_default_types.h b/contrib/sdk/sources/newlib/libc/include/machine/_default_types.h index 2f92019629..f0a79d7f4f 100644 --- a/contrib/sdk/sources/newlib/libc/include/machine/_default_types.h +++ b/contrib/sdk/sources/newlib/libc/include/machine/_default_types.h @@ -1,5 +1,5 @@ /* - * $Id: _default_types.h,v 1.6 2013/12/03 16:04:41 corinna Exp $ + * $Id$ */ #ifndef _MACHINE__DEFAULT_TYPES_H @@ -25,7 +25,11 @@ extern "C" { #ifdef __INT8_TYPE__ typedef __INT8_TYPE__ __int8_t; +#ifdef __UINT8_TYPE__ typedef __UINT8_TYPE__ __uint8_t; +#else +typedef unsigned __INT8_TYPE__ __uint8_t; +#endif #define ___int8_t_defined 1 #elif __EXP(SCHAR_MAX) == 0x7f typedef signed char __int8_t ; @@ -35,7 +39,11 @@ typedef unsigned char __uint8_t ; #ifdef __INT16_TYPE__ typedef __INT16_TYPE__ __int16_t; +#ifdef __UINT16_TYPE__ typedef __UINT16_TYPE__ __uint16_t; +#else +typedef unsigned __INT16_TYPE__ __uint16_t; +#endif #define ___int16_t_defined 1 #elif __EXP(INT_MAX) == 0x7fff typedef signed int __int16_t; @@ -53,7 +61,11 @@ typedef unsigned char __uint16_t; #ifdef __INT32_TYPE__ typedef __INT32_TYPE__ __int32_t; +#ifdef __UINT32_TYPE__ typedef __UINT32_TYPE__ __uint32_t; +#else +typedef unsigned __INT32_TYPE__ __uint32_t; +#endif #define ___int32_t_defined 1 #elif __EXP(INT_MAX) == 0x7fffffffL typedef signed int __int32_t; @@ -75,7 +87,11 @@ typedef unsigned char __uint32_t; #ifdef __INT64_TYPE__ typedef __INT64_TYPE__ __int64_t; +#ifdef __UINT64_TYPE__ typedef __UINT64_TYPE__ __uint64_t; +#else +typedef unsigned __INT64_TYPE__ __uint64_t; +#endif #define ___int64_t_defined 1 #elif __EXP(LONG_MAX) > 0x7fffffff typedef signed long __int64_t; @@ -102,7 +118,11 @@ typedef unsigned int __uint64_t; #ifdef __INT_LEAST8_TYPE__ typedef __INT_LEAST8_TYPE__ __int_least8_t; +#ifdef __UINT_LEAST8_TYPE__ typedef __UINT_LEAST8_TYPE__ __uint_least8_t; +#else +typedef unsigned __INT_LEAST8_TYPE__ __uint_least8_t; +#endif #define ___int_least8_t_defined 1 #elif defined(___int8_t_defined) typedef __int8_t __int_least8_t; @@ -124,7 +144,11 @@ typedef __uint64_t __uint_least8_t; #ifdef __INT_LEAST16_TYPE__ typedef __INT_LEAST16_TYPE__ __int_least16_t; +#ifdef __UINT_LEAST16_TYPE__ typedef __UINT_LEAST16_TYPE__ __uint_least16_t; +#else +typedef unsigned __INT_LEAST16_TYPE__ __uint_least16_t; +#endif #define ___int_least16_t_defined 1 #elif defined(___int16_t_defined) typedef __int16_t __int_least16_t; @@ -142,7 +166,11 @@ typedef __uint64_t __uint_least16_t; #ifdef __INT_LEAST32_TYPE__ typedef __INT_LEAST32_TYPE__ __int_least32_t; +#ifdef __UINT_LEAST32_TYPE__ typedef __UINT_LEAST32_TYPE__ __uint_least32_t; +#else +typedef unsigned __INT_LEAST32_TYPE__ __uint_least32_t; +#endif #define ___int_least32_t_defined 1 #elif defined(___int32_t_defined) typedef __int32_t __int_least32_t; @@ -156,7 +184,11 @@ typedef __uint64_t __uint_least32_t; #ifdef __INT_LEAST64_TYPE__ typedef __INT_LEAST64_TYPE__ __int_least64_t; +#ifdef __UINT_LEAST64_TYPE__ typedef __UINT_LEAST64_TYPE__ __uint_least64_t; +#else +typedef unsigned __INT_LEAST64_TYPE__ __uint_least64_t; +#endif #define ___int_least64_t_defined 1 #elif defined(___int64_t_defined) typedef __int64_t __int_least64_t; @@ -166,7 +198,11 @@ typedef __uint64_t __uint_least64_t; #ifdef __INTPTR_TYPE__ typedef __INTPTR_TYPE__ __intptr_t; +#ifdef __UINTPTR_TYPE__ typedef __UINTPTR_TYPE__ __uintptr_t; +#else +typedef unsigned __INTPTR_TYPE__ __uintptr_t; +#endif #elif defined(__PTRDIFF_TYPE__) typedef __PTRDIFF_TYPE__ __intptr_t; typedef unsigned __PTRDIFF_TYPE__ __uintptr_t; diff --git a/contrib/sdk/sources/newlib/libc/include/machine/_types.h b/contrib/sdk/sources/newlib/libc/include/machine/_types.h index f64609e423..219ce210e9 100644 --- a/contrib/sdk/sources/newlib/libc/include/machine/_types.h +++ b/contrib/sdk/sources/newlib/libc/include/machine/_types.h @@ -1,5 +1,5 @@ /* - * $Id: _types.h,v 1.3 2007/09/07 21:16:25 jjohnstn Exp $ + * $Id$ */ #ifndef _MACHINE__TYPES_H diff --git a/contrib/sdk/sources/newlib/libc/include/machine/ieeefp.h b/contrib/sdk/sources/newlib/libc/include/machine/ieeefp.h index d74df2d07f..fe20b42cbf 100644 --- a/contrib/sdk/sources/newlib/libc/include/machine/ieeefp.h +++ b/contrib/sdk/sources/newlib/libc/include/machine/ieeefp.h @@ -99,7 +99,7 @@ #define isfinite(__y) \ (__extension__ ({int __cy; \ - (sizeof (__y) == sizeof (float)) ? (1) : \ + (sizeof (__y) == sizeof (float)) ? (1) : \ (__cy = fpclassify(__y)) != FP_INFINITE && __cy != FP_NAN;})) #define isinf(__x) ((sizeof (__x) == sizeof (float)) ? (0) : __isinfd(__x)) @@ -283,6 +283,10 @@ #define __IEEE_BIG_ENDIAN #endif +#ifdef __FT32__ +#define __IEEE_LITTLE_ENDIAN +#endif + #ifdef __mcore__ #define __IEEE_BIG_ENDIAN #endif @@ -316,7 +320,7 @@ #define _DOUBLE_IS_32BITS #endif -#if defined(__or32__) || defined(__or1k__) || defined(__or16__) +#if defined(__or1k__) || defined(__OR1K__) || defined(__OR1KND__) #define __IEEE_BIG_ENDIAN #endif @@ -379,8 +383,10 @@ #ifdef __RL78__ #define __IEEE_LITTLE_ENDIAN #define __SMALL_BITFIELDS /* 16 Bit INT */ +#ifndef __RL78_64BIT_DOUBLES__ #define _DOUBLE_IS_32BITS #endif +#endif #ifdef __RX__ @@ -413,6 +419,10 @@ # endif #endif +#ifdef __VISIUM__ +#define __IEEE_BIG_ENDIAN +#endif + #ifndef __IEEE_BIG_ENDIAN #ifndef __IEEE_LITTLE_ENDIAN #error Endianess not declared!! diff --git a/contrib/sdk/sources/newlib/libc/include/machine/setjmp.h b/contrib/sdk/sources/newlib/libc/include/machine/setjmp.h index 38d2405268..f8c87d9bb3 100644 --- a/contrib/sdk/sources/newlib/libc/include/machine/setjmp.h +++ b/contrib/sdk/sources/newlib/libc/include/machine/setjmp.h @@ -1,6 +1,11 @@ _BEGIN_STD_C +#if defined(__or1k__) || defined(__or1knd__) +#define _JBLEN 31 /* 32 GPRs - r0 */ +#define _JBTYPE unsigned long +#endif + #if defined(__arm__) || defined(__thumb__) /* * All callee preserved registers: @@ -56,11 +61,18 @@ _BEGIN_STD_C #endif #ifdef __nds32__ -/* Only 17 words are currently needed. - Preserve one word slot if we need to expand. - Check newlib/libc/machine/nds32/setjmp.S for more information. */ +/* 17 words for GPRs, + 1 word for $fpcfg.freg and 30 words for FPUs + Reserved 2 words for aligement-adjustment. When storeing double-precision + floating-point register into memory, the address has to be + double-word-aligned. + Check libc/machine/nds32/setjmp.S for more information. */ +#if __NDS32_EXT_FPU_SP__ || __NDS32_EXT_FPU_DP__ +#define _JBLEN 50 +#else #define _JBLEN 18 #endif +#endif #if defined(__Z8001__) || defined(__Z8002__) /* 16 regs + pc */ @@ -106,7 +118,7 @@ _BEGIN_STD_C #endif #ifdef __mips__ -# if defined(__mips64) || (__mips_fpr == 64) +# if defined(__mips64) # define _JBTYPE long long # endif # ifdef __mips_soft_float @@ -238,6 +250,10 @@ _BEGIN_STD_C #define _JBLEN 10 #endif +#ifdef __FT32__ +#define _JBLEN 27 +#endif + #ifdef __iq2000__ #define _JBLEN 32 #endif @@ -246,6 +262,10 @@ _BEGIN_STD_C #define _JBLEN 16 #endif +#ifdef __arc__ +#define _JBLEN 25 /* r13-r30,blink,lp_count,lp_start,lp_end,mlo,mhi,status32 */ +#endif + #ifdef __MMIX__ /* Using a layout compatible with GCC's built-in. */ #define _JBLEN 5 @@ -275,6 +295,10 @@ _BEGIN_STD_C #define _JBLEN 18 #endif +#ifdef __ia64 +#define _JBLEN 64 +#endif + #ifdef __lm32__ #define _JBLEN 19 #endif @@ -326,6 +350,11 @@ _BEGIN_STD_C #define _JBLEN 0x44 #endif +#ifdef __VISIUM__ +/* All call-saved GP registers: r11-r19,r21,r22,r23. */ +#define _JBLEN 12 +#endif + #ifdef _JBLEN #ifdef _JBTYPE typedef _JBTYPE jmp_buf[_JBLEN]; @@ -364,6 +393,13 @@ typedef int sigjmp_buf[_JBLEN+1+(sizeof (sigset_t)/sizeof (int))]; #define __SIGMASK_FUNC sigprocmask #endif +#ifdef __CYGWIN__ +/* Per POSIX, siglongjmp has to be implemented as function. Cygwin + provides functions for both, siglongjmp and sigsetjmp since 2.2.0. */ +extern void siglongjmp (sigjmp_buf, int) __attribute__ ((__noreturn__)); +extern int sigsetjmp (sigjmp_buf, int); +#endif + #if defined(__GNUC__) #define sigsetjmp(env, savemask) \ @@ -401,8 +437,8 @@ typedef int sigjmp_buf[_JBLEN+1+(sizeof (sigset_t)/sizeof (int))]; are equivalent to sigsetjmp/siglongjmp when not saving the signal mask. New applications should use sigsetjmp/siglongjmp instead. */ #ifdef __CYGWIN__ -extern void _longjmp(jmp_buf, int); -extern int _setjmp(jmp_buf); +extern void _longjmp (jmp_buf, int) __attribute__ ((__noreturn__)); +extern int _setjmp (jmp_buf); #else #define _setjmp(env) sigsetjmp ((env), 0) #define _longjmp(env, val) siglongjmp ((env), (val)) diff --git a/contrib/sdk/sources/newlib/libc/include/machine/time.h b/contrib/sdk/sources/newlib/libc/include/machine/time.h index b7d6a79391..cf51ec6f48 100644 --- a/contrib/sdk/sources/newlib/libc/include/machine/time.h +++ b/contrib/sdk/sources/newlib/libc/include/machine/time.h @@ -1,19 +1,15 @@ #ifndef _MACHTIME_H_ #define _MACHTIME_H_ -#if defined(__rtems__) -#define _CLOCKS_PER_SEC_ sysconf(_SC_CLK_TCK) -#else /* !__rtems__ */ -#if defined(__aarch64__) || defined(__arm__) || defined(__thumb__) +#if defined(__rtems__) || defined(__VISIUM__) +#define _CLOCKS_PER_SEC_ 1000000 +#elif defined(__aarch64__) || defined(__arm__) || defined(__thumb__) #define _CLOCKS_PER_SEC_ 100 #endif -#endif /* !__rtems__ */ #ifdef __SPU__ -#include +#include int nanosleep (const struct timespec *, struct timespec *); #endif #endif /* _MACHTIME_H_ */ - - diff --git a/contrib/sdk/sources/newlib/libc/include/machine/types.h b/contrib/sdk/sources/newlib/libc/include/machine/types.h index 73d3475d05..cfa50c4d7e 100644 --- a/contrib/sdk/sources/newlib/libc/include/machine/types.h +++ b/contrib/sdk/sources/newlib/libc/include/machine/types.h @@ -25,6 +25,8 @@ typedef long int __loff_t; #endif #endif +typedef long __suseconds_t; /* microseconds (signed) */ + #endif /* _MACHTYPES_H_ */ diff --git a/contrib/sdk/sources/newlib/libc/include/math.h b/contrib/sdk/sources/newlib/libc/include/math.h index 7db9217def..a373922fac 100644 --- a/contrib/sdk/sources/newlib/libc/include/math.h +++ b/contrib/sdk/sources/newlib/libc/include/math.h @@ -136,7 +136,8 @@ extern double fmod _PARAMS((double, double)); #endif /* ! defined (__math_68881) */ #endif /* ! defined (_REENT_ONLY) */ -#if !defined(__STRICT_ANSI__) || defined(__cplusplus) || __STDC_VERSION__ >= 199901L +#if !defined(__STRICT_ANSI__) || defined(__cplusplus) || \ + (defined(__STDC_VERSION__) && __STDC_VERSION__ >= 199901L) /* ISO C99 types and macros. */ @@ -253,6 +254,10 @@ extern int __signbitd (double x); (__extension__ ({__typeof__(a) __a = (a); __typeof__(b) __b = (b); \ fpclassify(__a) == FP_NAN || fpclassify(__b) == FP_NAN;})) +/* Non ANSI long double precision functions. */ + +extern int finitel _PARAMS((long double)); + /* Non ANSI double precision functions. */ extern double infinity _PARAMS((void)); @@ -273,7 +278,7 @@ extern double scalbln _PARAMS((double, long int)); extern double tgamma _PARAMS((double)); extern double nearbyint _PARAMS((double)); extern long int lrint _PARAMS((double)); -extern _LONG_LONG_TYPE int llrint _PARAMS((double)); +extern long long int llrint _PARAMS((double)); extern double round _PARAMS((double)); extern long int lround _PARAMS((double)); extern long long int llround _PARAMS((double)); @@ -343,7 +348,7 @@ extern float scalblnf _PARAMS((float, long int)); extern float tgammaf _PARAMS((float)); extern float nearbyintf _PARAMS((float)); extern long int lrintf _PARAMS((float)); -extern _LONG_LONG_TYPE llrintf _PARAMS((float)); +extern long long int llrintf _PARAMS((float)); extern float roundf _PARAMS((float)); extern long int lroundf _PARAMS((float)); extern long long int llroundf _PARAMS((float)); @@ -390,7 +395,7 @@ extern long double cosl _PARAMS((long double)); extern long double sinl _PARAMS((long double)); extern long double tanl _PARAMS((long double)); extern long double tanhl _PARAMS((long double)); -extern long double frexpl _PARAMS((long double value, int *)); +extern long double frexpl _PARAMS((long double, int *)); extern long double modfl _PARAMS((long double, long double *)); extern long double ceill _PARAMS((long double)); extern long double fabsl _PARAMS((long double)); @@ -422,6 +427,11 @@ extern int ilogbl _PARAMS((long double)); extern long double asinhl _PARAMS((long double)); extern long double cbrtl _PARAMS((long double)); extern long double nextafterl _PARAMS((long double, long double)); +extern float nexttowardf _PARAMS((float, long double)); +extern double nexttoward _PARAMS((double, long double)); +extern long double nexttowardl _PARAMS((long double, long double)); +extern long double logbl _PARAMS((long double)); +extern long double log2l _PARAMS((long double)); extern long double rintl _PARAMS((long double)); extern long double scalbnl _PARAMS((long double, int)); extern long double exp2l _PARAMS((long double)); @@ -432,7 +442,7 @@ extern long int lrintl _PARAMS((long double)); extern long long int llrintl _PARAMS((long double)); extern long double roundl _PARAMS((long double)); extern long lroundl _PARAMS((long double)); -extern _LONG_LONG_TYPE int llroundl _PARAMS((long double)); +extern long long int llroundl _PARAMS((long double)); extern long double truncl _PARAMS((long double)); extern long double remquol _PARAMS((long double, long double, int *)); extern long double fdiml _PARAMS((long double, long double)); @@ -448,15 +458,17 @@ extern long double erfl _PARAMS((long double)); extern long double erfcl _PARAMS((long double)); #endif /* ! defined (_REENT_ONLY) */ #else /* !_LDBL_EQ_DBL */ +extern long double hypotl _PARAMS((long double, long double)); +extern long double sqrtl _PARAMS((long double)); #ifdef __i386__ /* Other long double precision functions. */ extern _LONG_DOUBLE rintl _PARAMS((_LONG_DOUBLE)); extern long int lrintl _PARAMS((_LONG_DOUBLE)); -extern _LONG_LONG_TYPE llrintl _PARAMS((_LONG_DOUBLE)); +extern long long int llrintl _PARAMS((_LONG_DOUBLE)); #endif /* __i386__ */ #endif /* !_LDBL_EQ_DBL */ -#endif /* !defined (__STRICT_ANSI__) || defined(__cplusplus) || __STDC_VERSION__ >= 199901L */ +#endif /* !defined (__STRICT_ANSI__) || defined(__cplusplus) || (defined(__STDC_VERSION__) && __STDC_VERSION__ >= 199901L) */ #if !defined (__STRICT_ANSI__) || defined(__cplusplus) @@ -542,8 +554,12 @@ extern int matherr _PARAMS((struct exception *e)); #define TLOSS 5 #define PLOSS 6 +#endif /* ! defined (__STRICT_ANSI__) */ + /* Useful constants. */ +#if !defined(__STRICT_ANSI__) || ((_XOPEN_SOURCE - 0) >= 500) + #define MAXFLOAT 3.40282347e+38F #define M_E 2.7182818284590452354 @@ -552,16 +568,21 @@ extern int matherr _PARAMS((struct exception *e)); #define M_LN2 _M_LN2 #define M_LN10 2.30258509299404568402 #define M_PI 3.14159265358979323846 -#define M_TWOPI (M_PI * 2.0) #define M_PI_2 1.57079632679489661923 #define M_PI_4 0.78539816339744830962 -#define M_3PI_4 2.3561944901923448370E0 -#define M_SQRTPI 1.77245385090551602792981 #define M_1_PI 0.31830988618379067154 #define M_2_PI 0.63661977236758134308 #define M_2_SQRTPI 1.12837916709551257390 #define M_SQRT2 1.41421356237309504880 #define M_SQRT1_2 0.70710678118654752440 + +#endif + +#ifndef __STRICT_ANSI__ + +#define M_TWOPI (M_PI * 2.0) +#define M_3PI_4 2.3561944901923448370E0 +#define M_SQRTPI 1.77245385090551602792981 #define M_LN2LO 1.9082149292705877000E-10 #define M_LN2HI 6.9314718036912381649E-1 #define M_SQRT3 1.73205080756887719000 diff --git a/contrib/sdk/sources/newlib/libc/include/newlib.h b/contrib/sdk/sources/newlib/libc/include/newlib.h index a9fef29957..34700e04e0 100644 --- a/contrib/sdk/sources/newlib/libc/include/newlib.h +++ b/contrib/sdk/sources/newlib/libc/include/newlib.h @@ -11,7 +11,7 @@ /* #undef _ELIX_LEVEL */ /* Newlib version */ -#define _NEWLIB_VERSION "2.1.0" +#define _NEWLIB_VERSION "2.3.0" /* C99 formats support (such as %a, %zu, ...) in IO functions like * printf/scanf enabled */ diff --git a/contrib/sdk/sources/newlib/libc/include/pthread.h b/contrib/sdk/sources/newlib/libc/include/pthread.h index 8cd4d71a8a..31dcd0f23a 100644 --- a/contrib/sdk/sources/newlib/libc/include/pthread.h +++ b/contrib/sdk/sources/newlib/libc/include/pthread.h @@ -15,7 +15,7 @@ * OR WARRANTY OF ANY KIND CONCERNING THE MERCHANTABILITY OF THIS * SOFTWARE OR ITS FITNESS FOR ANY PARTICULAR PURPOSE. * - * $Id: pthread.h,v 1.12 2013/11/29 23:35:34 joel Exp $ + * $Id$ */ #ifndef __PTHREAD_h @@ -31,7 +31,7 @@ extern "C" { #include #include -#include +#include #include struct _pthread_cleanup_context { diff --git a/contrib/sdk/sources/newlib/libc/include/pwd.h b/contrib/sdk/sources/newlib/libc/include/pwd.h index 7de2962087..0438cb0fde 100644 --- a/contrib/sdk/sources/newlib/libc/include/pwd.h +++ b/contrib/sdk/sources/newlib/libc/include/pwd.h @@ -39,9 +39,10 @@ extern "C" { #endif #define _PWD_H_ +#include #include -#ifndef _POSIX_SOURCE +#if __BSD_VISIBLE #define _PATH_PASSWD "/etc/passwd" #define _PASSWORD_LEN 128 /* max length, not counting NULL */ @@ -61,16 +62,24 @@ struct passwd { #ifndef __INSIDE_CYGWIN__ struct passwd *getpwuid (uid_t); struct passwd *getpwnam (const char *); + +#if __POSIX_VISIBLE >= 200112 || __XSI_VISIBLE >= 500 int getpwnam_r (const char *, struct passwd *, char *, size_t , struct passwd **); int getpwuid_r (uid_t, struct passwd *, char *, size_t, struct passwd **); -#ifndef _POSIX_SOURCE +#endif + +#if __XSI_VISIBLE >= 500 struct passwd *getpwent (void); void setpwent (void); void endpwent (void); #endif + +#if __BSD_VISIBLE +int setpassent (int); #endif +#endif /*!__INSIDE_CYGWIN__*/ #ifdef __cplusplus } diff --git a/contrib/sdk/sources/newlib/libc/include/reent.h b/contrib/sdk/sources/newlib/libc/include/reent.h index a1160dff71..9180a314c7 100644 --- a/contrib/sdk/sources/newlib/libc/include/reent.h +++ b/contrib/sdk/sources/newlib/libc/include/reent.h @@ -33,13 +33,13 @@ and do not supply functional interfaces for any of the reentrant calls. With this method, the reentrant syscalls are redefined to directly call the regular system call without the reentrancy argument. - When you do this, specify both -DREENTRANT_SYSCALLS_PROVIDED and + When you do this, specify both -DREENTRANT_SYSCALLS_PROVIDED and -DMISSING_SYSCALL_NAMES via newlib_cflags in configure.host and do not specify "syscall_dir". Stubs of the reentrant versions of the syscalls exist in the libc/reent - source directory and are provided if REENTRANT_SYSCALLS_PROVIDED isn't - defined. These stubs call the native system calls: _open, _close, etc. + source directory and are provided if REENTRANT_SYSCALLS_PROVIDED isn't + defined. These stubs call the native system calls: _open, _close, etc. if MISSING_SYSCALL_NAMES is *not* defined, otherwise they call the non-underscored versions: open, close, etc. when MISSING_SYSCALL_NAMES *is* defined. @@ -51,17 +51,17 @@ keep a separate errno value which is intuitive since the application flow cannot check for failure reliably otherwise. - The reentrant syscalls are either provided by the platform, by the - libc/reent stubs, or in the case of both MISSING_SYSCALL_NAMES and + The reentrant syscalls are either provided by the platform, by the + libc/reent stubs, or in the case of both MISSING_SYSCALL_NAMES and REENTRANT_SYSCALLS_PROVIDED being defined, the calls are redefined to simply call the regular syscalls with no reentrancy struct argument. A single-threaded application does not need to worry about the reentrancy - structure. It is used internally. + structure. It is used internally. - A multi-threaded application needs either to manually manage reentrancy + A multi-threaded application needs either to manually manage reentrancy structures or use dynamic reentrancy. - + Manually managing reentrancy structures entails calling special reentrant versions of newlib functions that have an additional reentrancy argument. For example, _printf_r. By convention, the first argument is the @@ -76,7 +76,7 @@ to __getreent(). This function needs to be implemented by the platform and it is meant to return the reentrancy structure for the current thread. When the regular C functions (e.g. printf) go to call internal - routines with the default _REENT structure, they end up calling with + routines with the default _REENT structure, they end up calling with the reentrancy structure for the thread. Thus, application code does not need to call the _r routines nor worry about reentrancy structures. */ @@ -116,10 +116,10 @@ struct timezone; #define _kill_r(__reent, __pid, __signal) kill(__pid, __signal) #define _link_r(__reent, __oldpath, __newpath) link(__oldpath, __newpath) #define _lseek_r(__reent, __fdes, __off, __w) lseek(__fdes, __off, __w) -#define _mkdir_r(__reent, __path, __m) mkdir(__path, __m) +#define _mkdir_r(__reent, __path, __m) mkdir(__path, __m) #define _open_r(__reent, __path, __flag, __m) open(__path, __flag, __m) #define _read_r(__reent, __fd, __buff, __cnt) read(__fd, __buff, __cnt) -#define _rename_r(__reent, __old, __new) rename(__old, __new) +#define _rename_r(__reent, __old, __new) rename(__old, __new) #define _sbrk_r(__reent, __incr) sbrk(__incr) #define _stat_r(__reent, __path, __buff) stat(__path, __buff) #define _times_r(__reent, __time) times(__time) diff --git a/contrib/sdk/sources/newlib/libc/include/sched.h b/contrib/sdk/sources/newlib/libc/include/sched.h index 792444f6f5..4022efe93d 100644 --- a/contrib/sdk/sources/newlib/libc/include/sched.h +++ b/contrib/sdk/sources/newlib/libc/include/sched.h @@ -14,7 +14,7 @@ * OR WARRANTY OF ANY KIND CONCERNING THE MERCHANTABILITY OF THIS * SOFTWARE OR ITS FITNESS FOR ANY PARTICULAR PURPOSE. * - * $Id: sched.h,v 1.2 2010/04/01 18:33:33 jjohnstn Exp $ + * $Id$ */ #ifndef _SCHED_H_ diff --git a/contrib/sdk/sources/newlib/libc/include/setjmp.h b/contrib/sdk/sources/newlib/libc/include/setjmp.h index 1a8bf1e74c..7e3ad5dcdb 100644 --- a/contrib/sdk/sources/newlib/libc/include/setjmp.h +++ b/contrib/sdk/sources/newlib/libc/include/setjmp.h @@ -11,7 +11,12 @@ _BEGIN_STD_C +#ifdef __GNUC__ +void _EXFUN(longjmp,(jmp_buf __jmpb, int __retval)) + __attribute__ ((__noreturn__)); +#else void _EXFUN(longjmp,(jmp_buf __jmpb, int __retval)); +#endif int _EXFUN(setjmp,(jmp_buf __jmpb)); _END_STD_C diff --git a/contrib/sdk/sources/newlib/libc/include/stdint.h b/contrib/sdk/sources/newlib/libc/include/stdint.h index 2b4f166881..ec6a7077b7 100644 --- a/contrib/sdk/sources/newlib/libc/include/stdint.h +++ b/contrib/sdk/sources/newlib/libc/include/stdint.h @@ -10,76 +10,31 @@ #define _STDINT_H #include +#include +#include #ifdef __cplusplus extern "C" { #endif -#if __GNUC_PREREQ (3, 2) -/* gcc > 3.2 implicitly defines the values we are interested */ -#define __STDINT_EXP(x) __##x##__ -#else -#define __STDINT_EXP(x) x -#include -#endif - -/* Check if "long long" is 64bit wide */ -/* Modern GCCs provide __LONG_LONG_MAX__, SUSv3 wants LLONG_MAX */ -#if ( defined(__LONG_LONG_MAX__) && (__LONG_LONG_MAX__ > 0x7fffffff) ) \ - || ( defined(LLONG_MAX) && (LLONG_MAX > 0x7fffffff) ) -#define __have_longlong64 1 -#endif - -/* Check if "long" is 64bit or 32bit wide */ -#if __STDINT_EXP(LONG_MAX) > 0x7fffffff -#define __have_long64 1 -#elif __STDINT_EXP(LONG_MAX) == 0x7fffffff && !defined(__SPU__) -#define __have_long32 1 -#define __have_long64 0 -#endif - -#ifdef ___int8_t_defined -typedef __int8_t int8_t ; -typedef __uint8_t uint8_t ; -#define __int8_t_defined 1 -#endif - #ifdef ___int_least8_t_defined typedef __int_least8_t int_least8_t; typedef __uint_least8_t uint_least8_t; #define __int_least8_t_defined 1 #endif -#ifdef ___int16_t_defined -typedef __int16_t int16_t ; -typedef __uint16_t uint16_t ; -#define __int16_t_defined 1 -#endif - #ifdef ___int_least16_t_defined typedef __int_least16_t int_least16_t; typedef __uint_least16_t uint_least16_t; #define __int_least16_t_defined 1 #endif -#ifdef ___int32_t_defined -typedef __int32_t int32_t ; -typedef __uint32_t uint32_t ; -#define __int32_t_defined 1 -#endif - #ifdef ___int_least32_t_defined typedef __int_least32_t int_least32_t; typedef __uint_least32_t uint_least32_t; #define __int_least32_t_defined 1 #endif -#ifdef ___int64_t_defined -typedef __int64_t int64_t ; -typedef __uint64_t uint64_t ; -#define __int64_t_defined 1 -#endif - #ifdef ___int_least64_t_defined typedef __int_least64_t int_least64_t; typedef __uint_least64_t uint_least64_t; @@ -89,7 +44,7 @@ typedef __uint_least64_t uint_least64_t; /* * Fastest minimum-width integer types * - * Assume int to be the fastest type for all types with a width + * Assume int to be the fastest type for all types with a width * less than __INT_MAX__ rsp. INT_MAX */ #ifdef __INT_FAST8_TYPE__ @@ -188,27 +143,24 @@ typedef __uint_least64_t uint_least64_t; typedef unsigned long uintmax_t; #endif -typedef __intptr_t intptr_t; -typedef __uintptr_t uintptr_t; - #ifdef __INTPTR_TYPE__ #define INTPTR_MIN (-__INTPTR_MAX__ - 1) -#define INTPTR_MAX __INTPTR_MAX__ -#define UINTPTR_MAX __UINTPTR_MAX__ +#define INTPTR_MAX (__INTPTR_MAX__) +#define UINTPTR_MAX (__UINTPTR_MAX__) #elif defined(__PTRDIFF_TYPE__) #define INTPTR_MAX PTRDIFF_MAX #define INTPTR_MIN PTRDIFF_MIN #ifdef __UINTPTR_MAX__ -#define UINTPTR_MAX __UINTPTR_MAX__ +#define UINTPTR_MAX (__UINTPTR_MAX__) #else #define UINTPTR_MAX (2UL * PTRDIFF_MAX + 1) #endif #else /* - * Fallback to hardcoded values, + * Fallback to hardcoded values, * should be valid on cpu's with 32bit int/32bit void* */ -#define INTPTR_MAX __STDINT_EXP(LONG_MAX) +#define INTPTR_MAX (__STDINT_EXP(LONG_MAX)) #define INTPTR_MIN (-__STDINT_EXP(LONG_MAX) - 1) #define UINTPTR_MAX (__STDINT_EXP(LONG_MAX) * 2UL + 1) #endif @@ -217,77 +169,77 @@ typedef __uintptr_t uintptr_t; #ifdef __INT8_MAX__ #define INT8_MIN (-__INT8_MAX__ - 1) -#define INT8_MAX __INT8_MAX__ -#define UINT8_MAX __UINT8_MAX__ +#define INT8_MAX (__INT8_MAX__) +#define UINT8_MAX (__UINT8_MAX__) #elif defined(__int8_t_defined) -#define INT8_MIN -128 -#define INT8_MAX 127 -#define UINT8_MAX 255 +#define INT8_MIN (-128) +#define INT8_MAX (127) +#define UINT8_MAX (255) #endif #ifdef __INT_LEAST8_MAX__ #define INT_LEAST8_MIN (-__INT_LEAST8_MAX__ - 1) -#define INT_LEAST8_MAX __INT_LEAST8_MAX__ -#define UINT_LEAST8_MAX __UINT_LEAST8_MAX__ +#define INT_LEAST8_MAX (__INT_LEAST8_MAX__) +#define UINT_LEAST8_MAX (__UINT_LEAST8_MAX__) #elif defined(__int_least8_t_defined) -#define INT_LEAST8_MIN -128 -#define INT_LEAST8_MAX 127 -#define UINT_LEAST8_MAX 255 +#define INT_LEAST8_MIN (-128) +#define INT_LEAST8_MAX (127) +#define UINT_LEAST8_MAX (255) #else #error required type int_least8_t missing #endif #ifdef __INT16_MAX__ #define INT16_MIN (-__INT16_MAX__ - 1) -#define INT16_MAX __INT16_MAX__ -#define UINT16_MAX __UINT16_MAX__ +#define INT16_MAX (__INT16_MAX__) +#define UINT16_MAX (__UINT16_MAX__) #elif defined(__int16_t_defined) -#define INT16_MIN -32768 -#define INT16_MAX 32767 -#define UINT16_MAX 65535 +#define INT16_MIN (-32768) +#define INT16_MAX (32767) +#define UINT16_MAX (65535) #endif #ifdef __INT_LEAST16_MAX__ #define INT_LEAST16_MIN (-__INT_LEAST16_MAX__ - 1) -#define INT_LEAST16_MAX __INT_LEAST16_MAX__ -#define UINT_LEAST16_MAX __UINT_LEAST16_MAX__ +#define INT_LEAST16_MAX (__INT_LEAST16_MAX__) +#define UINT_LEAST16_MAX (__UINT_LEAST16_MAX__) #elif defined(__int_least16_t_defined) -#define INT_LEAST16_MIN -32768 -#define INT_LEAST16_MAX 32767 -#define UINT_LEAST16_MAX 65535 +#define INT_LEAST16_MIN (-32768) +#define INT_LEAST16_MAX (32767) +#define UINT_LEAST16_MAX (65535) #else #error required type int_least16_t missing #endif #ifdef __INT32_MAX__ #define INT32_MIN (-__INT32_MAX__ - 1) -#define INT32_MAX __INT32_MAX__ -#define UINT32_MAX __UINT32_MAX__ +#define INT32_MAX (__INT32_MAX__) +#define UINT32_MAX (__UINT32_MAX__) #elif defined(__int32_t_defined) -#if __have_long32 +#if defined (_INT32_EQ_LONG) #define INT32_MIN (-2147483647L-1) -#define INT32_MAX 2147483647L -#define UINT32_MAX 4294967295UL +#define INT32_MAX (2147483647L) +#define UINT32_MAX (4294967295UL) #else #define INT32_MIN (-2147483647-1) -#define INT32_MAX 2147483647 -#define UINT32_MAX 4294967295U +#define INT32_MAX (2147483647) +#define UINT32_MAX (4294967295U) #endif #endif #ifdef __INT_LEAST32_MAX__ #define INT_LEAST32_MIN (-__INT_LEAST32_MAX__ - 1) -#define INT_LEAST32_MAX __INT_LEAST32_MAX__ -#define UINT_LEAST32_MAX __UINT_LEAST32_MAX__ +#define INT_LEAST32_MAX (__INT_LEAST32_MAX__) +#define UINT_LEAST32_MAX (__UINT_LEAST32_MAX__) #elif defined(__int_least32_t_defined) -#if __have_long32 +#if defined (_INT32_EQ_LONG) #define INT_LEAST32_MIN (-2147483647L-1) -#define INT_LEAST32_MAX 2147483647L -#define UINT_LEAST32_MAX 4294967295UL +#define INT_LEAST32_MAX (2147483647L) +#define UINT_LEAST32_MAX (4294967295UL) #else #define INT_LEAST32_MIN (-2147483647-1) -#define INT_LEAST32_MAX 2147483647 -#define UINT_LEAST32_MAX 4294967295U +#define INT_LEAST32_MAX (2147483647) +#define UINT_LEAST32_MAX (4294967295U) #endif #else #error required type int_least32_t missing @@ -295,44 +247,44 @@ typedef __uintptr_t uintptr_t; #ifdef __INT64_MAX__ #define INT64_MIN (-__INT64_MAX__ - 1) -#define INT64_MAX __INT64_MAX__ -#define UINT64_MAX __UINT64_MAX__ +#define INT64_MAX (__INT64_MAX__) +#define UINT64_MAX (__UINT64_MAX__) #elif defined(__int64_t_defined) #if __have_long64 #define INT64_MIN (-9223372036854775807L-1L) -#define INT64_MAX 9223372036854775807L -#define UINT64_MAX 18446744073709551615U +#define INT64_MAX (9223372036854775807L) +#define UINT64_MAX (18446744073709551615U) #elif __have_longlong64 #define INT64_MIN (-9223372036854775807LL-1LL) -#define INT64_MAX 9223372036854775807LL -#define UINT64_MAX 18446744073709551615ULL +#define INT64_MAX (9223372036854775807LL) +#define UINT64_MAX (18446744073709551615ULL) #endif #endif #ifdef __INT_LEAST64_MAX__ #define INT_LEAST64_MIN (-__INT_LEAST64_MAX__ - 1) -#define INT_LEAST64_MAX __INT_LEAST64_MAX__ -#define UINT_LEAST64_MAX __UINT_LEAST64_MAX__ +#define INT_LEAST64_MAX (__INT_LEAST64_MAX__) +#define UINT_LEAST64_MAX (__UINT_LEAST64_MAX__) #elif defined(__int_least64_t_defined) #if __have_long64 #define INT_LEAST64_MIN (-9223372036854775807L-1L) -#define INT_LEAST64_MAX 9223372036854775807L -#define UINT_LEAST64_MAX 18446744073709551615U +#define INT_LEAST64_MAX (9223372036854775807L) +#define UINT_LEAST64_MAX (18446744073709551615U) #elif __have_longlong64 #define INT_LEAST64_MIN (-9223372036854775807LL-1LL) -#define INT_LEAST64_MAX 9223372036854775807LL -#define UINT_LEAST64_MAX 18446744073709551615ULL +#define INT_LEAST64_MAX (9223372036854775807LL) +#define UINT_LEAST64_MAX (18446744073709551615ULL) #endif #endif #ifdef __INT_FAST8_MAX__ #define INT_FAST8_MIN (-__INT_FAST8_MAX__ - 1) -#define INT_FAST8_MAX __INT_FAST8_MAX__ -#define UINT_FAST8_MAX __UINT_FAST8_MAX__ +#define INT_FAST8_MAX (__INT_FAST8_MAX__) +#define UINT_FAST8_MAX (__UINT_FAST8_MAX__) #elif defined(__int_fast8_t_defined) #if __STDINT_EXP(INT_MAX) >= 0x7f #define INT_FAST8_MIN (-__STDINT_EXP(INT_MAX)-1) -#define INT_FAST8_MAX __STDINT_EXP(INT_MAX) +#define INT_FAST8_MAX (__STDINT_EXP(INT_MAX)) #define UINT_FAST8_MAX (__STDINT_EXP(INT_MAX)*2U+1U) #else #define INT_FAST8_MIN INT_LEAST8_MIN @@ -343,12 +295,12 @@ typedef __uintptr_t uintptr_t; #ifdef __INT_FAST16_MAX__ #define INT_FAST16_MIN (-__INT_FAST16_MAX__ - 1) -#define INT_FAST16_MAX __INT_FAST16_MAX__ -#define UINT_FAST16_MAX __UINT_FAST16_MAX__ +#define INT_FAST16_MAX (__INT_FAST16_MAX__) +#define UINT_FAST16_MAX (__UINT_FAST16_MAX__) #elif defined(__int_fast16_t_defined) #if __STDINT_EXP(INT_MAX) >= 0x7fff #define INT_FAST16_MIN (-__STDINT_EXP(INT_MAX)-1) -#define INT_FAST16_MAX __STDINT_EXP(INT_MAX) +#define INT_FAST16_MAX (__STDINT_EXP(INT_MAX)) #define UINT_FAST16_MAX (__STDINT_EXP(INT_MAX)*2U+1U) #else #define INT_FAST16_MIN INT_LEAST16_MIN @@ -359,12 +311,12 @@ typedef __uintptr_t uintptr_t; #ifdef __INT_FAST32_MAX__ #define INT_FAST32_MIN (-__INT_FAST32_MAX__ - 1) -#define INT_FAST32_MAX __INT_FAST32_MAX__ -#define UINT_FAST32_MAX __UINT_FAST32_MAX__ +#define INT_FAST32_MAX (__INT_FAST32_MAX__) +#define UINT_FAST32_MAX (__UINT_FAST32_MAX__) #elif defined(__int_fast32_t_defined) #if __STDINT_EXP(INT_MAX) >= 0x7fffffff #define INT_FAST32_MIN (-__STDINT_EXP(INT_MAX)-1) -#define INT_FAST32_MAX __STDINT_EXP(INT_MAX) +#define INT_FAST32_MAX (__STDINT_EXP(INT_MAX)) #define UINT_FAST32_MAX (__STDINT_EXP(INT_MAX)*2U+1U) #else #define INT_FAST32_MIN INT_LEAST32_MIN @@ -375,12 +327,12 @@ typedef __uintptr_t uintptr_t; #ifdef __INT_FAST64_MAX__ #define INT_FAST64_MIN (-__INT_FAST64_MAX__ - 1) -#define INT_FAST64_MAX __INT_FAST64_MAX__ -#define UINT_FAST64_MAX __UINT_FAST64_MAX__ +#define INT_FAST64_MAX (__INT_FAST64_MAX__) +#define UINT_FAST64_MAX (__UINT_FAST64_MAX__) #elif defined(__int_fast64_t_defined) #if __STDINT_EXP(INT_MAX) > 0x7fffffff #define INT_FAST64_MIN (-__STDINT_EXP(INT_MAX)-1) -#define INT_FAST64_MAX __STDINT_EXP(INT_MAX) +#define INT_FAST64_MAX (__STDINT_EXP(INT_MAX)) #define UINT_FAST64_MAX (__STDINT_EXP(INT_MAX)*2U+1U) #else #define INT_FAST64_MIN INT_LEAST64_MIN @@ -390,7 +342,7 @@ typedef __uintptr_t uintptr_t; #endif #ifdef __INTMAX_MAX__ -#define INTMAX_MAX __INTMAX_MAX__ +#define INTMAX_MAX (__INTMAX_MAX__) #define INTMAX_MIN (-INTMAX_MAX - 1) #elif defined(__INTMAX_TYPE__) /* All relevant GCC versions prefer long to long long for intmax_t. */ @@ -399,7 +351,7 @@ typedef __uintptr_t uintptr_t; #endif #ifdef __UINTMAX_MAX__ -#define UINTMAX_MAX __UINTMAX_MAX__ +#define UINTMAX_MAX (__UINTMAX_MAX__) #elif defined(__UINTMAX_TYPE__) /* All relevant GCC versions prefer long to long long for intmax_t. */ #define UINTMAX_MAX UINT64_MAX @@ -407,40 +359,55 @@ typedef __uintptr_t uintptr_t; /* This must match size_t in stddef.h, currently long unsigned int */ #ifdef __SIZE_MAX__ -#define SIZE_MAX __SIZE_MAX__ +#define SIZE_MAX (__SIZE_MAX__) #else #define SIZE_MAX (__STDINT_EXP(LONG_MAX) * 2UL + 1) #endif /* This must match sig_atomic_t in (currently int) */ #define SIG_ATOMIC_MIN (-__STDINT_EXP(INT_MAX) - 1) -#define SIG_ATOMIC_MAX __STDINT_EXP(INT_MAX) +#define SIG_ATOMIC_MAX (__STDINT_EXP(INT_MAX)) /* This must match ptrdiff_t in (currently long int) */ #ifdef __PTRDIFF_MAX__ -#define PTRDIFF_MAX __PTRDIFF_MAX__ +#define PTRDIFF_MAX (__PTRDIFF_MAX__) #else -#define PTRDIFF_MAX __STDINT_EXP(LONG_MAX) +#define PTRDIFF_MAX (__STDINT_EXP(LONG_MAX)) #endif #define PTRDIFF_MIN (-PTRDIFF_MAX - 1) -#ifdef __WCHAR_MAX__ -#define WCHAR_MAX __WCHAR_MAX__ -#endif +/* This must match definition in */ +#ifndef WCHAR_MIN #ifdef __WCHAR_MIN__ -#define WCHAR_MIN __WCHAR_MIN__ +#define WCHAR_MIN (__WCHAR_MIN__) +#elif defined(__WCHAR_UNSIGNED__) || (L'\0' - 1 > 0) +#define WCHAR_MIN (0 + L'\0') +#else +#define WCHAR_MIN (-0x7fffffff - 1 + L'\0') +#endif +#endif + +/* This must match definition in */ +#ifndef WCHAR_MAX +#ifdef __WCHAR_MAX__ +#define WCHAR_MAX (__WCHAR_MAX__) +#elif defined(__WCHAR_UNSIGNED__) || (L'\0' - 1 > 0) +#define WCHAR_MAX (0xffffffffu + L'\0') +#else +#define WCHAR_MAX (0x7fffffff + L'\0') +#endif #endif /* wint_t is unsigned int on almost all GCC targets. */ #ifdef __WINT_MAX__ -#define WINT_MAX __WINT_MAX__ +#define WINT_MAX (__WINT_MAX__) #else #define WINT_MAX (__STDINT_EXP(INT_MAX) * 2U + 1U) #endif #ifdef __WINT_MIN__ -#define WINT_MIN __WINT_MIN__ +#define WINT_MIN (__WINT_MIN__) #else -#define WINT_MIN 0U +#define WINT_MIN (0U) #endif /** Macros for minimum-width integer constant expressions */ @@ -472,7 +439,7 @@ typedef __uintptr_t uintptr_t; #define INT32_C(x) __INT32_C(x) #define UINT32_C(x) __UINT32_C(x) #else -#if __have_long32 +#if defined (_INT32_EQ_LONG) #define INT32_C(x) x##L #define UINT32_C(x) x##UL #else diff --git a/contrib/sdk/sources/newlib/libc/include/stdio.h b/contrib/sdk/sources/newlib/libc/include/stdio.h index ce92a1cf23..f279c89a95 100644 --- a/contrib/sdk/sources/newlib/libc/include/stdio.h +++ b/contrib/sdk/sources/newlib/libc/include/stdio.h @@ -32,6 +32,7 @@ #define __need_size_t #define __need_NULL +#include #include #define __need___va_list @@ -48,7 +49,10 @@ _BEGIN_STD_C +#if !defined(__FILE_defined) typedef __FILE FILE; +# define __FILE_defined +#endif #ifdef __CYGWIN__ typedef _fpos64_t fpos_t; @@ -82,6 +86,7 @@ typedef _fpos64_t fpos64_t; #define __SL64 0x8000 /* is 64-bit offset large file */ /* _flags2 flags */ +#define __SNLK 0x0001 /* stdio functions do not lock streams themselves */ #define __SWID 0x2000 /* true => stream orientation wide, false => byte, only valid if __SORD in _flags is true */ /* @@ -102,7 +107,7 @@ typedef _fpos64_t fpos64_t; #ifdef __BUFSIZ__ #define BUFSIZ __BUFSIZ__ #else -#define BUFSIZ 4096 +#define BUFSIZ 1024 #endif #ifdef __FOPEN_MAX__ @@ -161,6 +166,9 @@ typedef _fpos64_t fpos64_t; FILE * _EXFUN(tmpfile, (void)); char * _EXFUN(tmpnam, (char *)); +#if __BSD_VISIBLE || __XSI_VISIBLE || __POSIX_VISIBLE >= 200112 +char * _EXFUN(tempnam, (const char *, const char *)); +#endif int _EXFUN(fclose, (FILE *)); int _EXFUN(fflush, (FILE *)); FILE * _EXFUN(freopen, (const char *__restrict, const char *__restrict, FILE *__restrict)); @@ -231,7 +239,10 @@ int _EXFUN(fseeko, (FILE *, off_t, int)); off_t _EXFUN(ftello, ( FILE *)); #endif #endif -#if !defined(__STRICT_ANSI__) || (__STDC_VERSION__ >= 199901L) +#if __GNU_VISIBLE +int _EXFUN(fcloseall, (_VOID)); +#endif +#if !defined(__STRICT_ANSI__) || (__STDC_VERSION__ >= 199901L) || (__cplusplus >= 201103L) #ifndef _REENT_ONLY int _EXFUN(asiprintf, (char **, const char *, ...) _ATTRIBUTE ((__format__ (__printf__, 2, 3)))); @@ -245,7 +256,6 @@ int _EXFUN(asprintf, (char **__restrict, const char *__restrict, ...) int _EXFUN(diprintf, (int, const char *, ...) _ATTRIBUTE ((__format__ (__printf__, 2, 3)))); #endif -int _EXFUN(fcloseall, (_VOID)); int _EXFUN(fiprintf, (FILE *, const char *, ...) _ATTRIBUTE ((__format__ (__printf__, 2, 3)))); int _EXFUN(fiscanf, (FILE *, const char *, ...) @@ -260,9 +270,8 @@ int _EXFUN(siscanf, (const char *, const char *, ...) _ATTRIBUTE ((__format__ (__scanf__, 2, 3)))); int _EXFUN(snprintf, (char *__restrict, size_t, const char *__restrict, ...) _ATTRIBUTE ((__format__ (__printf__, 3, 4)))); -int _EXFUN(sniprintf, (char *, size_t, const char *, ...) +int _EXFUN(sniprintf, (char *, size_t, const char *, ...) _ATTRIBUTE ((__format__ (__printf__, 3, 4)))); -char * _EXFUN(tempnam, (const char *, const char *)); int _EXFUN(vasiprintf, (char **, const char *, __VALIST) _ATTRIBUTE ((__format__ (__printf__, 2, 0)))); char * _EXFUN(vasniprintf, (char *, size_t *, const char *, __VALIST) @@ -336,7 +345,7 @@ FILE * _EXFUN(fmemopen, (void *__restrict, size_t, const char *__restrict)); /* getdelim - see __getdelim for now */ /* getline - see __getline for now */ FILE * _EXFUN(open_memstream, (char **, size_t *)); -#if defined (__CYGWIN__) +#if __BSD_VISIBLE || __POSIX_VISIBLE >= 200809 int _EXFUN(renameat, (int, const char *, int, const char *)); #endif int _EXFUN(vdprintf, (int, const char *__restrict, __VALIST) @@ -365,7 +374,9 @@ int _EXFUN(_fcloseall_r, (struct _reent *)); FILE * _EXFUN(_fdopen_r, (struct _reent *, int, const char *)); int _EXFUN(_fflush_r, (struct _reent *, FILE *)); int _EXFUN(_fgetc_r, (struct _reent *, FILE *)); +int _EXFUN(_fgetc_unlocked_r, (struct _reent *, FILE *)); char * _EXFUN(_fgets_r, (struct _reent *, char *__restrict, int, FILE *__restrict)); +char * _EXFUN(_fgets_unlocked_r, (struct _reent *, char *__restrict, int, FILE *__restrict)); #ifdef _COMPILING_NEWLIB int _EXFUN(_fgetpos_r, (struct _reent *, FILE *__restrict, _fpos_t *__restrict)); int _EXFUN(_fsetpos_r, (struct _reent *, FILE *, const _fpos_t *)); @@ -384,8 +395,11 @@ int _EXFUN(_fprintf_r, (struct _reent *, FILE *__restrict, const char *__restric _ATTRIBUTE ((__format__ (__printf__, 3, 4)))); int _EXFUN(_fpurge_r, (struct _reent *, FILE *)); int _EXFUN(_fputc_r, (struct _reent *, int, FILE *)); +int _EXFUN(_fputc_unlocked_r, (struct _reent *, int, FILE *)); int _EXFUN(_fputs_r, (struct _reent *, const char *__restrict, FILE *__restrict)); +int _EXFUN(_fputs_unlocked_r, (struct _reent *, const char *__restrict, FILE *__restrict)); size_t _EXFUN(_fread_r, (struct _reent *, _PTR __restrict, size_t _size, size_t _n, FILE *__restrict)); +size_t _EXFUN(_fread_unlocked_r, (struct _reent *, _PTR __restrict, size_t _size, size_t _n, FILE *__restrict)); int _EXFUN(_fscanf_r, (struct _reent *, FILE *__restrict, const char *__restrict, ...) _ATTRIBUTE ((__format__ (__scanf__, 3, 4)))); int _EXFUN(_fseek_r, (struct _reent *, FILE *, long, int)); @@ -394,6 +408,7 @@ long _EXFUN(_ftell_r, (struct _reent *, FILE *)); _off_t _EXFUN(_ftello_r,(struct _reent *, FILE *)); void _EXFUN(_rewind_r, (struct _reent *, FILE *)); size_t _EXFUN(_fwrite_r, (struct _reent *, const _PTR __restrict, size_t _size, size_t _n, FILE *__restrict)); +size_t _EXFUN(_fwrite_unlocked_r, (struct _reent *, const _PTR __restrict, size_t _size, size_t _n, FILE *__restrict)); int _EXFUN(_getc_r, (struct _reent *, FILE *)); int _EXFUN(_getc_unlocked_r, (struct _reent *, FILE *)); int _EXFUN(_getchar_r, (struct _reent *)); @@ -480,6 +495,23 @@ int _EXFUN(fpurge, (FILE *)); ssize_t _EXFUN(__getdelim, (char **, size_t *, int, FILE *)); ssize_t _EXFUN(__getline, (char **, size_t *, FILE *)); +#if __BSD_VISIBLE +void _EXFUN(clearerr_unlocked, (FILE *)); +int _EXFUN(feof_unlocked, (FILE *)); +int _EXFUN(ferror_unlocked, (FILE *)); +int _EXFUN(fileno_unlocked, (FILE *)); +int _EXFUN(fflush_unlocked, (FILE *)); +int _EXFUN(fgetc_unlocked, (FILE *)); +int _EXFUN(fputc_unlocked, (int, FILE *)); +size_t _EXFUN(fread_unlocked, (_PTR __restrict, size_t _size, size_t _n, FILE *__restrict)); +size_t _EXFUN(fwrite_unlocked, (const _PTR __restrict , size_t _size, size_t _n, FILE *)); +#endif + +#if __GNU_VISIBLE +char * _EXFUN(fgets_unlocked, (char *__restrict, int, FILE *__restrict)); +int _EXFUN(fputs_unlocked, (const char *__restrict, FILE *__restrict)); +#endif + #ifdef __LARGE64_FILES #if !defined(__CYGWIN__) || defined(_COMPILING_NEWLIB) FILE * _EXFUN(fdopen64, (int, const char *)); @@ -578,7 +610,7 @@ FILE *_EXFUN(_fopencookie_r,(struct _reent *, void *__cookie, #ifndef __CUSTOM_FILE_IO__ /* - * The __sfoo macros are here so that we can + * The __sfoo macros are here so that we can * define function versions in the C library. */ #define __sgetc_raw_r(__ptr, __f) (--(__f)->_r < 0 ? __srget_r(__ptr, __f) : (int)(*(__f)->_p++)) @@ -587,7 +619,7 @@ FILE *_EXFUN(_fopencookie_r,(struct _reent *, void *__cookie, /* For a platform with CR/LF, additional logic is required by __sgetc_r which would otherwise simply be a macro; therefore we use an inlined function. The function is only meant to be inlined - in place as used and the function body should never be emitted. + in place as used and the function body should never be emitted. There are two possible means to this end when compiling with GCC, one when compiling with a standard C99 compiler, and for other @@ -644,8 +676,8 @@ _ELIDABLE_INLINE int __sputc_r(struct _reent *_ptr, int _c, FILE *_p) { #endif #endif -#define __sfeof(p) (((p)->_flags & __SEOF) != 0) -#define __sferror(p) (((p)->_flags & __SERR) != 0) +#define __sfeof(p) ((int)(((p)->_flags & __SEOF) != 0)) +#define __sferror(p) ((int)(((p)->_flags & __SERR) != 0)) #define __sclearerr(p) ((void)((p)->_flags &= ~(__SERR|__SEOF))) #define __sfileno(p) ((p)->_file) @@ -653,6 +685,16 @@ _ELIDABLE_INLINE int __sputc_r(struct _reent *_ptr, int _c, FILE *_p) { #define feof(p) __sfeof(p) #define ferror(p) __sferror(p) #define clearerr(p) __sclearerr(p) + +#if __BSD_VISIBLE +#define feof_unlocked(p) __sfeof(p) +#define ferror_unlocked(p) __sferror(p) +#define clearerr_unlocked(p) __sclearerr(p) +#endif /* __BSD_VISIBLE */ +#endif /* _REENT_SMALL */ + +#if 0 /*ndef __STRICT_ANSI__ - FIXME: must initialize stdio first, use fn */ +#define fileno(p) __sfileno(p) #endif #ifndef __CYGWIN__ @@ -678,6 +720,11 @@ _ELIDABLE_INLINE int __sputc_r(struct _reent *_ptr, int _c, FILE *_p) { #define getchar() getc(stdin) #define putchar(x) putc(x, stdout) +#ifndef __STRICT_ANSI__ +#define getchar_unlocked() getc_unlocked(stdin) +#define putchar_unlocked(x) putc_unlocked(x, stdout) +#endif + _END_STD_C #endif /* _STDIO_H_ */ diff --git a/contrib/sdk/sources/newlib/libc/include/stdio_ext.h b/contrib/sdk/sources/newlib/libc/include/stdio_ext.h index a830c88159..029ab02535 100644 --- a/contrib/sdk/sources/newlib/libc/include/stdio_ext.h +++ b/contrib/sdk/sources/newlib/libc/include/stdio_ext.h @@ -13,49 +13,65 @@ #include +#define FSETLOCKING_QUERY 0 +#define FSETLOCKING_INTERNAL 1 +#define FSETLOCKING_BYCALLER 2 + _BEGIN_STD_C void _EXFUN(__fpurge,(FILE *)); +int _EXFUN(__fsetlocking,(FILE *, int)); /* TODO: void _flushlbf (void); - int __fsetlocking (FILE *__fp, int __type); */ #ifdef __GNUC__ -_ELIDABLE_INLINE inline size_t +_ELIDABLE_INLINE size_t __fbufsize (FILE *__fp) { return (size_t) __fp->_bf._size; } -_ELIDABLE_INLINE inline int +_ELIDABLE_INLINE int __freading (FILE *__fp) { return (__fp->_flags & __SRD) != 0; } -_ELIDABLE_INLINE inline int +_ELIDABLE_INLINE int __fwriting (FILE *__fp) { return (__fp->_flags & __SWR) != 0; } -_ELIDABLE_INLINE inline int +_ELIDABLE_INLINE int __freadable (FILE *__fp) { return (__fp->_flags & (__SRD | __SRW)) != 0; } -_ELIDABLE_INLINE inline int -__fwriteable (FILE *__fp) { return (__fp->_flags & (__SWR | __SRW)) != 0; } +_ELIDABLE_INLINE int +__fwritable (FILE *__fp) { return (__fp->_flags & (__SWR | __SRW)) != 0; } -_ELIDABLE_INLINE inline int +_ELIDABLE_INLINE int __flbf (FILE *__fp) { return (__fp->_flags & __SLBF) != 0; } -_ELIDABLE_INLINE inline size_t +_ELIDABLE_INLINE size_t __fpending (FILE *__fp) { return __fp->_p - __fp->_bf._base; } #else +size_t _EXFUN(__fbufsize,(FILE *)); +int _EXFUN(__freading,(FILE *)); +int _EXFUN(__fwriting,(FILE *)); +int _EXFUN(__freadable,(FILE *)); +int _EXFUN(__fwritable,(FILE *)); +int _EXFUN(__flbf,(FILE *)); +size_t _EXFUN(__fpending,(FILE *)); + +#ifndef __cplusplus + #define __fbufsize(__fp) ((size_t) (__fp)->_bf._size) #define __freading(__fp) (((__fp)->_flags & __SRD) != 0) #define __fwriting(__fp) (((__fp)->_flags & __SWR) != 0) #define __freadable(__fp) (((__fp)->_flags & (__SRD | __SRW)) != 0) -#define __fwriteable(__fp) (((__fp)->_flags & (__SWR | __SRW)) != 0) +#define __fwritable(__fp) (((__fp)->_flags & (__SWR | __SRW)) != 0) #define __flbf(__fp) (((__fp)->_flags & __SLBF) != 0) #define __fpending(__fp) ((size_t) ((__fp)->_p - (__fp)->_bf._base)) +#endif /* __cplusplus */ + #endif /* __GNUC__ */ _END_STD_C diff --git a/contrib/sdk/sources/newlib/libc/include/stdlib.h b/contrib/sdk/sources/newlib/libc/include/stdlib.h index 901277f28e..9c1dc77969 100644 --- a/contrib/sdk/sources/newlib/libc/include/stdlib.h +++ b/contrib/sdk/sources/newlib/libc/include/stdlib.h @@ -16,6 +16,7 @@ #include #include +#include #include #ifndef __STRICT_ANSI__ #include @@ -27,13 +28,13 @@ _BEGIN_STD_C -typedef struct +typedef struct { int quot; /* quotient */ int rem; /* remainder */ } div_t; -typedef struct +typedef struct { long quot; /* quotient */ long rem; /* remainder */ @@ -63,7 +64,7 @@ int _EXFUN(__locale_mb_cur_max,(_VOID)); #define MB_CUR_MAX __locale_mb_cur_max() -_VOID _EXFUN(abort,(_VOID) _ATTRIBUTE ((noreturn))); +_VOID _EXFUN(abort,(_VOID) _ATTRIBUTE ((__noreturn__))); int _EXFUN(abs,(int)); int _EXFUN(atexit,(_VOID (*__func)(_VOID))); double _EXFUN(atof,(const char *__nptr)); @@ -81,7 +82,7 @@ _PTR _EXFUN(bsearch,(const _PTR __key, __compar_fn_t _compar)); _PTR _EXFUN_NOTHROW(calloc,(size_t __nmemb, size_t __size)); div_t _EXFUN(div,(int __numer, int __denom)); -_VOID _EXFUN(exit,(int __status) _ATTRIBUTE ((noreturn))); +_VOID _EXFUN(exit,(int __status) _ATTRIBUTE ((__noreturn__))); _VOID _EXFUN_NOTHROW(free,(_PTR)); char * _EXFUN(getenv,(const char *__string)); char * _EXFUN(_getenv_r,(struct _reent *, const char *__string)); @@ -111,14 +112,14 @@ int _EXFUN(mkostemp,(char *, int)); int _EXFUN(mkostemps,(char *, int, int)); int _EXFUN(mkstemp,(char *)); int _EXFUN(mkstemps,(char *, int)); -char * _EXFUN(mktemp,(char *) _ATTRIBUTE ((__warning__ ("the use of `mktemp' is dangerous; use `mkstemp' instead")))); +char * _EXFUN(mktemp,(char *) _ATTRIBUTE ((__deprecated__("the use of `mktemp' is dangerous; use `mkstemp' instead")))); #endif char * _EXFUN(_mkdtemp_r, (struct _reent *, char *)); int _EXFUN(_mkostemp_r, (struct _reent *, char *, int)); int _EXFUN(_mkostemps_r, (struct _reent *, char *, int, int)); int _EXFUN(_mkstemp_r, (struct _reent *, char *)); int _EXFUN(_mkstemps_r, (struct _reent *, char *, int)); -char * _EXFUN(_mktemp_r, (struct _reent *, char *) _ATTRIBUTE ((__warning__ ("the use of `mktemp' is dangerous; use `mkstemp' instead")))); +char * _EXFUN(_mktemp_r, (struct _reent *, char *) _ATTRIBUTE ((__deprecated__("the use of `mktemp' is dangerous; use `mkstemp' instead")))); #endif _VOID _EXFUN(qsort,(_PTR __base, size_t __nmemb, size_t __size, __compar_fn_t _compar)); int _EXFUN(rand,(_VOID)); @@ -126,16 +127,19 @@ _PTR _EXFUN_NOTHROW(realloc,(_PTR __r, size_t __size)); #ifndef __STRICT_ANSI__ _PTR _EXFUN(reallocf,(_PTR __r, size_t __size)); char * _EXFUN(realpath, (const char *__restrict path, char *__restrict resolved_path)); +int _EXFUN(rpmatch, (const char *response)); #endif _VOID _EXFUN(srand,(unsigned __seed)); double _EXFUN(strtod,(const char *__restrict __n, char **__restrict __end_PTR)); double _EXFUN(_strtod_r,(struct _reent *,const char *__restrict __n, char **__restrict __end_PTR)); -#if !defined(__STRICT_ANSI__) || (__STDC_VERSION__ >= 199901L) || (__cplusplus >= 201103L) +#if !defined(__STRICT_ANSI__) || \ + (defined(__STDC_VERSION__) && __STDC_VERSION__ >= 199901L) || \ + (defined(__cplusplus) && __cplusplus >= 201103L) float _EXFUN(strtof,(const char *__restrict __n, char **__restrict __end_PTR)); #endif #ifndef __STRICT_ANSI__ /* the following strtodf interface is deprecated...use strtof instead */ -# ifndef strtodf +# ifndef strtodf # define strtodf strtof # endif #endif @@ -151,7 +155,13 @@ long _EXFUN(a64l,(const char *__input)); char * _EXFUN(l64a,(long __input)); char * _EXFUN(_l64a_r,(struct _reent *,long __input)); int _EXFUN(on_exit,(_VOID (*__func)(int, _PTR),_PTR __arg)); -_VOID _EXFUN(_Exit,(int __status) _ATTRIBUTE ((noreturn))); +#endif /* ! __STRICT_ANSI__ */ +#if !defined(__STRICT_ANSI__) || \ + (defined(__STDC_VERSION__) && __STDC_VERSION__ >= 199901L) || \ + (defined(__cplusplus) && __cplusplus >= 201103L) +_VOID _EXFUN(_Exit,(int __status) _ATTRIBUTE ((__noreturn__))); +#endif +#ifndef __STRICT_ANSI__ int _EXFUN(putenv,(char *__string)); int _EXFUN(_putenv_r,(struct _reent *, char *__string)); _PTR _EXFUN(_reallocf_r,(struct _reent *, _PTR, size_t)); @@ -167,6 +177,12 @@ char * _EXFUN(ecvtbuf,(double, int, int*, int*, char *)); char * _EXFUN(fcvtbuf,(double, int, int*, int*, char *)); char * _EXFUN(ecvtf,(float,int,int *,int *)); char * _EXFUN(dtoa,(double, int, int, int *, int*, char**)); +#endif +char * _EXFUN(__itoa,(int, char *, int)); +char * _EXFUN(__utoa,(unsigned, char *, int)); +#ifndef __STRICT_ANSI__ +char * _EXFUN(itoa,(int, char *, int)); +char * _EXFUN(utoa,(unsigned, char *, int)); int _EXFUN(rand_r,(unsigned *__seed)); double _EXFUN(drand48,(_VOID)); @@ -189,18 +205,28 @@ unsigned short * _EXFUN(_seed48_r,(struct _reent *, unsigned short [3])); _VOID _EXFUN(srand48,(long)); _VOID _EXFUN(_srand48_r,(struct _reent *, long)); +#endif /* ! __STRICT_ANSI__ */ +#if !defined(__STRICT_ANSI__) || \ + (defined(__STDC_VERSION__) && __STDC_VERSION__ >= 199901L) || \ + (defined(__cplusplus) && __cplusplus >= 201103L) long long _EXFUN(atoll,(const char *__nptr)); +#endif +#ifndef __STRICT_ANSI__ long long _EXFUN(_atoll_r,(struct _reent *, const char *__nptr)); +#endif /* ! __STRICT_ANSI__ */ +#if !defined(__STRICT_ANSI__) || \ + (defined(__STDC_VERSION__) && __STDC_VERSION__ >= 199901L) || \ + (defined(__cplusplus) && __cplusplus >= 201103L) long long _EXFUN(llabs,(long long)); lldiv_t _EXFUN(lldiv,(long long __numer, long long __denom)); -#endif /* ! __STRICT_ANSI__ */ -#if !defined(__STRICT_ANSI__) || (__STDC_VERSION__ >= 199901L) || (__cplusplus >= 201103L) long long _EXFUN(strtoll,(const char *__restrict __n, char **__restrict __end_PTR, int __base)); #endif #ifndef __STRICT_ANSI__ long long _EXFUN(_strtoll_r,(struct _reent *, const char *__restrict __n, char **__restrict __end_PTR, int __base)); #endif /* ! __STRICT_ANSI__ */ -#if !defined(__STRICT_ANSI__) || (__STDC_VERSION__ >= 199901L) || (__cplusplus >= 201103L) +#if !defined(__STRICT_ANSI__) || \ + (defined(__STDC_VERSION__) && __STDC_VERSION__ >= 199901L) || \ + (defined(__cplusplus) && __cplusplus >= 201103L) unsigned long long _EXFUN(strtoull,(const char *__restrict __n, char **__restrict __end_PTR, int __base)); #endif #ifndef __STRICT_ANSI__ @@ -230,12 +256,42 @@ int _EXFUN(_system_r,(struct _reent *, const char *)); _VOID _EXFUN(__eprintf,(const char *, const char *, unsigned int, const char *)); +/* There are two common qsort_r variants. If you request + _BSD_SOURCE, you get the BSD version; otherwise you get the GNU + version. We want that #undef qsort_r will still let you + invoke the underlying function, but that requires gcc support. */ +#ifdef _BSD_SOURCE +# ifdef __GNUC__ +_VOID _EXFUN(qsort_r,(_PTR __base, size_t __nmemb, size_t __size, _PTR __thunk, int (*_compar)(_PTR, const _PTR, const _PTR))) + __asm__ (__ASMNAME ("__bsd_qsort_r")); +# else +_VOID _EXFUN(__bsd_qsort_r,(_PTR __base, size_t __nmemb, size_t __size, _PTR __thunk, int (*_compar)(_PTR, const _PTR, const _PTR))); +# define qsort_r __bsd_qsort_r +# endif +#elif __GNU_VISIBLE +_VOID _EXFUN(qsort_r,(_PTR __base, size_t __nmemb, size_t __size, int (*_compar)(const _PTR, const _PTR, _PTR), _PTR __thunk)); +#endif + /* On platforms where long double equals double. */ -#ifdef _LDBL_EQ_DBL -#if !defined(__STRICT_ANSI__) || (__STDC_VERSION__ >= 199901L) || (__cplusplus >= 201103L) +#ifdef _HAVE_LONG_DOUBLE +extern long double _strtold_r (struct _reent *, const char *__restrict, char **__restrict); +#if !defined(__STRICT_ANSI__) || \ + (defined(__STDC_VERSION__) && __STDC_VERSION__ >= 199901L) || \ + (defined(__cplusplus) && __cplusplus >= 201103L) extern long double strtold (const char *__restrict, char **__restrict); #endif -#endif /* _LDBL_EQ_DBL */ +#endif /* _HAVE_LONG_DOUBLE */ + +/* + * If we're in a mode greater than C99, expose C11 functions. + */ +#if __ISO_C_VISIBLE >= 2011 || __cplusplus >= 201103L +void * aligned_alloc(size_t, size_t) __malloc_like __alloc_align(1) + __alloc_size(2); +int at_quick_exit(void (*)(void)); +_Noreturn void + quick_exit(int); +#endif /* __ISO_C_VISIBLE >= 2011 */ _END_STD_C diff --git a/contrib/sdk/sources/newlib/libc/include/string.h b/contrib/sdk/sources/newlib/libc/include/string.h index 752fff0d0c..80940cf1d9 100644 --- a/contrib/sdk/sources/newlib/libc/include/string.h +++ b/contrib/sdk/sources/newlib/libc/include/string.h @@ -38,74 +38,116 @@ char *_EXFUN(strpbrk,(const char *, const char *)); char *_EXFUN(strrchr,(const char *, int)); size_t _EXFUN(strspn,(const char *, const char *)); char *_EXFUN(strstr,(const char *, const char *)); - #ifndef _REENT_ONLY char *_EXFUN(strtok,(char *__restrict, const char *__restrict)); #endif - size_t _EXFUN(strxfrm,(char *__restrict, const char *__restrict, size_t)); -#ifndef __STRICT_ANSI__ +#if __POSIX_VISIBLE char *_EXFUN(strtok_r,(char *__restrict, const char *__restrict, char **__restrict)); - +#endif +#if __BSD_VISIBLE int _EXFUN(bcmp,(const void *, const void *, size_t)); void _EXFUN(bcopy,(const void *, void *, size_t)); void _EXFUN(bzero,(void *, size_t)); int _EXFUN(ffs,(int)); char *_EXFUN(index,(const char *, int)); +#endif +#if __BSD_VISIBLE || __XSI_VISIBLE _PTR _EXFUN(memccpy,(_PTR __restrict, const _PTR __restrict, int, size_t)); +#endif +#if __GNU_VISIBLE _PTR _EXFUN(mempcpy,(_PTR, const _PTR, size_t)); _PTR _EXFUN(memmem, (const _PTR, size_t, const _PTR, size_t)); +#endif _PTR _EXFUN(memrchr,(const _PTR, int, size_t)); +#if __GNU_VISIBLE _PTR _EXFUN(rawmemchr,(const _PTR, int)); +#endif +#if __BSD_VISIBLE char *_EXFUN(rindex,(const char *, int)); +#endif char *_EXFUN(stpcpy,(char *__restrict, const char *__restrict)); char *_EXFUN(stpncpy,(char *__restrict, const char *__restrict, size_t)); +#if __BSD_VISIBLE || __POSIX_VISIBLE int _EXFUN(strcasecmp,(const char *, const char *)); +#endif +#if __GNU_VISIBLE char *_EXFUN(strcasestr,(const char *, const char *)); char *_EXFUN(strchrnul,(const char *, int)); #endif -#if !defined(__STRICT_ANSI__) || (_XOPEN_SOURCE - 0) >= 500 +#if __XSI_VISIBLE >= 500 char *_EXFUN(strdup,(const char *)); #endif #ifndef __STRICT_ANSI__ char *_EXFUN(_strdup_r,(struct _reent *, const char *)); #endif -#if !defined(__STRICT_ANSI__) || (_XOPEN_SOURCE - 0) >= 700 +#if __XSI_VISIBLE >= 700 char *_EXFUN(strndup,(const char *, size_t)); #endif + #ifndef __STRICT_ANSI__ char *_EXFUN(_strndup_r,(struct _reent *, const char *, size_t)); +#endif + +#if __GNU_VISIBLE +int _EXFUN(ffsl,(long)); +int _EXFUN(ffsll, (long long)); +#endif + /* There are two common strerror_r variants. If you request _GNU_SOURCE, you get the GNU version; otherwise you get the POSIX version. POSIX requires that #undef strerror_r will still let you invoke the underlying function, but that requires gcc support. */ -#ifdef _GNU_SOURCE -char *_EXFUN(strerror_r,(int, char *, size_t)); +#if __GNU_VISIBLE +char *_EXFUN(strerror_r,(int, char *, size_t)); #else # ifdef __GNUC__ -int _EXFUN(strerror_r,(int, char *, size_t)) __asm__ (__ASMNAME ("__xpg_strerror_r")); +int _EXFUN(strerror_r,(int, char *, size_t)) +#ifdef __ASMNAME + __asm__ (__ASMNAME ("__xpg_strerror_r")) +#endif + ; # else -int _EXFUN(__xpg_strerror_r,(int, char *, size_t)); +int _EXFUN(__xpg_strerror_r,(int, char *, size_t)); # define strerror_r __xpg_strerror_r # endif #endif -size_t _EXFUN(strlcat,(char *, const char *, size_t)); -size_t _EXFUN(strlcpy,(char *, const char *, size_t)); -int _EXFUN(strncasecmp,(const char *, const char *, size_t)); -size_t _EXFUN(strnlen,(const char *, size_t)); -char *_EXFUN(strsep,(char **, const char *)); -char *_EXFUN(strlwr,(char *)); -char *_EXFUN(strupr,(char *)); -#ifndef DEFS_H /* Kludge to work around problem compiling in gdb */ -char *_EXFUN(strsignal, (int __signo)); + +/* Reentrant version of strerror. */ +char * _EXFUN(_strerror_r, (struct _reent *, int, int, int *)); + +#if __BSD_VISIBLE +size_t _EXFUN(strlcat,(char *, const char *, size_t)); +size_t _EXFUN(strlcpy,(char *, const char *, size_t)); #endif -#ifdef __CYGWIN__ -int _EXFUN(strtosigno, (const char *__name)); +#if __BSD_VISIBLE || __POSIX_VISIBLE +int _EXFUN(strncasecmp,(const char *, const char *, size_t)); +#endif +#if !defined(__STRICT_ANSI__) || __POSIX_VISIBLE >= 200809 || \ + __XSI_VISIBLE >= 700 +size_t _EXFUN(strnlen,(const char *, size_t)); +#endif +#if __BSD_VISIBLE +char *_EXFUN(strsep,(char **, const char *)); #endif -/* Recursive version of strerror. */ -char * _EXFUN(_strerror_r, (struct _reent *, int, int, int *)); +/* + * The origin of these is unknown to me so I am conditionalizing them + * on __STRICT_ANSI__. Finetuning this is definitely needed. --joel + */ +#if !defined(__STRICT_ANSI__) +char *_EXFUN(strlwr,(char *)); +char *_EXFUN(strupr,(char *)); +#endif + +#ifndef DEFS_H /* Kludge to work around problem compiling in gdb */ +char *_EXFUN(strsignal, (int __signo)); +#endif + +#ifdef __CYGWIN__ +int _EXFUN(strtosigno, (const char *__name)); +#endif #if defined _GNU_SOURCE && defined __GNUC__ #define strdupa(__s) \ @@ -121,21 +163,21 @@ char * _EXFUN(_strerror_r, (struct _reent *, int, int, int *)); (char *) memcpy (__out, __in, __len-1);})) #endif /* _GNU_SOURCE && __GNUC__ */ -/* These function names are used on Windows and perhaps other systems. */ -#ifndef strcmpi -#define strcmpi strcasecmp -#endif -#ifndef stricmp -#define stricmp strcasecmp -#endif -#ifndef strncmpi -#define strncmpi strncasecmp -#endif -#ifndef strnicmp -#define strnicmp strncasecmp -#endif +/* There are two common basename variants. If you do NOT #include + and you do -#endif /* ! __STRICT_ANSI__ */ + #define _GNU_SOURCE + #include + + you get the GNU version. Otherwise you get the POSIX versionfor which you + should #include i for the function prototype. POSIX requires that + #undef basename will still let you invoke the underlying function. However, + this also implies that the POSIX version is used in this case. That's made + sure here. */ +#if __GNU_VISIBLE && !defined(basename) +# define basename basename +char *_EXFUN(__nonnull (1) basename,(const char *)) __asm__(__ASMNAME("__gnu_basename")); +#endif #include diff --git a/contrib/sdk/sources/newlib/libc/include/sys/_default_fcntl.h b/contrib/sdk/sources/newlib/libc/include/sys/_default_fcntl.h index 998c8e11b8..a65057e2da 100644 --- a/contrib/sdk/sources/newlib/libc/include/sys/_default_fcntl.h +++ b/contrib/sdk/sources/newlib/libc/include/sys/_default_fcntl.h @@ -5,6 +5,7 @@ extern "C" { #endif #define _SYS__DEFAULT_FCNTL_H_ #include <_ansi.h> +#include #define _FOPEN (-1) /* from sys/file.h, kernel use only */ #define _FREAD 0x0001 /* read enabled */ #define _FWRITE 0x0002 /* write enabled */ @@ -134,7 +135,7 @@ extern "C" { #define F_UNLKSYS 4 /* remove remote locks for a given system */ #endif /* !_POSIX_SOURCE */ -#ifdef __CYGWIN__ +#if __BSD_VISIBLE || __POSIX_VISIBLE >= 200809 || defined(__CYGWIN__) /* Special descriptor value to denote the cwd in calls to openat(2) etc. */ #define AT_FDCWD -2 @@ -145,6 +146,14 @@ extern "C" { #define AT_REMOVEDIR 8 #endif +#if __BSD_VISIBLE +/* lock operations for flock(2) */ +#define LOCK_SH 0x01 /* shared file lock */ +#define LOCK_EX 0x02 /* exclusive file lock */ +#define LOCK_NB 0x04 /* don't block when locking */ +#define LOCK_UN 0x08 /* unlock file */ +#endif + /*#include */ #ifndef __CYGWIN__ @@ -173,17 +182,21 @@ struct eflock { }; #endif /* !_POSIX_SOURCE */ - #include #include /* sigh. for the mode bits for open/creat */ extern int open _PARAMS ((const char *, int, ...)); +#if __BSD_VISIBLE || __POSIX_VISIBLE >= 200809 || defined(__CYGWIN__) +extern int openat _PARAMS ((int, const char *, int, ...)); +#endif extern int creat _PARAMS ((const char *, mode_t)); extern int fcntl _PARAMS ((int, int, ...)); +#if __BSD_VISIBLE +extern int flock _PARAMS ((int, int)); +#endif #ifdef __CYGWIN__ #include extern int futimesat _PARAMS ((int, const char *, const struct timeval *)); -extern int openat _PARAMS ((int, const char *, int, ...)); #endif /* Provide _ prototypes for functions provided by some versions diff --git a/contrib/sdk/sources/newlib/libc/include/sys/_intsup.h b/contrib/sdk/sources/newlib/libc/include/sys/_intsup.h new file mode 100644 index 0000000000..b979d5c4df --- /dev/null +++ b/contrib/sdk/sources/newlib/libc/include/sys/_intsup.h @@ -0,0 +1,209 @@ +/* + * Copyright (c) 2004, 2005 by + * Ralf Corsepius, Ulm/Germany. All rights reserved. + * + * Permission to use, copy, modify, and distribute this software + * is freely granted, provided that this notice is preserved. + */ + +#ifndef _SYS__INTSUP_H +#define _SYS__INTSUP_H + +#include + +#if __GNUC_PREREQ (3, 2) +/* gcc > 3.2 implicitly defines the values we are interested */ +#define __STDINT_EXP(x) __##x##__ +#else +#define __STDINT_EXP(x) x +#include +#endif + +/* Check if "long long" is 64bit wide */ +/* Modern GCCs provide __LONG_LONG_MAX__, SUSv3 wants LLONG_MAX */ +#if ( defined(__LONG_LONG_MAX__) && (__LONG_LONG_MAX__ > 0x7fffffff) ) \ + || ( defined(LLONG_MAX) && (LLONG_MAX > 0x7fffffff) ) +#define __have_longlong64 1 +#endif + +/* Check if "long" is 64bit or 32bit wide */ +#if __STDINT_EXP(LONG_MAX) > 0x7fffffff +#define __have_long64 1 +#elif __STDINT_EXP(LONG_MAX) == 0x7fffffff && !defined(__SPU__) +#define __have_long32 1 +#endif + +/* Determine how intptr_t and intN_t fastN_t and leastN_t are defined by gcc + for this target. This is used to determine the correct printf() constant in + inttypes.h and other constants in stdint.h. + So we end up with + ?(signed|unsigned) char == 0 + ?(signed|unsigned) short == 1 + ?(signed|unsigned) int == 2 + ?(signed|unsigned) short int == 3 + ?(signed|unsigned) long == 4 + ?(signed|unsigned) long int == 6 + ?(signed|unsigned) long long == 8 + ?(signed|unsigned) long long int == 10 + */ +#pragma push_macro("signed") +#pragma push_macro("unsigned") +#pragma push_macro("char") +#pragma push_macro("short") +#pragma push_macro("__int20") +#pragma push_macro("int") +#pragma push_macro("long") +#undef signed +#undef unsigned +#undef char +#undef short +#undef int +#undef __int20 +#undef long +#define signed +0 +#define unsigned +0 +#define char +0 +#define short +1 +#define __int20 +2 +#define int +2 +#define long +4 +#if (__INTPTR_TYPE__ == 8 || __INTPTR_TYPE__ == 10) +#define _INTPTR_EQ_LONGLONG +#elif (__INTPTR_TYPE__ == 4 || __INTPTR_TYPE__ == 6) +#define _INTPTR_EQ_LONG +/* Note - the tests for _INTPTR_EQ_INT and _INTPTR_EQ_SHORT are currently + redundant as the values are not used. But one day they may be needed + and so the tests remain. */ +#elif __INTPTR_TYPE__ == 2 +#define _INTPTR_EQ_INT +#elif (__INTPTR_TYPE__ == 1 || __INTPTR_TYPE__ == 3) +#define _INTPTR_EQ_SHORT +#else +#error "Unable to determine type definition of intptr_t" +#endif +#if (__INT32_TYPE__ == 4 || __INT32_TYPE__ == 6) +#define _INT32_EQ_LONG +#elif __INT32_TYPE__ == 2 +/* Nothing to define because int32_t is safe to print as an int. */ +#else +#error "Unable to determine type definition of int32_t" +#endif + +#if (__INT8_TYPE__ == 0) +#define __INT8 "hh" +#elif (__INT8_TYPE__ == 1 || __INT8_TYPE__ == 3) +#define __INT8 "h" +#elif (__INT8_TYPE__ == 2) +#define __INT8 +#elif (__INT8_TYPE__ == 4 || __INT8_TYPE__ == 6) +#define __INT8 "l" +#elif (__INT8_TYPE__ == 8 || __INT8_TYPE__ == 10) +#define __INT8 "ll" +#endif +#if (__INT16_TYPE__ == 1 || __INT16_TYPE__ == 3) +#define __INT16 "h" +#elif (__INT16_TYPE__ == 2) +#define __INT16 +#elif (__INT16_TYPE__ == 4 || __INT16_TYPE__ == 6) +#define __INT16 "l" +#elif (__INT16_TYPE__ == 8 || __INT16_TYPE__ == 10) +#define __INT16 "ll" +#endif +#if (__INT32_TYPE__ == 2) +#define __INT32 +#elif (__INT32_TYPE__ == 4 || __INT32_TYPE__ == 6) +#define __INT32 "l" +#elif (__INT32_TYPE__ == 8 || __INT32_TYPE__ == 10) +#define __INT32 "ll" +#endif +#if (__INT64_TYPE__ == 2) +#define __INT64 +#elif (__INT64_TYPE__ == 4 || __INT64_TYPE__ == 6) +#define __INT64 "l" +#elif (__INT64_TYPE__ == 8 || __INT64_TYPE__ == 10) +#define __INT64 "ll" +#endif +#if (__INT_FAST8_TYPE__ == 0) +#define __FAST8 "hh" +#elif (__INT_FAST8_TYPE__ == 1 || __INT_FAST8_TYPE__ == 3) +#define __FAST8 "h" +#elif (__INT_FAST8_TYPE__ == 2) +#define __FAST8 +#elif (__INT_FAST8_TYPE__ == 4 || __INT_FAST8_TYPE__ == 6) +#define __FAST8 "l" +#elif (__INT_FAST8_TYPE__ == 8 || __INT_FAST8_TYPE__ == 10) +#define __FAST8 "ll" +#endif +#if (__INT_FAST16_TYPE__ == 1 || __INT_FAST16_TYPE__ == 3) +#define __FAST16 "h" +#elif (__INT_FAST16_TYPE__ == 2) +#define __FAST16 +#elif (__INT_FAST16_TYPE__ == 4 || __INT_FAST16_TYPE__ == 6) +#define __FAST16 "l" +#elif (__INT_FAST16_TYPE__ == 8 || __INT_FAST16_TYPE__ == 10) +#define __FAST16 "ll" +#endif +#if (__INT_FAST32_TYPE__ == 2) +#define __FAST32 +#elif (__INT_FAST32_TYPE__ == 4 || __INT_FAST32_TYPE__ == 6) +#define __FAST32 "l" +#elif (__INT_FAST32_TYPE__ == 8 || __INT_FAST32_TYPE__ == 10) +#define __FAST32 "ll" +#endif +#if (__INT_FAST64_TYPE__ == 2) +#define __FAST64 +#elif (__INT_FAST64_TYPE__ == 4 || __INT_FAST64_TYPE__ == 6) +#define __FAST64 "l" +#elif (__INT_FAST64_TYPE__ == 8 || __INT_FAST64_TYPE__ == 10) +#define __FAST64 "ll" +#endif + +#if (__INT_LEAST8_TYPE__ == 0) +#define __LEAST8 "hh" +#elif (__INT_LEAST8_TYPE__ == 1 || __INT_LEAST8_TYPE__ == 3) +#define __LEAST8 "h" +#elif (__INT_LEAST8_TYPE__ == 2) +#define __LEAST8 +#elif (__INT_LEAST8_TYPE__ == 4 || __INT_LEAST8_TYPE__ == 6) +#define __LEAST8 "l" +#elif (__INT_LEAST8_TYPE__ == 8 || __INT_LEAST8_TYPE__ == 10) +#define __LEAST8 "ll" +#endif +#if (__INT_LEAST16_TYPE__ == 1 || __INT_LEAST16_TYPE__ == 3) +#define __LEAST16 "h" +#elif (__INT_LEAST16_TYPE__ == 2) +#define __LEAST16 +#elif (__INT_LEAST16_TYPE__ == 4 || __INT_LEAST16_TYPE__ == 6) +#define __LEAST16 "l" +#elif (__INT_LEAST16_TYPE__ == 8 || __INT_LEAST16_TYPE__ == 10) +#define __LEAST16 "ll" +#endif +#if (__INT_LEAST32_TYPE__ == 2) +#define __LEAST32 +#elif (__INT_LEAST32_TYPE__ == 4 || __INT_LEAST32_TYPE__ == 6) +#define __LEAST32 "l" +#elif (__INT_LEAST32_TYPE__ == 8 || __INT_LEAST32_TYPE__ == 10) +#define __LEAST32 "ll" +#endif +#if (__INT_LEAST64_TYPE__ == 2) +#define __LEAST64 +#elif (__INT_LEAST64_TYPE__ == 4 || __INT_LEAST64_TYPE__ == 6) +#define __LEAST64 "l" +#elif (__INT_LEAST64_TYPE__ == 8 || __INT_LEAST64_TYPE__ == 10) +#define __LEAST64 "ll" +#endif +#undef signed +#undef unsigned +#undef char +#undef short +#undef int +#undef long +#pragma pop_macro("signed") +#pragma pop_macro("unsigned") +#pragma pop_macro("char") +#pragma pop_macro("short") +#pragma pop_macro("__int20") +#pragma pop_macro("int") +#pragma pop_macro("long") + +#endif /* _SYS__INTSUP_H */ diff --git a/contrib/sdk/sources/newlib/libc/include/sys/_sigset.h b/contrib/sdk/sources/newlib/libc/include/sys/_sigset.h new file mode 100644 index 0000000000..a9c0d2d4e2 --- /dev/null +++ b/contrib/sdk/sources/newlib/libc/include/sys/_sigset.h @@ -0,0 +1,43 @@ +/*- + * Copyright (c) 1982, 1986, 1989, 1991, 1993 + * The Regents of the University of California. All rights reserved. + * (c) UNIX System Laboratories, Inc. + * All or some portions of this file are derived from material licensed + * to the University of California by American Telephone and Telegraph + * Co. or Unix System Laboratories, Inc. and are reproduced herein with + * the permission of UNIX System Laboratories, Inc. + * + * 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. + * 4. 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. + * + * @(#)signal.h 8.4 (Berkeley) 5/4/95 + * $FreeBSD$ + */ + +#ifndef _SYS__SIGSET_H_ +#define _SYS__SIGSET_H_ + +typedef unsigned long __sigset_t; + +#endif /* !_SYS__SIGSET_H_ */ diff --git a/contrib/sdk/sources/newlib/libc/include/sys/_stdint.h b/contrib/sdk/sources/newlib/libc/include/sys/_stdint.h new file mode 100644 index 0000000000..add1860c5c --- /dev/null +++ b/contrib/sdk/sources/newlib/libc/include/sys/_stdint.h @@ -0,0 +1,49 @@ +/* + * Copyright (c) 2004, 2005 by + * Ralf Corsepius, Ulm/Germany. All rights reserved. + * + * Permission to use, copy, modify, and distribute this software + * is freely granted, provided that this notice is preserved. + */ + +#ifndef _SYS__STDINT_H +#define _SYS__STDINT_H + +#include + +#ifdef __cplusplus +extern "C" { +#endif + +#ifdef ___int8_t_defined +typedef __int8_t int8_t ; +typedef __uint8_t uint8_t ; +#define __int8_t_defined 1 +#endif + +#ifdef ___int16_t_defined +typedef __int16_t int16_t ; +typedef __uint16_t uint16_t ; +#define __int16_t_defined 1 +#endif + +#ifdef ___int32_t_defined +typedef __int32_t int32_t ; +typedef __uint32_t uint32_t ; +#define __int32_t_defined 1 +#endif + +#ifdef ___int64_t_defined +typedef __int64_t int64_t ; +typedef __uint64_t uint64_t ; +#define __int64_t_defined 1 +#endif + +typedef __intptr_t intptr_t; +typedef __uintptr_t uintptr_t; + +#ifdef __cplusplus +} +#endif + +#endif /* _SYS__STDINT_H */ diff --git a/contrib/sdk/sources/newlib/libc/include/sys/_timespec.h b/contrib/sdk/sources/newlib/libc/include/sys/_timespec.h new file mode 100644 index 0000000000..bd66dfc710 --- /dev/null +++ b/contrib/sdk/sources/newlib/libc/include/sys/_timespec.h @@ -0,0 +1,49 @@ +/*- + * Copyright (c) 1982, 1986, 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. + * 4. 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. + * + * @(#)time.h 8.5 (Berkeley) 5/4/95 + * from: FreeBSD: src/sys/sys/time.h,v 1.43 2000/03/20 14:09:05 phk Exp + * $FreeBSD$ + */ + +#ifndef _SYS__TIMESPEC_H_ +#define _SYS__TIMESPEC_H_ + +#include + +#ifndef __time_t_defined +typedef _TIME_T_ time_t; +#define __time_t_defined +#endif + +struct timespec { + time_t tv_sec; /* seconds */ + long tv_nsec; /* and nanoseconds */ +}; + +#endif /* !_SYS__TIMESPEC_H_ */ diff --git a/contrib/sdk/sources/newlib/libc/include/sys/_timeval.h b/contrib/sdk/sources/newlib/libc/include/sys/_timeval.h new file mode 100644 index 0000000000..0a4c539d98 --- /dev/null +++ b/contrib/sdk/sources/newlib/libc/include/sys/_timeval.h @@ -0,0 +1,88 @@ +/*- + * Copyright (c) 2002 Mike Barcroft + * 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. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR 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 AUTHOR 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. + * + * $FreeBSD$ + */ + +#ifndef _SYS__TIMEVAL_H_ +#define _SYS__TIMEVAL_H_ + +#include + +#ifndef _SUSECONDS_T_DECLARED +typedef __suseconds_t suseconds_t; +#define _SUSECONDS_T_DECLARED +#endif + +#ifndef __time_t_defined +typedef _TIME_T_ time_t; +#define __time_t_defined +#endif + +/* This define is also used outside of Newlib, e.g. in MinGW-w64 */ +#ifndef _TIMEVAL_DEFINED +#define _TIMEVAL_DEFINED + +/* + * Structure returned by gettimeofday(2) system call, and used in other calls. + */ +struct timeval { + time_t tv_sec; /* seconds */ + suseconds_t tv_usec; /* and microseconds */ +}; + +#if __BSD_VISIBLE +#ifndef _KERNEL /* NetBSD/OpenBSD compatible interfaces */ + +#define timerclear(tvp) ((tvp)->tv_sec = (tvp)->tv_usec = 0) +#define timerisset(tvp) ((tvp)->tv_sec || (tvp)->tv_usec) +#define timercmp(tvp, uvp, cmp) \ + (((tvp)->tv_sec == (uvp)->tv_sec) ? \ + ((tvp)->tv_usec cmp (uvp)->tv_usec) : \ + ((tvp)->tv_sec cmp (uvp)->tv_sec)) +#define timeradd(tvp, uvp, vvp) \ + do { \ + (vvp)->tv_sec = (tvp)->tv_sec + (uvp)->tv_sec; \ + (vvp)->tv_usec = (tvp)->tv_usec + (uvp)->tv_usec; \ + if ((vvp)->tv_usec >= 1000000) { \ + (vvp)->tv_sec++; \ + (vvp)->tv_usec -= 1000000; \ + } \ + } while (0) +#define timersub(tvp, uvp, vvp) \ + do { \ + (vvp)->tv_sec = (tvp)->tv_sec - (uvp)->tv_sec; \ + (vvp)->tv_usec = (tvp)->tv_usec - (uvp)->tv_usec; \ + if ((vvp)->tv_usec < 0) { \ + (vvp)->tv_sec--; \ + (vvp)->tv_usec += 1000000; \ + } \ + } while (0) +#endif +#endif /* __BSD_VISIBLE */ + +#endif /* _TIMEVAL_DEFINED */ + +#endif /* !_SYS__TIMEVAL_H_ */ diff --git a/contrib/sdk/sources/newlib/libc/include/sys/cdefs.h b/contrib/sdk/sources/newlib/libc/include/sys/cdefs.h index 4641263344..e7d825fe65 100644 --- a/contrib/sdk/sources/newlib/libc/include/sys/cdefs.h +++ b/contrib/sdk/sources/newlib/libc/include/sys/cdefs.h @@ -69,7 +69,9 @@ /* * Testing against Clang-specific extensions. */ - +#ifndef __has_attribute +#define __has_attribute(x) 0 +#endif #ifndef __has_extension #define __has_extension __has_feature #endif @@ -100,33 +102,33 @@ #if defined(__GNUC__) || defined(__INTEL_COMPILER) #if __GNUC__ >= 3 || defined(__INTEL_COMPILER) -#define __GNUCLIKE_ASM 3 -#define __GNUCLIKE_MATH_BUILTIN_CONSTANTS +#define __GNUCLIKE_ASM 3 +#define __GNUCLIKE_MATH_BUILTIN_CONSTANTS #else -#define __GNUCLIKE_ASM 2 +#define __GNUCLIKE_ASM 2 #endif -#define __GNUCLIKE___TYPEOF 1 -#define __GNUCLIKE___OFFSETOF 1 -#define __GNUCLIKE___SECTION 1 +#define __GNUCLIKE___TYPEOF 1 +#define __GNUCLIKE___OFFSETOF 1 +#define __GNUCLIKE___SECTION 1 #ifndef __INTEL_COMPILER -# define __GNUCLIKE_CTOR_SECTION_HANDLING 1 +#define __GNUCLIKE_CTOR_SECTION_HANDLING 1 #endif -#define __GNUCLIKE_BUILTIN_CONSTANT_P 1 -# if defined(__INTEL_COMPILER) && defined(__cplusplus) \ - && __INTEL_COMPILER < 800 -# undef __GNUCLIKE_BUILTIN_CONSTANT_P -# endif +#define __GNUCLIKE_BUILTIN_CONSTANT_P 1 +#if defined(__INTEL_COMPILER) && defined(__cplusplus) && \ + __INTEL_COMPILER < 800 +#undef __GNUCLIKE_BUILTIN_CONSTANT_P +#endif -#if (__GNUC_MINOR__ > 95 || __GNUC__ >= 3) && !defined(__INTEL_COMPILER) -# define __GNUCLIKE_BUILTIN_VARARGS 1 -# define __GNUCLIKE_BUILTIN_STDARG 1 -# define __GNUCLIKE_BUILTIN_VAALIST 1 +#if (__GNUC_MINOR__ > 95 || __GNUC__ >= 3) +#define __GNUCLIKE_BUILTIN_VARARGS 1 +#define __GNUCLIKE_BUILTIN_STDARG 1 +#define __GNUCLIKE_BUILTIN_VAALIST 1 #endif #if defined(__GNUC__) -# define __GNUC_VA_LIST_COMPATIBILITY 1 +#define __GNUC_VA_LIST_COMPATIBILITY 1 #endif /* @@ -137,23 +139,23 @@ #endif #ifndef __INTEL_COMPILER -# define __GNUCLIKE_BUILTIN_NEXT_ARG 1 -# define __GNUCLIKE_MATH_BUILTIN_RELOPS +#define __GNUCLIKE_BUILTIN_NEXT_ARG 1 +#define __GNUCLIKE_MATH_BUILTIN_RELOPS #endif -#define __GNUCLIKE_BUILTIN_MEMCPY 1 +#define __GNUCLIKE_BUILTIN_MEMCPY 1 /* XXX: if __GNUC__ >= 2: not tested everywhere originally, where replaced */ -#define __CC_SUPPORTS_INLINE 1 -#define __CC_SUPPORTS___INLINE 1 -#define __CC_SUPPORTS___INLINE__ 1 +#define __CC_SUPPORTS_INLINE 1 +#define __CC_SUPPORTS___INLINE 1 +#define __CC_SUPPORTS___INLINE__ 1 -#define __CC_SUPPORTS___FUNC__ 1 -#define __CC_SUPPORTS_WARNING 1 +#define __CC_SUPPORTS___FUNC__ 1 +#define __CC_SUPPORTS_WARNING 1 -#define __CC_SUPPORTS_VARADIC_XXX 1 /* see varargs.h */ +#define __CC_SUPPORTS_VARADIC_XXX 1 /* see varargs.h */ -#define __CC_SUPPORTS_DYNAMIC_ARRAY_INIT 1 +#define __CC_SUPPORTS_DYNAMIC_ARRAY_INIT 1 #endif /* __GNUC__ || __INTEL_COMPILER */ @@ -171,10 +173,10 @@ */ #if defined(__STDC__) || defined(__cplusplus) #define __P(protos) protos /* full-blown ANSI C */ -#define __CONCAT1(x,y) x ## y -#define __CONCAT(x,y) __CONCAT1(x,y) -#define __STRING(x) #x /* stringify without expanding x */ -#define __XSTRING(x) __STRING(x) /* expand x, then stringify */ +#define __CONCAT1(x,y) x ## y +#define __CONCAT(x,y) __CONCAT1(x,y) +#define __STRING(x) #x /* stringify without expanding x */ +#define __XSTRING(x) __STRING(x) /* expand x, then stringify */ #define __const const /* define reserved names to standard */ #define __signed signed @@ -229,8 +231,12 @@ #define __unused #define __packed #define __aligned(x) +#define __alloc_align(x) +#define __alloc_size(x) #define __section(x) +#define __weak_symbol #else +#define __weak_symbol __attribute__((__weak__)) #if !__GNUC_PREREQ__(2, 5) && !defined(__INTEL_COMPILER) #define __dead2 #define __pure2 @@ -242,7 +248,7 @@ #define __unused /* XXX Find out what to do for __packed, __aligned and __section */ #endif -#if __GNUC_PREREQ__(2, 7) +#if __GNUC_PREREQ__(2, 7) || defined(__INTEL_COMPILER) #define __dead2 __attribute__((__noreturn__)) #define __pure2 __attribute__((__const__)) #define __unused __attribute__((__unused__)) @@ -251,16 +257,17 @@ #define __aligned(x) __attribute__((__aligned__(x))) #define __section(x) __attribute__((__section__(x))) #endif -#if defined(__INTEL_COMPILER) -#define __dead2 __attribute__((__noreturn__)) -#define __pure2 __attribute__((__const__)) -#define __unused __attribute__((__unused__)) -#define __used __attribute__((__used__)) -#define __packed __attribute__((__packed__)) -#define __aligned(x) __attribute__((__aligned__(x))) -#define __section(x) __attribute__((__section__(x))) +#if __GNUC_PREREQ__(4, 3) || __has_attribute(__alloc_size__) +#define __alloc_size(x) __attribute__((__alloc_size__(x))) +#else +#define __alloc_size(x) #endif +#if __GNUC_PREREQ__(4, 9) || __has_attribute(__alloc_align__) +#define __alloc_align(x) __attribute__((__alloc_align__(x))) +#else +#define __alloc_align(x) #endif +#endif /* lint */ #if !__GNUC_PREREQ__(2, 95) #define __alignof(x) __offsetof(struct { char __a; x __b; }, __b) @@ -270,7 +277,7 @@ * Keywords added in C11. */ -#if !defined(__STDC_VERSION__) || __STDC_VERSION__ < 201112L +#if !defined(__STDC_VERSION__) || __STDC_VERSION__ < 201112L || defined(lint) #if !__has_extension(c_alignas) #if (defined(__cplusplus) && __cplusplus >= 201103L) || \ @@ -302,23 +309,28 @@ #define _Noreturn __dead2 #endif -#if __GNUC_PREREQ__(4, 6) && !defined(__cplusplus) -/* Do nothing: _Static_assert() works as per C11 */ -#elif !__has_extension(c_static_assert) +#if !__has_extension(c_static_assert) #if (defined(__cplusplus) && __cplusplus >= 201103L) || \ __has_extension(cxx_static_assert) #define _Static_assert(x, y) static_assert(x, y) +#elif __GNUC_PREREQ__(4,6) +/* Nothing, gcc 4.6 and higher has _Static_assert built-in */ #elif defined(__COUNTER__) #define _Static_assert(x, y) __Static_assert(x, __COUNTER__) #define __Static_assert(x, y) ___Static_assert(x, y) -#define ___Static_assert(x, y) typedef char __assert_ ## y[(x) ? 1 : -1] +#define ___Static_assert(x, y) typedef char __assert_ ## y[(x) ? 1 : -1] \ + __unused #else #define _Static_assert(x, y) struct __hack #endif #endif #if !__has_extension(c_thread_local) -/* XXX: Change this to test against C++11 when clang in base supports it. */ +/* + * XXX: Some compilers (Clang 3.3, GCC 4.7) falsely announce C++11 mode + * without actually supporting the thread_local keyword. Don't check for + * the presence of C++11 when defining _Thread_local. + */ #if /* (defined(__cplusplus) && __cplusplus >= 201103L) || */ \ __has_extension(cxx_thread_local) #define _Thread_local thread_local @@ -338,7 +350,8 @@ * distinguish multiple cases. */ -#if defined(__STDC_VERSION__) && __STDC_VERSION__ >= 201112L +#if (defined(__STDC_VERSION__) && __STDC_VERSION__ >= 201112L) || \ + __has_extension(c_generic_selections) #define __generic(expr, t, yes, no) \ _Generic(expr, t: yes, default: no) #elif __GNUC_PREREQ__(3, 1) && !defined(__cplusplus) @@ -368,15 +381,19 @@ #endif #if __GNUC_PREREQ__(3, 3) -#define __nonnull(x) __attribute__((__nonnull__(x))) +#define __nonnull(x) __attribute__((__nonnull__(x))) +#define __nonnull_all __attribute__((__nonnull__)) #else -#define __nonnull(x) +#define __nonnull(x) +#define __nonnull_all #endif #if __GNUC_PREREQ__(3, 4) #define __fastcall __attribute__((__fastcall__)) +#define __result_use_check __attribute__((__warn_unused_result__)) #else #define __fastcall +#define __result_use_check #endif #if __GNUC_PREREQ__(4, 1) @@ -385,6 +402,12 @@ #define __returns_twice #endif +#if __GNUC_PREREQ__(4, 6) || __has_builtin(__builtin_unreachable) +#define __unreachable() __builtin_unreachable() +#else +#define __unreachable() ((void)0) +#endif + /* XXX: should use `#if __STDC_VERSION__ < 199901'. */ #if !__GNUC_PREREQ__(2, 7) && !defined(__INTEL_COMPILER) #define __func__ NULL @@ -433,19 +456,21 @@ * larger code. */ #if __GNUC_PREREQ__(2, 96) -#define __predict_true(exp) __builtin_expect((exp), 1) -#define __predict_false(exp) __builtin_expect((exp), 0) +#define __predict_true(exp) __builtin_expect((exp), 1) +#define __predict_false(exp) __builtin_expect((exp), 0) #else -#define __predict_true(exp) (exp) -#define __predict_false(exp) (exp) +#define __predict_true(exp) (exp) +#define __predict_false(exp) (exp) #endif -#if __GNUC_PREREQ__(4, 2) -#define __hidden __attribute__((__visibility__("hidden"))) +#if __GNUC_PREREQ__(4, 0) +#define __sentinel __attribute__((__sentinel__)) #define __exported __attribute__((__visibility__("default"))) +#define __hidden __attribute__((__visibility__("hidden"))) #else -#define __hidden +#define __sentinel #define __exported +#define __hidden #endif #define __offsetof(type, field) offsetof(type, field) @@ -460,7 +485,7 @@ */ #if __GNUC_PREREQ__(3, 1) #define __containerof(x, s, m) ({ \ - const volatile __typeof__(((s *)0)->m) *__x = (x); \ + const volatile __typeof(((s *)0)->m) *__x = (x); \ __DEQUALIFY(s *, (const volatile char *)__x - __offsetof(s, m));\ }) #else @@ -492,6 +517,22 @@ __attribute__((__format__ (__strftime__, fmtarg, firstvararg))) #endif +/* + * FORTIFY_SOURCE, and perhaps other compiler-specific features, require + * the use of non-standard inlining. In general we should try to avoid + * using these but GCC-compatible compilers tend to support the extensions + * well enough to use them in limited cases. + */ +#if defined(__GNUC_GNU_INLINE__) || defined(__GNUC_STDC_INLINE__) +#if __GNUC_PREREQ__(4, 3) || __has_attribute(__artificial__) +#define __gnu_inline __attribute__((__gnu_inline__, __artificial__)) +#else +#define __gnu_inline __attribute__((__gnu_inline__)) +#endif /* artificial */ +#else +#define __gnu_inline +#endif + /* Compiler-dependent macros that rely on FreeBSD-specific extensions. */ #if defined(__FreeBSD_cc_version) && __FreeBSD_cc_version >= 300001 && \ defined(__GNUC__) && !defined(__INTEL_COMPILER) @@ -606,6 +647,14 @@ * Our macros begin with two underscores to avoid namespace screwage. */ +/* Deal with _GNU_SOURCE, which implies everything and the kitchen sink */ +#ifdef _GNU_SOURCE +#undef _XOPEN_SOURCE +#define _XOPEN_SOURCE 700 +#define __BSD_VISIBLE 1 +#define __GNU_VISIBLE 1 +#endif + /* Deal with IEEE Std. 1003.1-1990, in which _POSIX_C_SOURCE == 1. */ #if defined(_POSIX_C_SOURCE) && _POSIX_C_SOURCE == 1 #undef _POSIX_C_SOURCE /* Probably illegal, but beyond caring now. */ @@ -693,12 +742,6 @@ #define __XSI_VISIBLE 0 #define __BSD_VISIBLE 0 #define __ISO_C_VISIBLE 2011 -#elif defined(_GNU_SOURCE) /* Everything and the kitchen sink. */ -#define __POSIX_VISIBLE 200809 -#define __XSI_VISIBLE 700 -#define __BSD_VISIBLE 1 -#define __ISO_C_VISIBLE 2011 -#define __GNU_VISIBLE 1 #else /* Default: everything except __GNU_VISIBLE. */ #define __POSIX_VISIBLE 200809 #define __XSI_VISIBLE 700 @@ -707,4 +750,79 @@ #endif #endif +/* + * Type Safety Checking + * + * Clang provides additional attributes to enable checking type safety + * properties that cannot be enforced by the C type system. + */ + +#if __has_attribute(__argument_with_type_tag__) && \ + __has_attribute(__type_tag_for_datatype__) && !defined(lint) +#define __arg_type_tag(arg_kind, arg_idx, type_tag_idx) \ + __attribute__((__argument_with_type_tag__(arg_kind, arg_idx, type_tag_idx))) +#define __datatype_type_tag(kind, type) \ + __attribute__((__type_tag_for_datatype__(kind, type))) +#else +#define __arg_type_tag(arg_kind, arg_idx, type_tag_idx) +#define __datatype_type_tag(kind, type) +#endif + +/* + * Lock annotations. + * + * Clang provides support for doing basic thread-safety tests at + * compile-time, by marking which locks will/should be held when + * entering/leaving a functions. + * + * Furthermore, it is also possible to annotate variables and structure + * members to enforce that they are only accessed when certain locks are + * held. + */ + +#if __has_extension(c_thread_safety_attributes) +#define __lock_annotate(x) __attribute__((x)) +#else +#define __lock_annotate(x) +#endif + +/* Structure implements a lock. */ +#define __lockable __lock_annotate(lockable) + +/* Function acquires an exclusive or shared lock. */ +#define __locks_exclusive(...) \ + __lock_annotate(exclusive_lock_function(__VA_ARGS__)) +#define __locks_shared(...) \ + __lock_annotate(shared_lock_function(__VA_ARGS__)) + +/* Function attempts to acquire an exclusive or shared lock. */ +#define __trylocks_exclusive(...) \ + __lock_annotate(exclusive_trylock_function(__VA_ARGS__)) +#define __trylocks_shared(...) \ + __lock_annotate(shared_trylock_function(__VA_ARGS__)) + +/* Function releases a lock. */ +#define __unlocks(...) __lock_annotate(unlock_function(__VA_ARGS__)) + +/* Function asserts that an exclusive or shared lock is held. */ +#define __asserts_exclusive(...) \ + __lock_annotate(assert_exclusive_lock(__VA_ARGS__)) +#define __asserts_shared(...) \ + __lock_annotate(assert_shared_lock(__VA_ARGS__)) + +/* Function requires that an exclusive or shared lock is or is not held. */ +#define __requires_exclusive(...) \ + __lock_annotate(exclusive_locks_required(__VA_ARGS__)) +#define __requires_shared(...) \ + __lock_annotate(shared_locks_required(__VA_ARGS__)) +#define __requires_unlocked(...) \ + __lock_annotate(locks_excluded(__VA_ARGS__)) + +/* Function should not be analyzed. */ +#define __no_lock_analysis __lock_annotate(no_thread_safety_analysis) + +/* Guard variables and structure members by lock. */ +#define __guarded_by(x) __lock_annotate(guarded_by(x)) +#define __pt_guarded_by(x) __lock_annotate(pt_guarded_by(x)) + #endif /* !_SYS_CDEFS_H_ */ diff --git a/contrib/sdk/sources/newlib/libc/include/sys/config.h b/contrib/sdk/sources/newlib/libc/include/sys/config.h index 70bae14724..b9a4571c52 100644 --- a/contrib/sdk/sources/newlib/libc/include/sys/config.h +++ b/contrib/sdk/sources/newlib/libc/include/sys/config.h @@ -75,6 +75,10 @@ #define _POINTER_INT short #endif +#if defined(__m68k__) || defined(__mc68000__) +#define _READ_WRITE_RETURN_TYPE _ssize_t +#endif + #ifdef ___AM29K__ #define _FLOAT_RET double #endif @@ -181,6 +185,10 @@ #define __CUSTOM_FILE_IO__ #endif +#if defined(__or1k__) || defined(__or1knd__) +#define __DYNAMIC_REENT__ +#endif + /* This block should be kept in sync with GCC's limits.h. The point of having these definitions here is to not include limits.h, which would pollute the user namespace, while still using types of the diff --git a/contrib/sdk/sources/newlib/libc/include/sys/errno.h b/contrib/sdk/sources/newlib/libc/include/sys/errno.h index 3f42e45335..4c9fdafa83 100644 --- a/contrib/sdk/sources/newlib/libc/include/sys/errno.h +++ b/contrib/sdk/sources/newlib/libc/include/sys/errno.h @@ -28,7 +28,7 @@ extern __IMPORT char *program_invocation_short_name; #define __errno_r(ptr) ((ptr)->_errno) -#define EPERM 1 /* Not super-user */ +#define EPERM 1 /* Not owner */ #define ENOENT 2 /* No such file or directory */ #define ESRCH 3 /* No such process */ #define EINTR 4 /* Interrupted system call */ @@ -39,13 +39,13 @@ extern __IMPORT char *program_invocation_short_name; #define EBADF 9 /* Bad file number */ #define ECHILD 10 /* No children */ #define EAGAIN 11 /* No more processes */ -#define ENOMEM 12 /* Not enough core */ +#define ENOMEM 12 /* Not enough space */ #define EACCES 13 /* Permission denied */ #define EFAULT 14 /* Bad address */ #ifdef __LINUX_ERRNO_EXTENSIONS__ #define ENOTBLK 15 /* Block device required */ #endif -#define EBUSY 16 /* Mount device busy */ +#define EBUSY 16 /* Device or resource busy */ #define EEXIST 17 /* File exists */ #define EXDEV 18 /* Cross-device link */ #define ENODEV 19 /* No such device */ @@ -53,17 +53,17 @@ extern __IMPORT char *program_invocation_short_name; #define EISDIR 21 /* Is a directory */ #define EINVAL 22 /* Invalid argument */ #define ENFILE 23 /* Too many open files in system */ -#define EMFILE 24 /* Too many open files */ -#define ENOTTY 25 /* Not a typewriter */ +#define EMFILE 24 /* File descriptor value too large */ +#define ENOTTY 25 /* Not a character device */ #define ETXTBSY 26 /* Text file busy */ #define EFBIG 27 /* File too large */ #define ENOSPC 28 /* No space left on device */ #define ESPIPE 29 /* Illegal seek */ -#define EROFS 30 /* Read only file system */ +#define EROFS 30 /* Read-only file system */ #define EMLINK 31 /* Too many links */ #define EPIPE 32 /* Broken pipe */ -#define EDOM 33 /* Math arg out of domain of func */ -#define ERANGE 34 /* Math result not representable */ +#define EDOM 33 /* Mathematics argument out of domain of function */ +#define ERANGE 34 /* Result too large */ #define ENOMSG 35 /* No message of desired type */ #define EIDRM 36 /* Identifier removed */ #ifdef __LINUX_ERRNO_EXTENSIONS__ @@ -76,8 +76,8 @@ extern __IMPORT char *program_invocation_short_name; #define ENOCSI 43 /* No CSI structure available */ #define EL2HLT 44 /* Level 2 halted */ #endif -#define EDEADLK 45 /* Deadlock condition */ -#define ENOLCK 46 /* No record locks available */ +#define EDEADLK 45 /* Deadlock */ +#define ENOLCK 46 /* No lock */ #ifdef __LINUX_ERRNO_EXTENSIONS__ #define EBADE 50 /* Invalid exchange */ #define EBADR 51 /* Invalid request descriptor */ @@ -88,16 +88,16 @@ extern __IMPORT char *program_invocation_short_name; #define EDEADLOCK 56 /* File locking deadlock error */ #define EBFONT 57 /* Bad font file fmt */ #endif -#define ENOSTR 60 /* Device not a stream */ +#define ENOSTR 60 /* Not a stream */ #define ENODATA 61 /* No data (for no delay io) */ -#define ETIME 62 /* Timer expired */ -#define ENOSR 63 /* Out of streams resources */ +#define ETIME 62 /* Stream ioctl timeout */ +#define ENOSR 63 /* No stream resources */ #ifdef __LINUX_ERRNO_EXTENSIONS__ #define ENONET 64 /* Machine is not on the network */ #define ENOPKG 65 /* Package not installed */ #define EREMOTE 66 /* The object is remote */ #endif -#define ENOLINK 67 /* The link has been severed */ +#define ENOLINK 67 /* Virtual circuit is gone */ #ifdef __LINUX_ERRNO_EXTENSIONS__ #define EADV 68 /* Advertise error */ #define ESRMNT 69 /* Srmount error */ @@ -109,7 +109,7 @@ extern __IMPORT char *program_invocation_short_name; #define ELBIN 75 /* Inode is remote (not really error) */ #define EDOTDOT 76 /* Cross mount point (not really error) */ #endif -#define EBADMSG 77 /* Trying to read unreadable message */ +#define EBADMSG 77 /* Bad message */ #define EFTYPE 79 /* Inappropriate file type or format */ #ifdef __LINUX_ERRNO_EXTENSIONS__ #define ENOTUNIQ 80 /* Given log. name not unique */ @@ -128,7 +128,7 @@ extern __IMPORT char *program_invocation_short_name; #define ENOTEMPTY 90 /* Directory not empty */ #define ENAMETOOLONG 91 /* File or path name too long */ #define ELOOP 92 /* Too many symbolic links */ -#define EOPNOTSUPP 95 /* Operation not supported on transport endpoint */ +#define EOPNOTSUPP 95 /* Operation not supported on socket */ #define EPFNOSUPPORT 96 /* Protocol family not supported */ #define ECONNRESET 104 /* Connection reset by peer */ #define ENOBUFS 105 /* No buffer space available */ @@ -141,7 +141,7 @@ extern __IMPORT char *program_invocation_short_name; #endif #define ECONNREFUSED 111 /* Connection refused */ #define EADDRINUSE 112 /* Address already in use */ -#define ECONNABORTED 113 /* Connection aborted */ +#define ECONNABORTED 113 /* Software caused connection abort */ #define ENETUNREACH 114 /* Network is unreachable */ #define ENETDOWN 115 /* Network interface is not configured */ #define ETIMEDOUT 116 /* Connection timed out */ @@ -156,7 +156,7 @@ extern __IMPORT char *program_invocation_short_name; #define ESOCKTNOSUPPORT 124 /* Socket type not supported */ #endif #define EADDRNOTAVAIL 125 /* Address not available */ -#define ENETRESET 126 +#define ENETRESET 126 /* Connection aborted by network */ #define EISCONN 127 /* Socket is already connected */ #define ENOTCONN 128 /* Socket is not connected */ #define ETOOMANYREFS 129 @@ -174,7 +174,7 @@ extern __IMPORT char *program_invocation_short_name; #define ENOSHARE 136 /* No such host or network path */ #define ECASECLASH 137 /* Filename exists with different case */ #endif -#define EILSEQ 138 +#define EILSEQ 138 /* Illegal byte sequence */ #define EOVERFLOW 139 /* Value too large for defined data type */ #define ECANCELED 140 /* Operation canceled */ #define ENOTRECOVERABLE 141 /* State not recoverable */ diff --git a/contrib/sdk/sources/newlib/libc/include/sys/features.h b/contrib/sdk/sources/newlib/libc/include/sys/features.h index 74a2cb8e12..cbfc7454d3 100644 --- a/contrib/sdk/sources/newlib/libc/include/sys/features.h +++ b/contrib/sdk/sources/newlib/libc/include/sys/features.h @@ -1,7 +1,7 @@ /* * Written by Joel Sherrill . * - * COPYRIGHT (c) 1989-2000. + * COPYRIGHT (c) 1989-2014. * * On-Line Applications Research Corporation (OAR). * @@ -15,7 +15,7 @@ * OR WARRANTY OF ANY KIND CONCERNING THE MERCHANTABILITY OF THIS * SOFTWARE OR ITS FITNESS FOR ANY PARTICULAR PURPOSE. * - * $Id: features.h,v 1.30 2013/04/23 09:42:25 corinna Exp $ + * $Id$ */ #ifndef _SYS_FEATURES_H @@ -25,6 +25,12 @@ extern "C" { #endif +/* Macros to determine that newlib is being used. Put in this header to + * be similar to where glibc stores its version of these macros. + */ +#define __NEWLIB__ 2 +#define __NEWLIB_MINOR__ 2 + /* Macro to test version of GCC. Returns 0 for non-GCC or too old GCC. */ #ifndef __GNUC_PREREQ # if defined __GNUC__ && defined __GNUC_MINOR__ diff --git a/contrib/sdk/sources/newlib/libc/include/sys/param.h b/contrib/sdk/sources/newlib/libc/include/sys/param.h index 4eaf670353..e311cb6f9e 100644 --- a/contrib/sdk/sources/newlib/libc/include/sys/param.h +++ b/contrib/sdk/sources/newlib/libc/include/sys/param.h @@ -10,6 +10,9 @@ #include #include +#ifndef NBBY +# define NBBY 8 /* number of bits in a byte */ +#endif #ifndef HZ # define HZ (60) #endif @@ -25,4 +28,8 @@ #define MAX(a,b) ((a) > (b) ? (a) : (b)) #define MIN(a,b) ((a) < (b) ? (a) : (b)) +#ifndef howmany +#define howmany(x, y) (((x)+((y)-1))/(y)) +#endif + #endif diff --git a/contrib/sdk/sources/newlib/libc/include/sys/queue.h b/contrib/sdk/sources/newlib/libc/include/sys/queue.h index 1b19e92535..301bbf0741 100644 --- a/contrib/sdk/sources/newlib/libc/include/sys/queue.h +++ b/contrib/sdk/sources/newlib/libc/include/sys/queue.h @@ -77,28 +77,28 @@ * For details on the use of these macros, see the queue(3) manual page. * * - * SLIST LIST STAILQ TAILQ - * _HEAD + + + + - * _HEAD_INITIALIZER + + + + - * _ENTRY + + + + - * _INIT + + + + - * _EMPTY + + + + - * _FIRST + + + + - * _NEXT + + + + + * SLIST LIST STAILQ TAILQ + * _HEAD + + + + + * _HEAD_INITIALIZER + + + + + * _ENTRY + + + + + * _INIT + + + + + * _EMPTY + + + + + * _FIRST + + + + + * _NEXT + + + + * _PREV - + - + - * _LAST - - + + - * _FOREACH + + + + + * _LAST - - + + + * _FOREACH + + + + * _FOREACH_SAFE + + + + - * _FOREACH_REVERSE - - - + + * _FOREACH_REVERSE - - - + * _FOREACH_REVERSE_SAFE - - - + - * _INSERT_HEAD + + + + - * _INSERT_BEFORE - + - + - * _INSERT_AFTER + + + + - * _INSERT_TAIL - - + + - * _CONCAT - - + + + * _INSERT_HEAD + + + + + * _INSERT_BEFORE - + - + + * _INSERT_AFTER + + + + + * _INSERT_TAIL - - + + + * _CONCAT - - + + * _REMOVE_AFTER + - + - - * _REMOVE_HEAD + - + - - * _REMOVE + + + + + * _REMOVE_HEAD + - + - + * _REMOVE + + + + * _SWAP + + + + * */ @@ -149,12 +149,12 @@ struct name { \ #define SLIST_HEAD_INITIALIZER(head) \ { NULL } - + #define SLIST_ENTRY(type) \ struct { \ struct type *sle_next; /* next element */ \ } - + /* * Singly-linked List functions. */ diff --git a/contrib/sdk/sources/newlib/libc/include/sys/reent.h b/contrib/sdk/sources/newlib/libc/include/sys/reent.h index 45b96aad9e..d59dccd86e 100644 --- a/contrib/sdk/sources/newlib/libc/include/sys/reent.h +++ b/contrib/sdk/sources/newlib/libc/include/sys/reent.h @@ -446,9 +446,8 @@ extern const struct __sFILE_fake __sf_fake_stderr; _NULL \ } -#define _REENT_INIT_PTR(var) \ - { memset((var), 0, sizeof(*(var))); \ - (var)->_stdin = (__FILE *)&__sf_fake_stdin; \ +#define _REENT_INIT_PTR_ZEROED(var) \ + { (var)->_stdin = (__FILE *)&__sf_fake_stdin; \ (var)->_stdout = (__FILE *)&__sf_fake_stdout; \ (var)->_stderr = (__FILE *)&__sf_fake_stderr; \ (var)->_current_locale = "C"; \ @@ -694,9 +693,8 @@ struct _reent {_NULL, 0, _NULL} \ } -#define _REENT_INIT_PTR(var) \ - { memset((var), 0, sizeof(*(var))); \ - (var)->_stdin = &(var)->__sf[0]; \ +#define _REENT_INIT_PTR_ZEROED(var) \ + { (var)->_stdin = &(var)->__sf[0]; \ (var)->_stdout = &(var)->__sf[1]; \ (var)->_stderr = &(var)->__sf[2]; \ (var)->_current_locale = "C"; \ @@ -745,6 +743,11 @@ struct _reent #endif /* !_REENT_SMALL */ +#define _REENT_INIT_PTR(var) \ + { memset((var), 0, sizeof(*(var))); \ + _REENT_INIT_PTR_ZEROED(var); \ + } + /* This value is used in stdlib/misc.c. reent/reent.c has to know it as well to make sure the freelist is correctly free'd. Therefore we define it here, rather than in stdlib/misc.c, as before. */ diff --git a/contrib/sdk/sources/newlib/libc/include/sys/resource.h b/contrib/sdk/sources/newlib/libc/include/sys/resource.h index 152e331f02..29a140853c 100644 --- a/contrib/sdk/sources/newlib/libc/include/sys/resource.h +++ b/contrib/sdk/sources/newlib/libc/include/sys/resource.h @@ -11,5 +11,7 @@ struct rusage { struct timeval ru_stime; /* system time used */ }; +int _EXFUN(getrusage, (int, struct rusage*)); + #endif diff --git a/contrib/sdk/sources/newlib/libc/include/sys/sched.h b/contrib/sdk/sources/newlib/libc/include/sys/sched.h index 88b6163e8f..e8adf83d90 100644 --- a/contrib/sdk/sources/newlib/libc/include/sys/sched.h +++ b/contrib/sdk/sources/newlib/libc/include/sys/sched.h @@ -14,13 +14,15 @@ * OR WARRANTY OF ANY KIND CONCERNING THE MERCHANTABILITY OF THIS * SOFTWARE OR ITS FITNESS FOR ANY PARTICULAR PURPOSE. * - * $Id: sched.h,v 1.3 2010/04/01 18:33:37 jjohnstn Exp $ + * $Id$ */ #ifndef _SYS_SCHED_H_ #define _SYS_SCHED_H_ +#include + #ifdef __cplusplus extern "C" { #endif @@ -60,7 +62,7 @@ struct sched_param { #ifdef __cplusplus } -#endif +#endif #endif /* end of include file */ diff --git a/contrib/sdk/sources/newlib/libc/include/sys/select.h b/contrib/sdk/sources/newlib/libc/include/sys/select.h new file mode 100644 index 0000000000..de779e61ac --- /dev/null +++ b/contrib/sdk/sources/newlib/libc/include/sys/select.h @@ -0,0 +1,86 @@ +/* select.h + Copyright 1998, 1999, 2000, 2001, 2005, 2009 Red Hat, Inc. + + Written by Geoffrey Noer + +This file is part of Cygwin. + +This software is a copyrighted work licensed under the terms of the +Cygwin license. Please consult the file "CYGWIN_LICENSE" for +details. */ + +#ifndef _SYS_SELECT_H +#define _SYS_SELECT_H + +/* We don't define fd_set and friends if we are compiling POSIX + source, or if we have included (or may include as indicated + by __USE_W32_SOCKETS) the W32api winsock[2].h header which + defines Windows versions of them. Note that a program which + includes the W32api winsock[2].h header must know what it is doing; + it must not call the Cygwin select function. +*/ +# if !(defined (_POSIX_SOURCE) || defined (_WINSOCK_H) || defined (_WINSOCKAPI_) || defined (__USE_W32_SOCKETS)) + +#include + +#include +#include +#include + +#if !defined(_SIGSET_T_DECLARED) +#define _SIGSET_T_DECLARED +typedef __sigset_t sigset_t; +#endif + +# define _SYS_TYPES_FD_SET +/* + * Select uses bit masks of file descriptors in longs. + * These macros manipulate such bit fields (the filesystem macros use chars). + * FD_SETSIZE may be defined by the user, but the default here + * should be >= NOFILE (param.h). + */ +# ifndef FD_SETSIZE +# define FD_SETSIZE 64 +# endif + +typedef unsigned long fd_mask; +# define NFDBITS (sizeof (fd_mask) * 8) /* bits per mask */ +# ifndef _howmany +# define _howmany(x,y) (((x)+((y)-1))/(y)) +# endif + +/* We use a macro for fd_set so that including Sockets.h afterwards + can work. */ +typedef struct _types_fd_set { + fd_mask fds_bits[_howmany(FD_SETSIZE, NFDBITS)]; +} _types_fd_set; + +#define fd_set _types_fd_set + +# define FD_SET(n, p) ((p)->fds_bits[(n)/NFDBITS] |= (1L << ((n) % NFDBITS))) +# define FD_CLR(n, p) ((p)->fds_bits[(n)/NFDBITS] &= ~(1L << ((n) % NFDBITS))) +# define FD_ISSET(n, p) ((p)->fds_bits[(n)/NFDBITS] & (1L << ((n) % NFDBITS))) +# define FD_ZERO(p) (__extension__ (void)({ \ + size_t __i; \ + char *__tmp = (char *)p; \ + for (__i = 0; __i < sizeof (*(p)); ++__i) \ + *__tmp++ = 0; \ +})) + +#if !defined (__INSIDE_CYGWIN_NET__) + +__BEGIN_DECLS + +int select __P ((int __n, fd_set *__readfds, fd_set *__writefds, + fd_set *__exceptfds, struct timeval *__timeout)); +int pselect __P ((int __n, fd_set *__readfds, fd_set *__writefds, + fd_set *__exceptfds, const struct timespec *__timeout, + const sigset_t *__set)); + +__END_DECLS + +#endif + +#endif /* !_POSIX_SOURCE, !__INSIDE_CYGWIN_NET__ */ + +#endif /* sys/select.h */ diff --git a/contrib/sdk/sources/newlib/libc/include/sys/signal.h b/contrib/sdk/sources/newlib/libc/include/sys/signal.h index ffce0b2ae3..f2a10ca6e5 100644 --- a/contrib/sdk/sources/newlib/libc/include/sys/signal.h +++ b/contrib/sdk/sources/newlib/libc/include/sys/signal.h @@ -7,14 +7,17 @@ extern "C" { #endif #include "_ansi.h" +#include #include #include +#include +#include /* #ifndef __STRICT_ANSI__*/ -/* Cygwin defines it's own sigset_t in include/cygwin/signal.h */ -#ifndef __CYGWIN__ -typedef unsigned long sigset_t; +#if !defined(_SIGSET_T_DECLARED) +#define _SIGSET_T_DECLARED +typedef __sigset_t sigset_t; #endif #if defined(__rtems__) @@ -71,9 +74,12 @@ typedef struct { /* 3.3.8 Synchronously Accept a Signal, P1003.1b-1993, p. 76 */ -#define SA_NOCLDSTOP 1 /* Do not generate SIGCHLD when children stop */ -#define SA_SIGINFO 2 /* Invoke the signal catching function with */ - /* three arguments instead of one. */ +#define SA_NOCLDSTOP 0x1 /* Do not generate SIGCHLD when children stop */ +#define SA_SIGINFO 0x2 /* Invoke the signal catching function with */ + /* three arguments instead of one. */ +#if __BSD_VISIBLE || __XSI_VISIBLE || __POSIX_VISIBLE >= 200112 +#define SA_ONSTACK 0x4 /* Signal delivery will be on a separate stack. */ +#endif /* struct sigaction notes from POSIX: * @@ -119,6 +125,35 @@ struct sigaction }; #endif /* defined(__rtems__) */ +#if __BSD_VISIBLE || __XSI_VISIBLE || __POSIX_VISIBLE >= 200112 +/* + * Minimum and default signal stack constants. Allow for target overrides + * from . + */ +#ifndef MINSIGSTKSZ +#define MINSIGSTKSZ 2048 +#endif +#ifndef SIGSTKSZ +#define SIGSTKSZ 8192 +#endif + +/* + * Possible values for ss_flags in stack_t below. + */ +#define SS_ONSTACK 0x1 +#define SS_DISABLE 0x2 + +#endif + +/* + * Structure used in sigaltstack call. + */ +typedef struct sigaltstack { + void *ss_sp; /* Stack base or pointer. */ + int ss_flags; /* Flags. */ + size_t ss_size; /* Stack size. */ +} stack_t; + #define SIG_SETMASK 0 /* set mask with sigprocmask() */ #define SIG_BLOCK 1 /* set of signals to block */ #define SIG_UNBLOCK 2 /* set of signals to, well, unblock */ @@ -138,7 +173,6 @@ int _EXFUN(sigprocmask, (int how, const sigset_t *set, sigset_t *oset)); int _EXFUN(pthread_sigmask, (int how, const sigset_t *set, sigset_t *oset)); #endif -/* protos for functions found in winsup sources for CYGWIN */ #if defined(__CYGWIN__) || defined(__rtems__) #undef sigaddset #undef sigdelset @@ -148,8 +182,12 @@ int _EXFUN(pthread_sigmask, (int how, const sigset_t *set, sigset_t *oset)); #ifdef _COMPILING_NEWLIB int _EXFUN(_kill, (pid_t, int)); -#endif +#endif /* _COMPILING_NEWLIB */ +#endif /* __CYGWIN__ || __rtems__ */ + int _EXFUN(kill, (pid_t, int)); + +#if defined(__CYGWIN__) || defined(__rtems__) int _EXFUN(killpg, (pid_t, int)); int _EXFUN(sigaction, (int, const struct sigaction *, struct sigaction *)); int _EXFUN(sigaddset, (sigset_t *, const int)); @@ -161,6 +199,12 @@ int _EXFUN(sigpending, (sigset_t *)); int _EXFUN(sigsuspend, (const sigset_t *)); int _EXFUN(sigpause, (int)); +#if defined(__CYGWIN__) || defined(__rtems__) +#if __BSD_VISIBLE || __XSI_VISIBLE || __POSIX_VISIBLE >= 200112 +int _EXFUN(sigaltstack, (const stack_t *__restrict, stack_t *__restrict)); +#endif +#endif + #if defined(_POSIX_THREADS) #ifdef __CYGWIN__ # ifndef _CYGWIN_TYPES_H @@ -309,6 +353,12 @@ int _EXFUN(sigqueue, (pid_t pid, int signo, const union sigval value)); } #endif +#if defined(__CYGWIN__) +#if __POSIX_VISIBLE >= 200809 +#include +#endif +#endif + #ifndef _SIGNAL_H_ /* Some applications take advantage of the fact that * and are equivalent in glibc. Allow for that here. */ diff --git a/contrib/sdk/sources/newlib/libc/include/sys/stat.h b/contrib/sdk/sources/newlib/libc/include/sys/stat.h index ac5906bcea..5bc7b192b8 100644 --- a/contrib/sdk/sources/newlib/libc/include/sys/stat.h +++ b/contrib/sdk/sources/newlib/libc/include/sys/stat.h @@ -7,7 +7,9 @@ extern "C" { #include <_ansi.h> #include +#include #include +#include /* dj's stat defines _STAT_H_ */ #ifndef _STAT_H_ @@ -22,7 +24,7 @@ extern "C" { #define stat64 stat #endif #else -struct stat +struct stat { dev_t st_dev; ino_t st_ino; @@ -142,6 +144,8 @@ struct stat #define UTIME_OMIT -1L #endif +int _EXFUN(chmod,( const char *__path, mode_t __mode )); +int _EXFUN(fchmod,(int __fd, mode_t __mode)); int _EXFUN(fstat,( int __fd, struct stat *__sbuf )); int _EXFUN(mkdir,( const char *_path, mode_t __mode )); int _EXFUN(mkfifo,( const char *__path, mode_t __mode )); @@ -153,12 +157,18 @@ int _EXFUN(lstat,( const char *__restrict __path, struct stat *__restrict __buf int _EXFUN(mknod,( const char *__path, mode_t __mode, dev_t __dev )); #endif -#if defined (__CYGWIN__) && !defined(__INSIDE_CYGWIN__) +#if (__POSIX_VISIBLE >= 200809 || defined (__CYGWIN__)) && !defined(__INSIDE_CYGWIN__) int _EXFUN(fchmodat, (int, const char *, mode_t, int)); +#endif +#if (__BSD_VISIBLE || __POSIX_VISIBLE >= 200809 || defined (__CYGWIN__)) && !defined(__INSIDE_CYGWIN__) int _EXFUN(fstatat, (int, const char *__restrict , struct stat *__restrict, int)); int _EXFUN(mkdirat, (int, const char *, mode_t)); int _EXFUN(mkfifoat, (int, const char *, mode_t)); +#endif +#if (__BSD_VISIBLE || __XSI_VISIBLE >= 700 || defined (__CYGWIN__)) && !defined(__INSIDE_CYGWIN__) int _EXFUN(mknodat, (int, const char *, mode_t, dev_t)); +#endif +#if (__BSD_VISIBLE || __POSIX_VISIBLE >= 200809 || defined (__CYGWIN__)) && !defined(__INSIDE_CYGWIN__) int _EXFUN(utimensat, (int, const char *, const struct timespec *, int)); int _EXFUN(futimens, (int, const struct timespec *)); #endif diff --git a/contrib/sdk/sources/newlib/libc/include/sys/time.h b/contrib/sdk/sources/newlib/libc/include/sys/time.h index 81ee20c2e7..8eba3e3667 100644 --- a/contrib/sdk/sources/newlib/libc/include/sys/time.h +++ b/contrib/sdk/sources/newlib/libc/include/sys/time.h @@ -2,87 +2,444 @@ Written by Geoffrey Noer Public domain; no rights reserved. */ +/*- + * Copyright (c) 1982, 1986, 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. + * 4. 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. + * + * @(#)time.h 8.5 (Berkeley) 5/4/95 + * $FreeBSD$ + */ + #ifndef _SYS_TIME_H_ -#define _SYS_TIME_H_ +#define _SYS_TIME_H_ #include <_ansi.h> +#include +#include #include +#include -#ifdef __cplusplus -extern "C" { +#if __BSD_VISIBLE +#include #endif -#ifndef _TIMEVAL_DEFINED -#define _TIMEVAL_DEFINED -struct timeval { - time_t tv_sec; - suseconds_t tv_usec; -}; - -/* BSD time macros used by RTEMS code */ -#if defined (__rtems__) || defined (__CYGWIN__) - -/* Convenience macros for operations on timevals. - NOTE: `timercmp' does not work for >= or <=. */ -#define timerisset(tvp) ((tvp)->tv_sec || (tvp)->tv_usec) -#define timerclear(tvp) ((tvp)->tv_sec = (tvp)->tv_usec = 0) -#define timercmp(a, b, CMP) \ - (((a)->tv_sec == (b)->tv_sec) ? \ - ((a)->tv_usec CMP (b)->tv_usec) : \ - ((a)->tv_sec CMP (b)->tv_sec)) -#define timeradd(a, b, result) \ - do { \ - (result)->tv_sec = (a)->tv_sec + (b)->tv_sec; \ - (result)->tv_usec = (a)->tv_usec + (b)->tv_usec; \ - if ((result)->tv_usec >= 1000000) \ - { \ - ++(result)->tv_sec; \ - (result)->tv_usec -= 1000000; \ - } \ - } while (0) -#define timersub(a, b, result) \ - do { \ - (result)->tv_sec = (a)->tv_sec - (b)->tv_sec; \ - (result)->tv_usec = (a)->tv_usec - (b)->tv_usec; \ - if ((result)->tv_usec < 0) { \ - --(result)->tv_sec; \ - (result)->tv_usec += 1000000; \ - } \ - } while (0) -#endif /* defined (__rtems__) || defined (__CYGWIN__) */ -#endif /* !_TIMEVAL_DEFINED */ - struct timezone { - int tz_minuteswest; - int tz_dsttime; + int tz_minuteswest; /* minutes west of Greenwich */ + int tz_dsttime; /* type of dst correction */ +}; +#define DST_NONE 0 /* not on dst */ +#define DST_USA 1 /* USA style dst */ +#define DST_AUST 2 /* Australian style dst */ +#define DST_WET 3 /* Western European dst */ +#define DST_MET 4 /* Middle European dst */ +#define DST_EET 5 /* Eastern European dst */ +#define DST_CAN 6 /* Canada */ + +#if __BSD_VISIBLE +struct bintime { + time_t sec; + uint64_t frac; }; -#ifdef __CYGWIN__ -#include -#endif /* __CYGWIN__ */ +static __inline void +bintime_addx(struct bintime *_bt, uint64_t _x) +{ + uint64_t _u; -#define ITIMER_REAL 0 -#define ITIMER_VIRTUAL 1 -#define ITIMER_PROF 2 + _u = _bt->frac; + _bt->frac += _x; + if (_u > _bt->frac) + _bt->sec++; +} -struct itimerval { - struct timeval it_interval; - struct timeval it_value; +static __inline void +bintime_add(struct bintime *_bt, const struct bintime *_bt2) +{ + uint64_t _u; + + _u = _bt->frac; + _bt->frac += _bt2->frac; + if (_u > _bt->frac) + _bt->sec++; + _bt->sec += _bt2->sec; +} + +static __inline void +bintime_sub(struct bintime *_bt, const struct bintime *_bt2) +{ + uint64_t _u; + + _u = _bt->frac; + _bt->frac -= _bt2->frac; + if (_u < _bt->frac) + _bt->sec--; + _bt->sec -= _bt2->sec; +} + +static __inline void +bintime_mul(struct bintime *_bt, u_int _x) +{ + uint64_t _p1, _p2; + + _p1 = (_bt->frac & 0xffffffffull) * _x; + _p2 = (_bt->frac >> 32) * _x + (_p1 >> 32); + _bt->sec *= _x; + _bt->sec += (_p2 >> 32); + _bt->frac = (_p2 << 32) | (_p1 & 0xffffffffull); +} + +static __inline void +bintime_shift(struct bintime *_bt, int _exp) +{ + + if (_exp > 0) { + _bt->sec <<= _exp; + _bt->sec |= _bt->frac >> (64 - _exp); + _bt->frac <<= _exp; + } else if (_exp < 0) { + _bt->frac >>= -_exp; + _bt->frac |= (uint64_t)_bt->sec << (64 + _exp); + _bt->sec >>= -_exp; + } +} + +#define bintime_clear(a) ((a)->sec = (a)->frac = 0) +#define bintime_isset(a) ((a)->sec || (a)->frac) +#define bintime_cmp(a, b, cmp) \ + (((a)->sec == (b)->sec) ? \ + ((a)->frac cmp (b)->frac) : \ + ((a)->sec cmp (b)->sec)) + +#define SBT_1S ((sbintime_t)1 << 32) +#define SBT_1M (SBT_1S * 60) +#define SBT_1MS (SBT_1S / 1000) +#define SBT_1US (SBT_1S / 1000000) +#define SBT_1NS (SBT_1S / 1000000000) +#define SBT_MAX 0x7fffffffffffffffLL + +static __inline int +sbintime_getsec(sbintime_t _sbt) +{ + + return (_sbt >> 32); +} + +static __inline sbintime_t +bttosbt(const struct bintime _bt) +{ + + return (((sbintime_t)_bt.sec << 32) + (_bt.frac >> 32)); +} + +static __inline struct bintime +sbttobt(sbintime_t _sbt) +{ + struct bintime _bt; + + _bt.sec = _sbt >> 32; + _bt.frac = _sbt << 32; + return (_bt); +} + +/*- + * Background information: + * + * When converting between timestamps on parallel timescales of differing + * resolutions it is historical and scientific practice to round down rather + * than doing 4/5 rounding. + * + * The date changes at midnight, not at noon. + * + * Even at 15:59:59.999999999 it's not four'o'clock. + * + * time_second ticks after N.999999999 not after N.4999999999 + */ + +static __inline void +bintime2timespec(const struct bintime *_bt, struct timespec *_ts) +{ + + _ts->tv_sec = _bt->sec; + _ts->tv_nsec = ((uint64_t)1000000000 * + (uint32_t)(_bt->frac >> 32)) >> 32; +} + +static __inline void +timespec2bintime(const struct timespec *_ts, struct bintime *_bt) +{ + + _bt->sec = _ts->tv_sec; + /* 18446744073 = int(2^64 / 1000000000) */ + _bt->frac = _ts->tv_nsec * (uint64_t)18446744073LL; +} + +static __inline void +bintime2timeval(const struct bintime *_bt, struct timeval *_tv) +{ + + _tv->tv_sec = _bt->sec; + _tv->tv_usec = ((uint64_t)1000000 * (uint32_t)(_bt->frac >> 32)) >> 32; +} + +static __inline void +timeval2bintime(const struct timeval *_tv, struct bintime *_bt) +{ + + _bt->sec = _tv->tv_sec; + /* 18446744073709 = int(2^64 / 1000000) */ + _bt->frac = _tv->tv_usec * (uint64_t)18446744073709LL; +} + +static __inline struct timespec +sbttots(sbintime_t _sbt) +{ + struct timespec _ts; + + _ts.tv_sec = _sbt >> 32; + _ts.tv_nsec = ((uint64_t)1000000000 * (uint32_t)_sbt) >> 32; + return (_ts); +} + +static __inline sbintime_t +tstosbt(struct timespec _ts) +{ + + return (((sbintime_t)_ts.tv_sec << 32) + + (_ts.tv_nsec * (((uint64_t)1 << 63) / 500000000) >> 32)); +} + +static __inline struct timeval +sbttotv(sbintime_t _sbt) +{ + struct timeval _tv; + + _tv.tv_sec = _sbt >> 32; + _tv.tv_usec = ((uint64_t)1000000 * (uint32_t)_sbt) >> 32; + return (_tv); +} + +static __inline sbintime_t +tvtosbt(struct timeval _tv) +{ + + return (((sbintime_t)_tv.tv_sec << 32) + + (_tv.tv_usec * (((uint64_t)1 << 63) / 500000) >> 32)); +} +#endif /* __BSD_VISIBLE */ + +#ifdef _KERNEL + +/* Operations on timespecs */ +#define timespecclear(tvp) ((tvp)->tv_sec = (tvp)->tv_nsec = 0) +#define timespecisset(tvp) ((tvp)->tv_sec || (tvp)->tv_nsec) +#define timespeccmp(tvp, uvp, cmp) \ + (((tvp)->tv_sec == (uvp)->tv_sec) ? \ + ((tvp)->tv_nsec cmp (uvp)->tv_nsec) : \ + ((tvp)->tv_sec cmp (uvp)->tv_sec)) +#define timespecadd(vvp, uvp) \ + do { \ + (vvp)->tv_sec += (uvp)->tv_sec; \ + (vvp)->tv_nsec += (uvp)->tv_nsec; \ + if ((vvp)->tv_nsec >= 1000000000) { \ + (vvp)->tv_sec++; \ + (vvp)->tv_nsec -= 1000000000; \ + } \ + } while (0) +#define timespecsub(vvp, uvp) \ + do { \ + (vvp)->tv_sec -= (uvp)->tv_sec; \ + (vvp)->tv_nsec -= (uvp)->tv_nsec; \ + if ((vvp)->tv_nsec < 0) { \ + (vvp)->tv_sec--; \ + (vvp)->tv_nsec += 1000000000; \ + } \ + } while (0) + +/* Operations on timevals. */ + +#define timevalclear(tvp) ((tvp)->tv_sec = (tvp)->tv_usec = 0) +#define timevalisset(tvp) ((tvp)->tv_sec || (tvp)->tv_usec) +#define timevalcmp(tvp, uvp, cmp) \ + (((tvp)->tv_sec == (uvp)->tv_sec) ? \ + ((tvp)->tv_usec cmp (uvp)->tv_usec) : \ + ((tvp)->tv_sec cmp (uvp)->tv_sec)) + +/* timevaladd and timevalsub are not inlined */ + +#endif /* _KERNEL */ + +/* + * Names of the interval timers, and structure + * defining a timer setting. + */ +#define ITIMER_REAL 0 +#define ITIMER_VIRTUAL 1 +#define ITIMER_PROF 2 + +struct itimerval { + struct timeval it_interval; /* timer interval */ + struct timeval it_value; /* current value */ }; +#ifdef _KERNEL + +/* + * Kernel to clock driver interface. + */ +void inittodr(time_t base); +void resettodr(void); + +extern volatile time_t time_second; +extern volatile time_t time_uptime; +extern struct bintime boottimebin; +extern struct timeval boottime; +extern struct bintime tc_tick_bt; +extern sbintime_t tc_tick_sbt; +extern struct bintime tick_bt; +extern sbintime_t tick_sbt; +extern int tc_precexp; +extern int tc_timepercentage; +extern struct bintime bt_timethreshold; +extern struct bintime bt_tickthreshold; +extern sbintime_t sbt_timethreshold; +extern sbintime_t sbt_tickthreshold; + +/* + * Functions for looking at our clock: [get]{bin,nano,micro}[up]time() + * + * Functions without the "get" prefix returns the best timestamp + * we can produce in the given format. + * + * "bin" == struct bintime == seconds + 64 bit fraction of seconds. + * "nano" == struct timespec == seconds + nanoseconds. + * "micro" == struct timeval == seconds + microseconds. + * + * Functions containing "up" returns time relative to boot and + * should be used for calculating time intervals. + * + * Functions without "up" returns UTC time. + * + * Functions with the "get" prefix returns a less precise result + * much faster than the functions without "get" prefix and should + * be used where a precision of 1/hz seconds is acceptable or where + * performance is priority. (NB: "precision", _not_ "resolution" !) + */ + +void binuptime(struct bintime *bt); +void nanouptime(struct timespec *tsp); +void microuptime(struct timeval *tvp); + +static __inline sbintime_t +sbinuptime(void) +{ + struct bintime _bt; + + binuptime(&_bt); + return (bttosbt(_bt)); +} + +void bintime(struct bintime *bt); +void nanotime(struct timespec *tsp); +void microtime(struct timeval *tvp); + +void getbinuptime(struct bintime *bt); +void getnanouptime(struct timespec *tsp); +void getmicrouptime(struct timeval *tvp); + +static __inline sbintime_t +getsbinuptime(void) +{ + struct bintime _bt; + + getbinuptime(&_bt); + return (bttosbt(_bt)); +} + +void getbintime(struct bintime *bt); +void getnanotime(struct timespec *tsp); +void getmicrotime(struct timeval *tvp); + +/* Other functions */ +int itimerdecr(struct itimerval *itp, int usec); +int itimerfix(struct timeval *tv); +int ppsratecheck(struct timeval *, int *, int); +int ratecheck(struct timeval *, const struct timeval *); +void timevaladd(struct timeval *t1, const struct timeval *t2); +void timevalsub(struct timeval *t1, const struct timeval *t2); +int tvtohz(struct timeval *tv); + +#define TC_DEFAULTPERC 5 + +#define BT2FREQ(bt) \ + (((uint64_t)0x8000000000000000 + ((bt)->frac >> 2)) / \ + ((bt)->frac >> 1)) + +#define SBT2FREQ(sbt) ((SBT_1S + ((sbt) >> 1)) / (sbt)) + +#define FREQ2BT(freq, bt) \ +{ \ + (bt)->sec = 0; \ + (bt)->frac = ((uint64_t)0x8000000000000000 / (freq)) << 1; \ +} + +#define TIMESEL(sbt, sbt2) \ + (((sbt2) >= sbt_timethreshold) ? \ + ((*(sbt) = getsbinuptime()), 1) : ((*(sbt) = sbinuptime()), 0)) + +#else /* !_KERNEL */ +#include + +#include + +__BEGIN_DECLS +int _EXFUN(setitimer, (int __which, const struct itimerval *__restrict __value, + struct itimerval *__restrict __ovalue)); +int _EXFUN(utimes, (const char *__path, const struct timeval *__tvp)); + +#if __BSD_VISIBLE +int _EXFUN(adjtime, (const struct timeval *, struct timeval *)); +int _EXFUN(futimes, (int, const struct timeval *)); +int _EXFUN(futimesat, (int, const char *, const struct timeval [2])); +int _EXFUN(lutimes, (const char *, const struct timeval *)); +int _EXFUN(settimeofday, (const struct timeval *, const struct timezone *)); +#endif + +#if __XSI_VISIBLE +int _EXFUN(getitimer, (int __which, struct itimerval *__value)); +int _EXFUN(gettimeofday, (struct timeval *__restrict __p, + void *__restrict __tz)); +#endif + #ifdef _COMPILING_NEWLIB int _EXFUN(_gettimeofday, (struct timeval *__p, void *__tz)); #endif -int _EXFUN(gettimeofday, (struct timeval *__restrict __p, - void *__restrict __tz)); -int _EXFUN(settimeofday, (const struct timeval *, const struct timezone *)); -int _EXFUN(utimes, (const char *__path, const struct timeval *__tvp)); -int _EXFUN(getitimer, (int __which, struct itimerval *__value)); -int _EXFUN(setitimer, (int __which, const struct itimerval *__restrict __value, - struct itimerval *__restrict __ovalue)); +__END_DECLS -#ifdef __cplusplus -} -#endif -#endif /* _SYS_TIME_H_ */ +#endif /* !_KERNEL */ + +#endif /* !_SYS_TIME_H_ */ diff --git a/contrib/sdk/sources/newlib/libc/include/sys/timespec.h b/contrib/sdk/sources/newlib/libc/include/sys/timespec.h new file mode 100644 index 0000000000..2505cef893 --- /dev/null +++ b/contrib/sdk/sources/newlib/libc/include/sys/timespec.h @@ -0,0 +1,63 @@ +/*- + * Copyright (c) 1982, 1986, 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. + * 4. 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. + * + * @(#)time.h 8.5 (Berkeley) 5/4/95 + * from: FreeBSD: src/sys/sys/time.h,v 1.43 2000/03/20 14:09:05 phk Exp + * $FreeBSD$ + */ + +#ifndef _SYS_TIMESPEC_H_ +#define _SYS_TIMESPEC_H_ + +#include +#include + +#if __BSD_VISIBLE +#define TIMEVAL_TO_TIMESPEC(tv, ts) \ + do { \ + (ts)->tv_sec = (tv)->tv_sec; \ + (ts)->tv_nsec = (tv)->tv_usec * 1000; \ + } while (0) +#define TIMESPEC_TO_TIMEVAL(tv, ts) \ + do { \ + (tv)->tv_sec = (ts)->tv_sec; \ + (tv)->tv_usec = (ts)->tv_nsec / 1000; \ + } while (0) + +#endif /* __BSD_VISIBLE */ + +/* + * Structure defined by POSIX.1b to be like a itimerval, but with + * timespecs. Used in the timer_*() system calls. + */ +struct itimerspec { + struct timespec it_interval; + struct timespec it_value; +}; + +#endif /* _SYS_TIMESPEC_H_ */ diff --git a/contrib/sdk/sources/newlib/libc/include/sys/tree.h b/contrib/sdk/sources/newlib/libc/include/sys/tree.h new file mode 100644 index 0000000000..f4167c4e4f --- /dev/null +++ b/contrib/sdk/sources/newlib/libc/include/sys/tree.h @@ -0,0 +1,801 @@ +/* $NetBSD: tree.h,v 1.8 2004/03/28 19:38:30 provos Exp $ */ +/* $OpenBSD: tree.h,v 1.7 2002/10/17 21:51:54 art Exp $ */ +/* $FreeBSD$ */ + +/*- + * Copyright 2002 Niels Provos + * 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. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``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 AUTHOR 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. + */ + +#ifndef _SYS_TREE_H_ +#define _SYS_TREE_H_ + +#include + +/* + * This file defines data structures for different types of trees: + * splay trees and red-black trees. + * + * A splay tree is a self-organizing data structure. Every operation + * on the tree causes a splay to happen. The splay moves the requested + * node to the root of the tree and partly rebalances it. + * + * This has the benefit that request locality causes faster lookups as + * the requested nodes move to the top of the tree. On the other hand, + * every lookup causes memory writes. + * + * The Balance Theorem bounds the total access time for m operations + * and n inserts on an initially empty tree as O((m + n)lg n). The + * amortized cost for a sequence of m accesses to a splay tree is O(lg n); + * + * A red-black tree is a binary search tree with the node color as an + * extra attribute. It fulfills a set of conditions: + * - every search path from the root to a leaf consists of the + * same number of black nodes, + * - each red node (except for the root) has a black parent, + * - each leaf node is black. + * + * Every operation on a red-black tree is bounded as O(lg n). + * The maximum height of a red-black tree is 2lg (n+1). + */ + +#define SPLAY_HEAD(name, type) \ +struct name { \ + struct type *sph_root; /* root of the tree */ \ +} + +#define SPLAY_INITIALIZER(root) \ + { NULL } + +#define SPLAY_INIT(root) do { \ + (root)->sph_root = NULL; \ +} while (/*CONSTCOND*/ 0) + +#define SPLAY_ENTRY(type) \ +struct { \ + struct type *spe_left; /* left element */ \ + struct type *spe_right; /* right element */ \ +} + +#define SPLAY_LEFT(elm, field) (elm)->field.spe_left +#define SPLAY_RIGHT(elm, field) (elm)->field.spe_right +#define SPLAY_ROOT(head) (head)->sph_root +#define SPLAY_EMPTY(head) (SPLAY_ROOT(head) == NULL) + +/* SPLAY_ROTATE_{LEFT,RIGHT} expect that tmp hold SPLAY_{RIGHT,LEFT} */ +#define SPLAY_ROTATE_RIGHT(head, tmp, field) do { \ + SPLAY_LEFT((head)->sph_root, field) = SPLAY_RIGHT(tmp, field); \ + SPLAY_RIGHT(tmp, field) = (head)->sph_root; \ + (head)->sph_root = tmp; \ +} while (/*CONSTCOND*/ 0) + +#define SPLAY_ROTATE_LEFT(head, tmp, field) do { \ + SPLAY_RIGHT((head)->sph_root, field) = SPLAY_LEFT(tmp, field); \ + SPLAY_LEFT(tmp, field) = (head)->sph_root; \ + (head)->sph_root = tmp; \ +} while (/*CONSTCOND*/ 0) + +#define SPLAY_LINKLEFT(head, tmp, field) do { \ + SPLAY_LEFT(tmp, field) = (head)->sph_root; \ + tmp = (head)->sph_root; \ + (head)->sph_root = SPLAY_LEFT((head)->sph_root, field); \ +} while (/*CONSTCOND*/ 0) + +#define SPLAY_LINKRIGHT(head, tmp, field) do { \ + SPLAY_RIGHT(tmp, field) = (head)->sph_root; \ + tmp = (head)->sph_root; \ + (head)->sph_root = SPLAY_RIGHT((head)->sph_root, field); \ +} while (/*CONSTCOND*/ 0) + +#define SPLAY_ASSEMBLE(head, node, left, right, field) do { \ + SPLAY_RIGHT(left, field) = SPLAY_LEFT((head)->sph_root, field); \ + SPLAY_LEFT(right, field) = SPLAY_RIGHT((head)->sph_root, field);\ + SPLAY_LEFT((head)->sph_root, field) = SPLAY_RIGHT(node, field); \ + SPLAY_RIGHT((head)->sph_root, field) = SPLAY_LEFT(node, field); \ +} while (/*CONSTCOND*/ 0) + +/* Generates prototypes and inline functions */ + +#define SPLAY_PROTOTYPE(name, type, field, cmp) \ +void name##_SPLAY(struct name *, struct type *); \ +void name##_SPLAY_MINMAX(struct name *, int); \ +struct type *name##_SPLAY_INSERT(struct name *, struct type *); \ +struct type *name##_SPLAY_REMOVE(struct name *, struct type *); \ + \ +/* Finds the node with the same key as elm */ \ +static __inline struct type * \ +name##_SPLAY_FIND(struct name *head, struct type *elm) \ +{ \ + if (SPLAY_EMPTY(head)) \ + return(NULL); \ + name##_SPLAY(head, elm); \ + if ((cmp)(elm, (head)->sph_root) == 0) \ + return (head->sph_root); \ + return (NULL); \ +} \ + \ +static __inline struct type * \ +name##_SPLAY_NEXT(struct name *head, struct type *elm) \ +{ \ + name##_SPLAY(head, elm); \ + if (SPLAY_RIGHT(elm, field) != NULL) { \ + elm = SPLAY_RIGHT(elm, field); \ + while (SPLAY_LEFT(elm, field) != NULL) { \ + elm = SPLAY_LEFT(elm, field); \ + } \ + } else \ + elm = NULL; \ + return (elm); \ +} \ + \ +static __inline struct type * \ +name##_SPLAY_MIN_MAX(struct name *head, int val) \ +{ \ + name##_SPLAY_MINMAX(head, val); \ + return (SPLAY_ROOT(head)); \ +} + +/* Main splay operation. + * Moves node close to the key of elm to top + */ +#define SPLAY_GENERATE(name, type, field, cmp) \ +struct type * \ +name##_SPLAY_INSERT(struct name *head, struct type *elm) \ +{ \ + if (SPLAY_EMPTY(head)) { \ + SPLAY_LEFT(elm, field) = SPLAY_RIGHT(elm, field) = NULL; \ + } else { \ + int __comp; \ + name##_SPLAY(head, elm); \ + __comp = (cmp)(elm, (head)->sph_root); \ + if(__comp < 0) { \ + SPLAY_LEFT(elm, field) = SPLAY_LEFT((head)->sph_root, field);\ + SPLAY_RIGHT(elm, field) = (head)->sph_root; \ + SPLAY_LEFT((head)->sph_root, field) = NULL; \ + } else if (__comp > 0) { \ + SPLAY_RIGHT(elm, field) = SPLAY_RIGHT((head)->sph_root, field);\ + SPLAY_LEFT(elm, field) = (head)->sph_root; \ + SPLAY_RIGHT((head)->sph_root, field) = NULL; \ + } else \ + return ((head)->sph_root); \ + } \ + (head)->sph_root = (elm); \ + return (NULL); \ +} \ + \ +struct type * \ +name##_SPLAY_REMOVE(struct name *head, struct type *elm) \ +{ \ + struct type *__tmp; \ + if (SPLAY_EMPTY(head)) \ + return (NULL); \ + name##_SPLAY(head, elm); \ + if ((cmp)(elm, (head)->sph_root) == 0) { \ + if (SPLAY_LEFT((head)->sph_root, field) == NULL) { \ + (head)->sph_root = SPLAY_RIGHT((head)->sph_root, field);\ + } else { \ + __tmp = SPLAY_RIGHT((head)->sph_root, field); \ + (head)->sph_root = SPLAY_LEFT((head)->sph_root, field);\ + name##_SPLAY(head, elm); \ + SPLAY_RIGHT((head)->sph_root, field) = __tmp; \ + } \ + return (elm); \ + } \ + return (NULL); \ +} \ + \ +void \ +name##_SPLAY(struct name *head, struct type *elm) \ +{ \ + struct type __node, *__left, *__right, *__tmp; \ + int __comp; \ +\ + SPLAY_LEFT(&__node, field) = SPLAY_RIGHT(&__node, field) = NULL;\ + __left = __right = &__node; \ +\ + while ((__comp = (cmp)(elm, (head)->sph_root)) != 0) { \ + if (__comp < 0) { \ + __tmp = SPLAY_LEFT((head)->sph_root, field); \ + if (__tmp == NULL) \ + break; \ + if ((cmp)(elm, __tmp) < 0){ \ + SPLAY_ROTATE_RIGHT(head, __tmp, field); \ + if (SPLAY_LEFT((head)->sph_root, field) == NULL)\ + break; \ + } \ + SPLAY_LINKLEFT(head, __right, field); \ + } else if (__comp > 0) { \ + __tmp = SPLAY_RIGHT((head)->sph_root, field); \ + if (__tmp == NULL) \ + break; \ + if ((cmp)(elm, __tmp) > 0){ \ + SPLAY_ROTATE_LEFT(head, __tmp, field); \ + if (SPLAY_RIGHT((head)->sph_root, field) == NULL)\ + break; \ + } \ + SPLAY_LINKRIGHT(head, __left, field); \ + } \ + } \ + SPLAY_ASSEMBLE(head, &__node, __left, __right, field); \ +} \ + \ +/* Splay with either the minimum or the maximum element \ + * Used to find minimum or maximum element in tree. \ + */ \ +void name##_SPLAY_MINMAX(struct name *head, int __comp) \ +{ \ + struct type __node, *__left, *__right, *__tmp; \ +\ + SPLAY_LEFT(&__node, field) = SPLAY_RIGHT(&__node, field) = NULL;\ + __left = __right = &__node; \ +\ + while (1) { \ + if (__comp < 0) { \ + __tmp = SPLAY_LEFT((head)->sph_root, field); \ + if (__tmp == NULL) \ + break; \ + if (__comp < 0){ \ + SPLAY_ROTATE_RIGHT(head, __tmp, field); \ + if (SPLAY_LEFT((head)->sph_root, field) == NULL)\ + break; \ + } \ + SPLAY_LINKLEFT(head, __right, field); \ + } else if (__comp > 0) { \ + __tmp = SPLAY_RIGHT((head)->sph_root, field); \ + if (__tmp == NULL) \ + break; \ + if (__comp > 0) { \ + SPLAY_ROTATE_LEFT(head, __tmp, field); \ + if (SPLAY_RIGHT((head)->sph_root, field) == NULL)\ + break; \ + } \ + SPLAY_LINKRIGHT(head, __left, field); \ + } \ + } \ + SPLAY_ASSEMBLE(head, &__node, __left, __right, field); \ +} + +#define SPLAY_NEGINF -1 +#define SPLAY_INF 1 + +#define SPLAY_INSERT(name, x, y) name##_SPLAY_INSERT(x, y) +#define SPLAY_REMOVE(name, x, y) name##_SPLAY_REMOVE(x, y) +#define SPLAY_FIND(name, x, y) name##_SPLAY_FIND(x, y) +#define SPLAY_NEXT(name, x, y) name##_SPLAY_NEXT(x, y) +#define SPLAY_MIN(name, x) (SPLAY_EMPTY(x) ? NULL \ + : name##_SPLAY_MIN_MAX(x, SPLAY_NEGINF)) +#define SPLAY_MAX(name, x) (SPLAY_EMPTY(x) ? NULL \ + : name##_SPLAY_MIN_MAX(x, SPLAY_INF)) + +#define SPLAY_FOREACH(x, name, head) \ + for ((x) = SPLAY_MIN(name, head); \ + (x) != NULL; \ + (x) = SPLAY_NEXT(name, head, x)) + +/* Macros that define a red-black tree */ +#define RB_HEAD(name, type) \ +struct name { \ + struct type *rbh_root; /* root of the tree */ \ +} + +#define RB_INITIALIZER(root) \ + { NULL } + +#define RB_INIT(root) do { \ + (root)->rbh_root = NULL; \ +} while (/*CONSTCOND*/ 0) + +#define RB_BLACK 0 +#define RB_RED 1 +#define RB_ENTRY(type) \ +struct { \ + struct type *rbe_left; /* left element */ \ + struct type *rbe_right; /* right element */ \ + struct type *rbe_parent; /* parent element */ \ + int rbe_color; /* node color */ \ +} + +#define RB_LEFT(elm, field) (elm)->field.rbe_left +#define RB_RIGHT(elm, field) (elm)->field.rbe_right +#define RB_PARENT(elm, field) (elm)->field.rbe_parent +#define RB_COLOR(elm, field) (elm)->field.rbe_color +#define RB_ROOT(head) (head)->rbh_root +#define RB_EMPTY(head) (RB_ROOT(head) == NULL) + +#define RB_SET(elm, parent, field) do { \ + RB_PARENT(elm, field) = parent; \ + RB_LEFT(elm, field) = RB_RIGHT(elm, field) = NULL; \ + RB_COLOR(elm, field) = RB_RED; \ +} while (/*CONSTCOND*/ 0) + +#define RB_SET_BLACKRED(black, red, field) do { \ + RB_COLOR(black, field) = RB_BLACK; \ + RB_COLOR(red, field) = RB_RED; \ +} while (/*CONSTCOND*/ 0) + +#ifndef RB_AUGMENT +#define RB_AUGMENT(x) do {} while (0) +#endif + +#define RB_ROTATE_LEFT(head, elm, tmp, field) do { \ + (tmp) = RB_RIGHT(elm, field); \ + if ((RB_RIGHT(elm, field) = RB_LEFT(tmp, field)) != NULL) { \ + RB_PARENT(RB_LEFT(tmp, field), field) = (elm); \ + } \ + RB_AUGMENT(elm); \ + if ((RB_PARENT(tmp, field) = RB_PARENT(elm, field)) != NULL) { \ + if ((elm) == RB_LEFT(RB_PARENT(elm, field), field)) \ + RB_LEFT(RB_PARENT(elm, field), field) = (tmp); \ + else \ + RB_RIGHT(RB_PARENT(elm, field), field) = (tmp); \ + } else \ + (head)->rbh_root = (tmp); \ + RB_LEFT(tmp, field) = (elm); \ + RB_PARENT(elm, field) = (tmp); \ + RB_AUGMENT(tmp); \ + if ((RB_PARENT(tmp, field))) \ + RB_AUGMENT(RB_PARENT(tmp, field)); \ +} while (/*CONSTCOND*/ 0) + +#define RB_ROTATE_RIGHT(head, elm, tmp, field) do { \ + (tmp) = RB_LEFT(elm, field); \ + if ((RB_LEFT(elm, field) = RB_RIGHT(tmp, field)) != NULL) { \ + RB_PARENT(RB_RIGHT(tmp, field), field) = (elm); \ + } \ + RB_AUGMENT(elm); \ + if ((RB_PARENT(tmp, field) = RB_PARENT(elm, field)) != NULL) { \ + if ((elm) == RB_LEFT(RB_PARENT(elm, field), field)) \ + RB_LEFT(RB_PARENT(elm, field), field) = (tmp); \ + else \ + RB_RIGHT(RB_PARENT(elm, field), field) = (tmp); \ + } else \ + (head)->rbh_root = (tmp); \ + RB_RIGHT(tmp, field) = (elm); \ + RB_PARENT(elm, field) = (tmp); \ + RB_AUGMENT(tmp); \ + if ((RB_PARENT(tmp, field))) \ + RB_AUGMENT(RB_PARENT(tmp, field)); \ +} while (/*CONSTCOND*/ 0) + +/* Generates prototypes and inline functions */ +#define RB_PROTOTYPE(name, type, field, cmp) \ + RB_PROTOTYPE_INTERNAL(name, type, field, cmp,) +#define RB_PROTOTYPE_STATIC(name, type, field, cmp) \ + RB_PROTOTYPE_INTERNAL(name, type, field, cmp, __unused static) +#define RB_PROTOTYPE_INTERNAL(name, type, field, cmp, attr) \ + RB_PROTOTYPE_INSERT_COLOR(name, type, attr); \ + RB_PROTOTYPE_REMOVE_COLOR(name, type, attr); \ + RB_PROTOTYPE_INSERT(name, type, attr); \ + RB_PROTOTYPE_REMOVE(name, type, attr); \ + RB_PROTOTYPE_FIND(name, type, attr); \ + RB_PROTOTYPE_NFIND(name, type, attr); \ + RB_PROTOTYPE_NEXT(name, type, attr); \ + RB_PROTOTYPE_PREV(name, type, attr); \ + RB_PROTOTYPE_MINMAX(name, type, attr); +#define RB_PROTOTYPE_INSERT_COLOR(name, type, attr) \ + attr void name##_RB_INSERT_COLOR(struct name *, struct type *) +#define RB_PROTOTYPE_REMOVE_COLOR(name, type, attr) \ + attr void name##_RB_REMOVE_COLOR(struct name *, struct type *, struct type *) +#define RB_PROTOTYPE_REMOVE(name, type, attr) \ + attr struct type *name##_RB_REMOVE(struct name *, struct type *) +#define RB_PROTOTYPE_INSERT(name, type, attr) \ + attr struct type *name##_RB_INSERT(struct name *, struct type *) +#define RB_PROTOTYPE_FIND(name, type, attr) \ + attr struct type *name##_RB_FIND(struct name *, struct type *) +#define RB_PROTOTYPE_NFIND(name, type, attr) \ + attr struct type *name##_RB_NFIND(struct name *, struct type *) +#define RB_PROTOTYPE_NEXT(name, type, attr) \ + attr struct type *name##_RB_NEXT(struct type *) +#define RB_PROTOTYPE_PREV(name, type, attr) \ + attr struct type *name##_RB_PREV(struct type *) +#define RB_PROTOTYPE_MINMAX(name, type, attr) \ + attr struct type *name##_RB_MINMAX(struct name *, int) + +/* Main rb operation. + * Moves node close to the key of elm to top + */ +#define RB_GENERATE(name, type, field, cmp) \ + RB_GENERATE_INTERNAL(name, type, field, cmp,) +#define RB_GENERATE_STATIC(name, type, field, cmp) \ + RB_GENERATE_INTERNAL(name, type, field, cmp, __unused static) +#define RB_GENERATE_INTERNAL(name, type, field, cmp, attr) \ + RB_GENERATE_INSERT_COLOR(name, type, field, attr) \ + RB_GENERATE_REMOVE_COLOR(name, type, field, attr) \ + RB_GENERATE_INSERT(name, type, field, cmp, attr) \ + RB_GENERATE_REMOVE(name, type, field, attr) \ + RB_GENERATE_FIND(name, type, field, cmp, attr) \ + RB_GENERATE_NFIND(name, type, field, cmp, attr) \ + RB_GENERATE_NEXT(name, type, field, attr) \ + RB_GENERATE_PREV(name, type, field, attr) \ + RB_GENERATE_MINMAX(name, type, field, attr) + +#define RB_GENERATE_INSERT_COLOR(name, type, field, attr) \ +attr void \ +name##_RB_INSERT_COLOR(struct name *head, struct type *elm) \ +{ \ + struct type *parent, *gparent, *tmp; \ + while ((parent = RB_PARENT(elm, field)) != NULL && \ + RB_COLOR(parent, field) == RB_RED) { \ + gparent = RB_PARENT(parent, field); \ + if (parent == RB_LEFT(gparent, field)) { \ + tmp = RB_RIGHT(gparent, field); \ + if (tmp && RB_COLOR(tmp, field) == RB_RED) { \ + RB_COLOR(tmp, field) = RB_BLACK; \ + RB_SET_BLACKRED(parent, gparent, field);\ + elm = gparent; \ + continue; \ + } \ + if (RB_RIGHT(parent, field) == elm) { \ + RB_ROTATE_LEFT(head, parent, tmp, field);\ + tmp = parent; \ + parent = elm; \ + elm = tmp; \ + } \ + RB_SET_BLACKRED(parent, gparent, field); \ + RB_ROTATE_RIGHT(head, gparent, tmp, field); \ + } else { \ + tmp = RB_LEFT(gparent, field); \ + if (tmp && RB_COLOR(tmp, field) == RB_RED) { \ + RB_COLOR(tmp, field) = RB_BLACK; \ + RB_SET_BLACKRED(parent, gparent, field);\ + elm = gparent; \ + continue; \ + } \ + if (RB_LEFT(parent, field) == elm) { \ + RB_ROTATE_RIGHT(head, parent, tmp, field);\ + tmp = parent; \ + parent = elm; \ + elm = tmp; \ + } \ + RB_SET_BLACKRED(parent, gparent, field); \ + RB_ROTATE_LEFT(head, gparent, tmp, field); \ + } \ + } \ + RB_COLOR(head->rbh_root, field) = RB_BLACK; \ +} + +#define RB_GENERATE_REMOVE_COLOR(name, type, field, attr) \ +attr void \ +name##_RB_REMOVE_COLOR(struct name *head, struct type *parent, struct type *elm) \ +{ \ + struct type *tmp; \ + while ((elm == NULL || RB_COLOR(elm, field) == RB_BLACK) && \ + elm != RB_ROOT(head)) { \ + if (RB_LEFT(parent, field) == elm) { \ + tmp = RB_RIGHT(parent, field); \ + if (RB_COLOR(tmp, field) == RB_RED) { \ + RB_SET_BLACKRED(tmp, parent, field); \ + RB_ROTATE_LEFT(head, parent, tmp, field);\ + tmp = RB_RIGHT(parent, field); \ + } \ + if ((RB_LEFT(tmp, field) == NULL || \ + RB_COLOR(RB_LEFT(tmp, field), field) == RB_BLACK) &&\ + (RB_RIGHT(tmp, field) == NULL || \ + RB_COLOR(RB_RIGHT(tmp, field), field) == RB_BLACK)) {\ + RB_COLOR(tmp, field) = RB_RED; \ + elm = parent; \ + parent = RB_PARENT(elm, field); \ + } else { \ + if (RB_RIGHT(tmp, field) == NULL || \ + RB_COLOR(RB_RIGHT(tmp, field), field) == RB_BLACK) {\ + struct type *oleft; \ + if ((oleft = RB_LEFT(tmp, field)) \ + != NULL) \ + RB_COLOR(oleft, field) = RB_BLACK;\ + RB_COLOR(tmp, field) = RB_RED; \ + RB_ROTATE_RIGHT(head, tmp, oleft, field);\ + tmp = RB_RIGHT(parent, field); \ + } \ + RB_COLOR(tmp, field) = RB_COLOR(parent, field);\ + RB_COLOR(parent, field) = RB_BLACK; \ + if (RB_RIGHT(tmp, field)) \ + RB_COLOR(RB_RIGHT(tmp, field), field) = RB_BLACK;\ + RB_ROTATE_LEFT(head, parent, tmp, field);\ + elm = RB_ROOT(head); \ + break; \ + } \ + } else { \ + tmp = RB_LEFT(parent, field); \ + if (RB_COLOR(tmp, field) == RB_RED) { \ + RB_SET_BLACKRED(tmp, parent, field); \ + RB_ROTATE_RIGHT(head, parent, tmp, field);\ + tmp = RB_LEFT(parent, field); \ + } \ + if ((RB_LEFT(tmp, field) == NULL || \ + RB_COLOR(RB_LEFT(tmp, field), field) == RB_BLACK) &&\ + (RB_RIGHT(tmp, field) == NULL || \ + RB_COLOR(RB_RIGHT(tmp, field), field) == RB_BLACK)) {\ + RB_COLOR(tmp, field) = RB_RED; \ + elm = parent; \ + parent = RB_PARENT(elm, field); \ + } else { \ + if (RB_LEFT(tmp, field) == NULL || \ + RB_COLOR(RB_LEFT(tmp, field), field) == RB_BLACK) {\ + struct type *oright; \ + if ((oright = RB_RIGHT(tmp, field)) \ + != NULL) \ + RB_COLOR(oright, field) = RB_BLACK;\ + RB_COLOR(tmp, field) = RB_RED; \ + RB_ROTATE_LEFT(head, tmp, oright, field);\ + tmp = RB_LEFT(parent, field); \ + } \ + RB_COLOR(tmp, field) = RB_COLOR(parent, field);\ + RB_COLOR(parent, field) = RB_BLACK; \ + if (RB_LEFT(tmp, field)) \ + RB_COLOR(RB_LEFT(tmp, field), field) = RB_BLACK;\ + RB_ROTATE_RIGHT(head, parent, tmp, field);\ + elm = RB_ROOT(head); \ + break; \ + } \ + } \ + } \ + if (elm) \ + RB_COLOR(elm, field) = RB_BLACK; \ +} + +#define RB_GENERATE_REMOVE(name, type, field, attr) \ +attr struct type * \ +name##_RB_REMOVE(struct name *head, struct type *elm) \ +{ \ + struct type *child, *parent, *old = elm; \ + int color; \ + if (RB_LEFT(elm, field) == NULL) \ + child = RB_RIGHT(elm, field); \ + else if (RB_RIGHT(elm, field) == NULL) \ + child = RB_LEFT(elm, field); \ + else { \ + struct type *left; \ + elm = RB_RIGHT(elm, field); \ + while ((left = RB_LEFT(elm, field)) != NULL) \ + elm = left; \ + child = RB_RIGHT(elm, field); \ + parent = RB_PARENT(elm, field); \ + color = RB_COLOR(elm, field); \ + if (child) \ + RB_PARENT(child, field) = parent; \ + if (parent) { \ + if (RB_LEFT(parent, field) == elm) \ + RB_LEFT(parent, field) = child; \ + else \ + RB_RIGHT(parent, field) = child; \ + RB_AUGMENT(parent); \ + } else \ + RB_ROOT(head) = child; \ + if (RB_PARENT(elm, field) == old) \ + parent = elm; \ + (elm)->field = (old)->field; \ + if (RB_PARENT(old, field)) { \ + if (RB_LEFT(RB_PARENT(old, field), field) == old)\ + RB_LEFT(RB_PARENT(old, field), field) = elm;\ + else \ + RB_RIGHT(RB_PARENT(old, field), field) = elm;\ + RB_AUGMENT(RB_PARENT(old, field)); \ + } else \ + RB_ROOT(head) = elm; \ + RB_PARENT(RB_LEFT(old, field), field) = elm; \ + if (RB_RIGHT(old, field)) \ + RB_PARENT(RB_RIGHT(old, field), field) = elm; \ + if (parent) { \ + left = parent; \ + do { \ + RB_AUGMENT(left); \ + } while ((left = RB_PARENT(left, field)) != NULL); \ + } \ + goto color; \ + } \ + parent = RB_PARENT(elm, field); \ + color = RB_COLOR(elm, field); \ + if (child) \ + RB_PARENT(child, field) = parent; \ + if (parent) { \ + if (RB_LEFT(parent, field) == elm) \ + RB_LEFT(parent, field) = child; \ + else \ + RB_RIGHT(parent, field) = child; \ + RB_AUGMENT(parent); \ + } else \ + RB_ROOT(head) = child; \ +color: \ + if (color == RB_BLACK) \ + name##_RB_REMOVE_COLOR(head, parent, child); \ + return (old); \ +} \ + +#define RB_GENERATE_INSERT(name, type, field, cmp, attr) \ +/* Inserts a node into the RB tree */ \ +attr struct type * \ +name##_RB_INSERT(struct name *head, struct type *elm) \ +{ \ + struct type *tmp; \ + struct type *parent = NULL; \ + int comp = 0; \ + tmp = RB_ROOT(head); \ + while (tmp) { \ + parent = tmp; \ + comp = (cmp)(elm, parent); \ + if (comp < 0) \ + tmp = RB_LEFT(tmp, field); \ + else if (comp > 0) \ + tmp = RB_RIGHT(tmp, field); \ + else \ + return (tmp); \ + } \ + RB_SET(elm, parent, field); \ + if (parent != NULL) { \ + if (comp < 0) \ + RB_LEFT(parent, field) = elm; \ + else \ + RB_RIGHT(parent, field) = elm; \ + RB_AUGMENT(parent); \ + } else \ + RB_ROOT(head) = elm; \ + name##_RB_INSERT_COLOR(head, elm); \ + return (NULL); \ +} + +#define RB_GENERATE_FIND(name, type, field, cmp, attr) \ +/* Finds the node with the same key as elm */ \ +attr struct type * \ +name##_RB_FIND(struct name *head, struct type *elm) \ +{ \ + struct type *tmp = RB_ROOT(head); \ + int comp; \ + while (tmp) { \ + comp = cmp(elm, tmp); \ + if (comp < 0) \ + tmp = RB_LEFT(tmp, field); \ + else if (comp > 0) \ + tmp = RB_RIGHT(tmp, field); \ + else \ + return (tmp); \ + } \ + return (NULL); \ +} + +#define RB_GENERATE_NFIND(name, type, field, cmp, attr) \ +/* Finds the first node greater than or equal to the search key */ \ +attr struct type * \ +name##_RB_NFIND(struct name *head, struct type *elm) \ +{ \ + struct type *tmp = RB_ROOT(head); \ + struct type *res = NULL; \ + int comp; \ + while (tmp) { \ + comp = cmp(elm, tmp); \ + if (comp < 0) { \ + res = tmp; \ + tmp = RB_LEFT(tmp, field); \ + } \ + else if (comp > 0) \ + tmp = RB_RIGHT(tmp, field); \ + else \ + return (tmp); \ + } \ + return (res); \ +} + +#define RB_GENERATE_NEXT(name, type, field, attr) \ +/* ARGSUSED */ \ +attr struct type * \ +name##_RB_NEXT(struct type *elm) \ +{ \ + if (RB_RIGHT(elm, field)) { \ + elm = RB_RIGHT(elm, field); \ + while (RB_LEFT(elm, field)) \ + elm = RB_LEFT(elm, field); \ + } else { \ + if (RB_PARENT(elm, field) && \ + (elm == RB_LEFT(RB_PARENT(elm, field), field))) \ + elm = RB_PARENT(elm, field); \ + else { \ + while (RB_PARENT(elm, field) && \ + (elm == RB_RIGHT(RB_PARENT(elm, field), field)))\ + elm = RB_PARENT(elm, field); \ + elm = RB_PARENT(elm, field); \ + } \ + } \ + return (elm); \ +} + +#define RB_GENERATE_PREV(name, type, field, attr) \ +/* ARGSUSED */ \ +attr struct type * \ +name##_RB_PREV(struct type *elm) \ +{ \ + if (RB_LEFT(elm, field)) { \ + elm = RB_LEFT(elm, field); \ + while (RB_RIGHT(elm, field)) \ + elm = RB_RIGHT(elm, field); \ + } else { \ + if (RB_PARENT(elm, field) && \ + (elm == RB_RIGHT(RB_PARENT(elm, field), field))) \ + elm = RB_PARENT(elm, field); \ + else { \ + while (RB_PARENT(elm, field) && \ + (elm == RB_LEFT(RB_PARENT(elm, field), field)))\ + elm = RB_PARENT(elm, field); \ + elm = RB_PARENT(elm, field); \ + } \ + } \ + return (elm); \ +} + +#define RB_GENERATE_MINMAX(name, type, field, attr) \ +attr struct type * \ +name##_RB_MINMAX(struct name *head, int val) \ +{ \ + struct type *tmp = RB_ROOT(head); \ + struct type *parent = NULL; \ + while (tmp) { \ + parent = tmp; \ + if (val < 0) \ + tmp = RB_LEFT(tmp, field); \ + else \ + tmp = RB_RIGHT(tmp, field); \ + } \ + return (parent); \ +} + +#define RB_NEGINF -1 +#define RB_INF 1 + +#define RB_INSERT(name, x, y) name##_RB_INSERT(x, y) +#define RB_REMOVE(name, x, y) name##_RB_REMOVE(x, y) +#define RB_FIND(name, x, y) name##_RB_FIND(x, y) +#define RB_NFIND(name, x, y) name##_RB_NFIND(x, y) +#define RB_NEXT(name, x, y) name##_RB_NEXT(y) +#define RB_PREV(name, x, y) name##_RB_PREV(y) +#define RB_MIN(name, x) name##_RB_MINMAX(x, RB_NEGINF) +#define RB_MAX(name, x) name##_RB_MINMAX(x, RB_INF) + +#define RB_FOREACH(x, name, head) \ + for ((x) = RB_MIN(name, head); \ + (x) != NULL; \ + (x) = name##_RB_NEXT(x)) + +#define RB_FOREACH_FROM(x, name, y) \ + for ((x) = (y); \ + ((x) != NULL) && ((y) = name##_RB_NEXT(x), (x) != NULL); \ + (x) = (y)) + +#define RB_FOREACH_SAFE(x, name, head, y) \ + for ((x) = RB_MIN(name, head); \ + ((x) != NULL) && ((y) = name##_RB_NEXT(x), (x) != NULL); \ + (x) = (y)) + +#define RB_FOREACH_REVERSE(x, name, head) \ + for ((x) = RB_MAX(name, head); \ + (x) != NULL; \ + (x) = name##_RB_PREV(x)) + +#define RB_FOREACH_REVERSE_FROM(x, name, y) \ + for ((x) = (y); \ + ((x) != NULL) && ((y) = name##_RB_PREV(x), (x) != NULL); \ + (x) = (y)) + +#define RB_FOREACH_REVERSE_SAFE(x, name, head, y) \ + for ((x) = RB_MAX(name, head); \ + ((x) != NULL) && ((y) = name##_RB_PREV(x), (x) != NULL); \ + (x) = (y)) + +#endif /* _SYS_TREE_H_ */ diff --git a/contrib/sdk/sources/newlib/libc/include/sys/types.h b/contrib/sdk/sources/newlib/libc/include/sys/types.h index 32f66ab958..a64097a0ee 100644 --- a/contrib/sdk/sources/newlib/libc/include/sys/types.h +++ b/contrib/sdk/sources/newlib/libc/include/sys/types.h @@ -18,6 +18,7 @@ #ifndef _SYS_TYPES_H #include <_ansi.h> +# include #ifndef __INTTYPES_DEFINED__ #define __INTTYPES_DEFINED__ @@ -59,6 +60,7 @@ typedef quad_t * qaddr_t; #define _SYS_TYPES_H #include +#include #ifdef __i386__ #if defined (GO32) || defined (__MSDOS__) @@ -82,7 +84,7 @@ typedef quad_t * qaddr_t; #define _ST_INT32 #endif -# ifndef _POSIX_SOURCE +# if __BSD_VISIBLE # define physadr physadr_t # define quad quad_t @@ -111,7 +113,7 @@ typedef unsigned long u_long; typedef unsigned short ushort; /* System V compatibility */ typedef unsigned int uint; /* System V compatibility */ typedef unsigned long ulong; /* System V compatibility */ -# endif /*!_POSIX_SOURCE */ +# endif /*__BSD_VISIBLE */ #ifndef __clock_t_defined typedef _CLOCK_T_ clock_t; @@ -123,21 +125,6 @@ typedef _TIME_T_ time_t; #define __time_t_defined #endif -#ifndef __timespec_defined -#define __timespec_defined -/* Time Value Specification Structures, P1003.1b-1993, p. 261 */ - -struct timespec { - time_t tv_sec; /* Seconds */ - long tv_nsec; /* Nanoseconds */ -}; -#endif - -struct itimerspec { - struct timespec it_interval; /* Timer period */ - struct timespec it_value; /* Timer expiration */ -}; - #ifndef __daddr_t_defined typedef long daddr_t; #define __daddr_t_defined @@ -221,52 +208,6 @@ typedef unsigned int mode_t _ST_INT32; typedef unsigned short nlink_t; -/* We don't define fd_set and friends if we are compiling POSIX - source, or if we have included (or may include as indicated - by __USE_W32_SOCKETS) the W32api winsock[2].h header which - defines Windows versions of them. Note that a program which - includes the W32api winsock[2].h header must know what it is doing; - it must not call the cygwin32 select function. -*/ -# if !(defined (_POSIX_SOURCE) || defined (_WINSOCK_H) || defined (_WINSOCKAPI_) || defined (__USE_W32_SOCKETS)) -# define _SYS_TYPES_FD_SET -# define NBBY 8 /* number of bits in a byte */ -/* - * Select uses bit masks of file descriptors in longs. - * These macros manipulate such bit fields (the filesystem macros use chars). - * FD_SETSIZE may be defined by the user, but the default here - * should be >= NOFILE (param.h). - */ -# ifndef FD_SETSIZE -# define FD_SETSIZE 64 -# endif - -typedef long fd_mask; -# define NFDBITS (sizeof (fd_mask) * NBBY) /* bits per mask */ -# ifndef howmany -# define howmany(x,y) (((x)+((y)-1))/(y)) -# endif - -/* We use a macro for fd_set so that including Sockets.h afterwards - can work. */ -typedef struct _types_fd_set { - fd_mask fds_bits[howmany(FD_SETSIZE, NFDBITS)]; -} _types_fd_set; - -#define fd_set _types_fd_set - -# define FD_SET(n, p) ((p)->fds_bits[(n)/NFDBITS] |= (1L << ((n) % NFDBITS))) -# define FD_CLR(n, p) ((p)->fds_bits[(n)/NFDBITS] &= ~(1L << ((n) % NFDBITS))) -# define FD_ISSET(n, p) ((p)->fds_bits[(n)/NFDBITS] & (1L << ((n) % NFDBITS))) -# define FD_ZERO(p) (__extension__ (void)({ \ - size_t __i; \ - char *__tmp = (char *)p; \ - for (__i = 0; __i < sizeof (*(p)); ++__i) \ - *__tmp++ = 0; \ -})) - -# endif /* !(defined (_POSIX_SOURCE) || defined (_WINSOCK_H) || defined (_WINSOCKAPI_) || defined (__USE_W32_SOCKETS)) */ - #undef __MS_types__ #undef _ST_INT32 @@ -282,7 +223,13 @@ typedef _TIMER_T_ timer_t; #endif typedef unsigned long useconds_t; -typedef long suseconds_t; + +#ifndef _SUSECONDS_T_DECLARED +typedef __suseconds_t suseconds_t; +#define _SUSECONDS_T_DECLARED +#endif + +typedef __int64_t sbintime_t; #include diff --git a/contrib/sdk/sources/newlib/libc/include/sys/unistd.h b/contrib/sdk/sources/newlib/libc/include/sys/unistd.h index 6a5719d309..ed2bf3e8ec 100644 --- a/contrib/sdk/sources/newlib/libc/include/sys/unistd.h +++ b/contrib/sdk/sources/newlib/libc/include/sys/unistd.h @@ -6,15 +6,16 @@ extern "C" { #endif #include <_ansi.h> -#include -#include #define __need_size_t #define __need_ptrdiff_t +#include +#include +#include #include extern char **environ; -void _EXFUN(_exit, (int __status ) _ATTRIBUTE ((noreturn))); +void _EXFUN(_exit, (int __status ) _ATTRIBUTE ((__noreturn__))); int _EXFUN(access,(const char *__path, int __amode )); unsigned _EXFUN(alarm, (unsigned __secs )); @@ -54,6 +55,8 @@ int _EXFUN(execve, (const char *__path, char * const __argv[], char * const int _EXFUN(execvp, (const char *__file, char * const __argv[] )); #if defined(__CYGWIN__) int _EXFUN(execvpe, (const char *__file, char * const __argv[], char * const __envp[] )); +#endif +#if __POSIX_VISIBLE >= 200809 || __BSD_VISIBLE || defined(__CYGWIN__) int _EXFUN(faccessat, (int __dirfd, const char *__path, int __mode, int __flags)); #endif #if defined(__CYGWIN__) || defined(__rtems__) || defined(__SPU__) @@ -63,8 +66,10 @@ int _EXFUN(fchmod, (int __fildes, mode_t __mode )); #if !defined(__INSIDE_CYGWIN__) int _EXFUN(fchown, (int __fildes, uid_t __owner, gid_t __group )); #endif -#if defined(__CYGWIN__) +#if __POSIX_VISIBLE >= 200809 || __BSD_VISIBLE || defined(__CYGWIN__) int _EXFUN(fchownat, (int __dirfd, const char *__path, uid_t __owner, gid_t __group, int __flags)); +#endif +#if defined(__CYGWIN__) int _EXFUN(fexecve, (int __fd, char * const __argv[], char * const __envp[] )); #endif pid_t _EXFUN(fork, (void )); @@ -112,11 +117,14 @@ char * _EXFUN(getwd, (char *__buf )); int _EXFUN(iruserok, (unsigned long raddr, int superuser, const char *ruser, const char *luser)); #endif int _EXFUN(isatty, (int __fildes )); +#if __BSD_VISIBLE +int _EXFUN(issetugid, (void)); +#endif #if !defined(__INSIDE_CYGWIN__) int _EXFUN(lchown, (const char *__path, uid_t __owner, gid_t __group )); #endif int _EXFUN(link, (const char *__path1, const char *__path2 )); -#if defined(__CYGWIN__) +#if __POSIX_VISIBLE >= 200809 || __BSD_VISIBLE || defined(__CYGWIN__) int _EXFUN(linkat, (int __dirfd1, const char *__path1, int __dirfd2, const char *__path2, int __flags )); #endif int _EXFUN(nice, (int __nice_value )); @@ -161,6 +169,9 @@ int _EXFUN(setgid, (gid_t __gid )); #if defined(__CYGWIN__) int _EXFUN(setgroups, (int ngroups, const gid_t *grouplist )); #endif +#if __BSD_VISIBLE || (defined(_XOPEN_SOURCE) && __XSI_VISIBLE < 500) +int _EXFUN(sethostname, (const char *, size_t)); +#endif int _EXFUN(setpgid, (pid_t __pid, pid_t __pgid )); int _EXFUN(setpgrp, (void )); #if defined(__CYGWIN__) && !defined(__INSIDE_CYGWIN__) @@ -246,12 +257,12 @@ void _EXFUN(sync, (void)); ssize_t _EXFUN(readlink, (const char *__restrict __path, char *__restrict __buf, size_t __buflen)); -#if defined(__CYGWIN__) +#if __POSIX_VISIBLE >= 200809 || __BSD_VISIBLE || defined(__CYGWIN__) ssize_t _EXFUN(readlinkat, (int __dirfd1, const char *__restrict __path, char *__restrict __buf, size_t __buflen)); #endif int _EXFUN(symlink, (const char *__name1, const char *__name2)); -#if defined(__CYGWIN__) +#if __POSIX_VISIBLE >= 200809 || __BSD_VISIBLE || defined(__CYGWIN__) int _EXFUN(symlinkat, (const char *, int, const char *)); int _EXFUN(unlinkat, (int, const char *, int)); #endif @@ -414,6 +425,21 @@ int _EXFUN(unlinkat, (int, const char *, int)); #define _SC_THREAD_ROBUST_PRIO_INHERIT 122 #define _SC_THREAD_ROBUST_PRIO_PROTECT 123 #define _SC_XOPEN_UUCP 124 +#define _SC_LEVEL1_ICACHE_SIZE 125 +#define _SC_LEVEL1_ICACHE_ASSOC 126 +#define _SC_LEVEL1_ICACHE_LINESIZE 127 +#define _SC_LEVEL1_DCACHE_SIZE 128 +#define _SC_LEVEL1_DCACHE_ASSOC 129 +#define _SC_LEVEL1_DCACHE_LINESIZE 130 +#define _SC_LEVEL2_CACHE_SIZE 131 +#define _SC_LEVEL2_CACHE_ASSOC 132 +#define _SC_LEVEL2_CACHE_LINESIZE 133 +#define _SC_LEVEL3_CACHE_SIZE 134 +#define _SC_LEVEL3_CACHE_ASSOC 135 +#define _SC_LEVEL3_CACHE_LINESIZE 136 +#define _SC_LEVEL4_CACHE_SIZE 137 +#define _SC_LEVEL4_CACHE_ASSOC 138 +#define _SC_LEVEL4_CACHE_LINESIZE 139 /* * pathconf values per IEEE Std 1003.1, 2008 Edition diff --git a/contrib/sdk/sources/newlib/libc/include/sys/wait.h b/contrib/sdk/sources/newlib/libc/include/sys/wait.h index 62a777ea20..0af3a52d55 100644 --- a/contrib/sdk/sources/newlib/libc/include/sys/wait.h +++ b/contrib/sdk/sources/newlib/libc/include/sys/wait.h @@ -11,7 +11,7 @@ extern "C" { #define WUNTRACED 2 /* A status looks like: - <2 bytes info> <2 bytes code> + <1 byte info> <1 byte code> == 0, child has exited, info is the exit value == 1..7e, child has exited, info is the signal number. diff --git a/contrib/sdk/sources/newlib/libc/include/threads.h b/contrib/sdk/sources/newlib/libc/include/threads.h new file mode 100644 index 0000000000..9fb08b03d1 --- /dev/null +++ b/contrib/sdk/sources/newlib/libc/include/threads.h @@ -0,0 +1,93 @@ +/*- + * Copyright (c) 2011 Ed Schouten + * 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. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR 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 AUTHOR 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. + */ + +#ifndef _THREADS_H_ +#define _THREADS_H_ + +#include +#include + +typedef void (*tss_dtor_t)(void *); +typedef int (*thrd_start_t)(void *); + +enum { + mtx_plain = 0x1, + mtx_recursive = 0x2, + mtx_timed = 0x4 +}; + +enum { + thrd_busy = 1, + thrd_error = 2, + thrd_nomem = 3, + thrd_success = 4, + thrd_timedout = 5 +}; + +#if !defined(__cplusplus) || __cplusplus < 201103L +#define thread_local _Thread_local +#endif + +__BEGIN_DECLS +void call_once(once_flag *, void (*)(void)); +int cnd_broadcast(cnd_t *); +void cnd_destroy(cnd_t *); +int cnd_init(cnd_t *); +int cnd_signal(cnd_t *); +int cnd_timedwait(cnd_t *__restrict, mtx_t *__restrict __mtx, + const struct timespec *__restrict) + __requires_exclusive(*__mtx); +int cnd_wait(cnd_t *, mtx_t *__mtx) + __requires_exclusive(*__mtx); +void mtx_destroy(mtx_t *__mtx) + __requires_unlocked(*__mtx); +int mtx_init(mtx_t *__mtx, int) + __requires_unlocked(*__mtx); +int mtx_lock(mtx_t *__mtx) + __locks_exclusive(*__mtx); +int mtx_timedlock(mtx_t *__restrict __mtx, + const struct timespec *__restrict) + __trylocks_exclusive(thrd_success, *__mtx); +int mtx_trylock(mtx_t *__mtx) + __trylocks_exclusive(thrd_success, *__mtx); +int mtx_unlock(mtx_t *__mtx) + __unlocks(*__mtx); +int thrd_create(thrd_t *, thrd_start_t, void *); +thrd_t thrd_current(void); +int thrd_detach(thrd_t); +int thrd_equal(thrd_t, thrd_t); +_Noreturn void + thrd_exit(int); +int thrd_join(thrd_t, int *); +int thrd_sleep(const struct timespec *, struct timespec *); +void thrd_yield(void); +int tss_create(tss_t *, tss_dtor_t); +void tss_delete(tss_t); +void * tss_get(tss_t); +int tss_set(tss_t, void *); +__END_DECLS + +#endif /* !_THREADS_H_ */ diff --git a/contrib/sdk/sources/newlib/libc/include/time.h b/contrib/sdk/sources/newlib/libc/include/time.h index 67f8d61b6d..ed7cfa4471 100644 --- a/contrib/sdk/sources/newlib/libc/include/time.h +++ b/contrib/sdk/sources/newlib/libc/include/time.h @@ -25,6 +25,7 @@ #define CLK_TCK CLOCKS_PER_SEC #include +#include _BEGIN_STD_C @@ -39,6 +40,12 @@ struct tm int tm_wday; int tm_yday; int tm_isdst; +#ifdef __TM_GMTOFF + long __TM_GMTOFF; +#endif +#ifdef __TM_ZONE + const char *__TM_ZONE; +#endif }; clock_t _EXFUN(clock, (void)); diff --git a/contrib/sdk/sources/newlib/libc/include/wchar.h b/contrib/sdk/sources/newlib/libc/include/wchar.h index 553641797f..291fd417ca 100644 --- a/contrib/sdk/sources/newlib/libc/include/wchar.h +++ b/contrib/sdk/sources/newlib/libc/include/wchar.h @@ -16,7 +16,7 @@ /* For _mbstate_t definition. */ #include - +#include /* For __STDC_ISO_10646__ */ #include @@ -24,6 +24,7 @@ # define WEOF ((wint_t)-1) #endif +/* This must match definition in */ #ifndef WCHAR_MIN #ifdef __WCHAR_MIN__ #define WCHAR_MIN __WCHAR_MIN__ @@ -34,6 +35,7 @@ #endif #endif +/* This must match definition in */ #ifndef WCHAR_MAX #ifdef __WCHAR_MAX__ #define WCHAR_MAX __WCHAR_MAX__ @@ -47,7 +49,10 @@ _BEGIN_STD_C /* As in stdio.h, defines __FILE. */ +#if !defined(__FILE_defined) typedef __FILE FILE; +# define __FILE_defined +#endif /* As required by POSIX.1-2008, declare tm as incomplete type. The actual definition is in time.h. */ @@ -141,10 +146,7 @@ long _EXFUN(_wcstol_r, (struct _reent *, const wchar_t *, wchar_t **, int)); long long _EXFUN(_wcstoll_r, (struct _reent *, const wchar_t *, wchar_t **, int)); unsigned long _EXFUN(_wcstoul_r, (struct _reent *, const wchar_t *, wchar_t **, int)); unsigned long long _EXFUN(_wcstoull_r, (struct _reent *, const wchar_t *, wchar_t **, int)); -/* On platforms where long double equals double. */ -#ifdef _LDBL_EQ_DBL long double _EXFUN(wcstold, (const wchar_t *, wchar_t **)); -#endif /* _LDBL_EQ_DBL */ wint_t _EXFUN(fgetwc, (__FILE *)); wchar_t *_EXFUN(fgetws, (wchar_t *__restrict, int, __FILE *__restrict)); @@ -158,16 +160,35 @@ wint_t _EXFUN(putwchar, (wchar_t)); wint_t _EXFUN (ungetwc, (wint_t wc, __FILE *)); wint_t _EXFUN(_fgetwc_r, (struct _reent *, __FILE *)); +wint_t _EXFUN(_fgetwc_unlocked_r, (struct _reent *, __FILE *)); wchar_t *_EXFUN(_fgetws_r, (struct _reent *, wchar_t *, int, __FILE *)); +wchar_t *_EXFUN(_fgetws_unlocked_r, (struct _reent *, wchar_t *, int, __FILE *)); wint_t _EXFUN(_fputwc_r, (struct _reent *, wchar_t, __FILE *)); +wint_t _EXFUN(_fputwc_unlocked_r, (struct _reent *, wchar_t, __FILE *)); int _EXFUN(_fputws_r, (struct _reent *, const wchar_t *, __FILE *)); +int _EXFUN(_fputws_unlocked_r, (struct _reent *, const wchar_t *, __FILE *)); int _EXFUN (_fwide_r, (struct _reent *, __FILE *, int)); wint_t _EXFUN (_getwc_r, (struct _reent *, __FILE *)); +wint_t _EXFUN (_getwc_unlocked_r, (struct _reent *, __FILE *)); wint_t _EXFUN (_getwchar_r, (struct _reent *ptr)); +wint_t _EXFUN (_getwchar_unlocked_r, (struct _reent *ptr)); wint_t _EXFUN(_putwc_r, (struct _reent *, wchar_t, __FILE *)); +wint_t _EXFUN(_putwc_unlocked_r, (struct _reent *, wchar_t, __FILE *)); wint_t _EXFUN(_putwchar_r, (struct _reent *, wchar_t)); +wint_t _EXFUN(_putwchar_unlocked_r, (struct _reent *, wchar_t)); wint_t _EXFUN (_ungetwc_r, (struct _reent *, wint_t wc, __FILE *)); +#if __GNU_VISIBLE +wint_t _EXFUN(fgetwc_unlocked, (__FILE *)); +wchar_t *_EXFUN(fgetws_unlocked, (wchar_t *__restrict, int, __FILE *__restrict)); +wint_t _EXFUN(fputwc_unlocked, (wchar_t, __FILE *)); +int _EXFUN(fputws_unlocked, (const wchar_t *__restrict, __FILE *__restrict)); +wint_t _EXFUN(getwc_unlocked, (__FILE *)); +wint_t _EXFUN(getwchar_unlocked, (void)); +wint_t _EXFUN(putwc_unlocked, (wchar_t, __FILE *)); +wint_t _EXFUN(putwchar_unlocked, (wchar_t)); +#endif + __FILE *_EXFUN (open_wmemstream, (wchar_t **, size_t *)); __FILE *_EXFUN (_open_wmemstream_r, (struct _reent *, wchar_t **, size_t *)); @@ -218,6 +239,13 @@ int _EXFUN(_wscanf_r, (struct _reent *, const wchar_t *, ...)); #define getwchar() fgetwc(_REENT->_stdin) #define putwchar(wc) fputwc((wc), _REENT->_stdout) +#if __GNU_VISIBLE +#define getwc_unlocked(fp) fgetwc_unlocked(fp) +#define putwc_unlocked(wc,fp) fputwc_unlocked((wc), (fp)) +#define getwchar_unlocked() fgetwc_unlocked(_REENT->_stdin) +#define putwchar_unlocked(wc) fputwc_unlocked((wc), _REENT->_stdout) +#endif + _END_STD_C #endif /* _WCHAR_H_ */ diff --git a/contrib/sdk/sources/newlib/libc/locale/ldpart.c b/contrib/sdk/sources/newlib/libc/locale/ldpart.c index 595532298f..35ad3bd13a 100644 --- a/contrib/sdk/sources/newlib/libc/locale/ldpart.c +++ b/contrib/sdk/sources/newlib/libc/locale/ldpart.c @@ -110,7 +110,7 @@ __part_load_locale(const char *name, goto bad_locale; if (st.st_size <= 0) goto bad_locale; - bufsize = namesize + st.st_size; + bufsize = namesize + st.st_size + 1; locale_buf = NULL; if (lbuf == NULL || lbuf == locale_buf_C) @@ -137,6 +137,7 @@ __part_load_locale(const char *name, /* * Parse the locale file into localebuf. */ + p[st.st_size] = '\0'; if (plim[-1] != '\n') goto bad_lbuf; num_lines = split_lines(p, plim); diff --git a/contrib/sdk/sources/newlib/libc/locale/locale.c b/contrib/sdk/sources/newlib/libc/locale/locale.c index 2c5b65e2a6..72815b9457 100644 --- a/contrib/sdk/sources/newlib/libc/locale/locale.c +++ b/contrib/sdk/sources/newlib/libc/locale/locale.c @@ -88,7 +88,7 @@ Cygwin additionally supports locales from the file /usr/share/locale/locale.alias. (<<"">> is also accepted; if given, the settings are read from the -corresponding LC_* environment variables and $LANG according to POSIX rules. +corresponding LC_* environment variables and $LANG according to POSIX rules.) This implementation also supports the modifier <<"cjknarrow">>, which affects how the functions <> and <> handle characters @@ -498,7 +498,7 @@ restart: locale = new_categories[category]; # define FAIL return NULL #endif - + /* "POSIX" is translated to "C", as on Linux. */ if (!strcmp (locale, "POSIX")) strcpy (locale, "C"); @@ -573,14 +573,14 @@ restart: FAIL; } if (c && c[0] == '@') - { - /* Modifier */ - /* Only one modifier is recognized right now. "cjknarrow" is used - to modify the behaviour of wcwidth() for East Asian languages. - For details see the comment at the end of this function. */ - if (!strcmp (c + 1, "cjknarrow")) - cjknarrow = 1; - } + { + /* Modifier */ + /* Only one modifier is recognized right now. "cjknarrow" is used + to modify the behaviour of wcwidth() for East Asian languages. + For details see the comment at the end of this function. */ + if (!strcmp (c + 1, "cjknarrow")) + cjknarrow = 1; + } /* We only support this subset of charsets. */ switch (charset[0]) { @@ -772,9 +772,9 @@ restart: || !strcasecmp (charset, "GB2312")) { strcpy (charset, charset[2] == '2' ? "GB2312" : "GBK"); - mbc_max = 2; - l_wctomb = __gbk_wctomb; - l_mbtowc = __gbk_mbtowc; + mbc_max = 2; + l_wctomb = __gbk_wctomb; + l_mbtowc = __gbk_mbtowc; } else #endif /* __CYGWIN__ */ diff --git a/contrib/sdk/sources/newlib/libc/reent/closer.c b/contrib/sdk/sources/newlib/libc/reent/closer.c index 70a46e9a40..4f52fdb760 100644 --- a/contrib/sdk/sources/newlib/libc/reent/closer.c +++ b/contrib/sdk/sources/newlib/libc/reent/closer.c @@ -22,7 +22,7 @@ extern int errno; /* FUNCTION <<_close_r>>---Reentrant version of close - + INDEX _close_r diff --git a/contrib/sdk/sources/newlib/libc/reent/fstatr.c b/contrib/sdk/sources/newlib/libc/reent/fstatr.c index 7d4163d148..5400e20b99 100644 --- a/contrib/sdk/sources/newlib/libc/reent/fstatr.c +++ b/contrib/sdk/sources/newlib/libc/reent/fstatr.c @@ -28,7 +28,7 @@ extern int errno; /* FUNCTION <<_fstat_r>>---Reentrant version of fstat - + INDEX _fstat_r diff --git a/contrib/sdk/sources/newlib/libc/reent/isattyr.c b/contrib/sdk/sources/newlib/libc/reent/isattyr.c index e59a0052b0..c0530c7737 100644 --- a/contrib/sdk/sources/newlib/libc/reent/isattyr.c +++ b/contrib/sdk/sources/newlib/libc/reent/isattyr.c @@ -26,7 +26,7 @@ extern int errno; /* FUNCTION <<_isatty_r>>---Reentrant version of isatty - + INDEX _isatty_r diff --git a/contrib/sdk/sources/newlib/libc/reent/lseekr.c b/contrib/sdk/sources/newlib/libc/reent/lseekr.c index 355ceeaa97..2a39480d8c 100644 --- a/contrib/sdk/sources/newlib/libc/reent/lseekr.c +++ b/contrib/sdk/sources/newlib/libc/reent/lseekr.c @@ -22,7 +22,7 @@ extern int errno; /* FUNCTION <<_lseek_r>>---Reentrant version of lseek - + INDEX _lseek_r diff --git a/contrib/sdk/sources/newlib/libc/reent/openr.c b/contrib/sdk/sources/newlib/libc/reent/openr.c index e120b68411..8924b5a254 100644 --- a/contrib/sdk/sources/newlib/libc/reent/openr.c +++ b/contrib/sdk/sources/newlib/libc/reent/openr.c @@ -23,7 +23,7 @@ extern int errno; /* FUNCTION <<_open_r>>---Reentrant version of open - + INDEX _open_r diff --git a/contrib/sdk/sources/newlib/libc/reent/readr.c b/contrib/sdk/sources/newlib/libc/reent/readr.c index ad64e5d561..781557c52d 100644 --- a/contrib/sdk/sources/newlib/libc/reent/readr.c +++ b/contrib/sdk/sources/newlib/libc/reent/readr.c @@ -22,7 +22,7 @@ extern int errno; /* FUNCTION <<_read_r>>---Reentrant version of read - + INDEX _read_r diff --git a/contrib/sdk/sources/newlib/libc/reent/writer.c b/contrib/sdk/sources/newlib/libc/reent/writer.c index 639838564f..dc3731e78b 100644 --- a/contrib/sdk/sources/newlib/libc/reent/writer.c +++ b/contrib/sdk/sources/newlib/libc/reent/writer.c @@ -22,7 +22,7 @@ extern int errno; /* FUNCTION <<_write_r>>---Reentrant version of write - + INDEX _write_r diff --git a/contrib/sdk/sources/newlib/libc/search/qsort.c b/contrib/sdk/sources/newlib/libc/search/qsort.c index 5b901a4300..7e4a6d8cca 100644 --- a/contrib/sdk/sources/newlib/libc/search/qsort.c +++ b/contrib/sdk/sources/newlib/libc/search/qsort.c @@ -53,11 +53,7 @@ PORTABILITY * 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. All advertising materials mentioning features or use of this software - * must display the following acknowledgement: - * This product includes software developed by the University of - * California, Berkeley and its contributors. - * 4. Neither the name of the University nor the names of its contributors + * 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. * @@ -75,13 +71,21 @@ PORTABILITY */ #include <_ansi.h> +#include #include #ifndef __GNUC__ #define inline #endif -static inline char *med3 _PARAMS((char *, char *, char *, int (*)())); +#if defined(I_AM_QSORT_R) +typedef int cmp_t(void *, const void *, const void *); +#elif defined(I_AM_GNU_QSORT_R) +typedef int cmp_t(const void *, const void *, void *); +#else +typedef int cmp_t(const void *, const void *); +#endif +static inline char *med3 _PARAMS((char *, char *, char *, cmp_t *, void *)); static inline void swapfunc _PARAMS((char *, char *, int, int)); #define min(a, b) (a) < (b) ? a : b @@ -91,10 +95,10 @@ static inline void swapfunc _PARAMS((char *, char *, int, int)); */ #define swapcode(TYPE, parmi, parmj, n) { \ long i = (n) / sizeof (TYPE); \ - register TYPE *pi = (TYPE *) (parmi); \ - register TYPE *pj = (TYPE *) (parmj); \ + TYPE *pi = (TYPE *) (parmi); \ + TYPE *pj = (TYPE *) (parmj); \ do { \ - register TYPE t = *pi; \ + TYPE t = *pi; \ *pi++ = *pj; \ *pj++ = t; \ } while (--i > 0); \ @@ -110,7 +114,7 @@ _DEFUN(swapfunc, (a, b, n, swaptype), int n _AND int swaptype) { - if(swaptype <= 1) + if(swaptype <= 1) swapcode(long, a, b, n) else swapcode(char, a, b, n) @@ -126,33 +130,67 @@ _DEFUN(swapfunc, (a, b, n, swaptype), #define vecswap(a, b, n) if ((n) > 0) swapfunc(a, b, n, swaptype) +#if defined(I_AM_QSORT_R) +#define CMP(t, x, y) (cmp((t), (x), (y))) +#elif defined(I_AM_GNU_QSORT_R) +#define CMP(t, x, y) (cmp((x), (y), (t))) +#else +#define CMP(t, x, y) (cmp((x), (y))) +#endif + static inline char * -_DEFUN(med3, (a, b, c, cmp), +_DEFUN(med3, (a, b, c, cmp, thunk), char *a _AND char *b _AND char *c _AND - int (*cmp)()) + cmp_t *cmp _AND + void *thunk +#if !defined(I_AM_QSORT_R) && !defined(I_AM_GNU_QSORT_R) +__unused +#endif +) { - return cmp(a, b) < 0 ? - (cmp(b, c) < 0 ? b : (cmp(a, c) < 0 ? c : a )) - :(cmp(b, c) > 0 ? b : (cmp(a, c) < 0 ? a : c )); + return CMP(thunk, a, b) < 0 ? + (CMP(thunk, b, c) < 0 ? b : (CMP(thunk, a, c) < 0 ? c : a )) + :(CMP(thunk, b, c) > 0 ? b : (CMP(thunk, a, c) < 0 ? a : c )); } +#if defined(I_AM_QSORT_R) +void +_DEFUN(__bsd_qsort_r, (a, n, es, thunk, cmp), + void *a _AND + size_t n _AND + size_t es _AND + void *thunk _AND + cmp_t *cmp) +#elif defined(I_AM_GNU_QSORT_R) +void +_DEFUN(qsort_r, (a, n, es, cmp, thunk), + void *a _AND + size_t n _AND + size_t es _AND + cmp_t *cmp _AND + void *thunk) +#else +#define thunk NULL void _DEFUN(qsort, (a, n, es, cmp), void *a _AND size_t n _AND size_t es _AND - int (*cmp)()) + cmp_t *cmp) +#endif { char *pa, *pb, *pc, *pd, *pl, *pm, *pn; - int d, r, swaptype, swap_cnt; + size_t d, r; + int cmp_result; + int swaptype, swap_cnt; loop: SWAPINIT(a, es); swap_cnt = 0; if (n < 7) { for (pm = (char *) a + es; pm < (char *) a + n * es; pm += es) - for (pl = pm; pl > (char *) a && cmp(pl - es, pl) > 0; + for (pl = pm; pl > (char *) a && CMP(thunk, pl - es, pl) > 0; pl -= es) swap(pl, pl - es); return; @@ -163,27 +201,27 @@ loop: SWAPINIT(a, es); pn = (char *) a + (n - 1) * es; if (n > 40) { d = (n / 8) * es; - pl = med3(pl, pl + d, pl + 2 * d, cmp); - pm = med3(pm - d, pm, pm + d, cmp); - pn = med3(pn - 2 * d, pn - d, pn, cmp); + pl = med3(pl, pl + d, pl + 2 * d, cmp, thunk); + pm = med3(pm - d, pm, pm + d, cmp, thunk); + pn = med3(pn - 2 * d, pn - d, pn, cmp, thunk); } - pm = med3(pl, pm, pn, cmp); + pm = med3(pl, pm, pn, cmp, thunk); } swap(a, pm); pa = pb = (char *) a + es; pc = pd = (char *) a + (n - 1) * es; for (;;) { - while (pb <= pc && (r = cmp(pb, a)) <= 0) { - if (r == 0) { + while (pb <= pc && (cmp_result = CMP(thunk, pb, a)) <= 0) { + if (cmp_result == 0) { swap_cnt = 1; swap(pa, pb); pa += es; } pb += es; } - while (pb <= pc && (r = cmp(pc, a)) >= 0) { - if (r == 0) { + while (pb <= pc && (cmp_result = CMP(thunk, pc, a)) >= 0) { + if (cmp_result == 0) { swap_cnt = 1; swap(pc, pd); pd -= es; @@ -199,7 +237,7 @@ loop: SWAPINIT(a, es); } if (swap_cnt == 0) { /* Switch to insertion sort */ for (pm = (char *) a + es; pm < (char *) a + n * es; pm += es) - for (pl = pm; pl > (char *) a && cmp(pl - es, pl) > 0; + for (pl = pm; pl > (char *) a && CMP(thunk, pl - es, pl) > 0; pl -= es) swap(pl, pl - es); return; @@ -211,8 +249,14 @@ loop: SWAPINIT(a, es); r = min(pd - pc, pn - pd - es); vecswap(pb, pn - r, r); if ((r = pb - pa) > es) +#if defined(I_AM_QSORT_R) + __bsd_qsort_r(a, r / es, es, thunk, cmp); +#elif defined(I_AM_GNU_QSORT_R) + qsort_r(a, r / es, es, cmp, thunk); +#else qsort(a, r / es, es, cmp); - if ((r = pd - pc) > es) { +#endif + if ((r = pd - pc) > es) { /* Iterate rather than recurse to save stack space */ a = pn - r; n = r / es; diff --git a/contrib/sdk/sources/newlib/libc/stdio/asnprintf.c b/contrib/sdk/sources/newlib/libc/stdio/asnprintf.c index a37c503588..2e8d8aabb5 100644 --- a/contrib/sdk/sources/newlib/libc/stdio/asnprintf.c +++ b/contrib/sdk/sources/newlib/libc/stdio/asnprintf.c @@ -58,6 +58,12 @@ _DEFUN(_asnprintf_r, (ptr, buf, lenp, fmt), return (char *) f._bf._base; } +#ifdef _NANO_FORMATTED_IO +char * +_EXFUN(_asniprintf_r, (struct _reent *, char *, size_t *, const char *, ...) + _ATTRIBUTE ((__alias__("_asnprintf_r")))); +#endif + #ifndef _REENT_ONLY char * @@ -105,4 +111,9 @@ _DEFUN(asnprintf, (buf, lenp, fmt), return (char *) f._bf._base; } +#ifdef _NANO_FORMATTED_IO +char * +_EXFUN(asniprintf, (char *, size_t *, const char *, ...) + _ATTRIBUTE ((__alias__("asnprintf")))); +#endif #endif /* ! _REENT_ONLY */ diff --git a/contrib/sdk/sources/newlib/libc/stdio/asprintf.c b/contrib/sdk/sources/newlib/libc/stdio/asprintf.c index d044112510..bf214f9aff 100644 --- a/contrib/sdk/sources/newlib/libc/stdio/asprintf.c +++ b/contrib/sdk/sources/newlib/libc/stdio/asprintf.c @@ -50,6 +50,12 @@ _DEFUN(_asprintf_r, (ptr, strp, fmt), return (ret); } +#ifdef _NANO_FORMATTED_IO +int +_EXFUN(_asiprintf_r, (struct _reent *, char **, const char *, ...) + _ATTRIBUTE ((__alias__("_asprintf_r")))); +#endif + #ifndef _REENT_ONLY int @@ -77,4 +83,9 @@ _DEFUN(asprintf, (strp, fmt), return (ret); } +#ifdef _NANO_FORMATTED_IO +int +_EXFUN(asiprintf, (char **, const char *, ...) + _ATTRIBUTE ((__alias__("asprintf")))); +#endif #endif /* ! _REENT_ONLY */ diff --git a/contrib/sdk/sources/newlib/libc/stdio/clearerr.c b/contrib/sdk/sources/newlib/libc/stdio/clearerr.c index ed4603ba21..9bf0837f57 100644 --- a/contrib/sdk/sources/newlib/libc/stdio/clearerr.c +++ b/contrib/sdk/sources/newlib/libc/stdio/clearerr.c @@ -17,20 +17,31 @@ /* FUNCTION -<>---clear file or stream error indicator +<>, <>---clear file or stream error indicator INDEX clearerr +INDEX + clearerr_unlocked ANSI_SYNOPSIS #include void clearerr(FILE *<[fp]>); + #define _BSD_SOURCE + #include + void clearerr_unlocked(FILE *<[fp]>); + TRAD_SYNOPSIS #include void clearerr(<[fp]>) FILE *<[fp]>; + #define _BSD_SOURCE + #include + void clearerr_unlocked(<[fp]>) + FILE *<[fp]>; + DESCRIPTION The <> functions maintain an error indicator with each file pointer <[fp]>, to record whether any read or write errors have @@ -42,6 +53,14 @@ Use <> to reset both of these indicators. See <> and <> to query the two indicators. +<> is a non-thread-safe version of <>. +<> may only safely be used within a scope +protected by flockfile() (or ftrylockfile()) and funlockfile(). This +function may safely be used in a multi-threaded program if and only +if they are called while the invoking thread owns the (FILE *) +object, as is the case after a successful call to the flockfile() or +ftrylockfile() functions. If threads are disabled, then +<> is equivalent to <>. RETURNS <> does not return a result. @@ -49,6 +68,8 @@ RETURNS PORTABILITY ANSI C requires <>. +<> is a BSD extension also provided by GNU libc. + No supporting OS subroutines are required. */ diff --git a/contrib/sdk/sources/newlib/libc/stdio/dprintf.c b/contrib/sdk/sources/newlib/libc/stdio/dprintf.c index 2271f4b5c2..2925ceb310 100644 --- a/contrib/sdk/sources/newlib/libc/stdio/dprintf.c +++ b/contrib/sdk/sources/newlib/libc/stdio/dprintf.c @@ -67,6 +67,12 @@ _DEFUN(_dprintf_r, (ptr, fd, format), return n; } +#ifdef _NANO_FORMATTED_IO +int +_EXFUN(_diprintf_r, (struct _reent *, int, const char *, ...) + _ATTRIBUTE ((__alias__("_dprintf_r")))); +#endif + #ifndef _REENT_ONLY int @@ -85,4 +91,9 @@ _DEFUN(dprintf, (fd, format), return n; } +#ifdef _NANO_FORMATTED_IO +int +_EXFUN(diprintf, (int, const char *, ...) + _ATTRIBUTE ((__alias__("dprintf")))); +#endif #endif /* ! _REENT_ONLY */ diff --git a/contrib/sdk/sources/newlib/libc/stdio/fclose.c b/contrib/sdk/sources/newlib/libc/stdio/fclose.c index 6c88407802..214c0500d4 100644 --- a/contrib/sdk/sources/newlib/libc/stdio/fclose.c +++ b/contrib/sdk/sources/newlib/libc/stdio/fclose.c @@ -82,20 +82,27 @@ _DEFUN(_fclose_r, (rptr, fp), int __oldcancel; pthread_setcancelstate (PTHREAD_CANCEL_DISABLE, &__oldcancel); #endif - _flockfile (fp); + if (!(fp->_flags2 & __SNLK)) + _flockfile (fp); if (fp->_flags == 0) /* not open! */ { - _funlockfile (fp); + if (!(fp->_flags2 & __SNLK)) + _funlockfile (fp); #ifdef _STDIO_WITH_THREAD_CANCELLATION_SUPPORT pthread_setcancelstate (__oldcancel, &__oldcancel); #endif return (0); } - /* Unconditionally flush to allow special handling for seekable read - files to reposition file to last byte processed as opposed to - last byte read ahead into the buffer. */ - r = _fflush_r (rptr, fp); +#ifdef _STDIO_BSD_SEMANTICS + /* BSD and Glibc systems only flush streams which have been written to. */ + r = (fp->_flags & __SWR) ? __sflush_r (rptr, fp) : 0; +#else + /* Follow POSIX semantics exactly. Unconditionally flush to allow + special handling for seekable read files to reposition file to last + byte processed as opposed to last byte read ahead into the buffer. */ + r = __sflush_r (rptr, fp); +#endif if (fp->_close != NULL && fp->_close (rptr, fp->_cookie) < 0) r = EOF; if (fp->_flags & __SMBF) @@ -106,7 +113,8 @@ _DEFUN(_fclose_r, (rptr, fp), FREELB (rptr, fp); __sfp_lock_acquire (); fp->_flags = 0; /* release this FILE for reuse */ - _funlockfile (fp); + if (!(fp->_flags2 & __SNLK)) + _funlockfile (fp); #ifndef __SINGLE_THREAD__ __lock_close_recursive (fp->_lock); #endif diff --git a/contrib/sdk/sources/newlib/libc/stdio/feof.c b/contrib/sdk/sources/newlib/libc/stdio/feof.c index c0216ffed4..7aadd82097 100644 --- a/contrib/sdk/sources/newlib/libc/stdio/feof.c +++ b/contrib/sdk/sources/newlib/libc/stdio/feof.c @@ -17,24 +17,44 @@ /* FUNCTION -<>---test for end of file +<>, <>---test for end of file INDEX feof +INDEX + feof_unlocked ANSI_SYNOPSIS #include int feof(FILE *<[fp]>); + #define _BSD_SOURCE + #include + int feof_unlocked(FILE *<[fp]>); + TRAD_SYNOPSIS #include int feof(<[fp]>) FILE *<[fp]>; + #define _BSD_SOURCE + #include + int feof_unlocked(<[fp]>) + FILE *<[fp]>; + DESCRIPTION <> tests whether or not the end of the file identified by <[fp]> has been reached. +<> is a non-thread-safe version of <>. +<> may only safely be used within a scope +protected by flockfile() (or ftrylockfile()) and funlockfile(). This +function may safely be used in a multi-threaded program if and only +if they are called while the invoking thread owns the (FILE *) +object, as is the case after a successful call to the flockfile() or +ftrylockfile() functions. If threads are disabled, then +<> is equivalent to <>. + RETURNS <> returns <<0>> if the end of file has not yet been reached; if at end of file, the result is nonzero. @@ -42,6 +62,8 @@ at end of file, the result is nonzero. PORTABILITY <> is required by ANSI C. +<> is a BSD extension also provided by GNU libc. + No supporting OS subroutines are required. */ diff --git a/contrib/sdk/sources/newlib/libc/stdio/ferror.c b/contrib/sdk/sources/newlib/libc/stdio/ferror.c index 0cd3c30893..f93063d710 100644 --- a/contrib/sdk/sources/newlib/libc/stdio/ferror.c +++ b/contrib/sdk/sources/newlib/libc/stdio/ferror.c @@ -17,20 +17,31 @@ /* FUNCTION -<>---test whether read/write error has occurred +<>, <>---test whether read/write error has occurred INDEX ferror +INDEX + ferror_unlocked ANSI_SYNOPSIS #include int ferror(FILE *<[fp]>); + #define _BSD_SOURCE + #include + int ferror_unlocked(FILE *<[fp]>); + TRAD_SYNOPSIS #include int ferror(<[fp]>) FILE *<[fp]>; + #define _BSD_SOURCE + #include + int ferror_unlocked(<[fp]>) + FILE *<[fp]>; + DESCRIPTION The <> functions maintain an error indicator with each file pointer <[fp]>, to record whether any read or write errors have @@ -39,6 +50,15 @@ Use <> to query this indicator. See <> to reset the error indicator. +<> is a non-thread-safe version of <>. +<> may only safely be used within a scope +protected by flockfile() (or ftrylockfile()) and funlockfile(). This +function may safely be used in a multi-threaded program if and only +if they are called while the invoking thread owns the (FILE *) +object, as is the case after a successful call to the flockfile() or +ftrylockfile() functions. If threads are disabled, then +<> is equivalent to <>. + RETURNS <> returns <<0>> if no errors have occurred; it returns a nonzero value otherwise. @@ -46,6 +66,8 @@ nonzero value otherwise. PORTABILITY ANSI C requires <>. +<> is a BSD extension also provided by GNU libc. + No supporting OS subroutines are required. */ diff --git a/contrib/sdk/sources/newlib/libc/stdio/fflush.c b/contrib/sdk/sources/newlib/libc/stdio/fflush.c index eab016174b..bb215d5b51 100644 --- a/contrib/sdk/sources/newlib/libc/stdio/fflush.c +++ b/contrib/sdk/sources/newlib/libc/stdio/fflush.c @@ -17,19 +17,32 @@ /* FUNCTION -<>---flush buffered file output +<>, <>---flush buffered file output INDEX fflush +INDEX + fflush_unlocked INDEX _fflush_r +INDEX + _fflush_unlocked_r ANSI_SYNOPSIS #include int fflush(FILE *<[fp]>); + #define _BSD_SOURCE + #include + int fflush_unlocked(FILE *<[fp]>); + + #include int _fflush_r(struct _reent *<[reent]>, FILE *<[fp]>); + #define _BSD_SOURCE + #include + int _fflush_unlocked_r(struct _reent *<[reent]>, FILE *<[fp]>); + DESCRIPTION The <> output functions can buffer output before delivering it to the host system, in order to minimize the overhead of system calls. @@ -45,9 +58,18 @@ descriptor, set the position of the file descriptor to match next unread byte, useful for obeying POSIX semantics when ending a process without consuming all input from the stream. -The alternate function <<_fflush_r>> is a reentrant version, where the -extra argument <[reent]> is a pointer to a reentrancy structure, and -<[fp]> must not be NULL. +<> is a non-thread-safe version of <>. +<> may only safely be used within a scope +protected by flockfile() (or ftrylockfile()) and funlockfile(). This +function may safely be used in a multi-threaded program if and only +if they are called while the invoking thread owns the (FILE *) +object, as is the case after a successful call to the flockfile() or +ftrylockfile() functions. If threads are disabled, then +<> is equivalent to <>. + +The alternate functions <<_fflush_r>> and <<_fflush_unlocked_r>> are +reentrant versions, where the extra argument <[reent]> is a pointer to +a reentrancy structure, and <[fp]> must not be NULL. RETURNS <> returns <<0>> unless it encounters a write error; in that @@ -57,6 +79,8 @@ PORTABILITY ANSI C requires <>. The behavior on input streams is only specified by POSIX, and not all implementations follow POSIX rules. +<> is a BSD extension also provided by GNU libc. + No supporting OS subroutines are required. */ @@ -65,6 +89,12 @@ No supporting OS subroutines are required. #include #include "local.h" +#ifdef __IMPL_UNLOCKED__ +#define _fflush_r _fflush_unlocked_r +#define fflush fflush_unlocked +#endif + +#ifndef __IMPL_UNLOCKED__ /* Flush a single file, or (if fp is NULL) all files. */ /* Core function which does not lock file pointer. This gets called @@ -204,6 +234,21 @@ _DEFUN(__sflush_r, (ptr, fp), return 0; } +#ifdef _STDIO_BSD_SEMANTICS +/* Called from _cleanup_r. At exit time, we don't need file locking, + and we don't want to move the underlying file pointer unless we're + writing. */ +int +_DEFUN(__sflushw_r, (ptr, fp), + struct _reent *ptr _AND + register FILE *fp) +{ + return (fp->_flags & __SWR) ? __sflush_r (ptr, fp) : 0; +} +#endif + +#endif /* __IMPL_UNLOCKED__ */ + int _DEFUN(_fflush_r, (ptr, fp), struct _reent *ptr _AND diff --git a/contrib/sdk/sources/newlib/libc/stdio/fgetc.c b/contrib/sdk/sources/newlib/libc/stdio/fgetc.c index 20492d24ba..34447a2c83 100644 --- a/contrib/sdk/sources/newlib/libc/stdio/fgetc.c +++ b/contrib/sdk/sources/newlib/libc/stdio/fgetc.c @@ -17,30 +17,53 @@ /* FUNCTION -<>---get a character from a file or stream +<>, <>---get a character from a file or stream INDEX fgetc +INDEX + fgetc_unlocked INDEX _fgetc_r +INDEX + _fgetc_unlocked_r ANSI_SYNOPSIS #include int fgetc(FILE *<[fp]>); + #define _BSD_SOURCE + #include + int fgetc_unlocked(FILE *<[fp]>); + #include int _fgetc_r(struct _reent *<[ptr]>, FILE *<[fp]>); + #define _BSD_SOURCE + #include + int _fgetc_unlocked_r(struct _reent *<[ptr]>, FILE *<[fp]>); + TRAD_SYNOPSIS #include int fgetc(<[fp]>) FILE *<[fp]>; + #define _BSD_SOURCE + #include + int fgetc_unlocked(<[fp]>) + FILE *<[fp]>; + #include int _fgetc_r(<[ptr]>, <[fp]>) struct _reent *<[ptr]>; FILE *<[fp]>; + #define _BSD_SOURCE + #include + int _fgetc_unlocked_r(<[ptr]>, <[fp]>) + struct _reent *<[ptr]>; + FILE *<[fp]>; + DESCRIPTION Use <> to get the next single character from the file or stream identified by <[fp]>. As a side effect, <> advances the file's @@ -48,9 +71,18 @@ current position indicator. For a macro version of this function, see <>. -The function <<_fgetc_r>> is simply a reentrant version of -<> that is passed the additional reentrant structure -pointer argument: <[ptr]>. +<> is a non-thread-safe version of <>. +<> may only safely be used within a scope +protected by flockfile() (or ftrylockfile()) and funlockfile(). This +function may safely be used in a multi-threaded program if and only +if they are called while the invoking thread owns the (FILE *) +object, as is the case after a successful call to the flockfile() or +ftrylockfile() functions. If threads are disabled, then +<> is equivalent to <>. + +The functions <<_fgetc_r>> and <<_fgetc_unlocked_r>> are simply reentrant +versions that are passed the additional reentrant structure pointer +argument: <[ptr]>. RETURNS The next character (read as an <>, and cast to @@ -63,6 +95,8 @@ using the <> and <> functions. PORTABILITY ANSI C requires <>. +<> is a BSD extension also provided by GNU libc. + Supporting OS subroutines required: <>, <>, <>, <>, <>, <>, <>. */ diff --git a/contrib/sdk/sources/newlib/libc/stdio/fgets.c b/contrib/sdk/sources/newlib/libc/stdio/fgets.c index 5fe11914ee..44717debe1 100644 --- a/contrib/sdk/sources/newlib/libc/stdio/fgets.c +++ b/contrib/sdk/sources/newlib/libc/stdio/fgets.c @@ -17,20 +17,31 @@ /* FUNCTION -<>---get character string from a file or stream +<>, <>---get character string from a file or stream INDEX fgets +INDEX + fgets_unlocked INDEX _fgets_r +INDEX + _fgets_unlocked_r ANSI_SYNOPSIS #include char *fgets(char *restrict <[buf]>, int <[n]>, FILE *restrict <[fp]>); + #define _GNU_SOURCE + #include + char *fgets_unlocked(char *restrict <[buf]>, int <[n]>, FILE *restrict <[fp]>); + #include char *_fgets_r(struct _reent *<[ptr]>, char *restrict <[buf]>, int <[n]>, FILE *restrict <[fp]>); + #include + char *_fgets_unlocked_r(struct _reent *<[ptr]>, char *restrict <[buf]>, int <[n]>, FILE *restrict <[fp]>); + TRAD_SYNOPSIS #include char *fgets(<[buf]>,<[n]>,<[fp]>) @@ -38,6 +49,13 @@ TRAD_SYNOPSIS int <[n]>; FILE *<[fp]>; + #define _GNU_SOURCE + #include + char *fgets_unlocked(<[buf]>,<[n]>,<[fp]>) + char *<[buf]>; + int <[n]>; + FILE *<[fp]>; + #include char *_fgets_r(<[ptr]>, <[buf]>,<[n]>,<[fp]>) struct _reent *<[ptr]>; @@ -45,14 +63,30 @@ TRAD_SYNOPSIS int <[n]>; FILE *<[fp]>; + #include + char *_fgets_unlocked_r(<[ptr]>, <[buf]>,<[n]>,<[fp]>) + struct _reent *<[ptr]>; + char *<[buf]>; + int <[n]>; + FILE *<[fp]>; + DESCRIPTION Reads at most <[n-1]> characters from <[fp]> until a newline is found. The characters including to the newline are stored in <[buf]>. The buffer is terminated with a 0. - The <<_fgets_r>> function is simply the reentrant version of - <> and is passed an additional reentrancy structure - pointer: <[ptr]>. + <> is a non-thread-safe version of <>. + <> may only safely be used within a scope + protected by flockfile() (or ftrylockfile()) and funlockfile(). This + function may safely be used in a multi-threaded program if and only + if they are called while the invoking thread owns the (FILE *) + object, as is the case after a successful call to the flockfile() or + ftrylockfile() functions. If threads are disabled, then + <> is equivalent to <>. + + The functions <<_fgets_r>> and <<_fgets_unlocked_r>> are simply + reentrant versions that are passed the additional reentrant structure + pointer argument: <[ptr]>. RETURNS <> returns the buffer passed to it, with the data @@ -65,6 +99,8 @@ PORTABILITY that <> returns all of the data, while <> removes the trailing newline (with no indication that it has done so.) + <> is a GNU extension. + Supporting OS subroutines required: <>, <>, <>, <>, <>, <>, <>. */ @@ -74,6 +110,11 @@ Supporting OS subroutines required: <>, <>, <>, #include #include "local.h" +#ifdef __IMPL_UNLOCKED__ +#define _fgets_r _fgets_unlocked_r +#define fgets fgets_unlocked +#endif + /* * Read at most n-1 characters from the given file. * Stop when a newline has been read, or the count runs out. diff --git a/contrib/sdk/sources/newlib/libc/stdio/fileno.c b/contrib/sdk/sources/newlib/libc/stdio/fileno.c index b3d0950764..16316c18c8 100644 --- a/contrib/sdk/sources/newlib/libc/stdio/fileno.c +++ b/contrib/sdk/sources/newlib/libc/stdio/fileno.c @@ -17,23 +17,43 @@ /* FUNCTION -<>---return file descriptor associated with stream +<>, <>---return file descriptor associated with stream INDEX fileno +INDEX + fileno_unlocked ANSI_SYNOPSIS #include int fileno(FILE *<[fp]>); + #define _BSD_SOURCE + #include + int fileno_unlocked(FILE *<[fp]>); + TRAD_SYNOPSIS #include int fileno(<[fp]>) FILE *<[fp]>; + #define _BSD_SOURCE + #include + int fileno_unlocked(<[fp]>) + FILE *<[fp]>; + DESCRIPTION You can use <> to return the file descriptor identified by <[fp]>. +<> is a non-thread-safe version of <>. +<> may only safely be used within a scope +protected by flockfile() (or ftrylockfile()) and funlockfile(). This +function may safely be used in a multi-threaded program if and only +if they are called while the invoking thread owns the (FILE *) +object, as is the case after a successful call to the flockfile() or +ftrylockfile() functions. If threads are disabled, then +<> is equivalent to <>. + RETURNS <> returns a non-negative integer when successful. If <[fp]> is not an open stream, <> returns -1. @@ -42,6 +62,8 @@ PORTABILITY <> is not part of ANSI C. POSIX requires <>. +<> is a BSD extension also provided by GNU libc. + Supporting OS subroutines required: none. */ @@ -58,7 +80,7 @@ _DEFUN(fileno, (f), CHECK_INIT (_REENT, f); _newlib_flockfile_start (f); if (f->_flags) - result = __sfileno (f); + result = __sfileno (f); else { result = -1; diff --git a/contrib/sdk/sources/newlib/libc/stdio/findfp.c b/contrib/sdk/sources/newlib/libc/stdio/findfp.c index 00d3880744..b43f7c3a0e 100644 --- a/contrib/sdk/sources/newlib/libc/stdio/findfp.c +++ b/contrib/sdk/sources/newlib/libc/stdio/findfp.c @@ -35,7 +35,11 @@ const struct __sFILE_fake __sf_fake_stderr = {_NULL, 0, 0, 0, 0, {_NULL, 0}, 0, _NULL}; #endif +#if (defined (__OPTIMIZE_SIZE__) || defined (PREFER_SIZE_OVER_SPEED)) +_NOINLINE_STATIC _VOID +#else static _VOID +#endif _DEFUN(std, (ptr, flags, file, data), FILE *ptr _AND int flags _AND @@ -170,8 +174,22 @@ _VOID _DEFUN(_cleanup_r, (ptr), struct _reent *ptr) { - _CAST_VOID _fwalk(ptr, fclose); - /* _CAST_VOID _fwalk (ptr, fflush); */ /* `cheating' */ + int (*cleanup_func) (struct _reent *, FILE *); +#ifdef _STDIO_BSD_SEMANTICS + /* BSD and Glibc systems only flush streams which have been written to + at exit time. Calling flush rather than close for speed, as on + the aforementioned systems. */ + cleanup_func = __sflushw_r; +#else + /* Otherwise close files and flush read streams, too. + Note we call flush directly if "--enable-lite-exit" is in effect. */ +#ifdef _LITE_EXIT + cleanup_func = _fflush_r; +#else + cleanup_func = _fclose_r; +#endif +#endif + _CAST_VOID _fwalk_reent (ptr, cleanup_func); } #ifndef _REENT_ONLY @@ -275,7 +293,8 @@ static int _DEFUN(__fp_lock, (ptr), FILE * ptr) { - _flockfile (ptr); + if (!(ptr->_flags2 & __SNLK)) + _flockfile (ptr); return 0; } @@ -285,7 +304,8 @@ static int _DEFUN(__fp_unlock, (ptr), FILE * ptr) { - _funlockfile (ptr); + if (!(ptr->_flags2 & __SNLK)) + _funlockfile (ptr); return 0; } diff --git a/contrib/sdk/sources/newlib/libc/stdio/flags.c b/contrib/sdk/sources/newlib/libc/stdio/flags.c index b8892718c4..59fc945a21 100644 --- a/contrib/sdk/sources/newlib/libc/stdio/flags.c +++ b/contrib/sdk/sources/newlib/libc/stdio/flags.c @@ -65,12 +65,12 @@ _DEFUN(__sflags, (ptr, mode, optr), switch (*mode) { case '+': - ret = (ret & ~(__SRD | __SWR)) | __SRW; + ret = (ret & ~(__SRD | __SWR)) | __SRW; m = (m & ~O_ACCMODE) | O_RDWR; break; case 'b': #ifdef O_BINARY - m |= O_BINARY; + m |= O_BINARY; #endif break; #ifdef __CYGWIN__ @@ -92,7 +92,7 @@ _DEFUN(__sflags, (ptr, mode, optr), } #if defined (O_TEXT) && !defined (__CYGWIN__) if (!(m | O_BINARY)) - m |= O_TEXT; + m |= O_TEXT; #endif *optr = m | o; return ret; diff --git a/contrib/sdk/sources/newlib/libc/stdio/fprintf.c b/contrib/sdk/sources/newlib/libc/stdio/fprintf.c index e0b760f80a..1cad968bf6 100644 --- a/contrib/sdk/sources/newlib/libc/stdio/fprintf.c +++ b/contrib/sdk/sources/newlib/libc/stdio/fprintf.c @@ -36,6 +36,12 @@ _DEFUN(_fprintf_r, (ptr, fp, fmt), return ret; } +#ifdef _NANO_FORMATTED_IO +int +_EXFUN(_fiprintf_r, (struct _reent *, FILE *, const char *, ...) + _ATTRIBUTE ((__alias__("_fprintf_r")))); +#endif + #ifndef _REENT_ONLY int @@ -52,4 +58,9 @@ _DEFUN(fprintf, (fp, fmt), return ret; } +#ifdef _NANO_FORMATTED_IO +int +_EXFUN(fiprintf, (FILE *, const char *, ...) + _ATTRIBUTE ((__alias__("fprintf")))); +#endif #endif /* ! _REENT_ONLY */ diff --git a/contrib/sdk/sources/newlib/libc/stdio/fputc.c b/contrib/sdk/sources/newlib/libc/stdio/fputc.c index 796c3e3017..aeb5b2777b 100644 --- a/contrib/sdk/sources/newlib/libc/stdio/fputc.c +++ b/contrib/sdk/sources/newlib/libc/stdio/fputc.c @@ -17,32 +17,55 @@ /* FUNCTION -<>---write a character on a stream or file +<>, <>---write a character on a stream or file INDEX fputc +INDEX + fputc_unlocked INDEX _fputc_r +INDEX + _fputc_unlocked_r ANSI_SYNOPSIS #include int fputc(int <[ch]>, FILE *<[fp]>); + #define _BSD_SOURCE + #include + int fputc_unlocked(int <[ch]>, FILE *<[fp]>); + #include int _fputc_r(struct _rent *<[ptr]>, int <[ch]>, FILE *<[fp]>); + #include + int _fputc_unlocked_r(struct _rent *<[ptr]>, int <[ch]>, FILE *<[fp]>); + TRAD_SYNOPSIS #include int fputc(<[ch]>, <[fp]>) int <[ch]>; FILE *<[fp]>; + #define _BSD_SOURCE + #include + int fputc_unlocked(<[ch]>, <[fp]>) + int <[ch]>; + FILE *<[fp]>; + #include int _fputc_r(<[ptr]>, <[ch]>, <[fp]>) struct _reent *<[ptr]>; int <[ch]>; FILE *<[fp]>; + #include + int _fputc_unlocked_r(<[ptr]>, <[ch]>, <[fp]>) + struct _reent *<[ptr]>; + int <[ch]>; + FILE *<[fp]>; + DESCRIPTION <> converts the argument <[ch]> from an <> to an <>, then writes it to the file or stream identified by @@ -56,8 +79,18 @@ oadvances by one. For a macro version of this function, see <>. -The <<_fputc_r>> function is simply a reentrant version of <> -that takes an additional reentrant structure argument: <[ptr]>. +<> is a non-thread-safe version of <>. +<> may only safely be used within a scope +protected by flockfile() (or ftrylockfile()) and funlockfile(). This +function may safely be used in a multi-threaded program if and only +if they are called while the invoking thread owns the (FILE *) +object, as is the case after a successful call to the flockfile() or +ftrylockfile() functions. If threads are disabled, then +<> is equivalent to <>. + +The <<_fputc_r>> and <<_fputc_unlocked_r>> functions are simply reentrant +versions of the above that take an additional reentrant structure +argument: <[ptr]>. RETURNS If successful, <> returns its argument <[ch]>. If an error @@ -67,6 +100,8 @@ query for errors. PORTABILITY <> is required by ANSI C. +<> is a BSD extension also provided by GNU libc. + Supporting OS subroutines required: <>, <>, <>, <>, <>, <>, <>. */ diff --git a/contrib/sdk/sources/newlib/libc/stdio/fputs.c b/contrib/sdk/sources/newlib/libc/stdio/fputs.c index e4d2cc4459..56d2b41b8b 100644 --- a/contrib/sdk/sources/newlib/libc/stdio/fputs.c +++ b/contrib/sdk/sources/newlib/libc/stdio/fputs.c @@ -17,38 +17,70 @@ /* FUNCTION -<>---write a character string in a file or stream +<>, <>---write a character string in a file or stream INDEX fputs +INDEX + fputs_unlocked INDEX _fputs_r +INDEX + _fputs_unlocked_r ANSI_SYNOPSIS #include int fputs(const char *restrict <[s]>, FILE *restrict <[fp]>); + #define _GNU_SOURCE + #include + int fputs_unlocked(const char *restrict <[s]>, FILE *restrict <[fp]>); + #include int _fputs_r(struct _reent *<[ptr]>, const char *restrict <[s]>, FILE *restrict <[fp]>); + #include + int _fputs_unlocked_r(struct _reent *<[ptr]>, const char *restrict <[s]>, FILE *restrict <[fp]>); + TRAD_SYNOPSIS #include int fputs(<[s]>, <[fp]>) char *<[s]>; FILE *<[fp]>; + #define _GNU_SOURCE + #include + int fputs_unlocked(<[s]>, <[fp]>) + char *<[s]>; + FILE *<[fp]>; + #include int _fputs_r(<[ptr]>, <[s]>, <[fp]>) struct _reent *<[ptr]>; char *<[s]>; FILE *<[fp]>; + #include + int _fputs_unlocked_r(<[ptr]>, <[s]>, <[fp]>) + struct _reent *<[ptr]>; + char *<[s]>; + FILE *<[fp]>; + DESCRIPTION <> writes the string at <[s]> (but without the trailing null) to the file or stream identified by <[fp]>. -<<_fputs_r>> is simply the reentrant version of <> that takes -an additional reentrant struct pointer argument: <[ptr]>. +<> is a non-thread-safe version of <>. +<> may only safely be used within a scope +protected by flockfile() (or ftrylockfile()) and funlockfile(). This +function may safely be used in a multi-threaded program if and only +if they are called while the invoking thread owns the (FILE *) +object, as is the case after a successful call to the flockfile() or +ftrylockfile() functions. If threads are disabled, then +<> is equivalent to <>. + +<<_fputs_r>> and <<_fputs_unlocked_r>> are simply reentrant versions of the +above that take an additional reentrant struct pointer argument: <[ptr]>. RETURNS If successful, the result is <<0>>; otherwise, the result is <>. @@ -57,6 +89,8 @@ PORTABILITY ANSI C requires <>, but does not specify that the result on success must be <<0>>; any non-negative value is permitted. +<> is a GNU extension. + Supporting OS subroutines required: <>, <>, <>, <>, <>, <>, <>. */ @@ -67,10 +101,14 @@ Supporting OS subroutines required: <>, <>, <>, #include "fvwrite.h" #include "local.h" +#ifdef __IMPL_UNLOCKED__ +#define _fputs_r _fputs_unlocked_r +#define fputs fputs_unlocked +#endif + /* * Write the given string to the given file. */ - int _DEFUN(_fputs_r, (ptr, s, fp), struct _reent * ptr _AND diff --git a/contrib/sdk/sources/newlib/libc/stdio/fputwc.c b/contrib/sdk/sources/newlib/libc/stdio/fputwc.c index 41d4119dce..b933ddef65 100644 --- a/contrib/sdk/sources/newlib/libc/stdio/fputwc.c +++ b/contrib/sdk/sources/newlib/libc/stdio/fputwc.c @@ -26,34 +26,60 @@ /* FUNCTION -<>, <>---write a wide character on a stream or file +<>, <>, <>, <>---write a wide character on a stream or file INDEX fputwc +INDEX + fputwc_unlocked INDEX _fputwc_r +INDEX + _fputwc_unlocked_r INDEX putwc +INDEX + putwc_unlocked INDEX _putwc_r +INDEX + _putwc_unlocked_r ANSI_SYNOPSIS #include #include wint_t fputwc(wchar_t <[wc]>, FILE *<[fp]>); + #define _GNU_SOURCE + #include + #include + wint_t fputwc_unlocked(wchar_t <[wc]>, FILE *<[fp]>); + #include #include wint_t _fputwc_r(struct _reent *<[ptr]>, wchar_t <[wc]>, FILE *<[fp]>); + #include + #include + wint_t _fputwc_unlocked_r(struct _reent *<[ptr]>, wchar_t <[wc]>, FILE *<[fp]>); + #include #include wint_t putwc(wchar_t <[wc]>, FILE *<[fp]>); + #define _GNU_SOURCE + #include + #include + wint_t putwc_unlocked(wchar_t <[wc]>, FILE *<[fp]>); + #include #include wint_t _putwc_r(struct _reent *<[ptr]>, wchar_t <[wc]>, FILE *<[fp]>); + #include + #include + wint_t _putwc_unlocked_r(struct _reent *<[ptr]>, wchar_t <[wc]>, FILE *<[fp]>); + TRAD_SYNOPSIS #include #include @@ -61,6 +87,13 @@ TRAD_SYNOPSIS wchar_t <[wc]>; FILE *<[fp]>; + #define _GNU_SOURCE + #include + #include + wint_t fputwc_unlocked(<[wc]>, <[fp]>) + wchar_t <[wc]>; + FILE *<[fp]>; + #include #include wint_t _fputwc_r(<[ptr]>, <[wc]>, <[fp]>) @@ -68,12 +101,26 @@ TRAD_SYNOPSIS wchar_t <[wc]>; FILE *<[fp]>; + #include + #include + wint_t _fputwc_unlocked_r(<[ptr]>, <[wc]>, <[fp]>) + struct _reent *<[ptr]>; + wchar_t <[wc]>; + FILE *<[fp]>; + #include #include wint_t putwc(<[wc]>, <[fp]>) wchar_t <[wc]>; FILE *<[fp]>; + #define _GNU_SOURCE + #include + #include + wint_t putwc_unlocked(<[wc]>, <[fp]>) + wchar_t <[wc]>; + FILE *<[fp]>; + #include #include wint_t _putwc_r(<[ptr]>, <[wc]>, <[fp]>) @@ -81,6 +128,13 @@ TRAD_SYNOPSIS wchar_t <[wc]>; FILE *<[fp]>; + #include + #include + wint_t _putwc_unlocked_r(<[ptr]>, <[wc]>, <[fp]>) + struct _reent *<[ptr]>; + wchar_t <[wc]>; + FILE *<[fp]>; + DESCRIPTION <> writes the wide character argument <[wc]> to the file or stream identified by <[fp]>. @@ -91,13 +145,22 @@ file or stream. Otherwise, the new wide character is written at the current value of the position indicator, and the position indicator oadvances by one. -The <> function or macro functions identically to <>. It -may be implemented as a macro, and may evaluate its argument more than -once. There is no reason ever to use it. +<> is a non-thread-safe version of <>. +<> may only safely be used within a scope +protected by flockfile() (or ftrylockfile()) and funlockfile(). This +function may safely be used in a multi-threaded program if and only +if they are called while the invoking thread owns the (FILE *) +object, as is the case after a successful call to the flockfile() or +ftrylockfile() functions. If threads are disabled, then +<> is equivalent to <>. -The <<_fputwc_r>> and <<_putwc_r>> functions are simply reentrant versions -of <> and <> that take an additional reentrant structure -argument: <[ptr]>. +The <> and <> functions or macros function identically +to <> and <>. They may be implemented as a macro, and +may evaluate its argument more than once. There is no reason ever to use them. + +The <<_fputwc_r>>, <<_putwc_r>>, <<_fputwc_unlocked_r>>, and +<<_putwc_unlocked_r>> functions are simply reentrant versions of the above +that take an additional reentrant structure argument: <[ptr]>. RETURNS If successful, <> and <> return their argument <[wc]>. @@ -105,7 +168,9 @@ If an error intervenes, the result is <>. You can use `<)>>' to query for errors. PORTABILITY -C99, POSIX.1-2001 +<> and <> are required by C99 and POSIX.1-2001. + +<> and <> are GNU extensions. */ #include <_ansi.h> @@ -117,7 +182,7 @@ C99, POSIX.1-2001 #include #include "local.h" -static wint_t +wint_t _DEFUN(__fputwc, (ptr, wc, fp), struct _reent *ptr _AND wchar_t wc _AND diff --git a/contrib/sdk/sources/newlib/libc/stdio/fread.c b/contrib/sdk/sources/newlib/libc/stdio/fread.c index b937d25f00..ab9ded5c7f 100644 --- a/contrib/sdk/sources/newlib/libc/stdio/fread.c +++ b/contrib/sdk/sources/newlib/libc/stdio/fread.c @@ -17,22 +17,35 @@ /* FUNCTION -<>---read array elements from a file +<>, <>---read array elements from a file INDEX fread +INDEX + fread_unlocked INDEX _fread_r +INDEX + _fread_unlocked_r ANSI_SYNOPSIS #include size_t fread(void *restrict <[buf]>, size_t <[size]>, size_t <[count]>, FILE *restrict <[fp]>); + #define _BSD_SOURCE + #include + size_t fread_unlocked(void *restrict <[buf]>, size_t <[size]>, size_t <[count]>, + FILE *restrict <[fp]>); + #include size_t _fread_r(struct _reent *<[ptr]>, void *restrict <[buf]>, size_t <[size]>, size_t <[count]>, FILE *restrict <[fp]>); + #include + size_t _fread_unlocked_r(struct _reent *<[ptr]>, void *restrict <[buf]>, + size_t <[size]>, size_t <[count]>, FILE *restrict <[fp]>); + TRAD_SYNOPSIS #include size_t fread(<[buf]>, <[size]>, <[count]>, <[fp]>) @@ -41,6 +54,14 @@ TRAD_SYNOPSIS size_t <[count]>; FILE *<[fp]>; + #define _BSD_SOURCE + #include + size_t fread_unlocked(<[buf]>, <[size]>, <[count]>, <[fp]>) + char *<[buf]>; + size_t <[size]>; + size_t <[count]>; + FILE *<[fp]>; + #include size_t _fread_r(<[ptr]>, <[buf]>, <[size]>, <[count]>, <[fp]>) struct _reent *<[ptr]>; @@ -49,6 +70,14 @@ TRAD_SYNOPSIS size_t <[count]>; FILE *<[fp]>; + #include + size_t _fread_unlocked_r(<[ptr]>, <[buf]>, <[size]>, <[count]>, <[fp]>) + struct _reent *<[ptr]>; + char *<[buf]>; + size_t <[size]>; + size_t <[count]>; + FILE *<[fp]>; + DESCRIPTION <> attempts to copy, from the file or stream identified by <[fp]>, <[count]> elements (each of size <[size]>) into memory, @@ -58,8 +87,17 @@ starting at <[buf]>. <> may copy fewer elements than <> also advances the file position indicator (if any) for <[fp]> by the number of @emph{characters} actually read. -<<_fread_r>> is simply the reentrant version of <> that -takes an additional reentrant structure pointer argument: <[ptr]>. +<> is a non-thread-safe version of <>. +<> may only safely be used within a scope +protected by flockfile() (or ftrylockfile()) and funlockfile(). This +function may safely be used in a multi-threaded program if and only +if they are called while the invoking thread owns the (FILE *) +object, as is the case after a successful call to the flockfile() or +ftrylockfile() functions. If threads are disabled, then +<> is equivalent to <>. + +<<_fread_r>> and <<_fread_unlocked_r>> are simply reentrant versions of the +above that take an additional reentrant structure pointer argument: <[ptr]>. RETURNS The result of <> is the number of elements it succeeded in @@ -68,6 +106,8 @@ reading. PORTABILITY ANSI C requires <>. +<> is a BSD extension also provided by GNU libc. + Supporting OS subroutines required: <>, <>, <>, <>, <>, <>, <>. */ @@ -78,6 +118,11 @@ Supporting OS subroutines required: <>, <>, <>, #include #include "local.h" +#ifdef __IMPL_UNLOCKED__ +#define _fread_r _fread_unlocked_r +#define fread fread_unlocked +#endif + #ifdef __SCLE static size_t _DEFUN(crlf_r, (ptr, fp, buf, count, eof), diff --git a/contrib/sdk/sources/newlib/libc/stdio/freopen.c b/contrib/sdk/sources/newlib/libc/stdio/freopen.c index 47bb790a9f..90a6d3483b 100644 --- a/contrib/sdk/sources/newlib/libc/stdio/freopen.c +++ b/contrib/sdk/sources/newlib/libc/stdio/freopen.c @@ -95,7 +95,7 @@ _DEFUN(_freopen_r, (ptr, file, mode, fp), register FILE *__restrict fp) { register int f; - int flags, oflags; + int flags, oflags, oflags2; int e = 0; CHECK_INIT (ptr, fp); @@ -106,11 +106,14 @@ _DEFUN(_freopen_r, (ptr, file, mode, fp), int __oldcancel; pthread_setcancelstate (PTHREAD_CANCEL_DISABLE, &__oldcancel); #endif - _flockfile (fp); + oflags2 = fp->_flags2; + if (!(oflags2 & __SNLK)) + _flockfile (fp); if ((flags = __sflags (ptr, mode, &oflags)) == 0) { - _funlockfile (fp); + if (!(oflags2 & __SNLK)) + _funlockfile (fp); #ifdef _STDIO_WITH_THREAD_CANCELLATION_SUPPORT pthread_setcancelstate (__oldcancel, &__oldcancel); #endif @@ -209,7 +212,7 @@ _DEFUN(_freopen_r, (ptr, file, mode, fp), FREELB (ptr, fp); fp->_lb._size = 0; fp->_flags &= ~__SORD; - fp->_flags2 = 0; + fp->_flags2 &= ~__SWID; memset (&fp->_mbstate, 0, sizeof (_mbstate_t)); if (f < 0) @@ -217,7 +220,8 @@ _DEFUN(_freopen_r, (ptr, file, mode, fp), __sfp_lock_acquire (); fp->_flags = 0; /* set it free */ ptr->_errno = e; /* restore in case _close clobbered */ - _funlockfile (fp); + if (!(oflags2 & __SNLK)) + _funlockfile (fp); #ifndef __SINGLE_THREAD__ __lock_close_recursive (fp->_lock); #endif @@ -241,7 +245,8 @@ _DEFUN(_freopen_r, (ptr, file, mode, fp), fp->_flags |= __SCLE; #endif - _funlockfile (fp); + if (!(oflags2 & __SNLK)) + _funlockfile (fp); #ifdef _STDIO_WITH_THREAD_CANCELLATION_SUPPORT pthread_setcancelstate (__oldcancel, &__oldcancel); #endif diff --git a/contrib/sdk/sources/newlib/libc/stdio/fscanf.c b/contrib/sdk/sources/newlib/libc/stdio/fscanf.c index d94c3ade76..b7510fc4eb 100644 --- a/contrib/sdk/sources/newlib/libc/stdio/fscanf.c +++ b/contrib/sdk/sources/newlib/libc/stdio/fscanf.c @@ -50,6 +50,12 @@ fscanf(FILE *fp, fmt, va_alist) return ret; } +#ifdef _NANO_FORMATTED_IO +int +_EXFUN(fiscanf, (FILE *, const char *, ...) + _ATTRIBUTE ((__alias__("fscanf")))); +#endif + #endif /* !_REENT_ONLY */ int @@ -76,3 +82,8 @@ _fscanf_r(ptr, FILE *fp, fmt, va_alist) return (ret); } +#ifdef _NANO_FORMATTED_IO +int +_EXFUN(_fiscanf_r, (struct _reent *, FILE *, const char *, ...) + _ATTRIBUTE ((__alias__("_fscanf_r")))); +#endif diff --git a/contrib/sdk/sources/newlib/libc/stdio/fseek.c b/contrib/sdk/sources/newlib/libc/stdio/fseek.c index 16e42b0e6e..e7672186f4 100644 --- a/contrib/sdk/sources/newlib/libc/stdio/fseek.c +++ b/contrib/sdk/sources/newlib/libc/stdio/fseek.c @@ -30,32 +30,32 @@ INDEX ANSI_SYNOPSIS #include - int fseek(FILE *<[fp]>, long <[offset]>, int <[whence]>) - int fseeko(FILE *<[fp]>, off_t <[offset]>, int <[whence]>) + int fseek(FILE *<[fp]>, long <[offset]>, int <[whence]>); + int fseeko(FILE *<[fp]>, off_t <[offset]>, int <[whence]>); int _fseek_r(struct _reent *<[ptr]>, FILE *<[fp]>, - long <[offset]>, int <[whence]>) + long <[offset]>, int <[whence]>); int _fseeko_r(struct _reent *<[ptr]>, FILE *<[fp]>, - off_t <[offset]>, int <[whence]>) + off_t <[offset]>, int <[whence]>); TRAD_SYNOPSIS #include - int fseek(<[fp]>, <[offset]>, <[whence]>) + int fseek(<[fp]>, <[offset]>, <[whence]>); FILE *<[fp]>; long <[offset]>; int <[whence]>; - int fseeko(<[fp]>, <[offset]>, <[whence]>) + int fseeko(<[fp]>, <[offset]>, <[whence]>); FILE *<[fp]>; off_t <[offset]>; int <[whence]>; - int _fseek_r(<[ptr]>, <[fp]>, <[offset]>, <[whence]>) + int _fseek_r(<[ptr]>, <[fp]>, <[offset]>, <[whence]>); struct _reent *<[ptr]>; FILE *<[fp]>; long <[offset]>; int <[whence]>; - int _fseeko_r(<[ptr]>, <[fp]>, <[offset]>, <[whence]>) + int _fseeko_r(<[ptr]>, <[fp]>, <[offset]>, <[whence]>); struct _reent *<[ptr]>; FILE *<[fp]>; off_t <[offset]>; diff --git a/contrib/sdk/sources/newlib/libc/stdio/fvwrite.c b/contrib/sdk/sources/newlib/libc/stdio/fvwrite.c index 82ad985f5c..3589f3ba95 100644 --- a/contrib/sdk/sources/newlib/libc/stdio/fvwrite.c +++ b/contrib/sdk/sources/newlib/libc/stdio/fvwrite.c @@ -62,7 +62,7 @@ _DEFUN(__sfvwrite_r, (ptr, fp, uio), /* make sure we can write */ if (cantwrite (ptr, fp)) - return EOF; + return EOF; iov = uio->uio_iov; len = 0; diff --git a/contrib/sdk/sources/newlib/libc/stdio/fwalk.c b/contrib/sdk/sources/newlib/libc/stdio/fwalk.c index 749f1c9541..f9e1052f13 100644 --- a/contrib/sdk/sources/newlib/libc/stdio/fwalk.c +++ b/contrib/sdk/sources/newlib/libc/stdio/fwalk.c @@ -46,8 +46,8 @@ _DEFUN(_fwalk, (ptr, function), */ for (g = &ptr->__sglue; g != NULL; g = g->_next) for (fp = g->_iobs, n = g->_niobs; --n >= 0; fp++) - if (fp->_flags != 0 && fp->_flags != 1 && fp->_file != -1) - ret |= (*function) (fp); + if (fp->_flags != 0 && fp->_flags != 1 && fp->_file != -1) + ret |= (*function) (fp); return ret; } @@ -73,11 +73,8 @@ _DEFUN(_fwalk_reent, (ptr, reent_function), */ for (g = &ptr->__sglue; g != NULL; g = g->_next) for (fp = g->_iobs, n = g->_niobs; --n >= 0; fp++) - if (fp->_flags != 0) - { - if (fp->_flags != 0 && fp->_flags != 1 && fp->_file != -1) - ret |= (*reent_function) (ptr, fp); - } + if (fp->_flags != 0 && fp->_flags != 1 && fp->_file != -1) + ret |= (*reent_function) (ptr, fp); return ret; } diff --git a/contrib/sdk/sources/newlib/libc/stdio/fwrite.c b/contrib/sdk/sources/newlib/libc/stdio/fwrite.c index 01cf5e6353..8e7a300b41 100644 --- a/contrib/sdk/sources/newlib/libc/stdio/fwrite.c +++ b/contrib/sdk/sources/newlib/libc/stdio/fwrite.c @@ -17,22 +17,35 @@ /* FUNCTION -<>---write array elements +<>, <>---write array elements INDEX fwrite +INDEX + fwrite_unlocked INDEX _fwrite_r +INDEX + _fwrite_unlocked_r ANSI_SYNOPSIS #include size_t fwrite(const void *restrict <[buf]>, size_t <[size]>, size_t <[count]>, FILE *restrict <[fp]>); + #define _BSD_SOURCE + #include + size_t fwrite_unlocked(const void *restrict <[buf]>, size_t <[size]>, + size_t <[count]>, FILE *restrict <[fp]>); + #include size_t _fwrite_r(struct _reent *<[ptr]>, const void *restrict <[buf]>, size_t <[size]>, size_t <[count]>, FILE *restrict <[fp]>); + #include + size_t _fwrite_unlocked_r(struct _reent *<[ptr]>, const void *restrict <[buf]>, size_t <[size]>, + size_t <[count]>, FILE *restrict <[fp]>); + TRAD_SYNOPSIS #include size_t fwrite(<[buf]>, <[size]>, <[count]>, <[fp]>) @@ -41,6 +54,14 @@ TRAD_SYNOPSIS size_t <[count]>; FILE *<[fp]>; + #define _BSD_SOURCE + #include + size_t fwrite_unlocked(<[buf]>, <[size]>, <[count]>, <[fp]>) + char *<[buf]>; + size_t <[size]>; + size_t <[count]>; + FILE *<[fp]>; + #include size_t _fwrite_r(<[ptr]>, <[buf]>, <[size]>, <[count]>, <[fp]>) struct _reent *<[ptr]>; @@ -49,6 +70,14 @@ TRAD_SYNOPSIS size_t <[count]>; FILE *<[fp]>; + #include + size_t _fwrite_unlocked_r(<[ptr]>, <[buf]>, <[size]>, <[count]>, <[fp]>) + struct _reent *<[ptr]>; + char *<[buf]>; + size_t <[size]>; + size_t <[count]>; + FILE *<[fp]>; + DESCRIPTION <> attempts to copy, starting from the memory location <[buf]>, <[count]> elements (each of size <[size]>) into the file or @@ -58,8 +87,17 @@ stream identified by <[fp]>. <> may copy fewer elements than <> also advances the file position indicator (if any) for <[fp]> by the number of @emph{characters} actually written. -<<_fwrite_r>> is simply the reentrant version of <> that -takes an additional reentrant structure argument: <[ptr]>. +<> is a non-thread-safe version of <>. +<> may only safely be used within a scope +protected by flockfile() (or ftrylockfile()) and funlockfile(). This +function may safely be used in a multi-threaded program if and only +if they are called while the invoking thread owns the (FILE *) +object, as is the case after a successful call to the flockfile() or +ftrylockfile() functions. If threads are disabled, then +<> is equivalent to <>. + +<<_fwrite_r>> and <<_fwrite_unlocked_r>> are simply reentrant versions of the +above that take an additional reentrant structure argument: <[ptr]>. RETURNS If <> succeeds in writing all the elements you specify, the @@ -70,6 +108,8 @@ the file. PORTABILITY ANSI C requires <>. +<> is a BSD extension also provided by GNU libc. + Supporting OS subroutines required: <>, <>, <>, <>, <>, <>, <>. */ @@ -89,6 +129,11 @@ static char sccsid[] = "%W% (Berkeley) %G%"; #include "fvwrite.h" #endif +#ifdef __IMPL_UNLOCKED__ +#define _fwrite_r _fwrite_unlocked_r +#define fwrite fwrite_unlocked +#endif + /* * Write `count' objects (each size `size') from memory to the given file. * Return the number of whole objects written. diff --git a/contrib/sdk/sources/newlib/libc/stdio/local.h b/contrib/sdk/sources/newlib/libc/stdio/local.h index 4345fa8f19..34565fc454 100644 --- a/contrib/sdk/sources/newlib/libc/stdio/local.h +++ b/contrib/sdk/sources/newlib/libc/stdio/local.h @@ -38,7 +38,7 @@ case _STDIO_CLOSE_PER_REENT_STD_STREAMS is defined these file descriptors will be closed via close() provided the owner of the reent structure triggerd the on demand reent initilization, see CHECK_INIT(). */ -#ifndef __rtems__ +#if !defined(__rtems__) && !defined(__tirtos__) #define _STDIO_CLOSE_PER_REENT_STD_STREAMS #endif @@ -60,7 +60,16 @@ #define _STDIO_WITH_THREAD_CANCELLATION_SUPPORT #endif -#ifdef _STDIO_WITH_THREAD_CANCELLATION_SUPPORT +#if defined(__SINGLE_THREAD__) || defined(__IMPL_UNLOCKED__) + +# define _newlib_flockfile_start(_fp) +# define _newlib_flockfile_exit(_fp) +# define _newlib_flockfile_end(_fp) +# define _newlib_sfp_lock_start() +# define _newlib_sfp_lock_exit() +# define _newlib_sfp_lock_end() + +#elif defined(_STDIO_WITH_THREAD_CANCELLATION_SUPPORT) #include /* Start a stream oriented critical section: */ @@ -68,16 +77,19 @@ { \ int __oldfpcancel; \ pthread_setcancelstate (PTHREAD_CANCEL_DISABLE, &__oldfpcancel); \ - _flockfile (_fp) + if (!(_fp->_flags2 & __SNLK)) \ + _flockfile (_fp) /* Exit from a stream oriented critical section prematurely: */ # define _newlib_flockfile_exit(_fp) \ - _funlockfile (_fp); \ + if (!(_fp->_flags2 & __SNLK)) \ + _funlockfile (_fp); \ pthread_setcancelstate (__oldfpcancel, &__oldfpcancel); /* End a stream oriented critical section: */ # define _newlib_flockfile_end(_fp) \ - _funlockfile (_fp); \ + if (!(_fp->_flags2 & __SNLK)) \ + _funlockfile (_fp); \ pthread_setcancelstate (__oldfpcancel, &__oldfpcancel); \ } @@ -99,17 +111,20 @@ pthread_setcancelstate (__oldsfpcancel, &__oldsfpcancel); \ } -#else /* !_STDIO_WITH_THREAD_CANCELLATION_SUPPORT */ +#else /* !__SINGLE_THREAD__ && !__IMPL_UNLOCKED__ && !_STDIO_WITH_THREAD_CANCELLATION_SUPPORT */ # define _newlib_flockfile_start(_fp) \ { \ - _flockfile(_fp) + if (!(_fp->_flags2 & __SNLK)) \ + _flockfile (_fp) # define _newlib_flockfile_exit(_fp) \ - _funlockfile(_fp); \ + if (!(_fp->_flags2 & __SNLK)) \ + _funlockfile(_fp); \ # define _newlib_flockfile_end(_fp) \ - _funlockfile(_fp); \ + if (!(_fp->_flags2 & __SNLK)) \ + _funlockfile(_fp); \ } # define _newlib_sfp_lock_start() \ @@ -123,8 +138,10 @@ __sfp_lock_release (); \ } -#endif /* _STDIO_WITH_THREAD_CANCELLATION_SUPPORT */ +#endif /* __SINGLE_THREAD__ || __IMPL_UNLOCKED__ */ +extern wint_t _EXFUN(__fgetwc, (struct _reent *, FILE *)); +extern wint_t _EXFUN(__fputwc, (struct _reent *, wchar_t, FILE *)); extern u_char *_EXFUN(__sccl, (char *, u_char *fmt)); extern int _EXFUN(__svfscanf_r,(struct _reent *,FILE *, _CONST char *,va_list)); extern int _EXFUN(__ssvfscanf_r,(struct _reent *,FILE *, _CONST char *,va_list)); @@ -134,19 +151,22 @@ extern int _EXFUN(__svfwscanf_r,(struct _reent *,FILE *, _CONST wchar_t *,va_ extern int _EXFUN(__ssvfwscanf_r,(struct _reent *,FILE *, _CONST wchar_t *,va_list)); extern int _EXFUN(__svfiwscanf_r,(struct _reent *,FILE *, _CONST wchar_t *,va_list)); extern int _EXFUN(__ssvfiwscanf_r,(struct _reent *,FILE *, _CONST wchar_t *,va_list)); -int _EXFUN(_svfprintf_r,(struct _reent *, FILE *, const char *, +int _EXFUN(_svfprintf_r,(struct _reent *, FILE *, const char *, va_list) _ATTRIBUTE ((__format__ (__printf__, 3, 0)))); -int _EXFUN(_svfiprintf_r,(struct _reent *, FILE *, const char *, +int _EXFUN(_svfiprintf_r,(struct _reent *, FILE *, const char *, va_list) _ATTRIBUTE ((__format__ (__printf__, 3, 0)))); -int _EXFUN(_svfwprintf_r,(struct _reent *, FILE *, const wchar_t *, +int _EXFUN(_svfwprintf_r,(struct _reent *, FILE *, const wchar_t *, va_list)); -int _EXFUN(_svfiwprintf_r,(struct _reent *, FILE *, const wchar_t *, +int _EXFUN(_svfiwprintf_r,(struct _reent *, FILE *, const wchar_t *, va_list)); extern FILE *_EXFUN(__sfp,(struct _reent *)); extern int _EXFUN(__sflags,(struct _reent *,_CONST char*, int*)); extern int _EXFUN(__sflush_r,(struct _reent *,FILE *)); +#ifdef _STDIO_BSD_SEMANTICS +extern int _EXFUN(__sflushw_r,(struct _reent *,FILE *)); +#endif extern int _EXFUN(__srefill_r,(struct _reent *,FILE *)); extern _READ_WRITE_RETURN_TYPE _EXFUN(__sread,(struct _reent *, void *, char *, _READ_WRITE_BUFSIZE_TYPE)); @@ -178,37 +198,37 @@ extern _READ_WRITE_RETURN_TYPE _EXFUN(__swrite64,(struct _reent *, void *, #ifdef _REENT_SMALL #define CHECK_INIT(ptr, fp) \ - do \ - { \ + do \ + { \ struct _reent *_check_init_ptr = (ptr); \ if ((_check_init_ptr) && !(_check_init_ptr)->__sdidinit) \ __sinit (_check_init_ptr); \ - if ((fp) == (FILE *)&__sf_fake_stdin) \ + if ((fp) == (FILE *)&__sf_fake_stdin) \ (fp) = _stdin_r(_check_init_ptr); \ - else if ((fp) == (FILE *)&__sf_fake_stdout) \ + else if ((fp) == (FILE *)&__sf_fake_stdout) \ (fp) = _stdout_r(_check_init_ptr); \ - else if ((fp) == (FILE *)&__sf_fake_stderr) \ + else if ((fp) == (FILE *)&__sf_fake_stderr) \ (fp) = _stderr_r(_check_init_ptr); \ - } \ + } \ while (0) #else /* !_REENT_SMALL */ #define CHECK_INIT(ptr, fp) \ - do \ - { \ + do \ + { \ struct _reent *_check_init_ptr = (ptr); \ if ((_check_init_ptr) && !(_check_init_ptr)->__sdidinit) \ __sinit (_check_init_ptr); \ - } \ + } \ while (0) #endif /* !_REENT_SMALL */ #define CHECK_STD_INIT(ptr) \ - do \ - { \ + do \ + { \ struct _reent *_check_init_ptr = (ptr); \ if ((_check_init_ptr) && !(_check_init_ptr)->__sdidinit) \ __sinit (_check_init_ptr); \ - } \ + } \ while (0) /* Return true and set errno and stream error flag iff the given FILE diff --git a/contrib/sdk/sources/newlib/libc/stdio/printf.c b/contrib/sdk/sources/newlib/libc/stdio/printf.c index 3327856071..e2b1a85555 100644 --- a/contrib/sdk/sources/newlib/libc/stdio/printf.c +++ b/contrib/sdk/sources/newlib/libc/stdio/printf.c @@ -37,6 +37,12 @@ _DEFUN(_printf_r, (ptr, fmt), return ret; } +#ifdef _NANO_FORMATTED_IO +int +_EXFUN(_iprintf_r, (struct _reent *, const char *, ...) + _ATTRIBUTE ((__alias__("_printf_r")))); +#endif + #ifndef _REENT_ONLY int @@ -54,4 +60,9 @@ _DEFUN(printf, (fmt), return ret; } +#ifdef _NANO_FORMATTED_IO +int +_EXFUN(iprintf, (const char *, ...) + _ATTRIBUTE ((__alias__("printf")))); +#endif #endif /* ! _REENT_ONLY */ diff --git a/contrib/sdk/sources/newlib/libc/stdio/puts.c b/contrib/sdk/sources/newlib/libc/stdio/puts.c index f498e37b69..e633866b05 100644 --- a/contrib/sdk/sources/newlib/libc/stdio/puts.c +++ b/contrib/sdk/sources/newlib/libc/stdio/puts.c @@ -95,6 +95,7 @@ _DEFUN(_puts_r, (ptr, s), _REENT_SMALL_CHECK_INIT (ptr); fp = _stdout_r (ptr); + CHECK_INIT (ptr, fp); _newlib_flockfile_start (fp); ORIENT (fp, -1); result = (__sfvwrite_r (ptr, fp, &uio) ? EOF : '\n'); @@ -107,6 +108,7 @@ _DEFUN(_puts_r, (ptr, s), _REENT_SMALL_CHECK_INIT (ptr); fp = _stdout_r (ptr); + CHECK_INIT (ptr, fp); _newlib_flockfile_start (fp); ORIENT (fp, -1); /* Make sure we can write. */ diff --git a/contrib/sdk/sources/newlib/libc/stdio/refill.c b/contrib/sdk/sources/newlib/libc/stdio/refill.c index 62d16b3b98..c02fe970f4 100644 --- a/contrib/sdk/sources/newlib/libc/stdio/refill.c +++ b/contrib/sdk/sources/newlib/libc/stdio/refill.c @@ -107,7 +107,7 @@ _DEFUN(__srefill_r, (ptr, fp), /* Ignore this file in _fwalk to avoid potential deadlock. */ short orig_flags = fp->_flags; fp->_flags = 1; - _CAST_VOID _fwalk (_GLOBAL_REENT, lflush); + _CAST_VOID _fwalk (_GLOBAL_REENT, lflush); fp->_flags = orig_flags; /* Now flush this file without locking it. */ diff --git a/contrib/sdk/sources/newlib/libc/stdio/siscanf.c b/contrib/sdk/sources/newlib/libc/stdio/siscanf.c new file mode 100644 index 0000000000..a6a812670e --- /dev/null +++ b/contrib/sdk/sources/newlib/libc/stdio/siscanf.c @@ -0,0 +1,188 @@ +/* + * Copyright (c) 1990 The Regents of the University of California. + * All rights reserved. + * + * Redistribution and use in source and binary forms are permitted + * provided that the above copyright notice and this paragraph are + * duplicated in all such forms and that any documentation, + * advertising materials, and other materials related to such + * distribution and use acknowledge that the software was developed + * by the University of California, Berkeley. The name of the + * University may not be used to endorse or promote products derived + * from this software without specific prior written permission. + * THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR + * IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED + * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. + */ + +/* +FUNCTION +<>, <>, <>---scan and format non-floating input + +INDEX + iscanf +INDEX + _iscanf_r +INDEX + fiscanf +INDEX + _fiscanf_r +INDEX + siscanf +INDEX + _siscanf_r + +ANSI_SYNOPSIS + #include + + int iscanf(const char *<[format]>, ...); + int fiscanf(FILE *<[fd]>, const char *<[format]>, ...); + int siscanf(const char *<[str]>, const char *<[format]>, ...); + + int _iscanf_r(struct _reent *<[ptr]>, const char *<[format]>, ...); + int _fiscanf_r(struct _reent *<[ptr]>, FILE *<[fd]>, + const char *<[format]>, ...); + int _siscanf_r(struct _reent *<[ptr]>, const char *<[str]>, + const char *<[format]>, ...); + + +TRAD_SYNOPSIS + #include + + int iscanf(<[format]> [, <[arg]>, ...]) + char *<[format]>; + + int fiscanf(<[fd]>, <[format]> [, <[arg]>, ...]); + FILE *<[fd]>; + char *<[format]>; + + int siscanf(<[str]>, <[format]> [, <[arg]>, ...]); + char *<[str]>; + char *<[format]>; + + int _iscanf_r(<[ptr]>, <[format]> [, <[arg]>, ...]) + struct _reent *<[ptr]>; + char *<[format]>; + + int _fiscanf_r(<[ptr]>, <[fd]>, <[format]> [, <[arg]>, ...]); + struct _reent *<[ptr]>; + FILE *<[fd]>; + char *<[format]>; + + int _siscanf_r(<[ptr]>, <[str]>, <[format]> [, <[arg]>, ...]); + struct _reent *<[ptr]>; + char *<[str]>; + char *<[format]>; + + +DESCRIPTION + <>, <>, and <> are the same as + <>, <>, and <> respectively, only that + they restrict the available formats to non-floating-point + format specifiers. + + The routines <<_iscanf_r>>, <<_fiscanf_r>>, and <<_siscanf_r>> are reentrant + versions of <>, <>, and <> that take an additional + first argument pointing to a reentrancy structure. + +RETURNS + <> returns the number of input fields successfully + scanned, converted and stored; the return value does + not include scanned fields which were not stored. + + If <> attempts to read at end-of-file, the return + value is <>. + + If no fields were stored, the return value is <<0>>. + +PORTABILITY +<>, <>, and <> are newlib extensions. + +Supporting OS subroutines required: <>, <>, <>, +<>, <>, <>, <>. +*/ + +#include <_ansi.h> +#include +#include +#include +#ifdef _HAVE_STDC +#include +#else +#include +#endif +#include "local.h" + +#ifndef _REENT_ONLY + +#ifdef _HAVE_STDC +int +_DEFUN(siscanf, (str, fmt), + _CONST char *str _AND + _CONST char *fmt _DOTS) +#else +int +siscanf(str, fmt, va_alist) + _CONST char *str; + _CONST char *fmt; + va_dcl +#endif +{ + int ret; + va_list ap; + FILE f; + + f._flags = __SRD | __SSTR; + f._bf._base = f._p = (unsigned char *) str; + f._bf._size = f._r = strlen (str); + f._read = __seofread; + f._ub._base = NULL; + f._lb._base = NULL; + f._file = -1; /* No file. */ +#ifdef _HAVE_STDC + va_start (ap, fmt); +#else + va_start (ap); +#endif + ret = __ssvfiscanf_r (_REENT, &f, fmt, ap); + va_end (ap); + return ret; +} + +#endif /* !_REENT_ONLY */ + +#ifdef _HAVE_STDC +int +_DEFUN(_siscanf_r, (ptr, str, fmt), + struct _reent *ptr _AND + _CONST char *str _AND + _CONST char *fmt _DOTS) +#else +int +_siscanf_r(ptr, str, fmt, va_alist) + struct _reent *ptr; + _CONST char *str; + _CONST char *fmt; + va_dcl +#endif +{ + int ret; + va_list ap; + FILE f; + + f._flags = __SRD | __SSTR; + f._bf._base = f._p = (unsigned char *) str; + f._bf._size = f._r = strlen (str); + f._read = __seofread; + f._ub._base = NULL; + f._lb._base = NULL; + f._file = -1; /* No file. */ +#ifdef _HAVE_STDC + va_start (ap, fmt); +#else + va_start (ap); +#endif + ret = __ssvfiscanf_r (ptr, &f, fmt, ap); + va_end (ap); + return ret; +} diff --git a/contrib/sdk/sources/newlib/libc/stdio/snprintf.c b/contrib/sdk/sources/newlib/libc/stdio/snprintf.c index 3b8d79ccf5..743fa2de87 100644 --- a/contrib/sdk/sources/newlib/libc/stdio/snprintf.c +++ b/contrib/sdk/sources/newlib/libc/stdio/snprintf.c @@ -72,6 +72,12 @@ _snprintf_r(ptr, str, size, fmt, va_alist) return (ret); } +#ifdef _NANO_FORMATTED_IO +int +_EXFUN(_sniprintf_r, (struct _reent *, char *, size_t, const char *, ...) + _ATTRIBUTE ((__alias__("_snprintf_r")))); +#endif + #ifndef _REENT_ONLY int @@ -116,4 +122,9 @@ snprintf(str, size, fmt, va_alist) return (ret); } +#ifdef _NANO_FORMATTED_IO +int +_EXFUN(sniprintf, (char *, size_t, const char *, ...) + _ATTRIBUTE ((__alias__("snprintf")))); +#endif #endif diff --git a/contrib/sdk/sources/newlib/libc/stdio/sprintf.c b/contrib/sdk/sources/newlib/libc/stdio/sprintf.c index 3b0d1b43ca..70710df3f0 100644 --- a/contrib/sdk/sources/newlib/libc/stdio/sprintf.c +++ b/contrib/sdk/sources/newlib/libc/stdio/sprintf.c @@ -199,38 +199,41 @@ DESCRIPTION o # The result is to be converted to an alternative form, according to the <[type]> - character: + character. + o- - o+ - o o - Increases precision to force the first - digit of the result to be a zero. + The alternative form output with the # flag depends on the <[type]> + character: - o x - A non-zero result will have a <<0x>> - prefix. + o+ + o o + Increases precision to force the first + digit of the result to be a zero. - o X - A non-zero result will have a <<0X>> - prefix. + o x + A non-zero result will have a <<0x>> + prefix. - o a, A, e, E, f, or F - The result will always contain a - decimal point even if no digits follow - the point. (Normally, a decimal point - appears only if a digit follows it.) - Trailing zeros are removed. + o X + A non-zero result will have a <<0X>> + prefix. - o g or G - The result will always contain a - decimal point even if no digits follow - the point. Trailing zeros are not - removed. + o a, A, e, E, f, or F + The result will always contain a + decimal point even if no digits follow + the point. (Normally, a decimal point + appears only if a digit follows it.) + Trailing zeros are removed. - o all others - Undefined. + o g or G + The result will always contain a + decimal point even if no digits follow + the point. Trailing zeros are not + removed. + + o all others + Undefined. - o- o- o <[width]> @@ -608,6 +611,12 @@ _sprintf_r(ptr, str, fmt, va_alist) return (ret); } +#ifdef _NANO_FORMATTED_IO +int +_EXFUN(_siprintf_r, (struct _reent *, char *, const char *, ...) + _ATTRIBUTE ((__alias__("_sprintf_r")))); +#endif + #ifndef _REENT_ONLY int @@ -641,4 +650,9 @@ sprintf(str, fmt, va_alist) return (ret); } +#ifdef _NANO_FORMATTED_IO +int +_EXFUN(siprintf, (char *, const char *, ...) + _ATTRIBUTE ((__alias__("sprintf")))); +#endif #endif diff --git a/contrib/sdk/sources/newlib/libc/stdio/sscanf.c b/contrib/sdk/sources/newlib/libc/stdio/sscanf.c index c5d6c9c58d..a704143bbe 100644 --- a/contrib/sdk/sources/newlib/libc/stdio/sscanf.c +++ b/contrib/sdk/sources/newlib/libc/stdio/sscanf.c @@ -132,12 +132,14 @@ DESCRIPTION Each format specification begins with the percent character (<<%>>). The other fields are: - o+ + O+ o * + an optional marker; if present, it suppresses interpretation and assignment of this input field. o <[width]> + an optional maximum field width: a decimal integer, which controls the maximum number of characters that will be read before converting the current input field. If the @@ -150,58 +152,115 @@ DESCRIPTION to that character are read, converted, and stored. Then <> proceeds to the next format specification. - o size + o <[size]> + <>, <>, <>, <>, <>, and <> are optional size characters which override the default way that <> interprets the data type of the corresponding argument. - -.Modifier Type(s) -. hh d, i, o, u, x, n convert input to char, -. store in char object -. -. h d, i, o, u, x, n convert input to short, -. store in short object -. -. h D, I, O, U, X no effect -. e, f, c, s, p -. -. j d, i, o, u, x, n convert input to intmax_t, -. store in intmax_t object -. -. j all others no effect -. -. l d, i, o, u, x, n convert input to long, -. store in long object -. -. l e, f, g convert input to double -. store in a double object -. -. l D, I, O, U, X no effect -. c, s, p -. -. ll d, i, o, u, x, n convert to long long, -. store in long long -. -. L d, i, o, u, x, n convert to long long, -. store in long long -. -. L e, f, g, E, G convert to long double, -. store in long double -. -. L all others no effect -. -. t d, i, o, u, x, n convert input to ptrdiff_t, -. store in ptrdiff_t object -. -. t all others no effect -. -. z d, i, o, u, x, n convert input to size_t, -. store in size_t object -. -. z all others no effect -. - + @multitable @columnfractions 0.18 0.30 0.52 + @headitem + Modifier + @tab + Type(s) + @tab + @item + hh + @tab + d, i, o, u, x, n + @tab + convert input to char, store in char object + @item + h + @tab + d, i, o, u, x, n + @tab + convert input to short, store in short object + @item + h + @tab + D, I, O, U, X, e, f, c, s, p + @tab + no effect + @item + j + @tab + d, i, o, u, x, n + @tab + convert input to intmax_t, store in intmax_t object + @item + j + @tab + all others + @tab + no effect + @item + l + @tab + d, i, o, u, x, n + @tab + convert input to long, store in long object + @item + l + @tab + e, f, g + @tab + convert input to double, store in a double object + @item + l + @tab + D, I, O, U, X, c, s, p + @tab + no effect + @item + ll + @tab + d, i, o, u, x, n + @tab + convert to long long, store in long long object + @item + L + @tab + d, i, o, u, x, n + @tab + convert to long long, store in long long object + @item + L + @tab + e, f, g, E, G + @tab + convert to long double, store in long double object + @item + L + @tab + all others + @tab + no effect + @item + t + @tab + d, i, o, u, x, n + @tab + convert input to ptrdiff_t, store in ptrdiff_t object + @item + t + @tab + all others + @tab + no effect + @item + z + @tab + d, i, o, u, x, n + @tab + convert input to size_t, store in size_t object + @item + z + @tab + all others + @tab + no effect + @end multitable o <[type]> @@ -210,7 +269,7 @@ DESCRIPTION characters: o+ - o % + o % No conversion is done; the percent character (<<%>>) is stored. o c @@ -220,7 +279,7 @@ DESCRIPTION Reads a character string into the array supplied. Corresponding <[arg]>: <<(char arg[])>>. - o [<[pattern]>] + o [<[pattern]>] Reads a non-empty character string into memory starting at <[arg]>. This area must be large enough to accept the sequence and a @@ -244,7 +303,6 @@ DESCRIPTION o u Reads an unsigned decimal integer into the corresponding <[arg]>: <<(unsigned int *arg)>>. - o U Reads an unsigned decimal integer into the corresponding <[arg]>: @@ -262,19 +320,19 @@ DESCRIPTION Read a floating-point number into the corresponding <[arg]>: <<(double *arg)>>. - o i + o i Reads a decimal, octal or hexadecimal integer into the corresponding <[arg]>: <<(int *arg)>>. - o I + o I Reads a decimal, octal or hexadecimal integer into the corresponding <[arg]>: <<(long *arg)>>. - o n + o n Stores the number of characters read in the corresponding <[arg]>: <<(int *arg)>>. - o p + o p Stores a scanned pointer. ANSI C leaves the details to each implementation; this implementation treats <<%p>> exactly the same as <<%U>>. Corresponding @@ -316,7 +374,7 @@ DESCRIPTION where objects inclosed in square brackets are optional, and <> represents decimal, octal, or hexadecimal digits. - o- + O- RETURNS <> returns the number of input fields successfully @@ -430,6 +488,12 @@ sscanf(str, fmt, va_alist) return ret; } +#ifdef _NANO_FORMATTED_IO +int +_EXFUN(siscanf, (const char *, const char *, ...) + _ATTRIBUTE ((__alias__("sscanf")))); +#endif + #endif /* !_REENT_ONLY */ #ifdef _HAVE_STDC @@ -467,3 +531,9 @@ _sscanf_r(ptr, str, fmt, va_alist) va_end (ap); return ret; } + +#ifdef _NANO_FORMATTED_IO +int +_EXFUN(_siscanf_r, (struct _reent *, const char *, const char *, ...) + _ATTRIBUTE ((__alias__("_sscanf_r")))); +#endif diff --git a/contrib/sdk/sources/newlib/libc/stdio/vasnprintf.c b/contrib/sdk/sources/newlib/libc/stdio/vasnprintf.c index cab89beff9..4cb43ce7af 100644 --- a/contrib/sdk/sources/newlib/libc/stdio/vasnprintf.c +++ b/contrib/sdk/sources/newlib/libc/stdio/vasnprintf.c @@ -56,6 +56,13 @@ _DEFUN(_vasnprintf_r, (ptr, buf, lenp, fmt, ap), return (char *) f._bf._base; } +#ifdef _NANO_FORMATTED_IO +char * +_EXFUN(_vasniprintf_r, (struct _reent*, char *, size_t *, + const char *, __VALIST) + _ATTRIBUTE ((__alias__("_vasnprintf_r")))); +#endif + #ifndef _REENT_ONLY char * @@ -68,4 +75,9 @@ _DEFUN(vasnprintf, (buf, lenp, fmt, ap), return _vasnprintf_r (_REENT, buf, lenp, fmt, ap); } +#ifdef _NANO_FORMATTED_IO +char * +_EXFUN(vasniprintf, (char *, size_t *, const char *, __VALIST) + _ATTRIBUTE ((__alias__("vasnprintf")))); +#endif #endif /* ! _REENT_ONLY */ diff --git a/contrib/sdk/sources/newlib/libc/stdio/vdprintf.c b/contrib/sdk/sources/newlib/libc/stdio/vdprintf.c index 7e875ac325..c295a39598 100644 --- a/contrib/sdk/sources/newlib/libc/stdio/vdprintf.c +++ b/contrib/sdk/sources/newlib/libc/stdio/vdprintf.c @@ -33,6 +33,12 @@ _DEFUN(_vdprintf_r, (ptr, fd, format, ap), return n; } +#ifdef _NANO_FORMATTED_IO +int +_EXFUN(_vdiprintf_r, (struct _reent *, int, const char *, __VALIST) + _ATTRIBUTE ((__alias__("_vdprintf_r")))); +#endif + #ifndef _REENT_ONLY int @@ -44,4 +50,9 @@ _DEFUN(vdprintf, (fd, format, ap), return _vdprintf_r (_REENT, fd, format, ap); } +#ifdef _NANO_FORMATTED_IO +int +_EXFUN(vdiprintf, (int, const char *, __VALIST) + _ATTRIBUTE ((__alias__("vdprintf")))); +#endif #endif /* ! _REENT_ONLY */ diff --git a/contrib/sdk/sources/newlib/libc/stdio/vfprintf.c b/contrib/sdk/sources/newlib/libc/stdio/vfprintf.c index 4536245e3f..c223a379f4 100644 --- a/contrib/sdk/sources/newlib/libc/stdio/vfprintf.c +++ b/contrib/sdk/sources/newlib/libc/stdio/vfprintf.c @@ -114,7 +114,7 @@ Supporting OS subroutines required: <>, <>, <>, #if defined(LIBC_SCCS) && !defined(lint) /*static char *sccsid = "from: @(#)vfprintf.c 5.50 (Berkeley) 12/16/92";*/ -static char *rcsid = "$Id: vfprintf.c,v 1.43 2002/08/13 02:40:06 fitzsim Exp $"; +static char *rcsid = "$Id$"; #endif /* LIBC_SCCS and not lint */ /* @@ -857,7 +857,7 @@ _DEFUN(_VFPRINTF_R, (data, fp, fmt0, ap), #ifndef STRING_ONLY /* Initialize std streams if not dealing with sprintf family. */ CHECK_INIT (data, fp); - _newlib_flockfile_start (fp); + _newlib_flockfile_start (fp); ORIENT(fp, -1); @@ -964,7 +964,7 @@ reswitch: switch (ch) { grouping = _localeconv_r (data)->grouping; if (thsnd_len > 0 && grouping && *grouping) flags |= GROUPING; - goto rflag; + goto rflag; #endif case ' ': /* @@ -1338,21 +1338,21 @@ reswitch: switch (ch) { # endif } else { if (ch == 'f') { /* f fmt */ - if (expt > 0) { + if (expt > 0) { + size = expt; + if (prec || flags & ALT) + size += prec + 1; + } else /* "0.X" */ + size = (prec || flags & ALT) + ? prec + 2 + : 1; + } else if (expt >= ndig) { /* fixed g fmt */ size = expt; - if (prec || flags & ALT) - size += prec + 1; - } else /* "0.X" */ - size = (prec || flags & ALT) - ? prec + 2 - : 1; - } else if (expt >= ndig) { /* fixed g fmt */ - size = expt; - if (flags & ALT) - ++size; - } else - size = ndig + (expt > 0 ? - 1 : 2 - expt); + if (flags & ALT) + ++size; + } else + size = ndig + (expt > 0 ? + 1 : 2 - expt); # ifdef _WANT_IO_C99_FORMATS if ((flags & GROUPING) && expt > 0) { /* space for thousands' grouping */ @@ -1521,11 +1521,9 @@ string: */ char *p = memchr (cp, 0, prec); - if (p != NULL) { + if (p != NULL) size = p - cp; - if (size > prec) - size = prec; - } else + else size = prec; } else size = strlen (cp); @@ -1598,7 +1596,7 @@ number: if ((dprec = prec) >= 0) ndig = 0; #endif do { - *--cp = to_char (_uquad % 10); + *--cp = to_char (_uquad % 10); #ifdef _WANT_IO_C99_FORMATS ndig++; /* If (*grouping == CHAR_MAX) then no @@ -1619,7 +1617,7 @@ number: if ((dprec = prec) >= 0) grouping++; } #endif - _uquad /= 10; + _uquad /= 10; } while (_uquad != 0); break; @@ -1744,7 +1742,7 @@ number: if ((dprec = prec) >= 0) } #endif if (expt < ndig || flags & ALT) - PRINT (decimal_point, decp_len); + PRINT (decimal_point, decp_len); PRINTANDPAD (cp, convbuf + ndig, ndig - expt, zeroes); } diff --git a/contrib/sdk/sources/newlib/libc/stdio/vfscanf.c b/contrib/sdk/sources/newlib/libc/stdio/vfscanf.c index 593eddaf13..79647f36dc 100644 --- a/contrib/sdk/sources/newlib/libc/stdio/vfscanf.c +++ b/contrib/sdk/sources/newlib/libc/stdio/vfscanf.c @@ -170,7 +170,6 @@ Supporting OS subroutines required: #define _NO_LONGDBL #if defined _WANT_IO_LONG_DOUBLE && (LDBL_MANT_DIG > DBL_MANT_DIG) #undef _NO_LONGDBL -extern _LONG_DOUBLE _strtold _PARAMS((char *s, char **sptr)); #endif #include "floatio.h" @@ -1596,12 +1595,13 @@ _DEFUN(__SVFSCANF_R, (rptr, fp, fmt0, ap), sprintf (exp_start, "e%ld", new_exp); } - /* Current _strtold routine is markedly slower than + /* FIXME: Is that still true? + Current _strtold routine is markedly slower than _strtod_r. Only use it if we have a long double result. */ #ifndef _NO_LONGDBL /* !_NO_LONGDBL */ if (flags & LONGDBL) - qres = _strtold (buf, NULL); + qres = _strtold_r (rptr, buf, NULL); else #endif res = _strtod_r (rptr, buf, NULL); diff --git a/contrib/sdk/sources/newlib/libc/stdio/vscanf.c b/contrib/sdk/sources/newlib/libc/stdio/vscanf.c index ec842b19f6..2268a65a06 100644 --- a/contrib/sdk/sources/newlib/libc/stdio/vscanf.c +++ b/contrib/sdk/sources/newlib/libc/stdio/vscanf.c @@ -40,6 +40,11 @@ _DEFUN(vscanf, (fmt, ap), return __svfscanf_r (reent, _stdin_r (reent), fmt, ap); } +#ifdef _NANO_FORMATTED_IO +int +_EXFUN(viscanf, (const char *, __VALIST) _ATTRIBUTE ((__alias__("vscanf")))); +#endif + #endif /* !_REENT_ONLY */ int @@ -52,3 +57,8 @@ _DEFUN(_vscanf_r, (ptr, fmt, ap), return __svfscanf_r (ptr, _stdin_r (ptr), fmt, ap); } +#ifdef _NANO_FORMATTED_IO +int +_EXFUN(_viscanf_r, (struct _reent *, const char *, __VALIST) + _ATTRIBUTE ((__alias__("_vscanf_r")))); +#endif diff --git a/contrib/sdk/sources/newlib/libc/stdio/vsnprintf.c b/contrib/sdk/sources/newlib/libc/stdio/vsnprintf.c index 00a772b0ed..9ab9a1806f 100644 --- a/contrib/sdk/sources/newlib/libc/stdio/vsnprintf.c +++ b/contrib/sdk/sources/newlib/libc/stdio/vsnprintf.c @@ -41,6 +41,12 @@ _DEFUN(vsnprintf, (str, size, fmt, ap), return _vsnprintf_r (_REENT, str, size, fmt, ap); } +#ifdef _NANO_FORMATTED_IO +int +_EXFUN(vsniprintf, (char *, size_t, const char *, __VALIST) + _ATTRIBUTE ((__alias__("vsnprintf")))); +#endif + #endif /* !_REENT_ONLY */ int @@ -70,3 +76,9 @@ _DEFUN(_vsnprintf_r, (ptr, str, size, fmt, ap), *f._p = 0; return ret; } + +#ifdef _NANO_FORMATTED_IO +int +_EXFUN(_vsniprintf_r, (struct _reent *, char *, size_t, const char *, __VALIST) + _ATTRIBUTE ((__alias__("_vsnprintf_r")))); +#endif diff --git a/contrib/sdk/sources/newlib/libc/stdio/vsprintf.c b/contrib/sdk/sources/newlib/libc/stdio/vsprintf.c index be5ff1c5f2..3d193dd635 100644 --- a/contrib/sdk/sources/newlib/libc/stdio/vsprintf.c +++ b/contrib/sdk/sources/newlib/libc/stdio/vsprintf.c @@ -39,6 +39,12 @@ _DEFUN(vsprintf, (str, fmt, ap), return _vsprintf_r (_REENT, str, fmt, ap); } +#ifdef _NANO_FORMATTED_IO +int +_EXFUN(vsiprintf, (char *, const char *, __VALIST) + _ATTRIBUTE ((__alias__("vsprintf")))); +#endif + #endif /* !_REENT_ONLY */ int @@ -59,3 +65,9 @@ _DEFUN(_vsprintf_r, (ptr, str, fmt, ap), *f._p = 0; return ret; } + +#ifdef _NANO_FORMATTED_IO +int +_EXFUN(_vsiprintf_r, (struct _reent *, char *, const char *, __VALIST) + _ATTRIBUTE ((__alias__("_vsprintf_r")))); +#endif diff --git a/contrib/sdk/sources/newlib/libc/stdio/vsscanf.c b/contrib/sdk/sources/newlib/libc/stdio/vsscanf.c index 6eff8d39f7..f62cfcf683 100644 --- a/contrib/sdk/sources/newlib/libc/stdio/vsscanf.c +++ b/contrib/sdk/sources/newlib/libc/stdio/vsscanf.c @@ -43,6 +43,12 @@ _DEFUN(vsscanf, (str, fmt, ap), return _vsscanf_r (_REENT, str, fmt, ap); } +#ifdef _NANO_FORMATTED_IO +int +_EXFUN(vsiscanf, (const char *, const char *, __VALIST) + _ATTRIBUTE ((__alias__("vsscanf")))); +#endif + #endif /* !_REENT_ONLY */ int @@ -63,3 +69,9 @@ _DEFUN(_vsscanf_r, (ptr, str, fmt, ap), f._file = -1; /* No file. */ return __ssvfscanf_r (ptr, &f, fmt, ap); } + +#ifdef _NANO_FORMATTED_IO +int +_EXFUN(_vsiscanf_r, (struct _reent *, const char *, const char *, __VALIST) + _ATTRIBUTE ((__alias__("_vsscanf_r")))); +#endif diff --git a/contrib/sdk/sources/newlib/libc/stdio/wbuf.c b/contrib/sdk/sources/newlib/libc/stdio/wbuf.c index fce036dc60..ce782e5878 100644 --- a/contrib/sdk/sources/newlib/libc/stdio/wbuf.c +++ b/contrib/sdk/sources/newlib/libc/stdio/wbuf.c @@ -54,7 +54,7 @@ _DEFUN(__swbuf_r, (ptr, c, fp), fp->_w = fp->_lbfsize; if (cantwrite (ptr, fp)) - return EOF; + return EOF; c = (unsigned char) c; ORIENT (fp, -1); diff --git a/contrib/sdk/sources/newlib/libc/stdio/wsetup.c b/contrib/sdk/sources/newlib/libc/stdio/wsetup.c index cb47eb890a..39cc48342d 100644 --- a/contrib/sdk/sources/newlib/libc/stdio/wsetup.c +++ b/contrib/sdk/sources/newlib/libc/stdio/wsetup.c @@ -48,7 +48,7 @@ _DEFUN(__swsetup_r, (ptr, fp), { ptr->_errno = EBADF; fp->_flags |= __SERR; - return EOF; + return EOF; } if (fp->_flags & __SRD) { @@ -67,7 +67,7 @@ _DEFUN(__swsetup_r, (ptr, fp), * A string I/O file should not explicitly allocate a buffer * unless asprintf is being used. */ - if (fp->_bf._base == NULL + if (fp->_bf._base == NULL && (!(fp->_flags & __SSTR) || (fp->_flags & __SMBF))) __smakebuf_r (ptr, fp); diff --git a/contrib/sdk/sources/newlib/libc/stdlib/__atexit.c b/contrib/sdk/sources/newlib/libc/stdlib/__atexit.c index 47898b827a..0682507999 100644 --- a/contrib/sdk/sources/newlib/libc/stdlib/__atexit.c +++ b/contrib/sdk/sources/newlib/libc/stdlib/__atexit.c @@ -79,16 +79,31 @@ _DEFUN (__register_exitproc, p = _GLOBAL_ATEXIT; if (p == NULL) - _GLOBAL_ATEXIT = p = _GLOBAL_ATEXIT0; + { + _GLOBAL_ATEXIT = p = _GLOBAL_ATEXIT0; +#ifdef _REENT_SMALL + extern struct _on_exit_args * const __on_exit_args _ATTRIBUTE ((weak)); + if (&__on_exit_args != NULL) + p->_on_exit_args_ptr = __on_exit_args; +#endif /* def _REENT_SMALL */ + } if (p->_ind >= _ATEXIT_SIZE) { #ifndef _ATEXIT_DYNAMIC_ALLOC +#ifndef __SINGLE_THREAD__ + __lock_release_recursive(__atexit_lock); +#endif return -1; #else /* Don't dynamically allocate the atexit array if malloc is not available. */ if (!malloc) - return -1; + { +#ifndef __SINGLE_THREAD__ + __lock_release_recursive(__atexit_lock); +#endif + return -1; + } p = (struct _atexit *) malloc (sizeof *p); if (p == NULL) @@ -116,6 +131,12 @@ _DEFUN (__register_exitproc, args = p->_on_exit_args_ptr; if (args == NULL) { +#ifndef _ATEXIT_DYNAMIC_ALLOC +#ifndef __SINGLE_THREAD__ + __lock_release_recursive(__atexit_lock); +#endif + return -1; +#else if (malloc) args = malloc (sizeof * p->_on_exit_args_ptr); @@ -129,6 +150,7 @@ _DEFUN (__register_exitproc, args->_fntypes = 0; args->_is_cxa = 0; p->_on_exit_args_ptr = args; +#endif } #else args = &p->_on_exit_args; diff --git a/contrib/sdk/sources/newlib/libc/stdlib/exit.c b/contrib/sdk/sources/newlib/libc/stdlib/exit.c index 39c8a00479..f8e721a3e5 100644 --- a/contrib/sdk/sources/newlib/libc/stdlib/exit.c +++ b/contrib/sdk/sources/newlib/libc/stdlib/exit.c @@ -63,7 +63,7 @@ _DEFUN (exit, (code), void __call_exitprocs _PARAMS ((int, _PTR)) __attribute__((weak)); if (__call_exitprocs) #endif - __call_exitprocs (code, NULL); + __call_exitprocs (code, NULL); if (_GLOBAL_REENT->__cleanup) (*_GLOBAL_REENT->__cleanup) (_GLOBAL_REENT); diff --git a/contrib/sdk/sources/newlib/libc/stdlib/gd_qnan.h b/contrib/sdk/sources/newlib/libc/stdlib/gd_qnan.h index 8234923d24..4ad3bda10e 100644 --- a/contrib/sdk/sources/newlib/libc/stdlib/gd_qnan.h +++ b/contrib/sdk/sources/newlib/libc/stdlib/gd_qnan.h @@ -1,5 +1,6 @@ #ifdef __IEEE_BIG_ENDIAN +#if !defined(__mips) #define f_QNAN 0x7fc00000 #define d_QNAN0 0x7ff80000 #define d_QNAN1 0x0 @@ -12,9 +13,19 @@ #define ldus_QNAN2 0x0 #define ldus_QNAN3 0x0 #define ldus_QNAN4 0x0 +#elif defined(__mips_nan2008) +#define f_QNAN 0x7fc00000 +#define d_QNAN0 0x7ff80000 +#define d_QNAN1 0x0 +#else +#define f_QNAN 0x7fbfffff +#define d_QNAN0 0x7ff7ffff +#define d_QNAN1 0xffffffff +#endif #elif defined(__IEEE_LITTLE_ENDIAN) +#if !defined(__mips) #define f_QNAN 0xffc00000 #define d_QNAN0 0x0 #define d_QNAN1 0xfff80000 @@ -27,6 +38,15 @@ #define ldus_QNAN2 0x0 #define ldus_QNAN3 0xc000 #define ldus_QNAN4 0xffff +#elif defined(__mips_nan2008) +#define f_QNAN 0x7fc00000 +#define d_QNAN0 0x0 +#define d_QNAN1 0x7ff80000 +#else +#define f_QNAN 0x7fbfffff +#define d_QNAN0 0xffffffff +#define d_QNAN1 0x7ff7ffff +#endif #else #error IEEE endian not defined diff --git a/contrib/sdk/sources/newlib/libc/stdlib/gdtoa-hexnan.c b/contrib/sdk/sources/newlib/libc/stdlib/gdtoa-hexnan.c index 43459fedc0..0f731c76f1 100644 --- a/contrib/sdk/sources/newlib/libc/stdlib/gdtoa-hexnan.c +++ b/contrib/sdk/sources/newlib/libc/stdlib/gdtoa-hexnan.c @@ -44,6 +44,24 @@ THIS SOFTWARE. #include "gdtoa.h" #ifdef INFNAN_CHECK +int +_DEFUN (match, (sp, t), + _CONST char **sp _AND + char *t) +{ + int c, d; + _CONST char *s = *sp; + + while( (d = *t++) !=0) { + if ((c = *++s) >= 'A' && c <= 'Z') + c += 'a' - 'A'; + if (c != d) + return 0; + } + *sp = s + 1; + return 1; +} + static void _DEFUN (L_shift, (x, x1, i), __ULong *x _AND diff --git a/contrib/sdk/sources/newlib/libc/stdlib/gdtoa.h b/contrib/sdk/sources/newlib/libc/stdlib/gdtoa.h index 8c48d44989..395b6e07e8 100644 --- a/contrib/sdk/sources/newlib/libc/stdlib/gdtoa.h +++ b/contrib/sdk/sources/newlib/libc/stdlib/gdtoa.h @@ -70,3 +70,5 @@ enum { /* FPI.rounding values: same as FLT_ROUNDS */ }; #endif /* GDTOA_H_INCLUDED */ + +typedef unsigned short __UShort; diff --git a/contrib/sdk/sources/newlib/libc/stdlib/getenv_r.c b/contrib/sdk/sources/newlib/libc/stdlib/getenv_r.c new file mode 100644 index 0000000000..b92e74e04d --- /dev/null +++ b/contrib/sdk/sources/newlib/libc/stdlib/getenv_r.c @@ -0,0 +1,105 @@ +/* +FUNCTION +<<_getenv_r>>---look up environment variable + +INDEX + _getenv_r +INDEX + environ + +ANSI_SYNOPSIS + #include + char *_getenv_r(struct _reent *<[reent_ptr]>, const char *<[name]>); + +TRAD_SYNOPSIS + #include + char *_getenv_r(<[reent_ptr]>, <[name]>) + struct _reent *<[reent_ptr]>; + char *<[name]>; + +DESCRIPTION +<<_getenv_r>> searches the list of environment variable names and values +(using the global pointer ``<>'') for a variable whose +name matches the string at <[name]>. If a variable name matches, +<<_getenv_r>> returns a pointer to the associated value. + +RETURNS +A pointer to the (string) value of the environment variable, or +<> if there is no such environment variable. + +PORTABILITY +<<_getenv_r>> is not ANSI; the rules for properly forming names of environment +variables vary from one system to another. This implementation does not +permit '=' to be in identifiers. + +<<_getenv_r>> requires a global pointer <>. +*/ + +/* This file may have been modified by DJ Delorie (Jan 1991). If so, +** these modifications are Copyright (C) 1991 DJ Delorie. +*/ + +/* + * Copyright (c) 1987 Regents of the University of California. + * All rights reserved. + * + * Redistribution and use in source and binary forms are permitted + * provided that: (1) source distributions retain this entire copyright + * notice and comment, and (2) distributions including binaries display + * the following acknowledgement: ``This product includes software + * developed by the University of California, Berkeley and its contributors'' + * in the documentation or other materials provided with the distribution + * and in all advertising materials mentioning features or use of this + * software. 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 ``AS IS'' AND WITHOUT ANY EXPRESS OR + * IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED + * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. + */ + +#include +#include +#include +#include "envlock.h" + +extern char **environ; + +/* Only deal with a pointer to environ, to work around subtle bugs with shared + libraries and/or small data systems where the user declares his own + 'environ'. */ +static char ***p_environ = &environ; + +/* + * _findenv -- + * Returns pointer to value associated with name, if any, else NULL. + * Sets offset to be the offset of the name/value combination in the + * environmental array, for use by setenv(3) and unsetenv(3). + * + * This routine *should* be a static; don't use it. + */ + +char * +_DEFUN (_findenv_r, (reent_ptr, name, offset), + struct _reent *reent_ptr _AND + register _CONST char *name _AND + int *offset) +{ + return NULL; +} + +/* + * _getenv_r -- + * Returns ptr to value associated with name, if any, else NULL. + */ + +char * +_DEFUN (_getenv_r, (reent_ptr, name), + struct _reent *reent_ptr _AND + _CONST char *name) +{ + int offset; + + return NULL; +// return _findenv_r (reent_ptr, name, &offset); +} diff --git a/contrib/sdk/sources/newlib/libc/stdlib/mallocr.c b/contrib/sdk/sources/newlib/libc/stdlib/mallocr.c index 994b8d8c2f..c2d734aa41 100644 --- a/contrib/sdk/sources/newlib/libc/stdlib/mallocr.c +++ b/contrib/sdk/sources/newlib/libc/stdlib/mallocr.c @@ -2093,21 +2093,21 @@ History: * malloc_extend_top: fix mask error that caused wastage after foreign sbrks * Add linux mremap support code from HJ Liu - + V2.6.2 Tue Dec 5 06:52:55 1995 Doug Lea (dl at gee) * Integrated most documentation with the code. - * Add support for mmap, with help from + * Add support for mmap, with help from Wolfram Gloger (Gloger@lrz.uni-muenchen.de). * Use last_remainder in more cases. * Pack bins using idea from colin@nyx10.cs.du.edu * Use ordered bins instead of best-fit threshhold * Eliminate block-local decls to simplify tracing and debugging. * Support another case of realloc via move into top - * Fix error occuring when initial sbrk_base not word-aligned. + * Fix error occuring when initial sbrk_base not word-aligned. * Rely on page size for units instead of SBRK_UNIT to avoid surprises about sbrk alignment conventions. * Add mallinfo, mallopt. Thanks to Raymond Nijssen - (raymond@es.ele.tue.nl) for the suggestion. + (raymond@es.ele.tue.nl) for the suggestion. * Add `pad' argument to malloc_trim and top_pad mallopt parameter. * More precautions for cases where other routines call sbrk, courtesy of Wolfram Gloger (Gloger@lrz.uni-muenchen.de). @@ -2131,7 +2131,7 @@ History: Paul Wilson (wilson@cs.texas.edu) for the suggestion. V2.5.4 Wed Nov 1 07:54:51 1995 Doug Lea (dl at gee) - * Added malloc_trim, with help from Wolfram Gloger + * Added malloc_trim, with help from Wolfram Gloger (wmglo@Dent.MED.Uni-Muenchen.DE). V2.5.3 Tue Apr 26 10:16:01 1994 Doug Lea (dl at g) @@ -2151,20 +2151,20 @@ History: (eliminating old malloc_find_space & malloc_clean_bin) * Scan 2 returns chunks (not just 1) * Propagate failure in realloc if malloc returns 0 - * Add stuff to allow compilation on non-ANSI compilers + * Add stuff to allow compilation on non-ANSI compilers from kpv@research.att.com - + V2.5 Sat Aug 7 07:41:59 1993 Doug Lea (dl at g.oswego.edu) * removed potential for odd address access in prev_chunk * removed dependency on getpagesize.h * misc cosmetics and a bit more internal documentation * anticosmetics: mangled names in macros to evade debugger strangeness - * tested on sparc, hp-700, dec-mips, rs6000 + * tested on sparc, hp-700, dec-mips, rs6000 with gcc & native cc (hp, dec only) allowing Detlefs & Zorn comparison study (in SIGPLAN Notices.) Trial version Fri Aug 28 13:14:29 1992 Doug Lea (dl at g.oswego.edu) - * Based loosely on libg++-1.2X malloc. (It retains some of the overall + * Based loosely on libg++-1.2X malloc. (It retains some of the overall structure of old version, but most details differ.) */ diff --git a/contrib/sdk/sources/newlib/libc/stdlib/mprec.h b/contrib/sdk/sources/newlib/libc/stdlib/mprec.h index b5e4ae83d1..0a4161a5d6 100644 --- a/contrib/sdk/sources/newlib/libc/stdlib/mprec.h +++ b/contrib/sdk/sources/newlib/libc/stdlib/mprec.h @@ -360,6 +360,7 @@ typedef struct _Bigint _Bigint; #define mult __multiply #define pow5mult __pow5mult #define lshift __lshift +#define match __match #define cmp __mcmp #define diff __mdiff #define ulp __ulp @@ -396,12 +397,18 @@ int _EXFUN(hi0bits,(__ULong)); int _EXFUN(lo0bits,(__ULong *)); _Bigint * _EXFUN(d2b,(struct _reent *p, double d, int *e, int *bits)); _Bigint * _EXFUN(lshift,(struct _reent *p, _Bigint *b, int k)); +int _EXFUN(match,(const char**, char*)); _Bigint * _EXFUN(diff,(struct _reent *p, _Bigint *a, _Bigint *b)); int _EXFUN(cmp,(_Bigint *a, _Bigint *b)); int _EXFUN(gethex,(struct _reent *p, _CONST char **sp, _CONST struct FPI *fpi, Long *exp, _Bigint **bp, int sign)); double _EXFUN(ratio,(_Bigint *a, _Bigint *b)); __ULong _EXFUN(any_on,(_Bigint *b, int k)); void _EXFUN(copybits,(__ULong *c, int n, _Bigint *b)); +#if defined (_HAVE_LONG_DOUBLE) && !defined (_LDBL_EQ_DBL) +int _EXFUN(_strtorx_r,(struct _reent *, _CONST char *, char **, int, void *)); +int _EXFUN(_strtodg_r,(struct _reent *p, _CONST char *s00, char **se, struct FPI *fpi, Long *exp, __ULong *bits)); +#endif /* _HAVE_LONG_DOUBLE && !_LDBL_EQ_DBL */ + #if defined(PREFER_SIZE_OVER_SPEED) || defined(__OPTIMIZE_SIZE__) || defined(_SMALL_HEXDIG) unsigned char _EXFUN(__hexdig_fun,(unsigned char)); #endif /* !defined(PREFER_SIZE_OVER_SPEED) && !defined(__OPTIMIZE_SIZE__) && !defined(_SMALL_HEXDIG) */ diff --git a/contrib/sdk/sources/newlib/libc/stdlib/strtod.c b/contrib/sdk/sources/newlib/libc/stdlib/strtod.c index 7dc3f8aece..a8bc121550 100644 --- a/contrib/sdk/sources/newlib/libc/stdlib/strtod.c +++ b/contrib/sdk/sources/newlib/libc/stdlib/strtod.c @@ -137,7 +137,7 @@ static _CONST double tinytens[] = { 1e-16, 1e-32, 1e-64, 1e-128, 9007199254740992. * 9007199254740992.e-256 #endif - }; + }; #endif #endif @@ -163,7 +163,7 @@ _DEFUN (sulp, (x, scale), rv = ulp(dval(x)); if (!scale || (i = 2*P + 1 - ((dword0(x) & Exp_mask) >> Exp_shift)) <= 0) return rv; /* Is there an example where i <= 0 ? */ - dword0(u) = Exp_1 + (i << Exp_shift); + dword0(u) = Exp_1 + ((__int32_t)i << Exp_shift); #ifndef _DOUBLE_IS_32BITS dword1(u) = 0; #endif @@ -212,27 +212,6 @@ _DEFUN (ULtod, (L, bits, exp, k), } #endif /* !NO_HEX_FP */ -#ifdef INFNAN_CHECK -static int -_DEFUN (match, (sp, t), - _CONST char **sp _AND - char *t) -{ - int c, d; - _CONST char *s = *sp; - - while( (d = *t++) !=0) { - if ((c = *++s) >= 'A' && c <= 'Z') - c += 'a' - 'A'; - if (c != d) - return 0; - } - *sp = s + 1; - return 1; -} -#endif /* INFNAN_CHECK */ - - double _DEFUN (_strtod_r, (ptr, s00, se), struct _reent *ptr _AND @@ -333,10 +312,10 @@ _DEFUN (_strtod_r, (ptr, s00, se), s0 = s; y = z = 0; for(nd = nf = 0; (c = *s) >= '0' && c <= '9'; nd++, s++) - if (nd < 9) - y = 10*y + c - '0'; - else - z = 10*z + c - '0'; + if (nd < 9) + y = 10*y + c - '0'; + else + z = 10*z + c - '0'; nd0 = nd; if (strncmp (s, _localeconv_r (ptr)->decimal_point, strlen (_localeconv_r (ptr)->decimal_point)) == 0) @@ -361,13 +340,13 @@ _DEFUN (_strtod_r, (ptr, s00, se), nf += nz; for(i = 1; i < nz; i++) if (nd++ < 9) - y *= 10; + y *= 10; else if (nd <= DBL_DIG + 1) - z *= 10; + z *= 10; if (nd++ < 9) - y = 10*y + c; + y = 10*y + c; else if (nd <= DBL_DIG + 1) - z = 10*z + c; + z = 10*z + c; nz = 0; } } @@ -759,7 +738,7 @@ _DEFUN (_strtod_r, (ptr, s00, se), j -= i; if (i < 32) Lsb <<= i; - else + else Lsb1 = Lsb << (i-32); } #else /*Avoid_Underflow*/ @@ -847,7 +826,7 @@ _DEFUN (_strtod_r, (ptr, s00, se), else if (!dsign) { adj = -1.; if (!dword1(rv) - && !(dword0(rv) & Frac_mask)) { + && !(dword0(rv) & Frac_mask)) { y = dword0(rv) & Exp_mask; #ifdef Avoid_Underflow if (!scale || y > 2*P*Exp_msk1) diff --git a/contrib/sdk/sources/newlib/libc/stdlib/strtodg.c b/contrib/sdk/sources/newlib/libc/stdlib/strtodg.c new file mode 100644 index 0000000000..a6b32908be --- /dev/null +++ b/contrib/sdk/sources/newlib/libc/stdlib/strtodg.c @@ -0,0 +1,1147 @@ +/**************************************************************** + +The author of this software is David M. Gay. + +Copyright (C) 1998-2001 by Lucent Technologies +All Rights Reserved + +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 and that both that the copyright notice and this +permission notice and warranty disclaimer appear in supporting +documentation, and that the name of Lucent or any of its entities +not be used in advertising or publicity pertaining to +distribution of the software without specific, written prior +permission. + +LUCENT DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, +INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS. +IN NO EVENT SHALL LUCENT OR ANY OF ITS ENTITIES BE LIABLE FOR ANY +SPECIAL, 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. + +****************************************************************/ + +/* Please send bug reports to David M. Gay (dmg at acm dot org, + * with " at " changed at "@" and " dot " changed to "."). */ + +#include <_ansi.h> +#include +#include +#include +#include "mprec.h" +#include "gdtoa.h" +#include "gd_qnan.h" + +#include "locale.h" + +#if defined (_HAVE_LONG_DOUBLE) && !defined (_LDBL_EQ_DBL) + +#define USE_LOCALE + + static const int +fivesbits[] = { 0, 3, 5, 7, 10, 12, 14, 17, 19, 21, + 24, 26, 28, 31, 33, 35, 38, 40, 42, 45, + 47, 49, 52 +#ifdef VAX + , 54, 56 +#endif + }; + +static _Bigint * +#ifdef KR_headers +sum(p, a, b) struct _reent *p; _Bigint *a; _Bigint *b; +#else +sum(struct _reent *p, _Bigint *a, _Bigint *b) +#endif +{ + _Bigint *c; + __ULong carry, *xc, *xa, *xb, *xe, y; +#ifdef Pack_32 + __ULong z; +#endif + + if (a->_wds < b->_wds) { + c = b; b = a; a = c; + } + c = Balloc(p, a->_k); + c->_wds = a->_wds; + carry = 0; + xa = a->_x; + xb = b->_x; + xc = c->_x; + xe = xc + b->_wds; +#ifdef Pack_32 + do { + y = (*xa & 0xffff) + (*xb & 0xffff) + carry; + carry = (y & 0x10000) >> 16; + z = (*xa++ >> 16) + (*xb++ >> 16) + carry; + carry = (z & 0x10000) >> 16; + Storeinc(xc, z, y); + } + while(xc < xe); + xe += a->_wds - b->_wds; + while(xc < xe) { + y = (*xa & 0xffff) + carry; + carry = (y & 0x10000) >> 16; + z = (*xa++ >> 16) + carry; + carry = (z & 0x10000) >> 16; + Storeinc(xc, z, y); + } +#else + do { + y = *xa++ + *xb++ + carry; + carry = (y & 0x10000) >> 16; + *xc++ = y & 0xffff; + } + while(xc < xe); + xe += a->_wds - b->_wds; + while(xc < xe) { + y = *xa++ + carry; + carry = (y & 0x10000) >> 16; + *xc++ = y & 0xffff; + } +#endif + if (carry) { + if (c->_wds == c->_maxwds) { + b = Balloc(p, c->_k + 1); + Bcopy(b, c); + Bfree(p, c); + c = b; + } + c->_x[c->_wds++] = 1; + } + return c; + } + +static void +#ifdef KR_headers +rshift(b, k) _Bigint *b; int k; +#else +rshift(_Bigint *b, int k) +#endif +{ + __ULong *x, *x1, *xe, y; + int n; + + x = x1 = b->_x; + n = k >> kshift; + if (n < b->_wds) { + xe = x + b->_wds; + x += n; + if (k &= kmask) { + n = ULbits - k; + y = *x++ >> k; + while(x < xe) { + *x1++ = (y | (*x << n)) & ALL_ON; + y = *x++ >> k; + } + if ((*x1 = y) !=0) + x1++; + } + else + while(x < xe) + *x1++ = *x++; + } + if ((b->_wds = x1 - b->_x) == 0) + b->_x[0] = 0; + } + +static int +#ifdef KR_headers +trailz(b) _Bigint *b; +#else +trailz(_Bigint *b) +#endif +{ + __ULong L, *x, *xe; + int n = 0; + + x = b->_x; + xe = x + b->_wds; + for(n = 0; x < xe && !*x; x++) + n += ULbits; + if (x < xe) { + L = *x; + n += lo0bits(&L); + } + return n; + } + + _Bigint * +#ifdef KR_headers +increment(p, b) struct _reent *p; _Bigint *b; +#else +increment(struct _reent *p, _Bigint *b) +#endif +{ + __ULong *x, *xe; + _Bigint *b1; +#ifdef Pack_16 + __ULong carry = 1, y; +#endif + + x = b->_x; + xe = x + b->_wds; +#ifdef Pack_32 + do { + if (*x < (__ULong)0xffffffffL) { + ++*x; + return b; + } + *x++ = 0; + } while(x < xe); +#else + do { + y = *x + carry; + carry = y >> 16; + *x++ = y & 0xffff; + if (!carry) + return b; + } while(x < xe); + if (carry) +#endif + { + if (b->_wds >= b->_maxwds) { + b1 = Balloc(p,b->_k+1); + Bcopy(b1,b); + Bfree(p,b); + b = b1; + } + b->_x[b->_wds++] = 1; + } + return b; + } + + int +#ifdef KR_headers +decrement(b) _Bigint *b; +#else +decrement(_Bigint *b) +#endif +{ + __ULong *x, *xe; +#ifdef Pack_16 + __ULong borrow = 1, y; +#endif + + x = b->_x; + xe = x + b->_wds; +#ifdef Pack_32 + do { + if (*x) { + --*x; + break; + } + *x++ = 0xffffffffL; + } + while(x < xe); +#else + do { + y = *x - borrow; + borrow = (y & 0x10000) >> 16; + *x++ = y & 0xffff; + } while(borrow && x < xe); +#endif + return STRTOG_Inexlo; + } + + static int +#ifdef KR_headers +all_on(b, n) _Bigint *b; int n; +#else +all_on(_Bigint *b, int n) +#endif +{ + __ULong *x, *xe; + + x = b->_x; + xe = x + (n >> kshift); + while(x < xe) + if ((*x++ & ALL_ON) != ALL_ON) + return 0; + if (n &= kmask) + return ((*x | (ALL_ON << n)) & ALL_ON) == ALL_ON; + return 1; + } + + _Bigint * +#ifdef KR_headers +set_ones(p, b, n) struct _reent *p; _Bigint *b; int n; +#else +set_ones(struct _reent *p, _Bigint *b, int n) +#endif +{ + int k; + __ULong *x, *xe; + + k = (n + ((1 << kshift) - 1)) >> kshift; + if (b->_k < k) { + Bfree(p,b); + b = Balloc(p,k); + } + k = n >> kshift; + if (n &= kmask) + k++; + b->_wds = k; + x = b->_x; + xe = x + k; + while(x < xe) + *x++ = ALL_ON; + if (n) + x[-1] >>= ULbits - n; + return b; + } + + static int +rvOK +#ifdef KR_headers + (p, d, fpi, exp, bits, exact, rd, irv) + struct _reent *p; double d; FPI *fpi; Long *exp; __ULong *bits; int exact, rd, *irv; +#else + (struct _reent *p, double d, FPI *fpi, Long *exp, __ULong *bits, int exact, int rd, int *irv) +#endif +{ + _Bigint *b; + __ULong carry, inex, lostbits; + int bdif, e, j, k, k1, nb, rv; + + carry = rv = 0; + b = d2b(p, d, &e, &bdif); + bdif -= nb = fpi->nbits; + e += bdif; + if (bdif <= 0) { + if (exact) + goto trunc; + goto ret; + } + if (P == nb) { + if ( +#ifndef IMPRECISE_INEXACT + exact && +#endif + fpi->rounding == +#ifdef RND_PRODQUOT + FPI_Round_near +#else + Flt_Rounds +#endif + ) goto trunc; + goto ret; + } + switch(rd) { + case 1: + goto trunc; + case 2: + break; + default: /* round near */ + k = bdif - 1; + if (k < 0) + goto trunc; + if (!k) { + if (!exact) + goto ret; + if (b->_x[0] & 2) + break; + goto trunc; + } + if (b->_x[k>>kshift] & ((__ULong)1 << (k & kmask))) + break; + goto trunc; + } + /* "break" cases: round up 1 bit, then truncate; bdif > 0 */ + carry = 1; + trunc: + inex = lostbits = 0; + if (bdif > 0) { + if ( (lostbits = any_on(b, bdif)) !=0) + inex = STRTOG_Inexlo; + rshift(b, bdif); + if (carry) { + inex = STRTOG_Inexhi; + b = increment(p, b); + if ( (j = nb & kmask) !=0) + j = ULbits - j; + if (hi0bits(b->_x[b->_wds - 1]) != j) { + if (!lostbits) + lostbits = b->_x[0] & 1; + rshift(b, 1); + e++; + } + } + } + else if (bdif < 0) + b = lshift(p, b, -bdif); + if (e < fpi->emin) { + k = fpi->emin - e; + e = fpi->emin; + if (k > nb || fpi->sudden_underflow) { + b->_wds = inex = 0; + *irv = STRTOG_Underflow | STRTOG_Inexlo; + } + else { + k1 = k - 1; + if (k1 > 0 && !lostbits) + lostbits = any_on(b, k1); + if (!lostbits && !exact) + goto ret; + lostbits |= + carry = b->_x[k1>>kshift] & (1 << (k1 & kmask)); + rshift(b, k); + *irv = STRTOG_Denormal; + if (carry) { + b = increment(p, b); + inex = STRTOG_Inexhi | STRTOG_Underflow; + } + else if (lostbits) + inex = STRTOG_Inexlo | STRTOG_Underflow; + } + } + else if (e > fpi->emax) { + e = fpi->emax + 1; + *irv = STRTOG_Infinite | STRTOG_Overflow | STRTOG_Inexhi; +#ifndef NO_ERRNO + errno = ERANGE; +#endif + b->_wds = inex = 0; + } + *exp = e; + copybits(bits, nb, b); + *irv |= inex; + rv = 1; + ret: + Bfree(p,b); + return rv; + } + + static int +#ifdef KR_headers +mantbits(d) double d; +#else +mantbits(U d) +#endif +{ + __ULong L; +#ifdef VAX + L = word1(d) << 16 | word1(d) >> 16; + if (L) +#else + if ( (L = word1(d)) !=0) +#endif + return P - lo0bits(&L); +#ifdef VAX + L = word0(d) << 16 | word0(d) >> 16 | Exp_msk11; +#else + L = word0(d) | Exp_msk1; +#endif + return P - 32 - lo0bits(&L); + } + + int +_strtodg_r +#ifdef KR_headers + (p, s00, se, fpi, exp, bits) + struct _reent *p; const char *s00; char **se; FPI *fpi; Long *exp; __ULong *bits; +#else + (struct _reent *p, const char *s00, char **se, FPI *fpi, Long *exp, __ULong *bits) +#endif +{ + int abe, abits, asub; + int bb0, bb2, bb5, bbe, bd2, bd5, bbbits, bs2, c, decpt, denorm; + int dsign, e, e1, e2, emin, esign, finished, i, inex, irv; + int j, k, nbits, nd, nd0, nf, nz, nz0, rd, rvbits, rve, rve1, sign; + int sudden_underflow; + const char *s, *s0, *s1; + //double adj, adj0, rv, tol; + double adj0, tol; + U adj, rv; + Long L; + __ULong y, z; + _Bigint *ab, *bb, *bb1, *bd, *bd0, *bs, *delta, *rvb, *rvb0; + + irv = STRTOG_Zero; + denorm = sign = nz0 = nz = 0; + dval(rv) = 0.; + rvb = 0; + nbits = fpi->nbits; + for(s = s00;;s++) switch(*s) { + case '-': + sign = 1; + /* no break */ + case '+': + if (*++s) + goto break2; + /* no break */ + case 0: + sign = 0; + irv = STRTOG_NoNumber; + s = s00; + goto ret; + case '\t': + case '\n': + case '\v': + case '\f': + case '\r': + case ' ': + continue; + default: + goto break2; + } + break2: + if (*s == '0') { +#ifndef NO_HEX_FP + switch(s[1]) { + case 'x': + case 'X': + irv = gethex(p, &s, fpi, exp, &rvb, sign); + if (irv == STRTOG_NoNumber) { + s = s00; + sign = 0; + } + goto ret; + } +#endif + nz0 = 1; + while(*++s == '0') ; + if (!*s) + goto ret; + } + sudden_underflow = fpi->sudden_underflow; + s0 = s; + y = z = 0; + for(decpt = nd = nf = 0; (c = *s) >= '0' && c <= '9'; nd++, s++) + if (nd < 9) + y = 10*y + c - '0'; + else if (nd < 16) + z = 10*z + c - '0'; + nd0 = nd; +#ifdef USE_LOCALE + if (strncmp (s, _localeconv_r (p)->decimal_point, + strlen (_localeconv_r (p)->decimal_point)) == 0) +#else + if (c == '.') +#endif + { + decpt = 1; +#ifdef USE_LOCALE + c = *(s += strlen (_localeconv_r (p)->decimal_point)); +#else + c = *++s; +#endif + if (!nd) { + for(; c == '0'; c = *++s) + nz++; + if (c > '0' && c <= '9') { + s0 = s; + nf += nz; + nz = 0; + goto have_dig; + } + goto dig_done; + } + for(; c >= '0' && c <= '9'; c = *++s) { + have_dig: + nz++; + if (c -= '0') { + nf += nz; + for(i = 1; i < nz; i++) + if (nd++ < 9) + y *= 10; + else if (nd <= DBL_DIG + 1) + z *= 10; + if (nd++ < 9) + y = 10*y + c; + else if (nd <= DBL_DIG + 1) + z = 10*z + c; + nz = 0; + } + } + } + dig_done: + e = 0; + if (c == 'e' || c == 'E') { + if (!nd && !nz && !nz0) { + irv = STRTOG_NoNumber; + s = s00; + goto ret; + } + s00 = s; + esign = 0; + switch(c = *++s) { + case '-': + esign = 1; + case '+': + c = *++s; + } + if (c >= '0' && c <= '9') { + while(c == '0') + c = *++s; + if (c > '0' && c <= '9') { + L = c - '0'; + s1 = s; + while((c = *++s) >= '0' && c <= '9') + L = 10*L + c - '0'; + if (s - s1 > 8 || L > 19999) + /* Avoid confusion from exponents + * so large that e might overflow. + */ + e = 19999; /* safe for 16 bit ints */ + else + e = (int)L; + if (esign) + e = -e; + } + else + e = 0; + } + else + s = s00; + } + if (!nd) { + if (!nz && !nz0) { +#ifdef INFNAN_CHECK + /* Check for Nan and Infinity */ + if (!decpt) + switch(c) { + case 'i': + case 'I': + if (match(&s,"nf")) { + --s; + if (!match(&s,"inity")) + ++s; + irv = STRTOG_Infinite; + goto infnanexp; + } + break; + case 'n': + case 'N': + if (match(&s, "an")) { + irv = STRTOG_NaN; + *exp = fpi->emax + 1; +#ifndef No_Hex_NaN + if (*s == '(') /*)*/ + irv = hexnan(&s, fpi, bits); +#endif + goto infnanexp; + } + } +#endif /* INFNAN_CHECK */ + irv = STRTOG_NoNumber; + s = s00; + } + goto ret; + } + + irv = STRTOG_Normal; + e1 = e -= nf; + rd = 0; + switch(fpi->rounding & 3) { + case FPI_Round_up: + rd = 2 - sign; + break; + case FPI_Round_zero: + rd = 1; + break; + case FPI_Round_down: + rd = 1 + sign; + } + + /* Now we have nd0 digits, starting at s0, followed by a + * decimal point, followed by nd-nd0 digits. The number we're + * after is the integer represented by those digits times + * 10**e */ + + if (!nd0) + nd0 = nd; + k = nd < DBL_DIG + 1 ? nd : DBL_DIG + 1; + dval(rv) = y; + if (k > 9) + dval(rv) = tens[k - 9] * dval(rv) + z; + bd0 = 0; + if (nbits <= P && nd <= DBL_DIG) { + if (!e) { + if (rvOK(p, dval(rv), fpi, exp, bits, 1, rd, &irv)) + goto ret; + } + else if (e > 0) { + if (e <= Ten_pmax) { +#ifdef VAX + goto vax_ovfl_check; +#else + i = fivesbits[e] + mantbits(rv) <= P; + /* rv = */ rounded_product(dval(rv), tens[e]); + if (rvOK(p, dval(rv), fpi, exp, bits, i, rd, &irv)) + goto ret; + e1 -= e; + goto rv_notOK; +#endif + } + i = DBL_DIG - nd; + if (e <= Ten_pmax + i) { + /* A fancier test would sometimes let us do + * this for larger i values. + */ + e2 = e - i; + e1 -= i; + dval(rv) *= tens[i]; +#ifdef VAX + /* VAX exponent range is so narrow we must + * worry about overflow here... + */ + vax_ovfl_check: + dval(adj) = dval(rv); + word0(adj) -= P*Exp_msk1; + /* adj = */ rounded_product(dval(adj), tens[e2]); + if ((word0(adj) & Exp_mask) + > Exp_msk1*(DBL_MAX_EXP+Bias-1-P)) + goto rv_notOK; + word0(adj) += P*Exp_msk1; + dval(rv) = dval(adj); +#else + /* rv = */ rounded_product(dval(rv), tens[e2]); +#endif + if (rvOK(p, dval(rv), fpi, exp, bits, 0, rd, &irv)) + goto ret; + e1 -= e2; + } + } +#ifndef Inaccurate_Divide + else if (e >= -Ten_pmax) { + /* rv = */ rounded_quotient(dval(rv), tens[-e]); + if (rvOK(p, dval(rv), fpi, exp, bits, 0, rd, &irv)) + goto ret; + e1 -= e; + } +#endif + } + rv_notOK: + e1 += nd - k; + + /* Get starting approximation = rv * 10**e1 */ + + e2 = 0; + if (e1 > 0) { + if ( (i = e1 & 15) !=0) + dval(rv) *= tens[i]; + if (e1 &= ~15) { + e1 >>= 4; + while(e1 >= (1 << n_bigtens-1)) { + e2 += ((word0(rv) & Exp_mask) + >> Exp_shift1) - Bias; + word0(rv) &= ~Exp_mask; + word0(rv) |= Bias << Exp_shift1; + dval(rv) *= bigtens[n_bigtens-1]; + e1 -= 1 << n_bigtens-1; + } + e2 += ((word0(rv) & Exp_mask) >> Exp_shift1) - Bias; + word0(rv) &= ~Exp_mask; + word0(rv) |= Bias << Exp_shift1; + for(j = 0; e1 > 0; j++, e1 >>= 1) + if (e1 & 1) + dval(rv) *= bigtens[j]; + } + } + else if (e1 < 0) { + e1 = -e1; + if ( (i = e1 & 15) !=0) + dval(rv) /= tens[i]; + if (e1 &= ~15) { + e1 >>= 4; + while(e1 >= (1 << n_bigtens-1)) { + e2 += ((word0(rv) & Exp_mask) + >> Exp_shift1) - Bias; + word0(rv) &= ~Exp_mask; + word0(rv) |= Bias << Exp_shift1; + dval(rv) *= tinytens[n_bigtens-1]; + e1 -= 1 << n_bigtens-1; + } + e2 += ((word0(rv) & Exp_mask) >> Exp_shift1) - Bias; + word0(rv) &= ~Exp_mask; + word0(rv) |= Bias << Exp_shift1; + for(j = 0; e1 > 0; j++, e1 >>= 1) + if (e1 & 1) + dval(rv) *= tinytens[j]; + } + } +#ifdef IBM + /* e2 is a correction to the (base 2) exponent of the return + * value, reflecting adjustments above to avoid overflow in the + * native arithmetic. For native IBM (base 16) arithmetic, we + * must multiply e2 by 4 to change from base 16 to 2. + */ + e2 <<= 2; +#endif + rvb = d2b(p, dval(rv), &rve, &rvbits); /* rv = rvb * 2^rve */ + rve += e2; + if ((j = rvbits - nbits) > 0) { + rshift(rvb, j); + rvbits = nbits; + rve += j; + } + bb0 = 0; /* trailing zero bits in rvb */ + e2 = rve + rvbits - nbits; + if (e2 > fpi->emax + 1) + goto huge; + rve1 = rve + rvbits - nbits; + if (e2 < (emin = fpi->emin)) { + denorm = 1; + j = rve - emin; + if (j > 0) { + rvb = lshift(p, rvb, j); + rvbits += j; + } + else if (j < 0) { + rvbits += j; + if (rvbits <= 0) { + if (rvbits < -1) { + ufl: + rvb->_wds = 0; + rvb->_x[0] = 0; + *exp = emin; + irv = STRTOG_Underflow | STRTOG_Inexlo; + goto ret; + } + rvb->_x[0] = rvb->_wds = rvbits = 1; + } + else + rshift(rvb, -j); + } + rve = rve1 = emin; + if (sudden_underflow && e2 + 1 < emin) + goto ufl; + } + + /* Now the hard part -- adjusting rv to the correct value.*/ + + /* Put digits into bd: true value = bd * 10^e */ + + bd0 = s2b(p, s0, nd0, nd, y); + + for(;;) { + bd = Balloc(p,bd0->_k); + Bcopy(bd, bd0); + bb = Balloc(p,rvb->_k); + Bcopy(bb, rvb); + bbbits = rvbits - bb0; + bbe = rve + bb0; + bs = i2b(p, 1); + + if (e >= 0) { + bb2 = bb5 = 0; + bd2 = bd5 = e; + } + else { + bb2 = bb5 = -e; + bd2 = bd5 = 0; + } + if (bbe >= 0) + bb2 += bbe; + else + bd2 -= bbe; + bs2 = bb2; + j = nbits + 1 - bbbits; + i = bbe + bbbits - nbits; + if (i < emin) /* denormal */ + j += i - emin; + bb2 += j; + bd2 += j; + i = bb2 < bd2 ? bb2 : bd2; + if (i > bs2) + i = bs2; + if (i > 0) { + bb2 -= i; + bd2 -= i; + bs2 -= i; + } + if (bb5 > 0) { + bs = pow5mult(p, bs, bb5); + bb1 = mult(p, bs, bb); + Bfree(p,bb); + bb = bb1; + } + bb2 -= bb0; + if (bb2 > 0) + bb = lshift(p, bb, bb2); + else if (bb2 < 0) + rshift(bb, -bb2); + if (bd5 > 0) + bd = pow5mult(p, bd, bd5); + if (bd2 > 0) + bd = lshift(p, bd, bd2); + if (bs2 > 0) + bs = lshift(p, bs, bs2); + asub = 1; + inex = STRTOG_Inexhi; + delta = diff(p, bb, bd); + if (delta->_wds <= 1 && !delta->_x[0]) + break; + dsign = delta->_sign; + delta->_sign = finished = 0; + L = 0; + i = cmp(delta, bs); + if (rd && i <= 0) { + irv = STRTOG_Normal; + if ( (finished = dsign ^ (rd&1)) !=0) { + if (dsign != 0) { + irv |= STRTOG_Inexhi; + goto adj1; + } + irv |= STRTOG_Inexlo; + if (rve1 == emin) + goto adj1; + for(i = 0, j = nbits; j >= ULbits; + i++, j -= ULbits) { + if (rvb->_x[i] & ALL_ON) + goto adj1; + } + if (j > 1 && lo0bits(rvb->_x + i) < j - 1) + goto adj1; + rve = rve1 - 1; + rvb = set_ones(p, rvb, rvbits = nbits); + break; + } + irv |= dsign ? STRTOG_Inexlo : STRTOG_Inexhi; + break; + } + if (i < 0) { + /* Error is less than half an ulp -- check for + * special case of mantissa a power of two. + */ + irv = dsign + ? STRTOG_Normal | STRTOG_Inexlo + : STRTOG_Normal | STRTOG_Inexhi; + if (dsign || bbbits > 1 || denorm || rve1 == emin) + break; + delta = lshift(p, delta,1); + if (cmp(delta, bs) > 0) { + irv = STRTOG_Normal | STRTOG_Inexlo; + goto drop_down; + } + break; + } + if (i == 0) { + /* exactly half-way between */ + if (dsign) { + if (denorm && all_on(rvb, rvbits)) { + /*boundary case -- increment exponent*/ + rvb->_wds = 1; + rvb->_x[0] = 1; + rve = emin + nbits - (rvbits = 1); + irv = STRTOG_Normal | STRTOG_Inexhi; + denorm = 0; + break; + } + irv = STRTOG_Normal | STRTOG_Inexlo; + } + else if (bbbits == 1) { + irv = STRTOG_Normal; + drop_down: + /* boundary case -- decrement exponent */ + if (rve1 == emin) { + irv = STRTOG_Normal | STRTOG_Inexhi; + if (rvb->_wds == 1 && rvb->_x[0] == 1) + sudden_underflow = 1; + break; + } + rve -= nbits; + rvb = set_ones(p, rvb, rvbits = nbits); + break; + } + else + irv = STRTOG_Normal | STRTOG_Inexhi; + if (bbbits < nbits && !denorm || !(rvb->_x[0] & 1)) + break; + if (dsign) { + rvb = increment(p, rvb); + j = kmask & (ULbits - (rvbits & kmask)); + if (hi0bits(rvb->_x[rvb->_wds - 1]) != j) + rvbits++; + irv = STRTOG_Normal | STRTOG_Inexhi; + } + else { + if (bbbits == 1) + goto undfl; + decrement(rvb); + irv = STRTOG_Normal | STRTOG_Inexlo; + } + break; + } + if ((dval(adj) = ratio(delta, bs)) <= 2.) { + adj1: + inex = STRTOG_Inexlo; + if (dsign) { + asub = 0; + inex = STRTOG_Inexhi; + } + else if (denorm && bbbits <= 1) { + undfl: + rvb->_wds = 0; + rve = emin; + irv = STRTOG_Underflow | STRTOG_Inexlo; + break; + } + adj0 = dval(adj) = 1.; + } + else { + adj0 = dval(adj) *= 0.5; + if (dsign) { + asub = 0; + inex = STRTOG_Inexlo; + } + if (dval(adj) < 2147483647.) { + L = adj0; + adj0 -= L; + switch(rd) { + case 0: + if (adj0 >= .5) + goto inc_L; + break; + case 1: + if (asub && adj0 > 0.) + goto inc_L; + break; + case 2: + if (!asub && adj0 > 0.) { + inc_L: + L++; + inex = STRTOG_Inexact - inex; + } + } + dval(adj) = L; + } + } + y = rve + rvbits; + + /* adj *= ulp(dval(rv)); */ + /* if (asub) rv -= adj; else rv += adj; */ + + if (!denorm && rvbits < nbits) { + rvb = lshift(p, rvb, j = nbits - rvbits); + rve -= j; + rvbits = nbits; + } + ab = d2b(p, dval(adj), &abe, &abits); + if (abe < 0) + rshift(ab, -abe); + else if (abe > 0) + ab = lshift(p, ab, abe); + rvb0 = rvb; + if (asub) { + /* rv -= adj; */ + j = hi0bits(rvb->_x[rvb->_wds-1]); + rvb = diff(p, rvb, ab); + k = rvb0->_wds - 1; + if (denorm) + /* do nothing */; + else if (rvb->_wds <= k + || hi0bits( rvb->_x[k]) > + hi0bits(rvb0->_x[k])) { + /* unlikely; can only have lost 1 high bit */ + if (rve1 == emin) { + --rvbits; + denorm = 1; + } + else { + rvb = lshift(p, rvb, 1); + --rve; + --rve1; + L = finished = 0; + } + } + } + else { + rvb = sum(p, rvb, ab); + k = rvb->_wds - 1; + if (k >= rvb0->_wds + || hi0bits(rvb->_x[k]) < hi0bits(rvb0->_x[k])) { + if (denorm) { + if (++rvbits == nbits) + denorm = 0; + } + else { + rshift(rvb, 1); + rve++; + rve1++; + L = 0; + } + } + } + Bfree(p,ab); + Bfree(p,rvb0); + if (finished) + break; + + z = rve + rvbits; + if (y == z && L) { + /* Can we stop now? */ + tol = dval(adj) * 5e-16; /* > max rel error */ + dval(adj) = adj0 - .5; + if (dval(adj) < -tol) { + if (adj0 > tol) { + irv |= inex; + break; + } + } + else if (dval(adj) > tol && adj0 < 1. - tol) { + irv |= inex; + break; + } + } + bb0 = denorm ? 0 : trailz(rvb); + Bfree(p,bb); + Bfree(p,bd); + Bfree(p,bs); + Bfree(p,delta); + } + if (!denorm && (j = nbits - rvbits)) { + if (j > 0) + rvb = lshift(p, rvb, j); + else + rshift(rvb, -j); + rve -= j; + } + *exp = rve; + Bfree(p,bb); + Bfree(p,bd); + Bfree(p,bs); + Bfree(p,bd0); + Bfree(p,delta); + if (rve > fpi->emax) { + huge: + rvb->_wds = 0; + irv = STRTOG_Infinite | STRTOG_Overflow | STRTOG_Inexhi; +#ifndef NO_ERRNO + errno = ERANGE; +#endif + infnanexp: + *exp = fpi->emax + 1; + } + ret: + if (denorm) { + if (sudden_underflow) { + rvb->_wds = 0; + irv = STRTOG_Underflow | STRTOG_Inexlo; + } + else { + irv = (irv & ~STRTOG_Retmask) | + (rvb->_wds > 0 ? STRTOG_Denormal : STRTOG_Zero); + if (irv & STRTOG_Inexact) + irv |= STRTOG_Underflow; + } + } + if (se) + *se = (char *)s; + if (sign) + irv |= STRTOG_Neg; + if (rvb) { + copybits(bits, nbits, rvb); + Bfree(p,rvb); + } + return irv; + } + +#endif /* _HAVE_LONG_DOUBLE && !_LDBL_EQ_DBL */ diff --git a/contrib/sdk/sources/newlib/libc/stdlib/strtold.c b/contrib/sdk/sources/newlib/libc/stdlib/strtold.c index 64f15fe40a..dd6ade2119 100644 --- a/contrib/sdk/sources/newlib/libc/stdlib/strtold.c +++ b/contrib/sdk/sources/newlib/libc/stdlib/strtold.c @@ -31,12 +31,50 @@ POSSIBILITY OF SUCH DAMAGE. #include #include "local.h" -/* On platforms where long double is as wide as double. */ +#ifdef _HAVE_LONG_DOUBLE + +#if defined (__x86_64__) || defined (__i386__) +static const int map[] = { + 1, /* round to nearest */ + 3, /* round to zero */ + 2, /* round to negative infinity */ + 0 /* round to positive infinity */ +}; + +int +__flt_rounds(void) +{ + int x; + + /* Assume that the x87 and the SSE unit agree on the rounding mode. */ + __asm("fnstcw %0" : "=m" (x)); + return (map[(x >> 10) & 0x03]); +} +#define FLT_ROUNDS __flt_rounds() +#else +#define FLT_ROUNDS 0 +#endif + +long double +_strtold_r (struct _reent *ptr, const char *__restrict s00, + char **__restrict se) +{ #ifdef _LDBL_EQ_DBL + /* On platforms where long double is as wide as double. */ + return _strtod_r (ptr, s00, se); +#else + long double result; + + _strtorx_r (ptr, s00, se, FLT_ROUNDS, &result); + return result; +#endif +} + long double strtold (const char *__restrict s00, char **__restrict se) { - return strtod(s00, se); + return _strtold_r (_REENT, s00, se); } -#endif /* _LDBL_EQ_DBL */ + +#endif /* _HAVE_LONG_DOUBLE */ diff --git a/contrib/sdk/sources/newlib/libc/stdlib/strtorx.c b/contrib/sdk/sources/newlib/libc/stdlib/strtorx.c new file mode 100644 index 0000000000..44f3db269a --- /dev/null +++ b/contrib/sdk/sources/newlib/libc/stdlib/strtorx.c @@ -0,0 +1,129 @@ +/**************************************************************** + +The author of this software is David M. Gay. + +Copyright (C) 1998, 2000 by Lucent Technologies +All Rights Reserved + +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 and that both that the copyright notice and this +permission notice and warranty disclaimer appear in supporting +documentation, and that the name of Lucent or any of its entities +not be used in advertising or publicity pertaining to +distribution of the software without specific, written prior +permission. + +LUCENT DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, +INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS. +IN NO EVENT SHALL LUCENT OR ANY OF ITS ENTITIES BE LIABLE FOR ANY +SPECIAL, 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. + +****************************************************************/ + +/* Please send bug reports to David M. Gay (dmg at acm dot org, + * with " at " changed at "@" and " dot " changed to "."). */ + +#include <_ansi.h> +#include +#include +#include +#include "mprec.h" +#include "gdtoa.h" +#include "gd_qnan.h" + +#if defined (_HAVE_LONG_DOUBLE) && !defined (_LDBL_EQ_DBL) + +#undef _0 +#undef _1 + +/* one or the other of IEEE_MC68k or IEEE_8087 should be #defined */ + +#ifdef IEEE_MC68k +#define _0 0 +#define _1 1 +#define _2 2 +#define _3 3 +#define _4 4 +#endif +#ifdef IEEE_8087 +#define _0 4 +#define _1 3 +#define _2 2 +#define _3 1 +#define _4 0 +#endif + + void +#ifdef KR_headers +ULtox(L, bits, exp, k) __UShort *L; __ULong *bits; Long exp; int k; +#else +ULtox(__UShort *L, __ULong *bits, Long exp, int k) +#endif +{ + switch(k & STRTOG_Retmask) { + case STRTOG_NoNumber: + case STRTOG_Zero: + L[0] = L[1] = L[2] = L[3] = L[4] = 0; + break; + + case STRTOG_Denormal: + L[_0] = 0; + goto normal_bits; + + case STRTOG_Normal: + case STRTOG_NaNbits: + L[_0] = exp + 0x3fff + 63; + normal_bits: + L[_4] = (__UShort)bits[0]; + L[_3] = (__UShort)(bits[0] >> 16); + L[_2] = (__UShort)bits[1]; + L[_1] = (__UShort)(bits[1] >> 16); + break; + + case STRTOG_Infinite: + L[_0] = 0x7fff; + L[_1] = L[_2] = L[_3] = L[_4] = 0; + break; + + case STRTOG_NaN: + L[0] = ldus_QNAN0; + L[1] = ldus_QNAN1; + L[2] = ldus_QNAN2; + L[3] = ldus_QNAN3; + L[4] = ldus_QNAN4; + } + if (k & STRTOG_Neg) + L[_0] |= 0x8000; + } + + int +#ifdef KR_headers +_strtorx_r(p, s, sp, rounding, L) struct _reent *p; const char *s; char **sp; int rounding; void *L; +#else +_strtorx_r(struct _reent *p, const char *s, char **sp, int rounding, void *L) +#endif +{ + static FPI fpi0 = { 64, 1-16383-64+1, 32766 - 16383 - 64 + 1, 1, SI }; + FPI *fpi, fpi1; + __ULong bits[2]; + Long exp; + int k; + + fpi = &fpi0; + if (rounding != FPI_Round_near) { + fpi1 = fpi0; + fpi1.rounding = rounding; + fpi = &fpi1; + } + k = _strtodg_r(p, s, sp, fpi, &exp, bits); + ULtox((__UShort*)L, bits, exp, k); + return k; + } + +#endif /* _HAVE_LONG_DOUBLE && !_LDBL_EQ_DBL */ diff --git a/contrib/sdk/sources/newlib/libc/stdlib/wctomb_r.c b/contrib/sdk/sources/newlib/libc/stdlib/wctomb_r.c index 13e1e4c36f..c93962fa43 100644 --- a/contrib/sdk/sources/newlib/libc/stdlib/wctomb_r.c +++ b/contrib/sdk/sources/newlib/libc/stdlib/wctomb_r.c @@ -74,7 +74,7 @@ _DEFUN (__utf8_wctomb, (r, s, wchar, charset, state), return 0; /* UTF-8 encoding is not state-dependent */ if (sizeof (wchar_t) == 2 && state->__count == -4 - && (wchar < 0xdc00 || wchar >= 0xdfff)) + && (wchar < 0xdc00 || wchar > 0xdfff)) { /* There's a leftover lone high surrogate. Write out the CESU-8 value of the surrogate and proceed to convert the given character. Note diff --git a/contrib/sdk/sources/newlib/libc/string/local.h b/contrib/sdk/sources/newlib/libc/string/local.h index 909cbbe4e5..babaad0e5f 100644 --- a/contrib/sdk/sources/newlib/libc/string/local.h +++ b/contrib/sdk/sources/newlib/libc/string/local.h @@ -1,24 +1,24 @@ -#include <_ansi.h> -#include <../ctype/local.h> - -/* internal function to compute width of wide char. */ -int _EXFUN (__wcwidth, (wint_t)); - -/* Defined in locale/locale.c. Returns a value != 0 if the current - language is assumed to use CJK fonts. */ -int __locale_cjk_lang (); - -/* - Taken from glibc: - Add the compiler optimization to inhibit loop transformation to library - calls. This is used to avoid recursive calls in memset and memmove - default implementations. -*/ -#ifdef _HAVE_CC_INHIBIT_LOOP_TO_LIBCALL -# define __inhibit_loop_to_libcall \ - __attribute__ ((__optimize__ ("-fno-tree-loop-distribute-patterns"))) -#else -# define __inhibit_loop_to_libcall -#endif - - +#include <_ansi.h> +#include <../ctype/local.h> + +/* internal function to compute width of wide char. */ +int _EXFUN (__wcwidth, (wint_t)); + +/* Defined in locale/locale.c. Returns a value != 0 if the current + language is assumed to use CJK fonts. */ +int _EXFUN (__locale_cjk_lang, (void)); + +/* + Taken from glibc: + Add the compiler optimization to inhibit loop transformation to library + calls. This is used to avoid recursive calls in memset and memmove + default implementations. +*/ +#ifdef _HAVE_CC_INHIBIT_LOOP_TO_LIBCALL +# define __inhibit_loop_to_libcall \ + __attribute__ ((__optimize__ ("-fno-tree-loop-distribute-patterns"))) +#else +# define __inhibit_loop_to_libcall +#endif + + diff --git a/contrib/sdk/sources/newlib/libc/string/memchr.c b/contrib/sdk/sources/newlib/libc/string/memchr.c index 74a61979f6..a4d84c5669 100644 --- a/contrib/sdk/sources/newlib/libc/string/memchr.c +++ b/contrib/sdk/sources/newlib/libc/string/memchr.c @@ -80,7 +80,7 @@ _DEFUN (memchr, (src_void, c, length), #if !defined(PREFER_SIZE_OVER_SPEED) && !defined(__OPTIMIZE_SIZE__) unsigned long *asrc; unsigned long mask; - int i; + unsigned int i; while (UNALIGNED (src)) { diff --git a/contrib/sdk/sources/newlib/libc/string/memset.c b/contrib/sdk/sources/newlib/libc/string/memset.c index 734bec2684..18850967c0 100644 --- a/contrib/sdk/sources/newlib/libc/string/memset.c +++ b/contrib/sdk/sources/newlib/libc/string/memset.c @@ -50,7 +50,7 @@ _DEFUN (memset, (m, c, n), char *s = (char *) m; #if !defined(PREFER_SIZE_OVER_SPEED) && !defined(__OPTIMIZE_SIZE__) - int i; + unsigned int i; unsigned long buffer; unsigned long *aligned_addr; unsigned int d = c & 0xff; /* To avoid sign extension, copy C to an diff --git a/contrib/sdk/sources/newlib/libc/string/str-two-way.h b/contrib/sdk/sources/newlib/libc/string/str-two-way.h index 0707521c8b..28e5be4386 100644 --- a/contrib/sdk/sources/newlib/libc/string/str-two-way.h +++ b/contrib/sdk/sources/newlib/libc/string/str-two-way.h @@ -336,7 +336,7 @@ two_way_long_needle (const unsigned char *haystack, size_t haystack_len, after the mismatch. */ shift = needle_len - period; } - memory = 0; + memory = 0; j += shift; continue; } diff --git a/contrib/sdk/sources/newlib/libc/string/strcasestr.c b/contrib/sdk/sources/newlib/libc/string/strcasestr.c index 1bde1cdbfb..8fff00b003 100644 --- a/contrib/sdk/sources/newlib/libc/string/strcasestr.c +++ b/contrib/sdk/sources/newlib/libc/string/strcasestr.c @@ -96,8 +96,9 @@ QUICKREF * Find the first occurrence of find in s, ignore case. */ char * -strcasestr(s, find) - const char *s, *find; +_DEFUN (strcasestr, (s, find), + _CONST char *s _AND + _CONST char *find) { #if defined(PREFER_SIZE_OVER_SPEED) || defined(__OPTIMIZE_SIZE__) diff --git a/contrib/sdk/sources/newlib/libc/string/strdup_r.c b/contrib/sdk/sources/newlib/libc/string/strdup_r.c index 008a1143b7..28e0098bda 100644 --- a/contrib/sdk/sources/newlib/libc/string/strdup_r.c +++ b/contrib/sdk/sources/newlib/libc/string/strdup_r.c @@ -3,7 +3,7 @@ #include char * -_DEFUN (_strdup_r, (reent_ptr, str), +_DEFUN (_strdup_r, (reent_ptr, str), struct _reent *reent_ptr _AND _CONST char *str) { diff --git a/contrib/sdk/sources/newlib/libc/string/strerror.c b/contrib/sdk/sources/newlib/libc/string/strerror.c index d366057ace..f1e7d5b7e7 100644 --- a/contrib/sdk/sources/newlib/libc/string/strerror.c +++ b/contrib/sdk/sources/newlib/libc/string/strerror.c @@ -45,6 +45,9 @@ Permission denied o EADDRINUSE Address already in use +o EADDRNOTAVAIL +Address not available + o EADV Advertise error @@ -66,6 +69,9 @@ Bad message o EBUSY Device or resource busy +o ECANCELED +Operation canceled + o ECHILD No children @@ -78,6 +84,9 @@ Software caused connection abort o ECONNREFUSED Connection refused +o ECONNRESET +Connection reset by peer + o EDEADLK Deadlock @@ -88,7 +97,7 @@ o EEXIST File exists o EDOM -Math argument +Mathematics argument out of domain of function o EFAULT Bad address @@ -105,6 +114,9 @@ Host is unreachable o EIDRM Identifier removed +o EILSEQ +Illegal byte sequence + o EINPROGRESS Connection already in progress @@ -139,7 +151,7 @@ o ELIBSCN <<.lib>> section in a.out corrupted o EMFILE -Too many open files +File descriptor value too large o EMLINK Too many links @@ -154,7 +166,10 @@ o ENAMETOOLONG File or path name too long o ENETDOWN -Network interface not configured +Network interface is not configured + +o ENETRESET +Connection aborted by network o ENETUNREACH Network is unreachable @@ -162,6 +177,12 @@ Network is unreachable o ENFILE Too many open files in system +o ENOBUFS +No buffer space available + +o ENODATA +No data + o ENODEV No such device @@ -216,6 +237,9 @@ Not a directory o ENOTEMPTY Directory not empty +o ENOTRECOVERABLE +State not recoverable + o ENOTSOCK Socket operation on non-socket @@ -228,6 +252,15 @@ Not a character device o ENXIO No such device or address +o EOPNOTSUPP +Operation not supported on socket + +o EOVERFLOW +Value too large for defined data type + +o EOWNERDEAD +Previous owner died + o EPERM Not owner @@ -267,6 +300,9 @@ No such process o ESRMNT Srmount error +o ESTRPIPE +Strings pipe error + o ETIME Stream ioctl timeout @@ -276,21 +312,12 @@ Connection timed out o ETXTBSY Text file busy +o EWOULDBLOCK +Operation would block (usually same as EAGAIN) + o EXDEV Cross-device link -o ECANCELED -Operation canceled - -o ENOTRECOVERABLE -State not recoverable - -o EOWNERDEAD -Previous owner died - -o ESTRPIPE -Strings pipe error - o- <<_strerror_r>> is a reentrant version of the above. @@ -504,6 +531,11 @@ _DEFUN (_strerror_r, (ptr, errnum, internal, errptr), error = "Network interface is not configured"; break; #endif +#ifdef ENETRESET + case ENETRESET: + error = "Connection aborted by network"; + break; +#endif #ifdef ENFILE case ENFILE: error = "Too many open files in system"; @@ -511,7 +543,7 @@ _DEFUN (_strerror_r, (ptr, errnum, internal, errptr), #endif #ifdef EMFILE case EMFILE: - error = "Too many open files"; + error = "File descriptor value too large"; break; #endif #ifdef ENOTTY @@ -566,7 +598,7 @@ _DEFUN (_strerror_r, (ptr, errnum, internal, errptr), #endif #ifdef EDOM case EDOM: - error = "Math argument"; + error = "Mathematics argument out of domain of function"; break; #endif #ifdef ERANGE @@ -584,6 +616,11 @@ _DEFUN (_strerror_r, (ptr, errnum, internal, errptr), error = "Identifier removed"; break; #endif +#ifdef EILSEQ + case EILSEQ: + error = "Illegal byte sequence"; + break; +#endif #ifdef EDEADLK case EDEADLK: error = "Deadlock"; @@ -724,6 +761,11 @@ _DEFUN (_strerror_r, (ptr, errnum, internal, errptr), error = "No buffer space available"; break; #endif +#ifdef ENODATA + case ENODATA: + error = "No data"; + break; +#endif #ifdef EAFNOSUPPORT case EAFNOSUPPORT: error = "Address family not supported by protocol family"; @@ -754,11 +796,21 @@ _DEFUN (_strerror_r, (ptr, errnum, internal, errptr), error = "Connection refused"; break; #endif +#ifdef ECONNRESET + case ECONNRESET: + error = "Connection reset by peer"; + break; +#endif #ifdef EADDRINUSE case EADDRINUSE: error = "Address already in use"; break; #endif +#ifdef EADDRNOTAVAIL + case EADDRNOTAVAIL: + error = "Address not available"; + break; +#endif #ifdef ECONNABORTED case ECONNABORTED: error = "Software caused connection abort"; @@ -809,6 +861,11 @@ _DEFUN (_strerror_r, (ptr, errnum, internal, errptr), error = "Operation not supported on socket"; break; #endif +#ifdef EOVERFLOW + case EOVERFLOW: + error = "Value too large for defined data type"; + break; +#endif #ifdef EMSGSIZE case EMSGSIZE: error = "Message too long"; @@ -823,7 +880,7 @@ _DEFUN (_strerror_r, (ptr, errnum, internal, errptr), if (!errptr) errptr = &ptr->_errno; if ((error = _user_strerror (errnum, internal, errptr)) == 0) - error = ""; + error = ""; break; } diff --git a/contrib/sdk/sources/newlib/libc/string/strtok.c b/contrib/sdk/sources/newlib/libc/string/strtok.c index 35460ba044..21607e04a9 100644 --- a/contrib/sdk/sources/newlib/libc/string/strtok.c +++ b/contrib/sdk/sources/newlib/libc/string/strtok.c @@ -14,24 +14,24 @@ INDEX ANSI_SYNOPSIS #include char *strtok(char *restrict <[source]>, - const char *restrict <[delimiters]>) + const char *restrict <[delimiters]>); char *strtok_r(char *restrict <[source]>, const char *restrict <[delimiters]>, - char **<[lasts]>) - char *strsep(char **<[source_ptr]>, const char *<[delimiters]>) + char **<[lasts]>); + char *strsep(char **<[source_ptr]>, const char *<[delimiters]>); TRAD_SYNOPSIS #include - char *strtok(<[source]>, <[delimiters]>) + char *strtok(<[source]>, <[delimiters]>); char *<[source]>; char *<[delimiters]>; - char *strtok_r(<[source]>, <[delimiters]>, <[lasts]>) + char *strtok_r(<[source]>, <[delimiters]>, <[lasts]>); char *<[source]>; char *<[delimiters]>; char **<[lasts]>; - char *strsep(<[source_ptr]>, <[delimiters]>) + char *strsep(<[source_ptr]>, <[delimiters]>); char **<[source_ptr]>; char *<[delimiters]>; diff --git a/contrib/sdk/sources/newlib/libc/string/u_strerr.c b/contrib/sdk/sources/newlib/libc/string/u_strerr.c index 3ba8d30e33..63b4955d8f 100644 --- a/contrib/sdk/sources/newlib/libc/string/u_strerr.c +++ b/contrib/sdk/sources/newlib/libc/string/u_strerr.c @@ -6,5 +6,10 @@ _DEFUN(_user_strerror, (errnum, internal, errptr), int internal _AND int *errptr) { + /* prevent warning about unused parameters */ + _CAST_VOID errnum; + _CAST_VOID internal; + _CAST_VOID errptr; + return 0; } diff --git a/contrib/sdk/sources/newlib/libc/time/clock.c b/contrib/sdk/sources/newlib/libc/time/clock.c index 64cf438fbc..0bcfbb6d3c 100644 --- a/contrib/sdk/sources/newlib/libc/time/clock.c +++ b/contrib/sdk/sources/newlib/libc/time/clock.c @@ -59,7 +59,7 @@ clock () struct tms tim_s; clock_t res; - if ((res = (clock_t) _times_r (_REENT, &tim_s)) != -1) + if ((res = (clock_t) _times_r (_REENT, &tim_s)) != (clock_t) -1) res = (clock_t) (tim_s.tms_utime + tim_s.tms_stime + tim_s.tms_cutime + tim_s.tms_cstime); diff --git a/contrib/sdk/sources/newlib/libc/time/gmtime_r.c b/contrib/sdk/sources/newlib/libc/time/gmtime_r.c index 232e133a89..ad363cf36b 100644 --- a/contrib/sdk/sources/newlib/libc/time/gmtime_r.c +++ b/contrib/sdk/sources/newlib/libc/time/gmtime_r.c @@ -1,14 +1,101 @@ /* * gmtime_r.c + * Original Author: Adapted from tzcode maintained by Arthur David Olson. + * Modifications: + * - Changed to mktm_r and added __tzcalc_limits - 04/10/02, Jeff Johnston + * - Fixed bug in mday computations - 08/12/04, Alex Mogilnikov + * - Fixed bug in __tzcalc_limits - 08/12/04, Alex Mogilnikov + * - Move code from _mktm_r() to gmtime_r() - 05/09/14, Freddie Chopin + * - Fixed bug in calculations for dates after year 2069 or before year 1901. Ideas for + * solution taken from musl's __secs_to_tm() - 07/12/2014, Freddie Chopin + * + * - Use faster algorithm from civil_from_days() by Howard Hinnant - 12/06/2014, + * Freddie Chopin + * + * Converts the calendar time pointed to by tim_p into a broken-down time + * expressed as local time. Returns a pointer to a structure containing the + * broken-down time. */ -#include #include "local.h" +/* Move epoch from 01.01.1970 to 01.03.0000 (yes, Year 0) - this is the first + * day of a 400-year long "era", right after additional day of leap year. + * This adjustment is required only for date calculation, so instead of + * modifying time_t value (which would require 64-bit operations to work + * correctly) it's enough to adjust the calculated number of days since epoch. + */ +#define EPOCH_ADJUSTMENT_DAYS 719468L +/* year to which the adjustment was made */ +#define ADJUSTED_EPOCH_YEAR 0 +/* 1st March of year 0 is Wednesday */ +#define ADJUSTED_EPOCH_WDAY 3 +/* there are 97 leap years in 400-year periods. ((400 - 97) * 365 + 97 * 366) */ +#define DAYS_PER_ERA 146097L +/* there are 24 leap years in 100-year periods. ((100 - 24) * 365 + 24 * 366) */ +#define DAYS_PER_CENTURY 36524L +/* there is one leap year every 4 years */ +#define DAYS_PER_4_YEARS (3 * 365 + 366) +/* number of days in a non-leap year */ +#define DAYS_PER_YEAR 365 +/* number of days in January */ +#define DAYS_IN_JANUARY 31 +/* number of days in non-leap February */ +#define DAYS_IN_FEBRUARY 28 +/* number of years per era */ +#define YEARS_PER_ERA 400 + struct tm * _DEFUN (gmtime_r, (tim_p, res), _CONST time_t *__restrict tim_p _AND struct tm *__restrict res) { - return (_mktm_r (tim_p, res, 1)); + long days, rem; + _CONST time_t lcltime = *tim_p; + int era, weekday, year; + unsigned erayear, yearday, month, day; + unsigned long eraday; + + days = ((long)lcltime) / SECSPERDAY + EPOCH_ADJUSTMENT_DAYS; + rem = ((long)lcltime) % SECSPERDAY; + if (rem < 0) + { + rem += SECSPERDAY; + --days; + } + + /* compute hour, min, and sec */ + res->tm_hour = (int) (rem / SECSPERHOUR); + rem %= SECSPERHOUR; + res->tm_min = (int) (rem / SECSPERMIN); + res->tm_sec = (int) (rem % SECSPERMIN); + + /* compute day of week */ + if ((weekday = ((ADJUSTED_EPOCH_WDAY + days) % DAYSPERWEEK)) < 0) + weekday += DAYSPERWEEK; + res->tm_wday = weekday; + + /* compute year, month, day & day of year */ + /* for description of this algorithm see + * http://howardhinnant.github.io/date_algorithms.html#civil_from_days */ + era = (days >= 0 ? days : days - (DAYS_PER_ERA - 1)) / DAYS_PER_ERA; + eraday = days - era * DAYS_PER_ERA; /* [0, 146096] */ + erayear = (eraday - eraday / (DAYS_PER_4_YEARS - 1) + eraday / DAYS_PER_CENTURY - + eraday / (DAYS_PER_ERA - 1)) / 365; /* [0, 399] */ + yearday = eraday - (DAYS_PER_YEAR * erayear + erayear / 4 - erayear / 100); /* [0, 365] */ + month = (5 * yearday + 2) / 153; /* [0, 11] */ + day = yearday - (153 * month + 2) / 5 + 1; /* [1, 31] */ + month += month < 10 ? 2 : -10; + year = ADJUSTED_EPOCH_YEAR + erayear + era * YEARS_PER_ERA + (month <= 1); + + res->tm_yday = yearday >= DAYS_PER_YEAR - DAYS_IN_JANUARY - DAYS_IN_FEBRUARY ? + yearday - (DAYS_PER_YEAR - DAYS_IN_JANUARY - DAYS_IN_FEBRUARY) : + yearday + DAYS_IN_JANUARY + DAYS_IN_FEBRUARY + isleap(erayear); + res->tm_year = year - YEAR_BASE; + res->tm_mon = month; + res->tm_mday = day; + + res->tm_isdst = 0; + + return (res); } diff --git a/contrib/sdk/sources/newlib/libc/time/lcltime_r.c b/contrib/sdk/sources/newlib/libc/time/lcltime_r.c index aac4f8b812..ffa7627d5f 100644 --- a/contrib/sdk/sources/newlib/libc/time/lcltime_r.c +++ b/contrib/sdk/sources/newlib/libc/time/lcltime_r.c @@ -1,12 +1,18 @@ /* * localtime_r.c + * Original Author: Adapted from tzcode maintained by Arthur David Olson. + * Modifications: + * - Changed to mktm_r and added __tzcalc_limits - 04/10/02, Jeff Johnston + * - Fixed bug in mday computations - 08/12/04, Alex Mogilnikov + * - Fixed bug in __tzcalc_limits - 08/12/04, Alex Mogilnikov + * - Implement localtime_r() with gmtime_r() and the conditional code moved + * from _mktm_r() - 05/09/14, Freddie Chopin * * Converts the calendar time pointed to by tim_p into a broken-down time * expressed as local time. Returns a pointer to a structure containing the * broken-down time. */ -#include #include "local.h" struct tm * @@ -14,5 +20,108 @@ _DEFUN (localtime_r, (tim_p, res), _CONST time_t *__restrict tim_p _AND struct tm *__restrict res) { - return _mktm_r (tim_p, res, 0); + long offset; + int hours, mins, secs; + int year; + __tzinfo_type *_CONST tz = __gettzinfo (); + _CONST int *ip; + + res = gmtime_r (tim_p, res); + + year = res->tm_year + YEAR_BASE; + ip = __month_lengths[isleap(year)]; + + TZ_LOCK; + _tzset_unlocked (); + if (_daylight) + { + if (year == tz->__tzyear || __tzcalc_limits (year)) + res->tm_isdst = (tz->__tznorth + ? (*tim_p >= tz->__tzrule[0].change + && *tim_p < tz->__tzrule[1].change) + : (*tim_p >= tz->__tzrule[0].change + || *tim_p < tz->__tzrule[1].change)); + else + res->tm_isdst = -1; + } + else + res->tm_isdst = 0; + + offset = (res->tm_isdst == 1 + ? tz->__tzrule[1].offset + : tz->__tzrule[0].offset); + + hours = (int) (offset / SECSPERHOUR); + offset = offset % SECSPERHOUR; + + mins = (int) (offset / SECSPERMIN); + secs = (int) (offset % SECSPERMIN); + + res->tm_sec -= secs; + res->tm_min -= mins; + res->tm_hour -= hours; + + if (res->tm_sec >= SECSPERMIN) + { + res->tm_min += 1; + res->tm_sec -= SECSPERMIN; + } + else if (res->tm_sec < 0) + { + res->tm_min -= 1; + res->tm_sec += SECSPERMIN; + } + if (res->tm_min >= MINSPERHOUR) + { + res->tm_hour += 1; + res->tm_min -= MINSPERHOUR; + } + else if (res->tm_min < 0) + { + res->tm_hour -= 1; + res->tm_min += MINSPERHOUR; + } + if (res->tm_hour >= HOURSPERDAY) + { + ++res->tm_yday; + ++res->tm_wday; + if (res->tm_wday > 6) + res->tm_wday = 0; + ++res->tm_mday; + res->tm_hour -= HOURSPERDAY; + if (res->tm_mday > ip[res->tm_mon]) + { + res->tm_mday -= ip[res->tm_mon]; + res->tm_mon += 1; + if (res->tm_mon == 12) + { + res->tm_mon = 0; + res->tm_year += 1; + res->tm_yday = 0; + } + } + } + else if (res->tm_hour < 0) + { + res->tm_yday -= 1; + res->tm_wday -= 1; + if (res->tm_wday < 0) + res->tm_wday = 6; + res->tm_mday -= 1; + res->tm_hour += 24; + if (res->tm_mday == 0) + { + res->tm_mon -= 1; + if (res->tm_mon < 0) + { + res->tm_mon = 11; + res->tm_year -= 1; + res->tm_yday = 364 + isleap(res->tm_year + YEAR_BASE); + } + res->tm_mday = ip[res->tm_mon]; + } + } + TZ_UNLOCK; + + return (res); } diff --git a/contrib/sdk/sources/newlib/libc/time/local.h b/contrib/sdk/sources/newlib/libc/time/local.h index 15928b4465..af5793af9a 100644 --- a/contrib/sdk/sources/newlib/libc/time/local.h +++ b/contrib/sdk/sources/newlib/libc/time/local.h @@ -1,36 +1,40 @@ -/* local header used by libc/time routines */ -#include <_ansi.h> -#include - -#define SECSPERMIN 60L -#define MINSPERHOUR 60L -#define HOURSPERDAY 24L -#define SECSPERHOUR (SECSPERMIN * MINSPERHOUR) -#define SECSPERDAY (SECSPERHOUR * HOURSPERDAY) -#define DAYSPERWEEK 7 -#define MONSPERYEAR 12 - -#define YEAR_BASE 1900 -#define EPOCH_YEAR 1970 -#define EPOCH_WDAY 4 -#define EPOCH_YEARS_SINCE_LEAP 2 -#define EPOCH_YEARS_SINCE_CENTURY 70 -#define EPOCH_YEARS_SINCE_LEAP_CENTURY 370 - -#define isleap(y) ((((y) % 4) == 0 && ((y) % 100) != 0) || ((y) % 400) == 0) - -struct tm * _EXFUN (_mktm_r, (_CONST time_t *, struct tm *, int __is_gmtime)); -int _EXFUN (__tzcalc_limits, (int __year)); - -/* locks for multi-threading */ -#ifdef __SINGLE_THREAD__ -#define TZ_LOCK -#define TZ_UNLOCK -#else -#define TZ_LOCK __tz_lock() -#define TZ_UNLOCK __tz_unlock() -#endif - -void _EXFUN(__tz_lock,(_VOID)); -void _EXFUN(__tz_unlock,(_VOID)); - +/* local header used by libc/time routines */ +#include <_ansi.h> +#include + +#define SECSPERMIN 60L +#define MINSPERHOUR 60L +#define HOURSPERDAY 24L +#define SECSPERHOUR (SECSPERMIN * MINSPERHOUR) +#define SECSPERDAY (SECSPERHOUR * HOURSPERDAY) +#define DAYSPERWEEK 7 +#define MONSPERYEAR 12 + +#define YEAR_BASE 1900 +#define EPOCH_YEAR 1970 +#define EPOCH_WDAY 4 +#define EPOCH_YEARS_SINCE_LEAP 2 +#define EPOCH_YEARS_SINCE_CENTURY 70 +#define EPOCH_YEARS_SINCE_LEAP_CENTURY 370 + +#define isleap(y) ((((y) % 4) == 0 && ((y) % 100) != 0) || ((y) % 400) == 0) + +int _EXFUN (__tzcalc_limits, (int __year)); + +extern _CONST int __month_lengths[2][MONSPERYEAR]; + +_VOID _EXFUN(_tzset_unlocked_r, (struct _reent *)); +_VOID _EXFUN(_tzset_unlocked, (_VOID)); + +/* locks for multi-threading */ +#ifdef __SINGLE_THREAD__ +#define TZ_LOCK +#define TZ_UNLOCK +#else +#define TZ_LOCK __tz_lock() +#define TZ_UNLOCK __tz_unlock() +#endif + +void _EXFUN(__tz_lock,(_VOID)); +void _EXFUN(__tz_unlock,(_VOID)); + diff --git a/contrib/sdk/sources/newlib/libc/time/mktime.c b/contrib/sdk/sources/newlib/libc/time/mktime.c index 6ad9ff3f69..e5a2cf2f56 100644 --- a/contrib/sdk/sources/newlib/libc/time/mktime.c +++ b/contrib/sdk/sources/newlib/libc/time/mktime.c @@ -199,13 +199,15 @@ _DEFUN(mktime, (tim_p), TZ_LOCK; + _tzset_unlocked (); + if (_daylight) { int tm_isdst; int y = tim_p->tm_year + YEAR_BASE; - /* Convert user positive into 1 */ - tm_isdst = tim_p->tm_isdst > 0 ? 1 : tim_p->tm_isdst; - isdst = tm_isdst; + /* Convert user positive into 1 */ + tm_isdst = tim_p->tm_isdst > 0 ? 1 : tim_p->tm_isdst; + isdst = tm_isdst; if (y == tz->__tzyear || __tzcalc_limits (y)) { diff --git a/contrib/sdk/sources/newlib/libc/time/mktm_r.c b/contrib/sdk/sources/newlib/libc/time/mktm_r.c deleted file mode 100644 index 70f6a9ff62..0000000000 --- a/contrib/sdk/sources/newlib/libc/time/mktm_r.c +++ /dev/null @@ -1,259 +0,0 @@ -/* - * mktm_r.c - * Original Author: Adapted from tzcode maintained by Arthur David Olson. - * Modifications: Changed to mktm_r and added __tzcalc_limits - 04/10/02, Jeff Johnston - * Fixed bug in mday computations - 08/12/04, Alex Mogilnikov - * Fixed bug in __tzcalc_limits - 08/12/04, Alex Mogilnikov - * - * Converts the calendar time pointed to by tim_p into a broken-down time - * expressed as local time. Returns a pointer to a structure containing the - * broken-down time. - */ - -#include -#include -#include "local.h" - -static _CONST int mon_lengths[2][MONSPERYEAR] = { - {31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31}, - {31, 29, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31} -} ; - -static _CONST int year_lengths[2] = { - 365, - 366 -} ; - -struct tm * -_DEFUN (_mktm_r, (tim_p, res, is_gmtime), - _CONST time_t * tim_p _AND - struct tm *res _AND - int is_gmtime) -{ - long days, rem; - time_t lcltime; - int y; - int yleap; - _CONST int *ip; - __tzinfo_type *tz = __gettzinfo (); - - /* base decision about std/dst time on current time */ - lcltime = *tim_p; - - days = ((long)lcltime) / SECSPERDAY; - rem = ((long)lcltime) % SECSPERDAY; - while (rem < 0) - { - rem += SECSPERDAY; - --days; - } - while (rem >= SECSPERDAY) - { - rem -= SECSPERDAY; - ++days; - } - - /* compute hour, min, and sec */ - res->tm_hour = (int) (rem / SECSPERHOUR); - rem %= SECSPERHOUR; - res->tm_min = (int) (rem / SECSPERMIN); - res->tm_sec = (int) (rem % SECSPERMIN); - - /* compute day of week */ - if ((res->tm_wday = ((EPOCH_WDAY + days) % DAYSPERWEEK)) < 0) - res->tm_wday += DAYSPERWEEK; - - /* compute year & day of year */ - y = EPOCH_YEAR; - if (days >= 0) - { - for (;;) - { - yleap = isleap(y); - if (days < year_lengths[yleap]) - break; - y++; - days -= year_lengths[yleap]; - } - } - else - { - do - { - --y; - yleap = isleap(y); - days += year_lengths[yleap]; - } while (days < 0); - } - - res->tm_year = y - YEAR_BASE; - res->tm_yday = days; - ip = mon_lengths[yleap]; - for (res->tm_mon = 0; days >= ip[res->tm_mon]; ++res->tm_mon) - days -= ip[res->tm_mon]; - res->tm_mday = days + 1; - - if (!is_gmtime) - { - long offset; - int hours, mins, secs; - - TZ_LOCK; - if (_daylight) - { - if (y == tz->__tzyear || __tzcalc_limits (y)) - res->tm_isdst = (tz->__tznorth - ? (*tim_p >= tz->__tzrule[0].change - && *tim_p < tz->__tzrule[1].change) - : (*tim_p >= tz->__tzrule[0].change - || *tim_p < tz->__tzrule[1].change)); - else - res->tm_isdst = -1; - } - else - res->tm_isdst = 0; - - offset = (res->tm_isdst == 1 - ? tz->__tzrule[1].offset - : tz->__tzrule[0].offset); - - hours = (int) (offset / SECSPERHOUR); - offset = offset % SECSPERHOUR; - - mins = (int) (offset / SECSPERMIN); - secs = (int) (offset % SECSPERMIN); - - res->tm_sec -= secs; - res->tm_min -= mins; - res->tm_hour -= hours; - - if (res->tm_sec >= SECSPERMIN) - { - res->tm_min += 1; - res->tm_sec -= SECSPERMIN; - } - else if (res->tm_sec < 0) - { - res->tm_min -= 1; - res->tm_sec += SECSPERMIN; - } - if (res->tm_min >= MINSPERHOUR) - { - res->tm_hour += 1; - res->tm_min -= MINSPERHOUR; - } - else if (res->tm_min < 0) - { - res->tm_hour -= 1; - res->tm_min += MINSPERHOUR; - } - if (res->tm_hour >= HOURSPERDAY) - { - ++res->tm_yday; - ++res->tm_wday; - if (res->tm_wday > 6) - res->tm_wday = 0; - ++res->tm_mday; - res->tm_hour -= HOURSPERDAY; - if (res->tm_mday > ip[res->tm_mon]) - { - res->tm_mday -= ip[res->tm_mon]; - res->tm_mon += 1; - if (res->tm_mon == 12) - { - res->tm_mon = 0; - res->tm_year += 1; - res->tm_yday = 0; - } - } - } - else if (res->tm_hour < 0) - { - res->tm_yday -= 1; - res->tm_wday -= 1; - if (res->tm_wday < 0) - res->tm_wday = 6; - res->tm_mday -= 1; - res->tm_hour += 24; - if (res->tm_mday == 0) - { - res->tm_mon -= 1; - if (res->tm_mon < 0) - { - res->tm_mon = 11; - res->tm_year -= 1; - res->tm_yday = 364 + isleap(res->tm_year + 1900); - } - res->tm_mday = ip[res->tm_mon]; - } - } - TZ_UNLOCK; - } - else - res->tm_isdst = 0; - - return (res); -} - -int -_DEFUN (__tzcalc_limits, (year), - int year) -{ - int days, year_days, years; - int i, j; - __tzinfo_type *tz = __gettzinfo (); - - if (year < EPOCH_YEAR) - return 0; - - tz->__tzyear = year; - - years = (year - EPOCH_YEAR); - - year_days = years * 365 + - (years - 1 + EPOCH_YEARS_SINCE_LEAP) / 4 - (years - 1 + EPOCH_YEARS_SINCE_CENTURY) / 100 + - (years - 1 + EPOCH_YEARS_SINCE_LEAP_CENTURY) / 400; - - for (i = 0; i < 2; ++i) - { - if (tz->__tzrule[i].ch == 'J') { - /* The Julian day n (1 <= n <= 365). */ - days = year_days + tz->__tzrule[i].d + - (isleap(year) && tz->__tzrule[i].d >= 60); - /* Convert to yday */ - --days; - } else if (tz->__tzrule[i].ch == 'D') - days = year_days + tz->__tzrule[i].d; - else - { - int yleap = isleap(year); - int m_day, m_wday, wday_diff; - _CONST int *ip = mon_lengths[yleap]; - - days = year_days; - - for (j = 1; j < tz->__tzrule[i].m; ++j) - days += ip[j-1]; - - m_wday = (EPOCH_WDAY + days) % DAYSPERWEEK; - - wday_diff = tz->__tzrule[i].d - m_wday; - if (wday_diff < 0) - wday_diff += DAYSPERWEEK; - m_day = (tz->__tzrule[i].n - 1) * DAYSPERWEEK + wday_diff; - - while (m_day >= ip[j-1]) - m_day -= DAYSPERWEEK; - - days += m_day; - } - - /* store the change-over time in GMT form by adding offset */ - tz->__tzrule[i].change = days * SECSPERDAY + - tz->__tzrule[i].s + tz->__tzrule[i].offset; - } - - tz->__tznorth = (tz->__tzrule[0].change < tz->__tzrule[1].change); - - return 1; -} diff --git a/contrib/sdk/sources/newlib/libc/time/month_lengths.c b/contrib/sdk/sources/newlib/libc/time/month_lengths.c new file mode 100644 index 0000000000..2871802f06 --- /dev/null +++ b/contrib/sdk/sources/newlib/libc/time/month_lengths.c @@ -0,0 +1,14 @@ +/* + * month_lengths.c + * + * Array __month_lengths[] is (indirectly) needed by tzset(), mktime(), + * gmtime() and localtime(). To break any dependencies, this array is moved to + * separate source file. + */ + +#include "local.h" + +_CONST int __month_lengths[2][MONSPERYEAR] = { + {31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31}, + {31, 29, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31} +} ; diff --git a/contrib/sdk/sources/newlib/libc/time/strftime.c b/contrib/sdk/sources/newlib/libc/time/strftime.c index ec6c6e5bca..3166988052 100644 --- a/contrib/sdk/sources/newlib/libc/time/strftime.c +++ b/contrib/sdk/sources/newlib/libc/time/strftime.c @@ -166,6 +166,10 @@ notations, the result is an empty string. [tm_sec, tm_min, tm_hour] o %R The 24-hour time, to the minute. Equivalent to "%H:%M". [tm_min, tm_hour] +o %s +The time elapsed, in seconds, since the start of the Unix epoch at +1970-01-01 00:00:00 UTC. + o %S The second, formatted with two digits (from `<<00>>' to `<<60>>'). The value 60 accounts for the occasional leap second. [tm_sec] @@ -282,44 +286,44 @@ the "C" locale settings. * string literals or wide-character constants and wide-character-string * literals, as appropriate. */ #if !defined(MAKE_WCSFTIME) -# define CHAR char /* string type basis */ -# define CQ(a) a /* character constant qualifier */ -# define SFLG /* %s flag (null for normal char) */ +# define CHAR char /* string type basis */ +# define CQ(a) a /* character constant qualifier */ +# define SFLG /* %s flag (null for normal char) */ # define _ctloc(x) (ctloclen = strlen (ctloc = _CurrentTimeLocale->x), ctloc) # define snprintf sniprintf /* avoid to pull in FP functions. */ -# define TOLOWER(c) tolower((int)(unsigned char)(c)) +# define TOLOWER(c) tolower((int)(unsigned char)(c)) # define STRTOUL(c,p,b) strtoul((c),(p),(b)) -# define STRCPY(a,b) strcpy((a),(b)) -# define STRCHR(a,b) strchr((a),(b)) -# define STRLEN(a) strlen(a) +# define STRCPY(a,b) strcpy((a),(b)) +# define STRCHR(a,b) strchr((a),(b)) +# define STRLEN(a) strlen(a) # else -# define strftime wcsftime /* Alternate function name */ -# define CHAR wchar_t /* string type basis */ -# define CQ(a) L##a /* character constant qualifier */ -# define snprintf swprintf /* wide-char equivalent function name */ -# define strncmp wcsncmp /* wide-char equivalent function name */ -# define TOLOWER(c) towlower((wint_t)(c)) +# define strftime wcsftime /* Alternate function name */ +# define CHAR wchar_t /* string type basis */ +# define CQ(a) L##a /* character constant qualifier */ +# define snprintf swprintf /* wide-char equivalent function name */ +# define strncmp wcsncmp /* wide-char equivalent function name */ +# define TOLOWER(c) towlower((wint_t)(c)) # define STRTOUL(c,p,b) wcstoul((c),(p),(b)) -# define STRCPY(a,b) wcscpy((a),(b)) -# define STRCHR(a,b) wcschr((a),(b)) -# define STRLEN(a) wcslen(a) -# define SFLG "l" /* %s flag (l for wide char) */ +# define STRCPY(a,b) wcscpy((a),(b)) +# define STRCHR(a,b) wcschr((a),(b)) +# define STRLEN(a) wcslen(a) +# define SFLG "l" /* %s flag (l for wide char) */ # ifdef __HAVE_LOCALE_INFO_EXTENDED__ # define _ctloc(x) (ctloclen = wcslen (ctloc = _CurrentTimeLocale->w##x), \ - ctloc) + ctloc) # else -# define CTLOCBUFLEN 256 /* Arbitrary big buffer size */ +# define CTLOCBUFLEN 256 /* Arbitrary big buffer size */ const wchar_t * __ctloc (wchar_t *buf, const char *elem, size_t *len_ret) { buf[CTLOCBUFLEN - 1] = L'\0'; *len_ret = mbstowcs (buf, elem, CTLOCBUFLEN - 1); if (*len_ret == (size_t) -1 ) - *len_ret = 0; + *len_ret = 0; return buf; } # define _ctloc(x) (ctloc = __ctloc (ctlocbuf, _CurrentTimeLocale->x, \ - &ctloclen)) + &ctloclen)) # endif #endif /* MAKE_WCSFTIME */ @@ -694,15 +698,16 @@ _DEFUN (strftime, (s, maxsize, format, tim_p), #endif /* !_WANT_C99_TIME_FORMATS */ { size_t count = 0; - int i, len = 0; + int len = 0; const CHAR *ctloc; #if defined (MAKE_WCSFTIME) && !defined (__HAVE_LOCALE_INFO_EXTENDED__) CHAR ctlocbuf[CTLOCBUFLEN]; #endif - size_t ctloclen; + size_t i, ctloclen; CHAR alt; CHAR pad; unsigned long width; + int tzset_called = 0; struct lc_time_T *_CurrentTimeLocale = __get_current_time_locale (); for (;;) @@ -737,7 +742,7 @@ _DEFUN (strftime, (s, maxsize, format, tim_p), if (*format == CQ('E')) { alt = *format++; -#ifdef _WANT_C99_TIME_FORMATS +#ifdef _WANT_C99_TIME_FORMATS #if defined (MAKE_WCSFTIME) && defined (__HAVE_LOCALE_INFO_EXTENDED__) if (!*era_info && *_CurrentTimeLocale->wera) *era_info = get_era_info (tim_p, _CurrentTimeLocale->wera); @@ -750,7 +755,7 @@ _DEFUN (strftime, (s, maxsize, format, tim_p), else if (*format == CQ('O')) { alt = *format++; -#ifdef _WANT_C99_TIME_FORMATS +#ifdef _WANT_C99_TIME_FORMATS #if defined (MAKE_WCSFTIME) && defined (__HAVE_LOCALE_INFO_EXTENDED__) if (!*alt_digits && *_CurrentTimeLocale->walt_digits) *alt_digits = get_alt_digits (_CurrentTimeLocale->walt_digits); @@ -933,7 +938,7 @@ recurse: { /* %F is equivalent to "%+4Y-%m-%d", flags and width can change that. Recurse to avoid need to replicate %Y formation. */ CHAR fmtbuf[32], *fmt = fmtbuf; - + *fmt++ = CQ('%'); if (pad) /* '0' or '+' */ *fmt++ = pad; @@ -1108,6 +1113,74 @@ recurse: tim_p->tm_hour, tim_p->tm_min); CHECK_LENGTH (); break; + case CQ('s'): +/* + * From: + * The Open Group Base Specifications Issue 7 + * IEEE Std 1003.1, 2013 Edition + * Copyright (c) 2001-2013 The IEEE and The Open Group + * XBD Base Definitions + * 4. General Concepts + * 4.15 Seconds Since the Epoch + * A value that approximates the number of seconds that have elapsed since the + * Epoch. A Coordinated Universal Time name (specified in terms of seconds + * (tm_sec), minutes (tm_min), hours (tm_hour), days since January 1 of the year + * (tm_yday), and calendar year minus 1900 (tm_year)) is related to a time + * represented as seconds since the Epoch, according to the expression below. + * If the year is <1970 or the value is negative, the relationship is undefined. + * If the year is >=1970 and the value is non-negative, the value is related to a + * Coordinated Universal Time name according to the C-language expression, where + * tm_sec, tm_min, tm_hour, tm_yday, and tm_year are all integer types: + * tm_sec + tm_min*60 + tm_hour*3600 + tm_yday*86400 + + * (tm_year-70)*31536000 + ((tm_year-69)/4)*86400 - + * ((tm_year-1)/100)*86400 + ((tm_year+299)/400)*86400 + * OR + * ((((tm_year-69)/4 - (tm_year-1)/100 + (tm_year+299)/400 + + * (tm_year-70)*365 + tm_yday)*24 + tm_hour)*60 + tm_min)*60 + tm_sec + */ +/* modified from %z case by hoisting offset outside if block and initializing */ + { + long offset = 0; /* offset < 0 => W of GMT, > 0 => E of GMT: + subtract to get UTC */ + + if (tim_p->tm_isdst >= 0) + { + TZ_LOCK; + if (!tzset_called) + { + _tzset_unlocked (); + tzset_called = 1; + } + +#if defined (__CYGWIN__) + /* Cygwin must check if the application has been built with or + without the extra tm members for backward compatibility, and + then use either that or the old method fetching from tzinfo. + Rather than pulling in the version check infrastructure, we + just call a Cygwin function. */ + extern long __cygwin_gettzoffset (const struct tm *tmp); + offset = __cygwin_gettzoffset (tim_p); +#elif defined (__TM_GMTOFF) + offset = tim_p->__TM_GMTOFF; +#else + __tzinfo_type *tz = __gettzinfo (); + /* The sign of this is exactly opposite the envvar TZ. We + could directly use the global _timezone for tm_isdst==0, + but have to use __tzrule for daylight savings. */ + offset = -tz->__tzrule[tim_p->tm_isdst > 0].offset; +#endif + TZ_UNLOCK; + } + len = snprintf (&s[count], maxsize - count, CQ("%lld"), + (((((long long)tim_p->tm_year - 69)/4 + - (tim_p->tm_year - 1)/100 + + (tim_p->tm_year + 299)/400 + + (tim_p->tm_year - 70)*365 + tim_p->tm_yday)*24 + + tim_p->tm_hour)*60 + tim_p->tm_min)*60 + + tim_p->tm_sec - offset); + CHECK_LENGTH (); + } + break; case CQ('S'): #ifdef _WANT_C99_TIME_FORMATS if (alt != CQ('O') || !*alt_digits @@ -1122,7 +1195,7 @@ recurse: if (count < maxsize - 1) s[count++] = CQ('\t'); else - return 0; + return 0; break; case CQ('T'): len = snprintf (&s[count], maxsize - count, CQ("%.2d:%.2d:%.2d"), @@ -1283,12 +1356,31 @@ recurse: if (tim_p->tm_isdst >= 0) { long offset; - __tzinfo_type *tz = __gettzinfo (); + TZ_LOCK; + if (!tzset_called) + { + _tzset_unlocked (); + tzset_called = 1; + } + +#if defined (__CYGWIN__) + /* Cygwin must check if the application has been built with or + without the extra tm members for backward compatibility, and + then use either that or the old method fetching from tzinfo. + Rather than pulling in the version check infrastructure, we + just call a Cygwin function. */ + extern long __cygwin_gettzoffset (const struct tm *tmp); + offset = __cygwin_gettzoffset (tim_p); +#elif defined (__TM_GMTOFF) + offset = tim_p->__TM_GMTOFF; +#else + __tzinfo_type *tz = __gettzinfo (); /* The sign of this is exactly opposite the envvar TZ. We - could directly use the global _timezone for tm_isdst==0, - but have to use __tzrule for daylight savings. */ + could directly use the global _timezone for tm_isdst==0, + but have to use __tzrule for daylight savings. */ offset = -tz->__tzrule[tim_p->tm_isdst > 0].offset; +#endif TZ_UNLOCK; len = snprintf (&s[count], maxsize - count, CQ("%+03ld%.2ld"), offset / SECSPERHOUR, @@ -1299,13 +1391,33 @@ recurse: case CQ('Z'): if (tim_p->tm_isdst >= 0) { - int size; + size_t size; + const char *tznam = NULL; + TZ_LOCK; - size = strlen(_tzname[tim_p->tm_isdst > 0]); + if (!tzset_called) + { + _tzset_unlocked (); + tzset_called = 1; + } +#if defined (__CYGWIN__) + /* See above. */ + extern const char *__cygwin_gettzname (const struct tm *tmp); + tznam = __cygwin_gettzname (tim_p); +#elif defined (__TM_ZONE) + tznam = tim_p->__TM_ZONE; +#endif + if (!tznam) + tznam = _tzname[tim_p->tm_isdst > 0]; + /* Note that in case of wcsftime this loop only works for + timezone abbreviations using the portable codeset (aka ASCII). + This seems to be the case, but if that ever changes, this + loop needs revisiting. */ + size = strlen (tznam); for (i = 0; i < size; i++) { if (count < maxsize - 1) - s[count++] = _tzname[tim_p->tm_isdst > 0][i]; + s[count++] = tznam[i]; else { TZ_UNLOCK; @@ -1338,13 +1450,13 @@ recurse: /* The remainder of this file can serve as a regression test. Compile * with -D_REGRESSION_TEST. */ #if defined(_REGRESSION_TEST) /* [Test code: */ - + /* This test code relies on ANSI C features, in particular on the ability * of adjacent strings to be pasted together into one string. */ - + /* Test output buffer size (should be larger than all expected results) */ #define OUTSIZE 256 - + struct test { CHAR *fmt; /* Testing format */ size_t max; /* Testing maxsize */ @@ -1356,9 +1468,9 @@ struct list { const struct test *vec; /* Test vectors */ int cnt; /* Number of vectors */ }; - + const char TZ[]="TZ=EST5EDT"; - + /* Define list of test inputs and expected outputs, for the given time zone * and time. */ const struct tm tm0 = { @@ -1402,6 +1514,7 @@ const struct test Vec0[] = { { CQ("%p"), 2+1, EXP(CQ("AM")) }, { CQ("%r"), 11+1, EXP(CQ("09:53:47 AM")) }, { CQ("%R"), 5+1, EXP(CQ("09:53")) }, + { CQ("%s"), 2+1, EXP(CQ("1230648827")) }, { CQ("%S"), 2+1, EXP(CQ("47")) }, { CQ("%t"), 1+1, EXP(CQ("\t")) }, { CQ("%T"), 8+1, EXP(CQ("09:53:47")) }, @@ -1462,6 +1575,7 @@ const struct test Vec1[] = { { CQ("%p"), 2+1, EXP(CQ("PM")) }, { CQ("%r"), 11+1, EXP(CQ("11:01:13 PM")) }, { CQ("%R"), 5+1, EXP(CQ("23:01")) }, + { CQ("%s"), 2+1, EXP(CQ("1215054073")) }, { CQ("%S"), 2+1, EXP(CQ("13")) }, { CQ("%t"), 1+1, EXP(CQ("\t")) }, { CQ("%T"), 8+1, EXP(CQ("23:01:13")) }, @@ -1486,7 +1600,7 @@ const struct test Vec1[] = { #undef VEC #undef EXP }; - + #if YEAR_BASE == 1900 /* ( */ /* Checks for very large years. YEAR_BASE value relied upon so that the * answer strings can be predetermined. @@ -1584,7 +1698,7 @@ const struct test Vecyr1[] = { #undef CENT #undef Year #endif /* YEAR_BASE ) */ - + /* Checks for years just over zero (also test for s=60). * Years less than 4 digits are not mentioned for %Y in the standard, so the * test for that case is based on the design intent. */ @@ -1655,7 +1769,7 @@ const struct test Vecyrzn[] = { #undef YEAR #undef CENT #undef Year - + const struct list ListYr[] = { { &tmyrzp, Vecyrzp, sizeof(Vecyrzp)/sizeof(Vecyrzp[0]) }, { &tmyrzn, Vecyrzn, sizeof(Vecyrzn)/sizeof(Vecyrzn[0]) }, @@ -1664,19 +1778,19 @@ const struct list ListYr[] = { { &tmyr1, Vecyr1, sizeof(Vecyr1)/sizeof(Vecyr1[0]) }, #endif }; - - + + /* List of tests to be run */ const struct list List[] = { { &tm0, Vec0, sizeof(Vec0)/sizeof(Vec0[0]) }, { &tm1, Vec1, sizeof(Vec1)/sizeof(Vec1[0]) }, }; - + #if defined(STUB_getenv_r) char * _getenv_r(struct _reent *p, const char *cp) { return getenv(cp); } #endif - + int main(void) { @@ -1684,7 +1798,7 @@ int i, l, errr=0, erro=0, tot=0; const char *cp; CHAR out[OUTSIZE]; size_t ret; - + /* Set timezone so that %z and %Z tests come out right */ cp = TZ; if((i=putenv(cp))) { @@ -1708,7 +1822,7 @@ __tzinfo_type *tz = __gettzinfo (); printf("tz->__tzrule[0].offset=%d, tz->__tzrule[1].offset=%d\n", tz->__tzrule[0].offset, tz->__tzrule[1].offset); } #endif - + /* Run all of the exact-length tests as-given--results should match */ for(l=0; l + * - Fixed bug in __tzcalc_limits - 08/12/04, Alex Mogilnikov + * - Moved __tzcalc_limits() to separate file - 05/09/14, Freddie Chopin + */ + +#include "local.h" + +int +_DEFUN (__tzcalc_limits, (year), + int year) +{ + int days, year_days, years; + int i, j; + __tzinfo_type *_CONST tz = __gettzinfo (); + + if (year < EPOCH_YEAR) + return 0; + + tz->__tzyear = year; + + years = (year - EPOCH_YEAR); + + year_days = years * 365 + + (years - 1 + EPOCH_YEARS_SINCE_LEAP) / 4 - + (years - 1 + EPOCH_YEARS_SINCE_CENTURY) / 100 + + (years - 1 + EPOCH_YEARS_SINCE_LEAP_CENTURY) / 400; + + for (i = 0; i < 2; ++i) + { + if (tz->__tzrule[i].ch == 'J') + { + /* The Julian day n (1 <= n <= 365). */ + days = year_days + tz->__tzrule[i].d + + (isleap(year) && tz->__tzrule[i].d >= 60); + /* Convert to yday */ + --days; + } + else if (tz->__tzrule[i].ch == 'D') + days = year_days + tz->__tzrule[i].d; + else + { + _CONST int yleap = isleap(year); + int m_day, m_wday, wday_diff; + _CONST int *_CONST ip = __month_lengths[yleap]; + + days = year_days; + + for (j = 1; j < tz->__tzrule[i].m; ++j) + days += ip[j-1]; + + m_wday = (EPOCH_WDAY + days) % DAYSPERWEEK; + + wday_diff = tz->__tzrule[i].d - m_wday; + if (wday_diff < 0) + wday_diff += DAYSPERWEEK; + m_day = (tz->__tzrule[i].n - 1) * DAYSPERWEEK + wday_diff; + + while (m_day >= ip[j-1]) + m_day -= DAYSPERWEEK; + + days += m_day; + } + + /* store the change-over time in GMT form by adding offset */ + tz->__tzrule[i].change = days * SECSPERDAY + + tz->__tzrule[i].s + tz->__tzrule[i].offset; + } + + tz->__tznorth = (tz->__tzrule[0].change < tz->__tzrule[1].change); + + return 1; +} diff --git a/contrib/sdk/sources/newlib/libc/time/tzset.c b/contrib/sdk/sources/newlib/libc/time/tzset.c new file mode 100644 index 0000000000..e0750e1fdf --- /dev/null +++ b/contrib/sdk/sources/newlib/libc/time/tzset.c @@ -0,0 +1,82 @@ +/* +FUNCTION +<>---set timezone characteristics from TZ environment variable + +INDEX + tzset +INDEX + _tzset_r + +ANSI_SYNOPSIS + #include + void tzset(void); + void _tzset_r (struct _reent *<[reent_ptr]>); + +TRAD_SYNOPSIS + #include + void tzset(); + void _tzset_r (<[reent_ptr]>); + struct _reent *reent_ptr; + +DESCRIPTION +<> examines the TZ environment variable and sets up the three +external variables: <<_timezone>>, <<_daylight>>, and <>. The +value of <<_timezone>> shall be the offset from the current time zone +to GMT. The value of <<_daylight>> shall be 0 if there is no daylight +savings time for the current time zone, otherwise it will be non-zero. +The <> array has two entries: the first is the name of the +standard time zone, the second is the name of the daylight-savings time +zone. + +The TZ environment variable is expected to be in the following POSIX +format: + + stdoffset1[dst[offset2][,start[/time1],end[/time2]]] + +where: std is the name of the standard time-zone (minimum 3 chars) + offset1 is the value to add to local time to arrive at Universal time + it has the form: hh[:mm[:ss]] + dst is the name of the alternate (daylight-savings) time-zone (min 3 chars) + offset2 is the value to add to local time to arrive at Universal time + it has the same format as the std offset + start is the day that the alternate time-zone starts + time1 is the optional time that the alternate time-zone starts + (this is in local time and defaults to 02:00:00 if not specified) + end is the day that the alternate time-zone ends + time2 is the time that the alternate time-zone ends + (it is in local time and defaults to 02:00:00 if not specified) + +Note that there is no white-space padding between fields. Also note that +if TZ is null, the default is Universal GMT which has no daylight-savings +time. If TZ is empty, the default EST5EDT is used. + +The function <<_tzset_r>> is identical to <> only it is reentrant +and is used for applications that use multiple threads. + +RETURNS +There is no return value. + +PORTABILITY +<> is part of the POSIX standard. + +Supporting OS subroutine required: None +*/ + +#include <_ansi.h> +#include +#include +#include "local.h" + +_VOID +_DEFUN_VOID (_tzset_unlocked) +{ + _tzset_unlocked_r (_REENT); +} + +_VOID +_DEFUN_VOID (tzset) +{ + TZ_LOCK; + _tzset_unlocked_r (_REENT); + TZ_UNLOCK; +} diff --git a/contrib/sdk/sources/newlib/libc/time/tzset_r.c b/contrib/sdk/sources/newlib/libc/time/tzset_r.c new file mode 100644 index 0000000000..6c21e822e5 --- /dev/null +++ b/contrib/sdk/sources/newlib/libc/time/tzset_r.c @@ -0,0 +1,193 @@ +#include <_ansi.h> +#include +#include +#include +#include +#include +#include +#include "local.h" + +#define sscanf siscanf /* avoid to pull in FP functions. */ + +static char __tzname_std[11]; +static char __tzname_dst[11]; +static char *prev_tzenv = NULL; + +_VOID +_DEFUN (_tzset_unlocked_r, (reent_ptr), + struct _reent *reent_ptr) +{ + char *tzenv; + unsigned short hh, mm, ss, m, w, d; + int sign, n; + int i, ch; + __tzinfo_type *tz = __gettzinfo (); + + if ((tzenv = _getenv_r (reent_ptr, "TZ")) == NULL) + { + _timezone = 0; + _daylight = 0; + _tzname[0] = "GMT"; + _tzname[1] = "GMT"; + free(prev_tzenv); + prev_tzenv = NULL; + return; + } + + if (prev_tzenv != NULL && strcmp(tzenv, prev_tzenv) == 0) + return; + + free(prev_tzenv); + prev_tzenv = _malloc_r (reent_ptr, strlen(tzenv) + 1); + if (prev_tzenv != NULL) + strcpy (prev_tzenv, tzenv); + + /* ignore implementation-specific format specifier */ + if (*tzenv == ':') + ++tzenv; + + if (sscanf (tzenv, "%10[^0-9,+-]%n", __tzname_std, &n) <= 0) + return; + + tzenv += n; + + sign = 1; + if (*tzenv == '-') + { + sign = -1; + ++tzenv; + } + else if (*tzenv == '+') + ++tzenv; + + mm = 0; + ss = 0; + + if (sscanf (tzenv, "%hu%n:%hu%n:%hu%n", &hh, &n, &mm, &n, &ss, &n) < 1) + return; + + tz->__tzrule[0].offset = sign * (ss + SECSPERMIN * mm + SECSPERHOUR * hh); + _tzname[0] = __tzname_std; + tzenv += n; + + if (sscanf (tzenv, "%10[^0-9,+-]%n", __tzname_dst, &n) <= 0) + { /* No dst */ + _tzname[1] = _tzname[0]; + _timezone = tz->__tzrule[0].offset; + _daylight = 0; + return; + } + else + _tzname[1] = __tzname_dst; + + tzenv += n; + + /* otherwise we have a dst name, look for the offset */ + sign = 1; + if (*tzenv == '-') + { + sign = -1; + ++tzenv; + } + else if (*tzenv == '+') + ++tzenv; + + hh = 0; + mm = 0; + ss = 0; + + n = 0; + if (sscanf (tzenv, "%hu%n:%hu%n:%hu%n", &hh, &n, &mm, &n, &ss, &n) <= 0) + tz->__tzrule[1].offset = tz->__tzrule[0].offset - 3600; + else + tz->__tzrule[1].offset = sign * (ss + SECSPERMIN * mm + SECSPERHOUR * hh); + + tzenv += n; + + for (i = 0; i < 2; ++i) + { + if (*tzenv == ',') + ++tzenv; + + if (*tzenv == 'M') + { + if (sscanf (tzenv, "M%hu%n.%hu%n.%hu%n", &m, &n, &w, &n, &d, &n) != 3 || + m < 1 || m > 12 || w < 1 || w > 5 || d > 6) + return; + + tz->__tzrule[i].ch = 'M'; + tz->__tzrule[i].m = m; + tz->__tzrule[i].n = w; + tz->__tzrule[i].d = d; + + tzenv += n; + } + else + { + char *end; + if (*tzenv == 'J') + { + ch = 'J'; + ++tzenv; + } + else + ch = 'D'; + + d = strtoul (tzenv, &end, 10); + + /* if unspecified, default to US settings */ + /* From 1987-2006, US was M4.1.0,M10.5.0, but starting in 2007 is + * M3.2.0,M11.1.0 (2nd Sunday March through 1st Sunday November) */ + if (end == tzenv) + { + if (i == 0) + { + tz->__tzrule[0].ch = 'M'; + tz->__tzrule[0].m = 3; + tz->__tzrule[0].n = 2; + tz->__tzrule[0].d = 0; + } + else + { + tz->__tzrule[1].ch = 'M'; + tz->__tzrule[1].m = 11; + tz->__tzrule[1].n = 1; + tz->__tzrule[1].d = 0; + } + } + else + { + tz->__tzrule[i].ch = ch; + tz->__tzrule[i].d = d; + } + + tzenv = end; + } + + /* default time is 02:00:00 am */ + hh = 2; + mm = 0; + ss = 0; + n = 0; + + if (*tzenv == '/') + sscanf (tzenv, "/%hu%n:%hu%n:%hu%n", &hh, &n, &mm, &n, &ss, &n); + + tz->__tzrule[i].s = ss + SECSPERMIN * mm + SECSPERHOUR * hh; + + tzenv += n; + } + + __tzcalc_limits (tz->__tzyear); + _timezone = tz->__tzrule[0].offset; + _daylight = tz->__tzrule[0].offset != tz->__tzrule[1].offset; +} + +_VOID +_DEFUN (_tzset_r, (reent_ptr), + struct _reent *reent_ptr) +{ + TZ_LOCK; + _tzset_unlocked_r (reent_ptr); + TZ_UNLOCK; +} diff --git a/contrib/sdk/sources/newlib/libc/time/tzvars.c b/contrib/sdk/sources/newlib/libc/time/tzvars.c index a15b25282f..d1f17649b7 100644 --- a/contrib/sdk/sources/newlib/libc/time/tzvars.c +++ b/contrib/sdk/sources/newlib/libc/time/tzvars.c @@ -1,10 +1,10 @@ -#include - -/* Global timezone variables. */ - -/* Default timezone to GMT */ -char *_tzname[2] = {"GMT", "GMT"}; -int _daylight = 0; -long _timezone = 0; - - +#include + +/* Global timezone variables. */ + +/* Default timezone to GMT */ +char *_tzname[2] = {"GMT", "GMT"}; +int _daylight = 0; +long _timezone = 0; + +