diff --git a/contrib/sdk/sources/newlib/libc/Makefile b/contrib/sdk/sources/newlib/libc/Makefile index 362e51dac7..c835bc5cb2 100644 --- a/contrib/sdk/sources/newlib/libc/Makefile +++ b/contrib/sdk/sources/newlib/libc/Makefile @@ -1,9 +1,10 @@ + CC = kos32-gcc AR = kos32-ar LD = kos32-ld -CFLAGS = -c -O2 -fomit-frame-pointer -DBUILD_DLL +CFLAGS = -c -O2 -fomit-frame-pointer -DBUILD_DLL -DMISSING_SYSCALL_NAMES LDFLAGS = -shared -s -T libcdll.lds --out-implib libc.dll.a --image-base 0 #LDFLAGS+= --output-def libc.orig.def ARFLAGS = crs @@ -53,28 +54,28 @@ LIBCRT_SRCS:= \ CORE_SRCS:= \ argz/buf_findstr.c \ argz/envz_get.c \ - crt/emutls.c \ - crt/thread.S \ - crt/tls.S \ + crt/emutls.c \ + crt/thread.S \ + crt/tls.S \ crt/setjmp.S \ crt/cpu_features.c \ ctype/ctype_.c \ ctype/isascii.c \ ctype/isblank.c \ - ctype/isalnum.c \ - ctype/isalpha.c \ - ctype/iscntrl.c \ - ctype/isdigit.c \ - ctype/islower.c \ + ctype/isalnum.c \ + ctype/isalpha.c \ + ctype/iscntrl.c \ + ctype/isdigit.c \ + ctype/islower.c \ ctype/isupper.c \ - ctype/isprint.c \ - ctype/ispunct.c \ - ctype/isspace.c \ - ctype/iswctype.c \ - ctype/iswalnum.c \ - ctype/iswalpha.c \ - ctype/iswblank.c \ - ctype/iswcntrl.c \ + ctype/isprint.c \ + ctype/ispunct.c \ + ctype/isspace.c \ + ctype/iswctype.c \ + ctype/iswalnum.c \ + ctype/iswalpha.c \ + ctype/iswblank.c \ + ctype/iswcntrl.c \ ctype/iswdigit.c \ ctype/iswgraph.c \ ctype/iswlower.c \ @@ -85,55 +86,71 @@ CORE_SRCS:= \ ctype/iswxdigit.c \ ctype/isxdigit.c \ ctype/toascii.c \ - ctype/tolower.c \ + ctype/tolower.c \ ctype/toupper.c \ - ctype/towctrans.c \ - ctype/towlower.c \ - ctype/towupper.c \ + ctype/towctrans.c \ + ctype/towlower.c \ + ctype/towupper.c \ ctype/wctrans.c \ - ctype/wctype.c \ - errno/errno.c \ + ctype/wctype.c \ + errno/errno.c \ locale/locale.c \ locale/lctype.c \ - reent/impure.c \ + locale/ldpart.c \ + reent/impure.c \ reent/init_reent.c \ - reent/getreent.c \ + reent/getreent.c \ reent/mutex.c \ reent/gettimeofdayr.c \ - reent/hdlman.c \ reent/isattyr.c \ - reent/openr.c \ - reent/closer.c \ - reent/readr.c \ - reent/lseekr.c \ - reent/fstatr.c \ - reent/writer.c \ - search/qsort.c \ - search/bsearch.c \ + reent/openr.c \ + reent/closer.c \ + reent/linkr.c \ + reent/readr.c \ + reent/lseekr.c \ + reent/fstatr.c \ + reent/writer.c \ + reent/timesr.c \ + reent/unlinkr.c \ + search/qsort.c \ + search/bsearch.c \ signal/signal.c \ - sys/create.c \ - sys/delete.c \ - sys/finfo.c \ - sys/read.c \ - sys/write.c \ - sys/fsize.c \ - time/asctime.c \ - time/asctime_r.c \ - time/clock.c \ - time/ctime.c \ - time/ctime_r.c \ + sys/close.c \ + sys/create.c \ + sys/delete.c \ + sys/errno.c \ + sys/finfo.c \ + sys/fsize.c \ + sys/fstat.c \ + sys/gettod.c \ + sys/io.c \ + sys/ioread.c \ + sys/iowrite.c \ + sys/isatty.c \ + sys/lseek.c \ + sys/open.c \ + sys/read.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/gettzinfo.c \ + time/gmtime.c \ time/gmtime_r.c \ - time/mktime.c \ - time/mktm_r.c \ - time/lcltime.c \ - time/lcltime_r.c \ + time/mktime.c \ + time/mktm_r.c \ + time/lcltime.c \ + time/lcltime_r.c \ time/strftime.c \ - time/time.c \ - time/tzlock.c \ - time/tzvars.c + time/time.c \ + time/timelocal.c \ + time/tzlock.c \ + time/tzvars.c STDLIB_SRCS= \ @@ -252,7 +269,6 @@ STDIO_SRCS= \ refill.c \ rget.c \ remove.c \ - rename.c \ setvbuf.c \ stdio.c \ tmpfile.c \ @@ -369,7 +385,7 @@ LIB_OBJS+= \ $(STRING_OBJS) \ $(STDLIB_OBJS) \ $(STDIO_OBJS) \ - $(PRINTF_OBJS) \ + $(PRINTF_OBJS) \ $(MATH_OBJS) diff --git a/contrib/sdk/sources/newlib/libc/crt/crtdll.c b/contrib/sdk/sources/newlib/libc/crt/crtdll.c index c4aad958d5..d5deff3da9 100644 --- a/contrib/sdk/sources/newlib/libc/crt/crtdll.c +++ b/contrib/sdk/sources/newlib/libc/crt/crtdll.c @@ -92,7 +92,7 @@ libc_crt_startup (void *libc_base) memset(_tls_map, 0xFF, 32*4); _tls_map[0] = 0xE0; init_reent(); - __initPOSIXHandles(); + init_stdio(); // __appenv = load_file("/sys/system.env", &__appenv_size); diff --git a/contrib/sdk/sources/newlib/libc/ctype/ctype_.c b/contrib/sdk/sources/newlib/libc/ctype/ctype_.c index 66c5e7e5c9..e63027b022 100644 --- a/contrib/sdk/sources/newlib/libc/ctype/ctype_.c +++ b/contrib/sdk/sources/newlib/libc/ctype/ctype_.c @@ -111,14 +111,21 @@ _CONST char __EXPORT *__ctype_ptr__ = (char *) _ctype_b + 127; # ifdef __CYGWIN__ - +# ifdef __x86_64__ +__asm__ (" \n\ + .data \n\ + .globl _ctype_ \n\ + .set _ctype_,_ctype_b+127 \n\ + .text \n\ +"); +# else __asm__ (" \n\ .data \n\ .globl __ctype_ \n\ .set __ctype_,__ctype_b+127 \n\ .text \n\ "); - +# endif # else /* !__CYGWIN__ */ _CONST char _ctype_[1 + 256] = { diff --git a/contrib/sdk/sources/newlib/libc/ctype/isalnum.c b/contrib/sdk/sources/newlib/libc/ctype/isalnum.c index 6513c56b05..d670987213 100644 --- a/contrib/sdk/sources/newlib/libc/ctype/isalnum.c +++ b/contrib/sdk/sources/newlib/libc/ctype/isalnum.c @@ -18,7 +18,7 @@ DESCRIPTION <> is a macro which classifies ASCII integer values by table lookup. It is a predicate returning non-zero for alphabetic or numeric ASCII characters, and <<0>> for other arguments. It is defined -for all integer values. +only if <[c]> is representable as an unsigned char or if <[c]> is EOF. You can use a compiled subroutine instead of the macro definition by undefining the macro using `<<#undef isalnum>>'. diff --git a/contrib/sdk/sources/newlib/libc/ctype/isalpha.c b/contrib/sdk/sources/newlib/libc/ctype/isalpha.c index c0839b6434..0bae165d68 100644 --- a/contrib/sdk/sources/newlib/libc/ctype/isalpha.c +++ b/contrib/sdk/sources/newlib/libc/ctype/isalpha.c @@ -16,8 +16,8 @@ TRAD_SYNOPSIS DESCRIPTION <> is a macro which classifies ASCII integer values by table lookup. It is a predicate returning non-zero when <[c]> represents an -alphabetic ASCII character, and 0 otherwise. It is defined only when -<>(<[c]>) is true or <[c]> is EOF. +alphabetic ASCII character, and 0 otherwise. It is defined only if +<[c]> is representable as an unsigned char or if <[c]> is EOF. You can use a compiled subroutine instead of the macro definition by undefining the macro using `<<#undef isalpha>>'. diff --git a/contrib/sdk/sources/newlib/libc/ctype/isblank.c b/contrib/sdk/sources/newlib/libc/ctype/isblank.c index c6ab2e11e3..47a4793047 100644 --- a/contrib/sdk/sources/newlib/libc/ctype/isblank.c +++ b/contrib/sdk/sources/newlib/libc/ctype/isblank.c @@ -17,7 +17,8 @@ TRAD_SYNOPSIS DESCRIPTION <> is a function which classifies ASCII integer values by table lookup. It is a predicate returning non-zero for blank characters, and 0 -for other characters. +for other characters. It is defined only if <[c]> is representable as an +unsigned char or if <[c]> is EOF. RETURNS <> returns non-zero if <[c]> is a blank character. diff --git a/contrib/sdk/sources/newlib/libc/ctype/iscntrl.c b/contrib/sdk/sources/newlib/libc/ctype/iscntrl.c index b03439500f..960d743408 100644 --- a/contrib/sdk/sources/newlib/libc/ctype/iscntrl.c +++ b/contrib/sdk/sources/newlib/libc/ctype/iscntrl.c @@ -17,8 +17,8 @@ TRAD_SYNOPSIS DESCRIPTION <> is a macro which classifies ASCII integer values by table lookup. It is a predicate returning non-zero for control characters, and 0 -for other characters. It is defined only when <>(<[c]>) is -true or <[c]> is EOF. +for other characters. It is defined only if <[c]> is representable as an +unsigned char or if <[c]> is EOF. You can use a compiled subroutine instead of the macro definition by undefining the macro using `<<#undef iscntrl>>'. diff --git a/contrib/sdk/sources/newlib/libc/ctype/isdigit.c b/contrib/sdk/sources/newlib/libc/ctype/isdigit.c index 8d35cb2abb..01ca6cc6da 100644 --- a/contrib/sdk/sources/newlib/libc/ctype/isdigit.c +++ b/contrib/sdk/sources/newlib/libc/ctype/isdigit.c @@ -16,8 +16,8 @@ int isdigit(<[c]>); DESCRIPTION <> is a macro which classifies ASCII integer values by table lookup. It is a predicate returning non-zero for decimal digits, and 0 for -other characters. It is defined only when <>(<[c]>) is true -or <[c]> is EOF. +other characters. It is defined only if <[c]> is representable as an +unsigned char or if <[c]> is EOF. You can use a compiled subroutine instead of the macro definition by undefining the macro using `<<#undef isdigit>>'. diff --git a/contrib/sdk/sources/newlib/libc/ctype/islower.c b/contrib/sdk/sources/newlib/libc/ctype/islower.c index 121d61b8db..0a0dd5753a 100644 --- a/contrib/sdk/sources/newlib/libc/ctype/islower.c +++ b/contrib/sdk/sources/newlib/libc/ctype/islower.c @@ -18,7 +18,8 @@ DESCRIPTION <> is a macro which classifies ASCII integer values by table lookup. It is a predicate returning non-zero for minuscules (lowercase alphabetic characters), and 0 for other characters. -It is defined only when <>(<[c]>) is true or <[c]> is EOF. +It is defined only if <[c]> is representable as an unsigned char or if +<[c]> is EOF. You can use a compiled subroutine instead of the macro definition by undefining the macro using `<<#undef islower>>'. diff --git a/contrib/sdk/sources/newlib/libc/ctype/isprint.c b/contrib/sdk/sources/newlib/libc/ctype/isprint.c index e0226813c2..5b78b6c439 100644 --- a/contrib/sdk/sources/newlib/libc/ctype/isprint.c +++ b/contrib/sdk/sources/newlib/libc/ctype/isprint.c @@ -23,7 +23,8 @@ DESCRIPTION <> is a macro which classifies ASCII integer values by table lookup. It is a predicate returning non-zero for printable characters, and 0 for other character arguments. -It is defined only when <>(<[c]>) is true or <[c]> is EOF. +It is defined only if <[c]> is representable as an unsigned char or if +<[c]> is EOF. You can use a compiled subroutine instead of the macro definition by undefining either macro using `<<#undef isprint>>' or `<<#undef isgraph>>'. diff --git a/contrib/sdk/sources/newlib/libc/ctype/ispunct.c b/contrib/sdk/sources/newlib/libc/ctype/ispunct.c index 7fc496092a..1e3a124a7c 100644 --- a/contrib/sdk/sources/newlib/libc/ctype/ispunct.c +++ b/contrib/sdk/sources/newlib/libc/ctype/ispunct.c @@ -17,8 +17,8 @@ int ispunct(<[c]>); DESCRIPTION <> is a macro which classifies ASCII integer values by table lookup. It is a predicate returning non-zero for printable -punctuation characters, and 0 for other characters. It is defined -only when <>(<[c]>) is true or <[c]> is EOF. +punctuation characters, and 0 for other characters. It is defined only +if <[c]> is representable as an unsigned char or if <[c]> is EOF. You can use a compiled subroutine instead of the macro definition by undefining the macro using `<<#undef ispunct>>'. diff --git a/contrib/sdk/sources/newlib/libc/ctype/isxdigit.c b/contrib/sdk/sources/newlib/libc/ctype/isxdigit.c index 42ed0f07b5..03b642cf61 100644 --- a/contrib/sdk/sources/newlib/libc/ctype/isxdigit.c +++ b/contrib/sdk/sources/newlib/libc/ctype/isxdigit.c @@ -17,8 +17,8 @@ int isxdigit(int <[c]>); DESCRIPTION <> is a macro which classifies ASCII integer values by table lookup. It is a predicate returning non-zero for hexadecimal digits, -and <<0>> for other characters. It is defined only when -<>(<[c]>) is true or <[c]> is EOF. +and <<0>> for other characters. It is defined only if <[c]> is +representable as an unsigned char or if <[c]> is EOF. You can use a compiled subroutine instead of the macro definition by undefining the macro using `<<#undef isxdigit>>'. diff --git a/contrib/sdk/sources/newlib/libc/ctype/jp2uc.c b/contrib/sdk/sources/newlib/libc/ctype/jp2uc.c new file mode 100644 index 0000000000..0b0085f15b --- /dev/null +++ b/contrib/sdk/sources/newlib/libc/ctype/jp2uc.c @@ -0,0 +1,166 @@ +/* Routine to translate from Japanese characters to Unicode */ + +/* Copyright (c) 2002 Red Hat Incorporated. + All rights reserved. + + Redistribution and use in source and binary forms, with or without + modification, are permitted provided that the following conditions are met: + + Redistributions of source code must retain the above copyright + notice, this list of conditions and the following disclaimer. + + 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. + + The name of Red Hat Incorporated may not be used to endorse + or promote products derived from this software without specific + prior written permission. + + THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS 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 RED HAT INCORPORATED BE LIABLE FOR ANY + DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES + (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; + LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND + ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS + SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. +*/ + +#include + +#ifdef _MB_CAPABLE +/* Under Cygwin, the incoming wide character is already given in UTF due + to the requirements of the underlying OS. */ +#ifndef __CYGWIN__ + +#include <_ansi.h> +#include +#include "local.h" +#include "jp2uc.h" + +/* Japanese encoding types supported */ +#define JP_JIS 1 +#define JP_SJIS 2 +#define JP_EUCJP 3 + +static wint_t +_DEFUN (__jp2uc, (c, type), wint_t c _AND int type) +{ + int index, adj; + unsigned char byte1, byte2; + wint_t ret; + + /* we actually use tables of EUCJP to Unicode. For JIS, we simply + note that EUCJP is essentially JIS with the top bits on in each + byte and translate to EUCJP. For SJIS, we do a translation to EUCJP before + accessing the tables. */ + switch (type) + { + case JP_JIS: + byte1 = (c >> 8) + 0x80; + byte2 = (c & 0xff) + 0x80; + break; + case JP_EUCJP: + byte1 = (c >> 8); + byte2 = (c & 0xff); + break; + case JP_SJIS: + byte1 = c >> 8; + byte2 = c & 0xff; + if (byte2 <= 0x9e) + { + adj = 0xa1 - 0x22; + byte2 = (byte2 - 31) + 0xa1; + } + else + { + adj = 0xa1 - 0x21; + byte2 = (byte2 - 126) + 0xa1; + } + if (byte1 <= 0x9f) + byte1 = ((byte1 - 112) << 1) + adj; + else + byte1 = ((byte1 - 176) << 1) + adj; + break; + default: + return WEOF; + } + + /* find conversion in jp2uc arrays */ + + /* handle larger ranges first */ + if (byte1 >= 0xb0 && byte1 <= 0xcf && c <= 0xcfd3) + { + index = (byte1 - 0xb0) * 0xfe + (byte2 - 0xa1); + return b02cf[index]; + } + else if (byte1 >= 0xd0 && byte1 <= 0xf4 && c <= 0xf4a6) + { + index = (byte1 - 0xd0) * 0xfe + (byte2 - 0xa1); + return d02f4[index]; + } + + /* handle smaller ranges here */ + switch (byte1) + { + case 0xA1: + return (wint_t)a1[byte2 - 0xa1]; + case 0xA2: + ret = a2[byte2 - 0xa1]; + if (ret != 0) + return (wint_t)ret; + break; + case 0xA3: + if (a3[byte2 - 0xa1]) + return (wint_t)(0xff00 + (byte2 - 0xa0)); + break; + case 0xA4: + if (byte2 <= 0xf3) + return (wint_t)(0x3000 + (byte2 - 0x60)); + break; + case 0xA5: + if (byte2 <= 0xf6) + return (wint_t)(0x3000 + byte2); + break; + case 0xA6: + ret = 0; + if (byte2 <= 0xd8) + ret = (wint_t)a6[byte2 - 0xa1]; + if (ret != 0) + return ret; + break; + case 0xA7: + ret = 0; + if (byte2 <= 0xf1) + ret = (wint_t)a7[byte2 - 0xa1]; + if (ret != 0) + return ret; + break; + case 0xA8: + if (byte2 <= 0xc0) + return (wint_t)a8[byte2 - 0xa1]; + break; + default: + return WEOF; + } + + return WEOF; +} + +wint_t +_DEFUN (_jp2uc, (c), wint_t c) +{ + if (!strcmp (__locale_charset (), "JIS")) + c = __jp2uc (c, JP_JIS); + else if (!strcmp (__locale_charset (), "SJIS")) + c = __jp2uc (c, JP_SJIS); + else if (!strcmp (__locale_charset (), "EUCJP")) + c = __jp2uc (c, JP_EUCJP); + return c; +} + +#endif /* !__CYGWIN__ */ +#endif /* _MB_CAPABLE */ diff --git a/contrib/sdk/sources/newlib/libc/include/_ansi.h b/contrib/sdk/sources/newlib/libc/include/_ansi.h index 5e06047827..cd2b8c177b 100644 --- a/contrib/sdk/sources/newlib/libc/include/_ansi.h +++ b/contrib/sdk/sources/newlib/libc/include/_ansi.h @@ -34,9 +34,7 @@ #define _BEGIN_STD_C extern "C" { #define _END_STD_C } #endif -#if defined(__GNUC__) && \ - ( (__GNUC__ >= 4) || \ - ( (__GNUC__ >= 3) && defined(__GNUC_MINOR__) && (__GNUC_MINOR__ >= 3) ) ) +#if __GNUC_PREREQ (3, 3) #define _NOTHROW __attribute__ ((nothrow)) #else #define _NOTHROW throw() @@ -113,21 +111,34 @@ to emit the function body unless the address is explicitly taken. However this behaviour is changing to match the C99 standard, which uses 'extern inline' to indicate that the - function body *must* be emitted. If we are using GCC, but do - not have the new behaviour, we need to use extern inline; if - we are using a new GCC with the C99-compatible behaviour, or - a non-GCC compiler (which we will have to hope is C99, since - there is no other way to achieve the effect of omitting the - function if it isn't referenced) we just use plain 'inline', - which c99 defines to mean more-or-less the same as the Gnu C - 'extern inline'. */ + function body *must* be emitted. Likewise, a function declared + without either 'extern' or 'static' defaults to extern linkage + (C99 6.2.2p5), and the compiler may choose whether to use the + inline version or call the extern linkage version (6.7.4p6). + If we are using GCC, but do not have the new behaviour, we need + to use extern inline; if we are using a new GCC with the + C99-compatible behaviour, or a non-GCC compiler (which we will + have to hope is C99, since there is no other way to achieve the + effect of omitting the function if it isn't referenced) we use + 'static inline', which c99 defines to mean more-or-less the same + as the Gnu C 'extern inline'. */ #if defined(__GNUC__) && !defined(__GNUC_STDC_INLINE__) /* 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 just have to hope obeys the C99 semantics of inline. */ -#define _ELIDABLE_INLINE __inline__ +#define _ELIDABLE_INLINE static __inline__ +#endif + +#if __GNUC_PREREQ (3, 1) +#define _NOINLINE __attribute__ ((__noinline__)) +#define _NOINLINE_STATIC _NOINLINE static +#else +/* On non-GNU compilers and GCC prior to version 3.1 the compiler can't be + trusted not to inline if it is static. */ +#define _NOINLINE +#define _NOINLINE_STATIC #endif #endif /* _ANSIDECL_H_ */ diff --git a/contrib/sdk/sources/newlib/libc/include/assert.h b/contrib/sdk/sources/newlib/libc/include/assert.h index 09f1774284..9fa79c7de7 100644 --- a/contrib/sdk/sources/newlib/libc/include/assert.h +++ b/contrib/sdk/sources/newlib/libc/include/assert.h @@ -1,8 +1,6 @@ /* assert.h */ -#ifndef _NEWLIB_ASSERT_H -#define _NEWLIB_ASSERT_H #ifdef __cplusplus extern "C" { @@ -43,8 +41,10 @@ void _EXFUN(__assert, (const char *, int, const char *) void _EXFUN(__assert_func, (const char *, int, const char *, const char *) _ATTRIBUTE ((__noreturn__))); +#if __STDC_VERSION__ >= 201112L && !defined __cplusplus +# define static_assert _Static_assert +#endif + #ifdef __cplusplus } #endif - -#endif /* _NEWLIB_ASSERT_H */ diff --git a/contrib/sdk/sources/newlib/libc/include/complex.h b/contrib/sdk/sources/newlib/libc/include/complex.h index 5fed69e90d..370938e2d5 100644 --- a/contrib/sdk/sources/newlib/libc/include/complex.h +++ b/contrib/sdk/sources/newlib/libc/include/complex.h @@ -77,7 +77,7 @@ float complex clogf(float complex); /* 7.3.8 Power and absolute-value functions */ /* 7.3.8.1 The cabs functions */ -/*#ifndef __LIBM0_SOURCE__ +/*#ifndef __LIBM0_SOURCE__ */ /* avoid conflict with historical cabs(struct complex) */ /* double cabs(double complex) __RENAME(__c99_cabs); float cabsf(float complex) __RENAME(__c99_cabsf); diff --git a/contrib/sdk/sources/newlib/libc/include/getopt.h b/contrib/sdk/sources/newlib/libc/include/getopt.h index 9b1dfa5626..556bc01c06 100644 --- a/contrib/sdk/sources/newlib/libc/include/getopt.h +++ b/contrib/sdk/sources/newlib/libc/include/getopt.h @@ -104,7 +104,7 @@ extern "C" /* types defined by this include file */ struct option { - char *name; /* the name of the long option */ + const char *name; /* the name of the long option */ int has_arg; /* one of the above macros */ int *flag; /* determines if getopt_long() returns a * value for a long option; if it is diff --git a/contrib/sdk/sources/newlib/libc/include/glob.h b/contrib/sdk/sources/newlib/libc/include/glob.h index 9c862b0cbb..fae54082af 100644 --- a/contrib/sdk/sources/newlib/libc/include/glob.h +++ b/contrib/sdk/sources/newlib/libc/include/glob.h @@ -82,7 +82,8 @@ typedef struct { #define GLOB_ABEND (-2) /* Unignored error. */ __BEGIN_DECLS -int glob(const char *, int, int (*)(const char *, int), glob_t *); +int glob(const char *__restrict, int, int (*)(const char *, int), + glob_t *__restrict); void globfree(glob_t *); __END_DECLS diff --git a/contrib/sdk/sources/newlib/libc/include/iconv.h b/contrib/sdk/sources/newlib/libc/include/iconv.h index f3e75a4ade..b45bad3ce5 100644 --- a/contrib/sdk/sources/newlib/libc/include/iconv.h +++ b/contrib/sdk/sources/newlib/libc/include/iconv.h @@ -41,7 +41,8 @@ iconv_t _EXFUN(iconv_open, (_CONST char *, _CONST char *)); size_t -_EXFUN(iconv, (iconv_t, char **, size_t *, char **, size_t *)); +_EXFUN(iconv, (iconv_t, char **__restrict, size_t *__restrict, + char **__restrict, size_t *__restrict)); int _EXFUN(iconv_close, (iconv_t)); diff --git a/contrib/sdk/sources/newlib/libc/include/inttypes.h b/contrib/sdk/sources/newlib/libc/include/inttypes.h index 0b32da85fe..d9d23028ff 100644 --- a/contrib/sdk/sources/newlib/libc/include/inttypes.h +++ b/contrib/sdk/sources/newlib/libc/include/inttypes.h @@ -13,10 +13,20 @@ #ifndef _INTTYPES_H #define _INTTYPES_H +#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 */ @@ -242,15 +252,15 @@ #define SCNxMAX __SCNMAX(x) /* ptr types */ -#if __have_long64 -#define __PRIPTR(x) __STRINGIFY(l##x) -#define __SCNPTR(x) __STRINGIFY(l##x) -#elif __have_longlong64 -#define __PRIPTR(x) __STRINGIFY(ll##x) -#define __SCNPTR(x) __STRINGIFY(ll##x) +#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) +# define __PRIPTR(x) __STRINGIFY(l##x) +# define __SCNPTR(x) __STRINGIFY(l##x) #else -#define __PRIPTR(x) __STRINGIFY(x) -#define __SCNPTR(x) __STRINGIFY(x) +# define __PRIPTR(x) __STRINGIFY(ll##x) +# define __SCNPTR(x) __STRINGIFY(ll##x) #endif #define PRIdPTR __PRIPTR(d) diff --git a/contrib/sdk/sources/newlib/libc/include/limits.h b/contrib/sdk/sources/newlib/libc/include/limits.h index e96d8f031f..b3524fc814 100644 --- a/contrib/sdk/sources/newlib/libc/include/limits.h +++ b/contrib/sdk/sources/newlib/libc/include/limits.h @@ -96,7 +96,8 @@ # define __LONG_LONG_MAX__ 9223372036854775807LL # endif -# if defined (__STDC_VERSION__) && __STDC_VERSION__ >= 199901L +# if (defined (__STDC_VERSION__) && __STDC_VERSION__ >= 199901L) || \ + (defined(__cplusplus) && __cplusplus >= 201103L) /* Minimum and maximum values a `signed long long int' can hold. */ # undef LLONG_MIN # define LLONG_MIN (-LLONG_MAX-1) @@ -143,4 +144,3 @@ #ifndef PATH_MAX #define PATH_MAX 4096 #endif - diff --git a/contrib/sdk/sources/newlib/libc/include/locale.h b/contrib/sdk/sources/newlib/libc/include/locale.h index 944588843f..ed8a2d3e05 100644 --- a/contrib/sdk/sources/newlib/libc/include/locale.h +++ b/contrib/sdk/sources/newlib/libc/include/locale.h @@ -9,9 +9,8 @@ #include "_ansi.h" -#ifndef NULL -#define NULL 0 -#endif +#define __need_NULL +#include #define LC_ALL 0 #define LC_COLLATE 1 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 db36bad069..2f92019629 100644 --- a/contrib/sdk/sources/newlib/libc/include/machine/_default_types.h +++ b/contrib/sdk/sources/newlib/libc/include/machine/_default_types.h @@ -1,19 +1,16 @@ /* - * $Id: _default_types.h,v 1.2 2008/06/11 22:14:54 jjohnstn Exp $ + * $Id: _default_types.h,v 1.6 2013/12/03 16:04:41 corinna Exp $ */ #ifndef _MACHINE__DEFAULT_TYPES_H #define _MACHINE__DEFAULT_TYPES_H -#ifdef __cplusplus -extern "C" { -#endif +#include /* * Guess on types by examining *_MIN / *_MAX defines. */ -#if defined(__GNUC__) && ((__GNUC__ >= 4) || (__GNUC__ >= 3 ) \ - && defined(__GNUC_MINOR__) && (__GNUC_MINOR__ > 2 )) +#if __GNUC_PREREQ (3, 3) /* GCC >= 3.3.0 has ____ implicitly defined. */ #define __EXP(x) __##x##__ #else @@ -22,13 +19,25 @@ extern "C" { #include #endif -#if __EXP(SCHAR_MAX) == 0x7f +#ifdef __cplusplus +extern "C" { +#endif + +#ifdef __INT8_TYPE__ +typedef __INT8_TYPE__ __int8_t; +typedef __UINT8_TYPE__ __uint8_t; +#define ___int8_t_defined 1 +#elif __EXP(SCHAR_MAX) == 0x7f typedef signed char __int8_t ; typedef unsigned char __uint8_t ; #define ___int8_t_defined 1 #endif -#if __EXP(INT_MAX) == 0x7fff +#ifdef __INT16_TYPE__ +typedef __INT16_TYPE__ __int16_t; +typedef __UINT16_TYPE__ __uint16_t; +#define ___int16_t_defined 1 +#elif __EXP(INT_MAX) == 0x7fff typedef signed int __int16_t; typedef unsigned int __uint16_t; #define ___int16_t_defined 1 @@ -42,19 +51,11 @@ typedef unsigned char __uint16_t; #define ___int16_t_defined 1 #endif -#if ___int16_t_defined -typedef __int16_t __int_least16_t; -typedef __uint16_t __uint_least16_t; -#define ___int_least16_t_defined 1 - -#if !___int8_t_defined -typedef __int16_t __int_least8_t; -typedef __uint16_t __uint_least8_t; -#define ___int_least8_t_defined 1 -#endif -#endif - -#if __EXP(INT_MAX) == 0x7fffffffL +#ifdef __INT32_TYPE__ +typedef __INT32_TYPE__ __int32_t; +typedef __UINT32_TYPE__ __uint32_t; +#define ___int32_t_defined 1 +#elif __EXP(INT_MAX) == 0x7fffffffL typedef signed int __int32_t; typedef unsigned int __uint32_t; #define ___int32_t_defined 1 @@ -72,24 +73,11 @@ typedef unsigned char __uint32_t; #define ___int32_t_defined 1 #endif -#if ___int32_t_defined -typedef __int32_t __int_least32_t; -typedef __uint32_t __uint_least32_t; -#define ___int_least32_t_defined 1 - -#if !___int8_t_defined -typedef __int32_t __int_least8_t; -typedef __uint32_t __uint_least8_t; -#define ___int_least8_t_defined 1 -#endif -#if !___int16_t_defined -typedef __int32_t __int_least16_t; -typedef __uint32_t __uint_least16_t; -#define ___int_least16_t_defined 1 -#endif -#endif - -#if __EXP(LONG_MAX) > 0x7fffffff +#ifdef __INT64_TYPE__ +typedef __INT64_TYPE__ __int64_t; +typedef __UINT64_TYPE__ __uint64_t; +#define ___int64_t_defined 1 +#elif __EXP(LONG_MAX) > 0x7fffffff typedef signed long __int64_t; typedef unsigned long __uint64_t; #define ___int64_t_defined 1 @@ -112,6 +100,81 @@ typedef unsigned int __uint64_t; #define ___int64_t_defined 1 #endif +#ifdef __INT_LEAST8_TYPE__ +typedef __INT_LEAST8_TYPE__ __int_least8_t; +typedef __UINT_LEAST8_TYPE__ __uint_least8_t; +#define ___int_least8_t_defined 1 +#elif defined(___int8_t_defined) +typedef __int8_t __int_least8_t; +typedef __uint8_t __uint_least8_t; +#define ___int_least8_t_defined 1 +#elif defined(___int16_t_defined) +typedef __int16_t __int_least8_t; +typedef __uint16_t __uint_least8_t; +#define ___int_least8_t_defined 1 +#elif defined(___int32_t_defined) +typedef __int32_t __int_least8_t; +typedef __uint32_t __uint_least8_t; +#define ___int_least8_t_defined 1 +#elif defined(___int64_t_defined) +typedef __int64_t __int_least8_t; +typedef __uint64_t __uint_least8_t; +#define ___int_least8_t_defined 1 +#endif + +#ifdef __INT_LEAST16_TYPE__ +typedef __INT_LEAST16_TYPE__ __int_least16_t; +typedef __UINT_LEAST16_TYPE__ __uint_least16_t; +#define ___int_least16_t_defined 1 +#elif defined(___int16_t_defined) +typedef __int16_t __int_least16_t; +typedef __uint16_t __uint_least16_t; +#define ___int_least16_t_defined 1 +#elif defined(___int32_t_defined) +typedef __int32_t __int_least16_t; +typedef __uint32_t __uint_least16_t; +#define ___int_least16_t_defined 1 +#elif defined(___int64_t_defined) +typedef __int64_t __int_least16_t; +typedef __uint64_t __uint_least16_t; +#define ___int_least16_t_defined 1 +#endif + +#ifdef __INT_LEAST32_TYPE__ +typedef __INT_LEAST32_TYPE__ __int_least32_t; +typedef __UINT_LEAST32_TYPE__ __uint_least32_t; +#define ___int_least32_t_defined 1 +#elif defined(___int32_t_defined) +typedef __int32_t __int_least32_t; +typedef __uint32_t __uint_least32_t; +#define ___int_least32_t_defined 1 +#elif defined(___int64_t_defined) +typedef __int64_t __int_least32_t; +typedef __uint64_t __uint_least32_t; +#define ___int_least32_t_defined 1 +#endif + +#ifdef __INT_LEAST64_TYPE__ +typedef __INT_LEAST64_TYPE__ __int_least64_t; +typedef __UINT_LEAST64_TYPE__ __uint_least64_t; +#define ___int_least64_t_defined 1 +#elif defined(___int64_t_defined) +typedef __int64_t __int_least64_t; +typedef __uint64_t __uint_least64_t; +#define ___int_least64_t_defined 1 +#endif + +#ifdef __INTPTR_TYPE__ +typedef __INTPTR_TYPE__ __intptr_t; +typedef __UINTPTR_TYPE__ __uintptr_t; +#elif defined(__PTRDIFF_TYPE__) +typedef __PTRDIFF_TYPE__ __intptr_t; +typedef unsigned __PTRDIFF_TYPE__ __uintptr_t; +#else +typedef long __intptr_t; +typedef unsigned long __uintptr_t; +#endif + #undef __EXP #ifdef __cplusplus diff --git a/contrib/sdk/sources/newlib/libc/include/machine/ieeefp.h b/contrib/sdk/sources/newlib/libc/include/machine/ieeefp.h index c9bb58e1c7..d74df2d07f 100644 --- a/contrib/sdk/sources/newlib/libc/include/machine/ieeefp.h +++ b/contrib/sdk/sources/newlib/libc/include/machine/ieeefp.h @@ -69,10 +69,31 @@ #endif #endif +#if defined (__aarch64__) +#if defined (__AARCH64EL__) +#define __IEEE_LITTLE_ENDIAN +#else +#define __IEEE_BIG_ENDIAN +#endif +#endif + +#ifdef __epiphany__ +#define __IEEE_LITTLE_ENDIAN +#define Sudden_Underflow 1 +#endif + #ifdef __hppa__ #define __IEEE_BIG_ENDIAN #endif +#ifdef __nds32__ +#ifdef __big_endian__ +#define __IEEE_BIG_ENDIAN +#else +#define __IEEE_LITTLE_ENDIAN +#endif +#endif + #ifdef __SPU__ #define __IEEE_BIG_ENDIAN @@ -275,7 +296,11 @@ #endif #ifdef __moxie__ +#ifdef __MOXIE_BIG_ENDIAN__ #define __IEEE_BIG_ENDIAN +#else +#define __IEEE_LITTLE_ENDIAN +#endif #endif #ifdef __ia64__ @@ -339,7 +364,16 @@ #endif #ifdef __MICROBLAZE__ +#ifndef __MICROBLAZEEL__ #define __IEEE_BIG_ENDIAN +#else +#define __IEEE_LITTLE_ENDIAN +#endif +#endif + +#ifdef __MSP430__ +#define __IEEE_LITTLE_ENDIAN +#define __SMALL_BITFIELDS /* 16 Bit INT */ #endif #ifdef __RL78__ @@ -371,6 +405,14 @@ #define __SMALL_BITFIELDS /* 16 Bit INT */ #endif +#ifdef __NIOS2__ +# ifdef __nios2_big_endian__ +# define __IEEE_BIG_ENDIAN +# else +# define __IEEE_LITTLE_ENDIAN +# endif +#endif + #ifndef __IEEE_BIG_ENDIAN #ifndef __IEEE_LITTLE_ENDIAN #error Endianess not declared!! diff --git a/contrib/sdk/sources/newlib/libc/include/machine/setjmp-dj.h b/contrib/sdk/sources/newlib/libc/include/machine/setjmp-dj.h index ab0d0d65d9..e080f7f976 100644 --- a/contrib/sdk/sources/newlib/libc/include/machine/setjmp-dj.h +++ b/contrib/sdk/sources/newlib/libc/include/machine/setjmp-dj.h @@ -2,7 +2,7 @@ * Copyright (C) 1991 DJ Delorie * All rights reserved. * - * Redistribution and use in source and binary forms is permitted + * Redistribution, modification, and use in source and binary forms is permitted * provided that the above copyright notice and following paragraph are * duplicated in all such forms. * diff --git a/contrib/sdk/sources/newlib/libc/include/machine/setjmp.h b/contrib/sdk/sources/newlib/libc/include/machine/setjmp.h index 5ee1eac03f..38d2405268 100644 --- a/contrib/sdk/sources/newlib/libc/include/machine/setjmp.h +++ b/contrib/sdk/sources/newlib/libc/include/machine/setjmp.h @@ -1,8 +1,414 @@ _BEGIN_STD_C -#include "setjmp-dj.h" +#if defined(__arm__) || defined(__thumb__) +/* + * All callee preserved registers: + * v1 - v7, fp, ip, sp, lr, f4, f5, f6, f7 + */ +#define _JBLEN 23 +#endif + +#if defined(__aarch64__) +#define _JBLEN 22 +#define _JBTYPE long long +#endif + +#if defined(__AVR__) +#define _JBLEN 24 +#endif + +#ifdef __sparc__ +/* + * onsstack,sigmask,sp,pc,npc,psr,g1,o0,wbcnt (sigcontext). + * All else recovered by under/over(flow) handling. + */ +#define _JBLEN 13 +#endif + +#ifdef __BFIN__ +#define _JBLEN 40 +#endif + +#ifdef __epiphany__ +/* All callee preserved registers: r4-r10,fp, sp, lr,r15, r32-r39 */ +#define _JBTYPE long long +#define _JBLEN 10 +#endif + +/* necv70 was 9 as well. */ + +#if defined(__m68k__) || defined(__mc68000__) +/* + * onsstack,sigmask,sp,pc,psl,d2-d7,a2-a6, + * fp2-fp7 for 68881. + * All else recovered by under/over(flow) handling. + */ +#define _JBLEN 34 +#endif + +#if defined(__mc68hc11__) || defined(__mc68hc12__) || defined(__mc68hc1x__) +/* + * D, X, Y are not saved. + * Only take into account the pseudo soft registers (max 32). + */ +#define _JBLEN 32 +#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. */ +#define _JBLEN 18 +#endif + +#if defined(__Z8001__) || defined(__Z8002__) +/* 16 regs + pc */ +#define _JBLEN 20 +#endif + +#ifdef _AM29K +/* + * onsstack,sigmask,sp,pc,npc,psr,g1,o0,wbcnt (sigcontext). + * All else recovered by under/over(flow) handling. + */ +#define _JBLEN 9 +#endif + +#ifdef __i386__ +# if defined(__CYGWIN__) && !defined (_JBLEN) +# define _JBLEN (13 * 4) +# elif defined(__unix__) || defined(__rtems__) +# define _JBLEN 9 +# else +# include "setjmp-dj.h" +# endif +#endif + +#ifdef __x86_64__ +# ifdef __CYGWIN__ +# define _JBTYPE long +# define _JBLEN 32 +# else +# define _JBTYPE long long +# define _JBLEN 8 +# endif +#endif + +#ifdef __i960__ +#define _JBLEN 35 +#endif + +#ifdef __M32R__ +/* Only 8 words are currently needed. 10 gives us some slop if we need + to expand. */ +#define _JBLEN 10 +#endif + +#ifdef __mips__ +# if defined(__mips64) || (__mips_fpr == 64) +# define _JBTYPE long long +# endif +# ifdef __mips_soft_float +# define _JBLEN 11 +# else +# define _JBLEN 23 +# endif +#endif + +#ifdef __m88000__ +#define _JBLEN 21 +#endif + +#ifdef __H8300__ +#define _JBLEN 5 +#define _JBTYPE int +#endif + +#ifdef __H8300H__ +/* same as H8/300 but registers are twice as big */ +#define _JBLEN 5 +#define _JBTYPE long +#endif + +#if defined (__H8300S__) || defined (__H8300SX__) +/* same as H8/300 but registers are twice as big */ +#define _JBLEN 5 +#define _JBTYPE long +#endif + +#ifdef __H8500__ +#define _JBLEN 4 +#endif + +#ifdef __sh__ +#if __SH5__ +#define _JBLEN 50 +#define _JBTYPE long long +#else +#define _JBLEN 20 +#endif /* __SH5__ */ +#endif + +#ifdef __v800 +#define _JBLEN 28 +#endif + +#ifdef __PPC__ +#ifdef __ALTIVEC__ +#define _JBLEN 64 +#else +#define _JBLEN 32 +#endif +#define _JBTYPE double +#endif + +#ifdef __MICROBLAZE__ +#define _JBLEN 20 +#define _JBTYPE unsigned int +#endif + +#ifdef __hppa__ +/* %r30, %r2-%r18, %r27, pad, %fr12-%fr15. + Note space exists for the FP registers, but they are not + saved. */ +#define _JBLEN 28 +#endif + +#if defined(__mn10300__) || defined(__mn10200__) +#ifdef __AM33_2__ +#define _JBLEN 26 +#else +/* A guess */ +#define _JBLEN 10 +#endif +#endif + +#ifdef __v850 +/* I think our setjmp is saving 15 regs at the moment. Gives us one word + slop if we need to expand. */ +#define _JBLEN 16 +#endif + +#if defined(_C4x) +#define _JBLEN 10 +#endif +#if defined(_C3x) +#define _JBLEN 9 +#endif + +#ifdef __TMS320C6X__ +#define _JBLEN 13 +#endif + +#ifdef __TIC80__ +#define _JBLEN 13 +#endif + +#ifdef __D10V__ +#define _JBLEN 8 +#endif + +#ifdef __D30V__ +#define _JBLEN ((64 /* GPR */ + (2*2) /* ACs */ + 18 /* CRs */) / 2) +#define _JBTYPE double +#endif + +#ifdef __frv__ +#define _JBLEN (68/2) /* room for 68 32-bit regs */ +#define _JBTYPE double +#endif + +#ifdef __moxie__ +#define _JBLEN 16 +#endif + +#ifdef __CRX__ +#define _JBLEN 9 +#endif + +#if (defined(__CR16__) || defined(__CR16C__) ||defined(__CR16CP__)) +/* r6, r7, r8, r9, r10, r11, r12 (r12L, r12H), + * r13 (r13L, r13H), ra(raL, raH), sp(spL, spH) */ +#define _JBLEN 14 +#define _JBTYPE unsigned short +#endif + +#ifdef __fr30__ +#define _JBLEN 10 +#endif + +#ifdef __iq2000__ +#define _JBLEN 32 +#endif + +#ifdef __mcore__ +#define _JBLEN 16 +#endif + +#ifdef __MMIX__ +/* Using a layout compatible with GCC's built-in. */ +#define _JBLEN 5 +#define _JBTYPE unsigned long +#endif + +#ifdef __mt__ +#define _JBLEN 16 +#endif + +#ifdef __SPU__ +#define _JBLEN 50 +#define _JBTYPE __vector signed int +#endif + +#ifdef __xstormy16__ +/* 4 GPRs plus SP plus PC. */ +#define _JBLEN 8 +#endif + +#ifdef __mep__ +/* 16 GPRs, pc, hi, lo */ +#define _JBLEN 19 +#endif + +#ifdef __CRIS__ +#define _JBLEN 18 +#endif + +#ifdef __lm32__ +#define _JBLEN 19 +#endif + +#ifdef __m32c__ +#if defined(__r8c_cpu__) || defined(__m16c_cpu__) +#define _JBLEN (22/2) +#else +#define _JBLEN (34/2) +#endif +#define _JBTYPE unsigned short +#endif /* __m32c__ */ + +#ifdef __MSP430__ +#define _JBLEN 9 + +#ifdef __MSP430X_LARGE__ +#define _JBTYPE unsigned long +#else +#define _JBTYPE unsigned short +#endif +#endif + +#ifdef __RL78__ +/* Three banks of registers, SP, CS, ES, PC */ +#define _JBLEN (8*3+8) +#define _JBTYPE unsigned char +#endif + +/* + * There are two versions of setjmp()/longjmp(): + * 1) Compiler (gcc) built-in versions. + * 2) Function-call versions. + * + * The built-in versions are used most of the time. When used, gcc replaces + * calls to setjmp()/longjmp() with inline assembly code. The built-in + * versions save/restore a variable number of registers. + + * _JBLEN is set to 40 to be ultra-safe with the built-in versions. + * It only needs to be 12 for the function-call versions + * but this data structure is used by both versions. + */ +#ifdef __NIOS2__ +#define _JBLEN 40 +#define _JBTYPE unsigned long +#endif + +#ifdef __RX__ +#define _JBLEN 0x44 +#endif + +#ifdef _JBLEN +#ifdef _JBTYPE +typedef _JBTYPE jmp_buf[_JBLEN]; +#else +typedef int jmp_buf[_JBLEN]; +#endif +#endif _END_STD_C +#if defined(__CYGWIN__) || defined(__rtems__) +#include +#ifdef __cplusplus +extern "C" { +#endif + +/* POSIX sigsetjmp/siglongjmp macros */ +#ifdef _JBTYPE +typedef _JBTYPE sigjmp_buf[_JBLEN+1+((sizeof (_JBTYPE) + sizeof (sigset_t) - 1) + /sizeof (_JBTYPE))]; +#else +typedef int sigjmp_buf[_JBLEN+1+(sizeof (sigset_t)/sizeof (int))]; +#endif + +#define _SAVEMASK _JBLEN +#define _SIGMASK (_JBLEN+1) + +#ifdef __CYGWIN__ +# define _CYGWIN_WORKING_SIGSETJMP +#endif + +#ifdef _POSIX_THREADS +#define __SIGMASK_FUNC pthread_sigmask +#else +#define __SIGMASK_FUNC sigprocmask +#endif + +#if defined(__GNUC__) + +#define sigsetjmp(env, savemask) \ + __extension__ \ + ({ \ + sigjmp_buf *_sjbuf = &(env); \ + ((*_sjbuf)[_SAVEMASK] = savemask,\ + __SIGMASK_FUNC (SIG_SETMASK, 0, (sigset_t *)((*_sjbuf) + _SIGMASK)),\ + setjmp (*_sjbuf)); \ + }) + +#define siglongjmp(env, val) \ + __extension__ \ + ({ \ + sigjmp_buf *_sjbuf = &(env); \ + ((((*_sjbuf)[_SAVEMASK]) ? \ + __SIGMASK_FUNC (SIG_SETMASK, (sigset_t *)((*_sjbuf) + _SIGMASK), 0)\ + : 0), \ + longjmp (*_sjbuf, val)); \ + }) + +#else /* !__GNUC__ */ + +#define sigsetjmp(env, savemask) ((env)[_SAVEMASK] = savemask,\ + __SIGMASK_FUNC (SIG_SETMASK, 0, (sigset_t *) ((env) + _SIGMASK)),\ + setjmp (env)) + +#define siglongjmp(env, val) ((((env)[_SAVEMASK])?\ + __SIGMASK_FUNC (SIG_SETMASK, (sigset_t *) ((env) + _SIGMASK), 0):0),\ + longjmp (env, val)) + +#endif + +/* POSIX _setjmp/_longjmp, maintained for XSI compatibility. These + 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); +#else +#define _setjmp(env) sigsetjmp ((env), 0) +#define _longjmp(env, val) siglongjmp ((env), (val)) +#endif + +#ifdef __cplusplus +} +#endif +#endif /* __CYGWIN__ or __rtems__ */ diff --git a/contrib/sdk/sources/newlib/libc/include/machine/time.h b/contrib/sdk/sources/newlib/libc/include/machine/time.h index d397af28a6..b7d6a79391 100644 --- a/contrib/sdk/sources/newlib/libc/include/machine/time.h +++ b/contrib/sdk/sources/newlib/libc/include/machine/time.h @@ -4,7 +4,7 @@ #if defined(__rtems__) #define _CLOCKS_PER_SEC_ sysconf(_SC_CLK_TCK) #else /* !__rtems__ */ -#if defined(__arm__) || defined(__thumb__) +#if defined(__aarch64__) || defined(__arm__) || defined(__thumb__) #define _CLOCKS_PER_SEC_ 100 #endif #endif /* !__rtems__ */ diff --git a/contrib/sdk/sources/newlib/libc/include/malloc.h b/contrib/sdk/sources/newlib/libc/include/malloc.h index 8e5d1d4db5..94eb9003ef 100644 --- a/contrib/sdk/sources/newlib/libc/include/malloc.h +++ b/contrib/sdk/sources/newlib/libc/include/malloc.h @@ -20,16 +20,16 @@ extern "C" { libc/stdlib/mallocr.c. */ struct mallinfo { - int arena; /* total space allocated from system */ - int ordblks; /* number of non-inuse chunks */ - int smblks; /* unused -- always zero */ - int hblks; /* number of mmapped regions */ - int hblkhd; /* total space in mmapped regions */ - int usmblks; /* unused -- always zero */ - int fsmblks; /* unused -- always zero */ - int uordblks; /* total allocated space */ - int fordblks; /* total non-inuse space */ - int keepcost; /* top-most, releasable (via malloc_trim) space */ + size_t arena; /* total space allocated from system */ + size_t ordblks; /* number of non-inuse chunks */ + size_t smblks; /* unused -- always zero */ + size_t hblks; /* number of mmapped regions */ + size_t hblkhd; /* total space in mmapped regions */ + size_t usmblks; /* unused -- always zero */ + size_t fsmblks; /* unused -- always zero */ + size_t uordblks; /* total allocated space */ + size_t fordblks; /* total non-inuse space */ + size_t keepcost; /* top-most, releasable (via malloc_trim) space */ }; /* The routines. */ diff --git a/contrib/sdk/sources/newlib/libc/include/math.h b/contrib/sdk/sources/newlib/libc/include/math.h index 65859abd55..7db9217def 100644 --- a/contrib/sdk/sources/newlib/libc/include/math.h +++ b/contrib/sdk/sources/newlib/libc/include/math.h @@ -34,10 +34,7 @@ union __ldmath /* Natural log of 2 */ #define _M_LN2 0.693147180559945309417 -#if defined(__GNUC__) && \ - ( (__GNUC__ >= 4) || \ - ( (__GNUC__ >= 3) && defined(__GNUC_MINOR__) && (__GNUC_MINOR__ >= 3) ) ) - +#if __GNUC_PREREQ (3, 3) /* gcc >= 3.3 implicitly defines builtins for HUGE_VALx values. */ # ifndef HUGE_VAL @@ -143,11 +140,37 @@ extern double fmod _PARAMS((double, double)); /* ISO C99 types and macros. */ -#ifndef FLT_EVAL_METHOD -#define FLT_EVAL_METHOD 0 -typedef float float_t; -typedef double double_t; +/* FIXME: FLT_EVAL_METHOD should somehow be gotten from float.h (which is hard, + * considering that the standard says the includes it defines should not + * include other includes that it defines) and that value used. (This can be + * solved, but autoconf has a bug which makes the solution more difficult, so + * it has been skipped for now.) */ +#if !defined(FLT_EVAL_METHOD) && defined(__FLT_EVAL_METHOD__) + #define FLT_EVAL_METHOD __FLT_EVAL_METHOD__ + #define __TMP_FLT_EVAL_METHOD #endif /* FLT_EVAL_METHOD */ +#if defined FLT_EVAL_METHOD + #if FLT_EVAL_METHOD == 0 + typedef float float_t; + typedef double double_t; + #elif FLT_EVAL_METHOD == 1 + typedef double float_t; + typedef double double_t; + #elif FLT_EVAL_METHOD == 2 + typedef long double float_t; + typedef long double double_t; + #else + /* Implementation-defined. Assume float_t and double_t have been + * defined previously for this configuration (e.g. config.h). */ + #endif +#else + /* Assume basic definitions. */ + typedef float float_t; + typedef double double_t; +#endif +#if defined(__TMP_FLT_EVAL_METHOD) + #undef FLT_EVAL_METHOD +#endif #define FP_NAN 0 #define FP_INFINITE 1 @@ -355,9 +378,6 @@ extern float lgammaf _PARAMS((float)); extern float erff _PARAMS((float)); extern float erfcf _PARAMS((float)); extern float log2f _PARAMS((float)); -#if !defined(__cplusplus) -#define log2f(x) (logf (x) / (float_t) _M_LN2) -#endif extern float hypotf _PARAMS((float, float)); #endif /* ! defined (_REENT_ONLY) */ diff --git a/contrib/sdk/sources/newlib/libc/include/newlib.h b/contrib/sdk/sources/newlib/libc/include/newlib.h index e6c5ad0130..a9fef29957 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 "1.19.0" +#define _NEWLIB_VERSION "2.1.0" /* C99 formats support (such as %a, %zu, ...) in IO functions like * printf/scanf enabled */ diff --git a/contrib/sdk/sources/newlib/libc/include/paths.h b/contrib/sdk/sources/newlib/libc/include/paths.h index 148070a704..31a86ac869 100644 --- a/contrib/sdk/sources/newlib/libc/include/paths.h +++ b/contrib/sdk/sources/newlib/libc/include/paths.h @@ -2,6 +2,8 @@ #define _PATHS_H_ #define _PATH_DEV "/dev/" +#define _PATH_DEVNULL "/dev/null" +#define _PATH_DEVZERO "/dev/zero" #define _PATH_BSHELL "/bin/sh" #endif /* _PATHS_H_ */ diff --git a/contrib/sdk/sources/newlib/libc/include/pthread.h b/contrib/sdk/sources/newlib/libc/include/pthread.h index a337870b17..8cd4d71a8a 100644 --- a/contrib/sdk/sources/newlib/libc/include/pthread.h +++ b/contrib/sdk/sources/newlib/libc/include/pthread.h @@ -2,7 +2,7 @@ * * Written by Joel Sherrill . * - * COPYRIGHT (c) 1989-2010. + * COPYRIGHT (c) 1989-2013. * On-Line Applications Research Corporation (OAR). * * Permission to use, copy, modify, and distribute this software for any @@ -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.9 2010/12/08 14:44:06 corinna Exp $ + * $Id: pthread.h,v 1.12 2013/11/29 23:35:34 joel Exp $ */ #ifndef __PTHREAD_h @@ -32,6 +32,14 @@ extern "C" { #include #include #include +#include + +struct _pthread_cleanup_context { + void (*_routine)(void *); + void *_arg; + int _canceltype; + struct _pthread_cleanup_context *_previous; +}; /* Register Fork Handlers */ int _EXFUN(pthread_atfork,(void (*prepare)(void), void (*parent)(void), @@ -104,7 +112,7 @@ int _EXFUN(pthread_cond_destroy, (pthread_cond_t *__mutex)); pthread_cond_t cond = PTHREAD_COND_INITIALIZER; */ -#define PTHREAD_COND_INITIALIZER ((pthread_mutex_t) 0xFFFFFFFF) +#define PTHREAD_COND_INITIALIZER ((pthread_cond_t) 0xFFFFFFFF) /* Broadcasting and Signaling a Condition, P1003.1c/Draft 10, p. 101 */ @@ -206,6 +214,29 @@ int _EXFUN(pthread_attr_getguardsize, int _EXFUN(pthread_attr_setguardsize, (pthread_attr_t *__attr, size_t __guardsize)); +/* POSIX thread APIs beyond the POSIX standard but provided + * in GNU/Linux. They may be provided by other OSes for + * compatibility. + */ +#if defined(__GNU_VISIBLE) +#if defined(__rtems__) +int _EXFUN(pthread_attr_setaffinity_np, + (pthread_attr_t *__attr, size_t __cpusetsize, + const cpu_set_t *__cpuset)); +int _EXFUN(pthread_attr_getaffinity_np, + (const pthread_attr_t *__attr, size_t __cpusetsize, + cpu_set_t *__cpuset)); + +int _EXFUN(pthread_setaffinity_np, + (pthread_t __id, size_t __cpusetsize, const cpu_set_t *__cpuset)); +int _EXFUN(pthread_getaffinity_np, + (const pthread_t __id, size_t __cpusetsize, cpu_set_t *__cpuset)); + +int _EXFUN(pthread_getattr_np, + (pthread_t __id, pthread_attr_t *__attr)); +#endif /* defined(__rtems__) */ +#endif /* defined(__GNU_VISIBLE) */ + /* Thread Creation, P1003.1c/Draft 10, p. 144 */ int _EXFUN(pthread_create, @@ -280,9 +311,43 @@ void _EXFUN(pthread_testcancel, (void)); /* Establishing Cancellation Handlers, P1003.1c/Draft 10, p. 184 */ -void _EXFUN(pthread_cleanup_push, - (void (*__routine)( void * ), void *__arg)); -void _EXFUN(pthread_cleanup_pop, (int __execute)); +void _EXFUN(_pthread_cleanup_push, + (struct _pthread_cleanup_context *_context, + void (*_routine)(void *), void *_arg)); + +void _EXFUN(_pthread_cleanup_pop, + (struct _pthread_cleanup_context *_context, + int _execute)); + +/* It is intentional to open and close the scope in two different macros */ +#define pthread_cleanup_push(_routine, _arg) \ + do { \ + struct _pthread_cleanup_context _pthread_clup_ctx; \ + _pthread_cleanup_push(&_pthread_clup_ctx, (_routine), (_arg)) + +#define pthread_cleanup_pop(_execute) \ + _pthread_cleanup_pop(&_pthread_clup_ctx, (_execute)); \ + } while (0) + +#if defined(_GNU_SOURCE) +void _EXFUN(_pthread_cleanup_push_defer, + (struct _pthread_cleanup_context *_context, + void (*_routine)(void *), void *_arg)); + +void _EXFUN(_pthread_cleanup_pop_restore, + (struct _pthread_cleanup_context *_context, + int _execute)); + +/* It is intentional to open and close the scope in two different macros */ +#define pthread_cleanup_push_defer_np(_routine, _arg) \ + do { \ + struct _pthread_cleanup_context _pthread_clup_ctx; \ + _pthread_cleanup_push_defer(&_pthread_clup_ctx, (_routine), (_arg)) + +#define pthread_cleanup_pop_restore_np(_execute) \ + _pthread_cleanup_pop_restore(&_pthread_clup_ctx, (_execute)); \ + } while (0) +#endif /* defined(_GNU_SOURCE) */ #if defined(_POSIX_THREAD_CPUTIME) @@ -328,6 +393,13 @@ int _EXFUN(pthread_spin_unlock, (pthread_spinlock_t *__spinlock)); #if defined(_POSIX_READER_WRITER_LOCKS) +/* This is used to statically initialize a pthread_rwlock_t. Example: + + pthread_mutex_t mutex = PTHREAD_RWLOCK_INITIALIZER; + */ + +#define PTHREAD_RWLOCK_INITIALIZER ((pthread_rwlock_t) 0xFFFFFFFF) + int _EXFUN(pthread_rwlockattr_init, (pthread_rwlockattr_t *__attr)); int _EXFUN(pthread_rwlockattr_destroy, (pthread_rwlockattr_t *__attr)); int _EXFUN(pthread_rwlockattr_getpshared, diff --git a/contrib/sdk/sources/newlib/libc/include/reent.h b/contrib/sdk/sources/newlib/libc/include/reent.h index 8386c7513b..a1160dff71 100644 --- a/contrib/sdk/sources/newlib/libc/include/reent.h +++ b/contrib/sdk/sources/newlib/libc/include/reent.h @@ -104,14 +104,6 @@ struct tms; struct timeval; struct timezone; -typedef struct -{ - char *name; - unsigned int offset; - int (*write)(const char*, const void *, size_t, size_t, size_t*); -}__file_handle; - - #if defined(REENTRANT_SYSCALLS_PROVIDED) && defined(MISSING_SYSCALL_NAMES) #define _close_r(__reent, __fd) close(__fd) @@ -179,16 +171,22 @@ extern int _gettimeofday_r _PARAMS ((struct _reent *, struct timeval *__tp, void #ifdef __LARGE64_FILES -#if defined(__CYGWIN__) && defined(_COMPILING_NEWLIB) -#define stat64 __stat64 -#endif +#if defined(__CYGWIN__) +#define stat64 stat +#endif struct stat64; extern _off64_t _lseek64_r _PARAMS ((struct _reent *, int, _off64_t, int)); extern int _fstat64_r _PARAMS ((struct _reent *, int, struct stat64 *)); extern int _open64_r _PARAMS ((struct _reent *, const char *, int, int)); extern int _stat64_r _PARAMS ((struct _reent *, const char *, struct stat64 *)); + +/* Don't pollute namespace if not building newlib. */ +#if defined (__CYGWIN__) && !defined (_COMPILING_NEWLIB) +#undef stat64 +#endif + #endif #endif diff --git a/contrib/sdk/sources/newlib/libc/include/regex.h b/contrib/sdk/sources/newlib/libc/include/regex.h index 16dade0f54..feb657bb6f 100644 --- a/contrib/sdk/sources/newlib/libc/include/regex.h +++ b/contrib/sdk/sources/newlib/libc/include/regex.h @@ -93,9 +93,10 @@ typedef struct { #define REG_BACKR 02000 /* force use of backref code */ __BEGIN_DECLS -int regcomp(regex_t *, const char *, int); -size_t regerror(int, const regex_t *, char *, size_t); -int regexec(const regex_t *, const char *, size_t, regmatch_t [], int); +int regcomp(regex_t *__restrict, const char *__restrict, int); +size_t regerror(int, const regex_t *__restrict, char *__restrict, size_t); +int regexec(const regex_t *__restrict, const char *__restrict, + size_t, regmatch_t [__restrict], int); void regfree(regex_t *); __END_DECLS diff --git a/contrib/sdk/sources/newlib/libc/include/rpc/types.h b/contrib/sdk/sources/newlib/libc/include/rpc/types.h index 831299a486..c8de3e562a 100644 --- a/contrib/sdk/sources/newlib/libc/include/rpc/types.h +++ b/contrib/sdk/sources/newlib/libc/include/rpc/types.h @@ -41,6 +41,9 @@ #include #include +#define __need_NULL +#include + #ifdef __cplusplus extern "C" { #endif @@ -59,9 +62,6 @@ typedef u_int32_t rpcprot_t; typedef u_int32_t rpcport_t; typedef int32_t rpc_inline_t; -#ifndef NULL -# define NULL 0 -#endif #define __dontcare__ -1 #ifndef FALSE diff --git a/contrib/sdk/sources/newlib/libc/include/search.h b/contrib/sdk/sources/newlib/libc/include/search.h index 719556cf1c..52e0ea8a9b 100644 --- a/contrib/sdk/sources/newlib/libc/include/search.h +++ b/contrib/sdk/sources/newlib/libc/include/search.h @@ -42,6 +42,11 @@ struct hsearch_data size_t htablesize; }; +#ifndef __compar_fn_t_defined +#define __compar_fn_t_defined +typedef int (*__compar_fn_t) (const void *, const void *); +#endif + __BEGIN_DECLS int hcreate(size_t); void hdestroy(void); @@ -49,10 +54,10 @@ ENTRY *hsearch(ENTRY, ACTION); int hcreate_r(size_t, struct hsearch_data *); void hdestroy_r(struct hsearch_data *); int hsearch_r(ENTRY, ACTION, ENTRY **, struct hsearch_data *); -void *tdelete(const void *, void **, int (*)(const void *, const void *)); +void *tdelete(const void *__restrict, void **__restrict, __compar_fn_t); void tdestroy (void *, void (*)(void *)); -void *tfind(const void *, void **, int (*)(const void *, const void *)); -void *tsearch(const void *, void **, int (*)(const void *, const void *)); +void *tfind(const void *, void **, __compar_fn_t); +void *tsearch(const void *, void **, __compar_fn_t); void twalk(const void *, void (*)(const void *, VISIT, int)); __END_DECLS diff --git a/contrib/sdk/sources/newlib/libc/include/spawn.h b/contrib/sdk/sources/newlib/libc/include/spawn.h new file mode 100644 index 0000000000..5a6692f115 --- /dev/null +++ b/contrib/sdk/sources/newlib/libc/include/spawn.h @@ -0,0 +1,119 @@ +/*- + * Copyright (c) 2008 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 _SPAWN_H_ +#define _SPAWN_H_ + +#include <_ansi.h> +#include +#include +#include +#define __need_sigset_t +#include + +struct sched_param; + +typedef struct __posix_spawnattr *posix_spawnattr_t; +typedef struct __posix_spawn_file_actions *posix_spawn_file_actions_t; + +#define POSIX_SPAWN_RESETIDS 0x01 +#define POSIX_SPAWN_SETPGROUP 0x02 +#define POSIX_SPAWN_SETSCHEDPARAM 0x04 +#define POSIX_SPAWN_SETSCHEDULER 0x08 +#define POSIX_SPAWN_SETSIGDEF 0x10 +#define POSIX_SPAWN_SETSIGMASK 0x20 + +_BEGIN_STD_C +/* + * Spawn routines + * + * XXX both arrays should be __restrict, but this does not work when GCC + * is invoked with -std=c99. + */ +int _EXFUN(posix_spawn, (pid_t * __restrict, const char * __restrict, + const posix_spawn_file_actions_t *, const posix_spawnattr_t * __restrict, + char * const [], char * const []) +); +int _EXFUN(posix_spawnp, (pid_t * __restrict, const char * __restrict, + const posix_spawn_file_actions_t *, const posix_spawnattr_t * __restrict, + char * const [], char * const []) +); + +/* + * File descriptor actions + */ +int _EXFUN(posix_spawn_file_actions_init, (posix_spawn_file_actions_t *)); +int _EXFUN(posix_spawn_file_actions_destroy, (posix_spawn_file_actions_t *)); + +int _EXFUN(posix_spawn_file_actions_addopen, + (posix_spawn_file_actions_t * __restrict, int, const char * __restrict, int, mode_t) +); +int _EXFUN(posix_spawn_file_actions_adddup2, + (posix_spawn_file_actions_t *, int, int) +); +int _EXFUN(posix_spawn_file_actions_addclose, + (posix_spawn_file_actions_t *, int) +); + +/* + * Spawn attributes + */ +int _EXFUN(posix_spawnattr_init, (posix_spawnattr_t *)); +int _EXFUN(posix_spawnattr_destroy, (posix_spawnattr_t *)); + +int _EXFUN(posix_spawnattr_getflags, + (const posix_spawnattr_t * __restrict, short * __restrict) +); +int _EXFUN(posix_spawnattr_getpgroup, + (const posix_spawnattr_t * __restrict, pid_t * __restrict)); +int _EXFUN(posix_spawnattr_getschedparam, + (const posix_spawnattr_t * __restrict, struct sched_param * __restrict) +); +int _EXFUN(posix_spawnattr_getschedpolicy, + (const posix_spawnattr_t * __restrict, int * __restrict) +); +int _EXFUN(posix_spawnattr_getsigdefault, + (const posix_spawnattr_t * __restrict, sigset_t * __restrict) +); +int _EXFUN(posix_spawnattr_getsigmask, + (const posix_spawnattr_t * __restrict, sigset_t * __restrict) +); + +int _EXFUN(posix_spawnattr_setflags, (posix_spawnattr_t *, short)); +int _EXFUN(posix_spawnattr_setpgroup, (posix_spawnattr_t *, pid_t)); +int _EXFUN(posix_spawnattr_setschedparam, + (posix_spawnattr_t * __restrict, const struct sched_param * __restrict) +); +int _EXFUN(posix_spawnattr_setschedpolicy, (posix_spawnattr_t *, int)); +int _EXFUN(posix_spawnattr_setsigdefault, + (posix_spawnattr_t * __restrict, const sigset_t * __restrict) +); +int _EXFUN(posix_spawnattr_setsigmask, + (posix_spawnattr_t * __restrict, const sigset_t * __restrict) +); +_END_STD_C + +#endif /* !_SPAWN_H_ */ diff --git a/contrib/sdk/sources/newlib/libc/include/stdatomic.h b/contrib/sdk/sources/newlib/libc/include/stdatomic.h new file mode 100644 index 0000000000..09c0cf73e0 --- /dev/null +++ b/contrib/sdk/sources/newlib/libc/include/stdatomic.h @@ -0,0 +1,413 @@ +/*- + * Copyright (c) 2011 Ed Schouten + * David Chisnall + * 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 _STDATOMIC_H_ +#define _STDATOMIC_H_ + +#include +#include + +#if __has_extension(c_atomic) || __has_extension(cxx_atomic) +#define __CLANG_ATOMICS +#elif __GNUC_PREREQ__(4, 7) +#define __GNUC_ATOMICS +#elif defined(__GNUC__) +#define __SYNC_ATOMICS +#else +#error "stdatomic.h does not support your compiler" +#endif + +/* + * 7.17.1 Atomic lock-free macros. + */ + +#ifdef __GCC_ATOMIC_BOOL_LOCK_FREE +#define ATOMIC_BOOL_LOCK_FREE __GCC_ATOMIC_BOOL_LOCK_FREE +#endif +#ifdef __GCC_ATOMIC_CHAR_LOCK_FREE +#define ATOMIC_CHAR_LOCK_FREE __GCC_ATOMIC_CHAR_LOCK_FREE +#endif +#ifdef __GCC_ATOMIC_CHAR16_T_LOCK_FREE +#define ATOMIC_CHAR16_T_LOCK_FREE __GCC_ATOMIC_CHAR16_T_LOCK_FREE +#endif +#ifdef __GCC_ATOMIC_CHAR32_T_LOCK_FREE +#define ATOMIC_CHAR32_T_LOCK_FREE __GCC_ATOMIC_CHAR32_T_LOCK_FREE +#endif +#ifdef __GCC_ATOMIC_WCHAR_T_LOCK_FREE +#define ATOMIC_WCHAR_T_LOCK_FREE __GCC_ATOMIC_WCHAR_T_LOCK_FREE +#endif +#ifdef __GCC_ATOMIC_SHORT_LOCK_FREE +#define ATOMIC_SHORT_LOCK_FREE __GCC_ATOMIC_SHORT_LOCK_FREE +#endif +#ifdef __GCC_ATOMIC_INT_LOCK_FREE +#define ATOMIC_INT_LOCK_FREE __GCC_ATOMIC_INT_LOCK_FREE +#endif +#ifdef __GCC_ATOMIC_LONG_LOCK_FREE +#define ATOMIC_LONG_LOCK_FREE __GCC_ATOMIC_LONG_LOCK_FREE +#endif +#ifdef __GCC_ATOMIC_LLONG_LOCK_FREE +#define ATOMIC_LLONG_LOCK_FREE __GCC_ATOMIC_LLONG_LOCK_FREE +#endif +#ifdef __GCC_ATOMIC_POINTER_LOCK_FREE +#define ATOMIC_POINTER_LOCK_FREE __GCC_ATOMIC_POINTER_LOCK_FREE +#endif + +/* + * 7.17.2 Initialization. + */ + +#if defined(__CLANG_ATOMICS) +#define ATOMIC_VAR_INIT(value) (value) +#define atomic_init(obj, value) __c11_atomic_init(obj, value) +#else +#define ATOMIC_VAR_INIT(value) { .__val = (value) } +#define atomic_init(obj, value) ((void)((obj)->__val = (value))) +#endif + +/* + * Clang and recent GCC both provide predefined macros for the memory + * orderings. If we are using a compiler that doesn't define them, use the + * clang values - these will be ignored in the fallback path. + */ + +#ifndef __ATOMIC_RELAXED +#define __ATOMIC_RELAXED 0 +#endif +#ifndef __ATOMIC_CONSUME +#define __ATOMIC_CONSUME 1 +#endif +#ifndef __ATOMIC_ACQUIRE +#define __ATOMIC_ACQUIRE 2 +#endif +#ifndef __ATOMIC_RELEASE +#define __ATOMIC_RELEASE 3 +#endif +#ifndef __ATOMIC_ACQ_REL +#define __ATOMIC_ACQ_REL 4 +#endif +#ifndef __ATOMIC_SEQ_CST +#define __ATOMIC_SEQ_CST 5 +#endif + +/* + * 7.17.3 Order and consistency. + * + * The memory_order_* constants that denote the barrier behaviour of the + * atomic operations. + */ + +typedef enum { + memory_order_relaxed = __ATOMIC_RELAXED, + memory_order_consume = __ATOMIC_CONSUME, + memory_order_acquire = __ATOMIC_ACQUIRE, + memory_order_release = __ATOMIC_RELEASE, + memory_order_acq_rel = __ATOMIC_ACQ_REL, + memory_order_seq_cst = __ATOMIC_SEQ_CST +} memory_order; + +/* + * 7.17.4 Fences. + */ + +static __inline void +atomic_thread_fence(memory_order __order __unused) +{ + +#ifdef __CLANG_ATOMICS + __c11_atomic_thread_fence(__order); +#elif defined(__GNUC_ATOMICS) + __atomic_thread_fence(__order); +#else + __sync_synchronize(); +#endif +} + +static __inline void +atomic_signal_fence(memory_order __order __unused) +{ + +#ifdef __CLANG_ATOMICS + __c11_atomic_signal_fence(__order); +#elif defined(__GNUC_ATOMICS) + __atomic_signal_fence(__order); +#else + __asm volatile ("" ::: "memory"); +#endif +} + +/* + * 7.17.5 Lock-free property. + */ + +#if defined(_KERNEL) +/* Atomics in kernelspace are always lock-free. */ +#define atomic_is_lock_free(obj) \ + ((void)(obj), (_Bool)1) +#elif defined(__CLANG_ATOMICS) +#define atomic_is_lock_free(obj) \ + __atomic_is_lock_free(sizeof(*(obj)), obj) +#elif defined(__GNUC_ATOMICS) +#define atomic_is_lock_free(obj) \ + __atomic_is_lock_free(sizeof((obj)->__val), &(obj)->__val) +#else +#define atomic_is_lock_free(obj) \ + ((void)(obj), sizeof((obj)->__val) <= sizeof(void *)) +#endif + +/* + * 7.17.6 Atomic integer types. + */ + +typedef _Atomic(_Bool) atomic_bool; +typedef _Atomic(char) atomic_char; +typedef _Atomic(signed char) atomic_schar; +typedef _Atomic(unsigned char) atomic_uchar; +typedef _Atomic(short) atomic_short; +typedef _Atomic(unsigned short) atomic_ushort; +typedef _Atomic(int) atomic_int; +typedef _Atomic(unsigned int) atomic_uint; +typedef _Atomic(long) atomic_long; +typedef _Atomic(unsigned long) atomic_ulong; +typedef _Atomic(long long) atomic_llong; +typedef _Atomic(unsigned long long) atomic_ullong; +#if 0 +typedef _Atomic(__char16_t) atomic_char16_t; +typedef _Atomic(__char32_t) atomic_char32_t; +#endif +typedef _Atomic(wchar_t) atomic_wchar_t; +typedef _Atomic(int_least8_t) atomic_int_least8_t; +typedef _Atomic(uint_least8_t) atomic_uint_least8_t; +typedef _Atomic(int_least16_t) atomic_int_least16_t; +typedef _Atomic(uint_least16_t) atomic_uint_least16_t; +typedef _Atomic(int_least32_t) atomic_int_least32_t; +typedef _Atomic(uint_least32_t) atomic_uint_least32_t; +typedef _Atomic(int_least64_t) atomic_int_least64_t; +typedef _Atomic(uint_least64_t) atomic_uint_least64_t; +typedef _Atomic(int_fast8_t) atomic_int_fast8_t; +typedef _Atomic(uint_fast8_t) atomic_uint_fast8_t; +typedef _Atomic(int_fast16_t) atomic_int_fast16_t; +typedef _Atomic(uint_fast16_t) atomic_uint_fast16_t; +typedef _Atomic(int_fast32_t) atomic_int_fast32_t; +typedef _Atomic(uint_fast32_t) atomic_uint_fast32_t; +typedef _Atomic(int_fast64_t) atomic_int_fast64_t; +typedef _Atomic(uint_fast64_t) atomic_uint_fast64_t; +typedef _Atomic(intptr_t) atomic_intptr_t; +typedef _Atomic(uintptr_t) atomic_uintptr_t; +typedef _Atomic(size_t) atomic_size_t; +typedef _Atomic(ptrdiff_t) atomic_ptrdiff_t; +typedef _Atomic(intmax_t) atomic_intmax_t; +typedef _Atomic(uintmax_t) atomic_uintmax_t; + +/* + * 7.17.7 Operations on atomic types. + */ + +/* + * Compiler-specific operations. + */ + +#if defined(__CLANG_ATOMICS) +#define atomic_compare_exchange_strong_explicit(object, expected, \ + desired, success, failure) \ + __c11_atomic_compare_exchange_strong(object, expected, desired, \ + success, failure) +#define atomic_compare_exchange_weak_explicit(object, expected, \ + desired, success, failure) \ + __c11_atomic_compare_exchange_weak(object, expected, desired, \ + success, failure) +#define atomic_exchange_explicit(object, desired, order) \ + __c11_atomic_exchange(object, desired, order) +#define atomic_fetch_add_explicit(object, operand, order) \ + __c11_atomic_fetch_add(object, operand, order) +#define atomic_fetch_and_explicit(object, operand, order) \ + __c11_atomic_fetch_and(object, operand, order) +#define atomic_fetch_or_explicit(object, operand, order) \ + __c11_atomic_fetch_or(object, operand, order) +#define atomic_fetch_sub_explicit(object, operand, order) \ + __c11_atomic_fetch_sub(object, operand, order) +#define atomic_fetch_xor_explicit(object, operand, order) \ + __c11_atomic_fetch_xor(object, operand, order) +#define atomic_load_explicit(object, order) \ + __c11_atomic_load(object, order) +#define atomic_store_explicit(object, desired, order) \ + __c11_atomic_store(object, desired, order) +#elif defined(__GNUC_ATOMICS) +#define atomic_compare_exchange_strong_explicit(object, expected, \ + desired, success, failure) \ + __atomic_compare_exchange_n(&(object)->__val, expected, \ + desired, 0, success, failure) +#define atomic_compare_exchange_weak_explicit(object, expected, \ + desired, success, failure) \ + __atomic_compare_exchange_n(&(object)->__val, expected, \ + desired, 1, success, failure) +#define atomic_exchange_explicit(object, desired, order) \ + __atomic_exchange_n(&(object)->__val, desired, order) +#define atomic_fetch_add_explicit(object, operand, order) \ + __atomic_fetch_add(&(object)->__val, operand, order) +#define atomic_fetch_and_explicit(object, operand, order) \ + __atomic_fetch_and(&(object)->__val, operand, order) +#define atomic_fetch_or_explicit(object, operand, order) \ + __atomic_fetch_or(&(object)->__val, operand, order) +#define atomic_fetch_sub_explicit(object, operand, order) \ + __atomic_fetch_sub(&(object)->__val, operand, order) +#define atomic_fetch_xor_explicit(object, operand, order) \ + __atomic_fetch_xor(&(object)->__val, operand, order) +#define atomic_load_explicit(object, order) \ + __atomic_load_n(&(object)->__val, order) +#define atomic_store_explicit(object, desired, order) \ + __atomic_store_n(&(object)->__val, desired, order) +#else +#define __atomic_apply_stride(object, operand) \ + (((__typeof__((object)->__val))0) + (operand)) +#define atomic_compare_exchange_strong_explicit(object, expected, \ + desired, success, failure) __extension__ ({ \ + __typeof__(expected) __ep = (expected); \ + __typeof__(*__ep) __e = *__ep; \ + (void)(success); (void)(failure); \ + (_Bool)((*__ep = __sync_val_compare_and_swap(&(object)->__val, \ + __e, desired)) == __e); \ +}) +#define atomic_compare_exchange_weak_explicit(object, expected, \ + desired, success, failure) \ + atomic_compare_exchange_strong_explicit(object, expected, \ + desired, success, failure) +#if __has_builtin(__sync_swap) +/* Clang provides a full-barrier atomic exchange - use it if available. */ +#define atomic_exchange_explicit(object, desired, order) \ + ((void)(order), __sync_swap(&(object)->__val, desired)) +#else +/* + * __sync_lock_test_and_set() is only an acquire barrier in theory (although in + * practice it is usually a full barrier) so we need an explicit barrier before + * it. + */ +#define atomic_exchange_explicit(object, desired, order) \ +__extension__ ({ \ + __typeof__(object) __o = (object); \ + __typeof__(desired) __d = (desired); \ + (void)(order); \ + __sync_synchronize(); \ + __sync_lock_test_and_set(&(__o)->__val, __d); \ +}) +#endif +#define atomic_fetch_add_explicit(object, operand, order) \ + ((void)(order), __sync_fetch_and_add(&(object)->__val, \ + __atomic_apply_stride(object, operand))) +#define atomic_fetch_and_explicit(object, operand, order) \ + ((void)(order), __sync_fetch_and_and(&(object)->__val, operand)) +#define atomic_fetch_or_explicit(object, operand, order) \ + ((void)(order), __sync_fetch_and_or(&(object)->__val, operand)) +#define atomic_fetch_sub_explicit(object, operand, order) \ + ((void)(order), __sync_fetch_and_sub(&(object)->__val, \ + __atomic_apply_stride(object, operand))) +#define atomic_fetch_xor_explicit(object, operand, order) \ + ((void)(order), __sync_fetch_and_xor(&(object)->__val, operand)) +#define atomic_load_explicit(object, order) \ + ((void)(order), __sync_fetch_and_add(&(object)->__val, 0)) +#define atomic_store_explicit(object, desired, order) \ + ((void)atomic_exchange_explicit(object, desired, order)) +#endif + +/* + * Convenience functions. + * + * Don't provide these in kernel space. In kernel space, we should be + * disciplined enough to always provide explicit barriers. + */ + +#ifndef _KERNEL +#define atomic_compare_exchange_strong(object, expected, desired) \ + atomic_compare_exchange_strong_explicit(object, expected, \ + desired, memory_order_seq_cst, memory_order_seq_cst) +#define atomic_compare_exchange_weak(object, expected, desired) \ + atomic_compare_exchange_weak_explicit(object, expected, \ + desired, memory_order_seq_cst, memory_order_seq_cst) +#define atomic_exchange(object, desired) \ + atomic_exchange_explicit(object, desired, memory_order_seq_cst) +#define atomic_fetch_add(object, operand) \ + atomic_fetch_add_explicit(object, operand, memory_order_seq_cst) +#define atomic_fetch_and(object, operand) \ + atomic_fetch_and_explicit(object, operand, memory_order_seq_cst) +#define atomic_fetch_or(object, operand) \ + atomic_fetch_or_explicit(object, operand, memory_order_seq_cst) +#define atomic_fetch_sub(object, operand) \ + atomic_fetch_sub_explicit(object, operand, memory_order_seq_cst) +#define atomic_fetch_xor(object, operand) \ + atomic_fetch_xor_explicit(object, operand, memory_order_seq_cst) +#define atomic_load(object) \ + atomic_load_explicit(object, memory_order_seq_cst) +#define atomic_store(object, desired) \ + atomic_store_explicit(object, desired, memory_order_seq_cst) +#endif /* !_KERNEL */ + +/* + * 7.17.8 Atomic flag type and operations. + * + * XXX: Assume atomic_bool can be used as an atomic_flag. Is there some + * kind of compiler built-in type we could use? + */ + +typedef struct { + atomic_bool __flag; +} atomic_flag; + +#define ATOMIC_FLAG_INIT { ATOMIC_VAR_INIT(0) } + +static __inline _Bool +atomic_flag_test_and_set_explicit(volatile atomic_flag *__object, + memory_order __order) +{ + return (atomic_exchange_explicit(&__object->__flag, 1, __order)); +} + +static __inline void +atomic_flag_clear_explicit(volatile atomic_flag *__object, memory_order __order) +{ + + atomic_store_explicit(&__object->__flag, 0, __order); +} + +#ifndef _KERNEL +static __inline _Bool +atomic_flag_test_and_set(volatile atomic_flag *__object) +{ + + return (atomic_flag_test_and_set_explicit(__object, + memory_order_seq_cst)); +} + +static __inline void +atomic_flag_clear(volatile atomic_flag *__object) +{ + + atomic_flag_clear_explicit(__object, memory_order_seq_cst); +} +#endif /* !_KERNEL */ + +#endif /* !_STDATOMIC_H_ */ diff --git a/contrib/sdk/sources/newlib/libc/include/stdint.h b/contrib/sdk/sources/newlib/libc/include/stdint.h index f15f735081..6ec6c1e469 100644 --- a/contrib/sdk/sources/newlib/libc/include/stdint.h +++ b/contrib/sdk/sources/newlib/libc/include/stdint.h @@ -9,13 +9,13 @@ #ifndef _STDINT_H #define _STDINT_H +#include + #ifdef __cplusplus extern "C" { #endif -#if defined(__GNUC__) && \ - ( (__GNUC__ >= 4) || \ - ( (__GNUC__ >= 3) && defined(__GNUC_MINOR__) && (__GNUC_MINOR__ > 2) ) ) +#if __GNUC_PREREQ (3, 2) /* gcc > 3.2 implicitly defines the values we are interested */ #define __STDINT_EXP(x) __##x##__ #else @@ -35,119 +35,54 @@ extern "C" { #define __have_long64 1 #elif __STDINT_EXP(LONG_MAX) == 0x7fffffff && !defined(__SPU__) #define __have_long32 1 -#define __have_long64 0 #endif -#if __STDINT_EXP(SCHAR_MAX) == 0x7f -typedef signed char int8_t ; -typedef unsigned char uint8_t ; +#ifdef ___int8_t_defined +typedef __int8_t int8_t ; +typedef __uint8_t uint8_t ; #define __int8_t_defined 1 #endif -#if __int8_t_defined -typedef signed char int_least8_t; -typedef unsigned char uint_least8_t; +#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 -#if __STDINT_EXP(SHRT_MAX) == 0x7fff -typedef signed short int16_t; -typedef unsigned short uint16_t; -#define __int16_t_defined 1 -#elif __STDINT_EXP(INT_MAX) == 0x7fff -typedef signed int int16_t; -typedef unsigned int uint16_t; -#define __int16_t_defined 1 -#elif __STDINT_EXP(SCHAR_MAX) == 0x7fff -typedef signed char int16_t; -typedef unsigned char uint16_t; +#ifdef ___int16_t_defined +typedef __int16_t int16_t ; +typedef __uint16_t uint16_t ; #define __int16_t_defined 1 #endif -#if __int16_t_defined -typedef int16_t int_least16_t; -typedef uint16_t uint_least16_t; +#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 - -#if !__int_least8_t_defined -typedef int16_t int_least8_t; -typedef uint16_t uint_least8_t; -#define __int_least8_t_defined 1 -#endif #endif -//#if __have_long32 -//typedef signed long int32_t; -//typedef unsigned long uint32_t; -//#define __int32_t_defined 1 -//#elif __STDINT_EXP(INT_MAX) == 0x7fffffffL -typedef signed int int32_t; -typedef unsigned int uint32_t; +#ifdef ___int32_t_defined +typedef __int32_t int32_t ; +typedef __uint32_t uint32_t ; #define __int32_t_defined 1 -//#elif __STDINT_EXP(SHRT_MAX) == 0x7fffffffL -//typedef signed short int32_t; -//typedef unsigned short uint32_t; -//#define __int32_t_defined 1 -//#elif __STDINT_EXP(SCHAR_MAX) == 0x7fffffffL -//typedef signed char int32_t; -//typedef unsigned char uint32_t; -//#define __int32_t_defined 1 -//#endif +#endif -#if __int32_t_defined -typedef int32_t int_least32_t; -typedef uint32_t uint_least32_t; +#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 - -#if !__int_least8_t_defined -typedef int32_t int_least8_t; -typedef uint32_t uint_least8_t; -#define __int_least8_t_defined 1 #endif -#if !__int_least16_t_defined -typedef int32_t int_least16_t; -typedef uint32_t uint_least16_t; -#define __int_least16_t_defined 1 -#endif -#endif - -#if __have_long64 -typedef signed long int64_t; -typedef unsigned long uint64_t; -#define __int64_t_defined 1 -#elif __have_longlong64 -typedef signed long long int64_t; -typedef unsigned long long uint64_t; -#define __int64_t_defined 1 -#elif __STDINT_EXP(INT_MAX) > 0x7fffffff -typedef signed int int64_t; -typedef unsigned int uint64_t; +#ifdef ___int64_t_defined +typedef __int64_t int64_t ; +typedef __uint64_t uint64_t ; #define __int64_t_defined 1 #endif -#if __int64_t_defined -typedef int64_t int_least64_t; -typedef uint64_t uint_least64_t; +#ifdef ___int_least64_t_defined +typedef __int_least64_t int_least64_t; +typedef __uint_least64_t uint_least64_t; #define __int_least64_t_defined 1 - -#if !__int_least8_t_defined -typedef int64_t int_least8_t; -typedef uint64_t uint_least8_t; -#define __int_least8_t_defined 1 -#endif - -#if !__int_least16_t_defined -typedef int64_t int_least16_t; -typedef uint64_t uint_least16_t; -#define __int_least16_t_defined 1 -#endif - -#if !__int_least32_t_defined -typedef int64_t int_least32_t; -typedef uint64_t uint_least32_t; -#define __int_least32_t_defined 1 -#endif #endif /* @@ -156,30 +91,44 @@ typedef uint64_t uint_least32_t; * Assume int to be the fastest type for all types with a width * less than __INT_MAX__ rsp. INT_MAX */ -#if __STDINT_EXP(INT_MAX) >= 0x7f +#ifdef __INT_FAST8_TYPE__ + typedef __INT_FAST8_TYPE__ int_fast8_t; + typedef __UINT_FAST8_TYPE__ uint_fast8_t; +#define __int_fast8_t_defined 1 +#elif __STDINT_EXP(INT_MAX) >= 0x7f typedef signed int int_fast8_t; typedef unsigned int uint_fast8_t; #define __int_fast8_t_defined 1 #endif -#if __STDINT_EXP(INT_MAX) >= 0x7fff +#ifdef __INT_FAST16_TYPE__ + typedef __INT_FAST16_TYPE__ int_fast16_t; + typedef __UINT_FAST16_TYPE__ uint_fast16_t; +#define __int_fast16_t_defined 1 +#elif __STDINT_EXP(INT_MAX) >= 0x7fff typedef signed int int_fast16_t; typedef unsigned int uint_fast16_t; #define __int_fast16_t_defined 1 #endif -#if __STDINT_EXP(INT_MAX) >= 0x7fffffff +#ifdef __INT_FAST32_TYPE__ + typedef __INT_FAST32_TYPE__ int_fast32_t; + typedef __UINT_FAST32_TYPE__ uint_fast32_t; +#define __int_fast32_t_defined 1 +#elif __STDINT_EXP(INT_MAX) >= 0x7fffffff typedef signed int int_fast32_t; typedef unsigned int uint_fast32_t; #define __int_fast32_t_defined 1 #endif -#if __STDINT_EXP(INT_MAX) > 0x7fffffff +#ifdef __INT_FAST64_TYPE__ + typedef __INT_FAST64_TYPE__ int_fast64_t; + typedef __UINT_FAST64_TYPE__ uint_fast64_t; +#define __int_fast64_t_defined 1 +#elif __STDINT_EXP(INT_MAX) > 0x7fffffff typedef signed int int_fast64_t; typedef unsigned int uint_fast64_t; #define __int_fast64_t_defined 1 -#else -#define __int_fast64_t_defined 0 #endif /* @@ -215,7 +164,6 @@ typedef uint64_t uint_least32_t; #if __int_least64_t_defined typedef int_least64_t int_fast64_t; typedef uint_least64_t uint_fast64_t; -#undef __int_fast64_t_defined #define __int_fast64_t_defined 1 #endif #endif @@ -239,13 +187,14 @@ typedef uint64_t uint_least32_t; typedef unsigned long uintmax_t; #endif -/* - * GCC doesn't provide an appropriate macro for [u]intptr_t - * For now, use __PTRDIFF_TYPE__ - */ -#if defined(__PTRDIFF_TYPE__) -typedef signed __PTRDIFF_TYPE__ intptr_t; -typedef unsigned __PTRDIFF_TYPE__ uintptr_t; +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__ +#elif defined(__PTRDIFF_TYPE__) #define INTPTR_MAX PTRDIFF_MAX #define INTPTR_MIN PTRDIFF_MIN #ifdef __UINTPTR_MAX__ @@ -258,8 +207,6 @@ typedef unsigned __PTRDIFF_TYPE__ uintptr_t; * Fallback to hardcoded values, * should be valid on cpu's with 32bit int/32bit void* */ -typedef signed long intptr_t; -typedef unsigned long uintptr_t; #define INTPTR_MAX __STDINT_EXP(LONG_MAX) #define INTPTR_MIN (-__STDINT_EXP(LONG_MAX) - 1) #define UINTPTR_MAX (__STDINT_EXP(LONG_MAX) * 2UL + 1) @@ -267,13 +214,21 @@ typedef unsigned long uintptr_t; /* Limits of Specified-Width Integer Types */ -#if __int8_t_defined +#ifdef __INT8_MAX__ +#define INT8_MIN (-__INT8_MAX__ - 1) +#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 #endif -#if __int_least8_t_defined +#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__ +#elif defined(__int_least8_t_defined) #define INT_LEAST8_MIN -128 #define INT_LEAST8_MAX 127 #define UINT_LEAST8_MAX 255 @@ -281,13 +236,21 @@ typedef unsigned long uintptr_t; #error required type int_least8_t missing #endif -#if __int16_t_defined +#ifdef __INT16_MAX__ +#define INT16_MIN (-__INT16_MAX__ - 1) +#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 #endif -#if __int_least16_t_defined +#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__ +#elif defined(__int_least16_t_defined) #define INT_LEAST16_MIN -32768 #define INT_LEAST16_MAX 32767 #define UINT_LEAST16_MAX 65535 @@ -295,7 +258,11 @@ typedef unsigned long uintptr_t; #error required type int_least16_t missing #endif -#if __int32_t_defined +#ifdef __INT32_MAX__ +#define INT32_MIN (-__INT32_MAX__ - 1) +#define INT32_MAX __INT32_MAX__ +#define UINT32_MAX __UINT32_MAX__ +#elif defined(__int32_t_defined) #if __have_long32 #define INT32_MIN (-2147483647L-1) #define INT32_MAX 2147483647L @@ -307,7 +274,11 @@ typedef unsigned long uintptr_t; #endif #endif -#if __int_least32_t_defined +#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__ +#elif defined(__int_least32_t_defined) #if __have_long32 #define INT_LEAST32_MIN (-2147483647L-1) #define INT_LEAST32_MAX 2147483647L @@ -321,7 +292,11 @@ typedef unsigned long uintptr_t; #error required type int_least32_t missing #endif -#if __int64_t_defined +#ifdef __INT64_MAX__ +#define INT64_MIN (-__INT64_MAX__ - 1) +#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 @@ -333,7 +308,11 @@ typedef unsigned long uintptr_t; #endif #endif -#if __int_least64_t_defined +#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__ +#elif defined(__int_least64_t_defined) #if __have_long64 #define INT_LEAST64_MIN (-9223372036854775807L-1L) #define INT_LEAST64_MAX 9223372036854775807L @@ -345,7 +324,11 @@ typedef unsigned long uintptr_t; #endif #endif -#if __int_fast8_t_defined +#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__ +#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) @@ -357,7 +340,11 @@ typedef unsigned long uintptr_t; #endif #endif -#if __int_fast16_t_defined +#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__ +#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) @@ -369,7 +356,11 @@ typedef unsigned long uintptr_t; #endif #endif -#if __int_fast32_t_defined +#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__ +#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) @@ -381,7 +372,11 @@ typedef unsigned long uintptr_t; #endif #endif -#if __int_fast64_t_defined +#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__ +#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) @@ -448,20 +443,34 @@ typedef unsigned long uintptr_t; #endif /** Macros for minimum-width integer constant expressions */ +#ifdef __INT8_C +#define INT8_C(x) __INT8_C(x) +#define UINT8_C(x) __UINT8_C(x) +#else #define INT8_C(x) x #if __STDINT_EXP(INT_MAX) > 0x7f #define UINT8_C(x) x #else #define UINT8_C(x) x##U #endif +#endif +#ifdef __INT16_C +#define INT16_C(x) __INT16_C(x) +#define UINT16_C(x) __UINT16_C(x) +#else #define INT16_C(x) x #if __STDINT_EXP(INT_MAX) > 0x7fff #define UINT16_C(x) x #else #define UINT16_C(x) x##U #endif +#endif +#ifdef __INT32_C +#define INT32_C(x) __INT32_C(x) +#define UINT32_C(x) __UINT32_C(x) +#else #if __have_long32 #define INT32_C(x) x##L #define UINT32_C(x) x##UL @@ -469,7 +478,12 @@ typedef unsigned long uintptr_t; #define INT32_C(x) x #define UINT32_C(x) x##U #endif +#endif +#ifdef __INT64_C +#define INT64_C(x) __INT64_C(x) +#define UINT64_C(x) __UINT64_C(x) +#else #if __int64_t_defined #if __have_long64 #define INT64_C(x) x##L @@ -479,8 +493,13 @@ typedef unsigned long uintptr_t; #define UINT64_C(x) x##ULL #endif #endif +#endif /** Macros for greatest-width integer constant expression */ +#ifdef __INTMAX_C +#define INTMAX_C(x) __INTMAX_C(x) +#define UINTMAX_C(x) __UINTMAX_C(x) +#else #if __have_long64 #define INTMAX_C(x) x##L #define UINTMAX_C(x) x##UL @@ -488,6 +507,7 @@ typedef unsigned long uintptr_t; #define INTMAX_C(x) x##LL #define UINTMAX_C(x) x##ULL #endif +#endif #ifdef __cplusplus diff --git a/contrib/sdk/sources/newlib/libc/include/stdio.h b/contrib/sdk/sources/newlib/libc/include/stdio.h index ec9ee5f772..c8125e9fa3 100644 --- a/contrib/sdk/sources/newlib/libc/include/stdio.h +++ b/contrib/sdk/sources/newlib/libc/include/stdio.h @@ -31,6 +31,7 @@ #define _FSTDIO /* ``function stdio'' */ #define __need_size_t +#define __need_NULL #include #define __need___va_list @@ -96,10 +97,6 @@ typedef _fpos64_t fpos64_t; #define _IOLBF 1 /* setvbuf should set line buffered */ #define _IONBF 2 /* setvbuf should set unbuffered */ -#ifndef NULL -#define NULL 0 -#endif - #define EOF (-1) #ifdef __BUFSIZ__ @@ -142,15 +139,9 @@ typedef _fpos64_t fpos64_t; #define TMP_MAX 26 -#ifndef _REENT_ONLY #define stdin (_REENT->_stdin) #define stdout (_REENT->_stdout) #define stderr (_REENT->_stderr) -#else /* _REENT_ONLY */ -#define stdin (_impure_ptr->_stdin) -#define stdout (_impure_ptr->_stdout) -#define stderr (_impure_ptr->_stderr) -#endif /* _REENT_ONLY */ #define _stdin_r(x) ((x)->_stdin) #define _stdout_r(x) ((x)->_stdout) @@ -172,29 +163,29 @@ FILE * _EXFUN(tmpfile, (void)); char * _EXFUN(tmpnam, (char *)); int _EXFUN(fclose, (FILE *)); int _EXFUN(fflush, (FILE *)); -FILE * _EXFUN(freopen, (const char *, const char *, FILE *)); -void _EXFUN(setbuf, (FILE *, char *)); -int _EXFUN(setvbuf, (FILE *, char *, int, size_t)); -int _EXFUN(fprintf, (FILE *, const char *, ...) +FILE * _EXFUN(freopen, (const char *__restrict, const char *__restrict, FILE *__restrict)); +void _EXFUN(setbuf, (FILE *__restrict, char *__restrict)); +int _EXFUN(setvbuf, (FILE *__restrict, char *__restrict, int, size_t)); +int _EXFUN(fprintf, (FILE *__restrict, const char *__restrict, ...) _ATTRIBUTE ((__format__ (__printf__, 2, 3)))); -int _EXFUN(fscanf, (FILE *, const char *, ...) +int _EXFUN(fscanf, (FILE *__restrict, const char *__restrict, ...) _ATTRIBUTE ((__format__ (__scanf__, 2, 3)))); -int _EXFUN(printf, (const char *, ...) +int _EXFUN(printf, (const char *__restrict, ...) _ATTRIBUTE ((__format__ (__printf__, 1, 2)))); -int _EXFUN(scanf, (const char *, ...) +int _EXFUN(scanf, (const char *__restrict, ...) _ATTRIBUTE ((__format__ (__scanf__, 1, 2)))); -int _EXFUN(sscanf, (const char *, const char *, ...) +int _EXFUN(sscanf, (const char *__restrict, const char *__restrict, ...) _ATTRIBUTE ((__format__ (__scanf__, 2, 3)))); -int _EXFUN(vfprintf, (FILE *, const char *, __VALIST) +int _EXFUN(vfprintf, (FILE *__restrict, const char *__restrict, __VALIST) _ATTRIBUTE ((__format__ (__printf__, 2, 0)))); int _EXFUN(vprintf, (const char *, __VALIST) _ATTRIBUTE ((__format__ (__printf__, 1, 0)))); -int _EXFUN(vsprintf, (char *, const char *, __VALIST) +int _EXFUN(vsprintf, (char *__restrict, const char *__restrict, __VALIST) _ATTRIBUTE ((__format__ (__printf__, 2, 0)))); int _EXFUN(fgetc, (FILE *)); -char * _EXFUN(fgets, (char *, int, FILE *)); +char * _EXFUN(fgets, (char *__restrict, int, FILE *__restrict)); int _EXFUN(fputc, (int, FILE *)); -int _EXFUN(fputs, (const char *, FILE *)); +int _EXFUN(fputs, (const char *__restrict, FILE *__restrict)); int _EXFUN(getc, (FILE *)); int _EXFUN(getchar, (void)); char * _EXFUN(gets, (char *)); @@ -202,12 +193,12 @@ int _EXFUN(putc, (int, FILE *)); int _EXFUN(putchar, (int)); int _EXFUN(puts, (const char *)); int _EXFUN(ungetc, (int, FILE *)); -size_t _EXFUN(fread, (_PTR, size_t _size, size_t _n, FILE *)); -size_t _EXFUN(fwrite, (const _PTR , size_t _size, size_t _n, FILE *)); +size_t _EXFUN(fread, (_PTR __restrict, size_t _size, size_t _n, FILE *__restrict)); +size_t _EXFUN(fwrite, (const _PTR __restrict , size_t _size, size_t _n, FILE *)); #ifdef _COMPILING_NEWLIB int _EXFUN(fgetpos, (FILE *, _fpos_t *)); #else -int _EXFUN(fgetpos, (FILE *, fpos_t *)); +int _EXFUN(fgetpos, (FILE *__restrict, fpos_t *__restrict)); #endif int _EXFUN(fseek, (FILE *, long, int)); #ifdef _COMPILING_NEWLIB @@ -222,11 +213,14 @@ int _EXFUN(feof, (FILE *)); int _EXFUN(ferror, (FILE *)); void _EXFUN(perror, (const char *)); #ifndef _REENT_ONLY -FILE * _EXFUN(fopen, (const char *_name, const char *_type)); -int _EXFUN(sprintf, (char *, const char *, ...) +FILE * _EXFUN(fopen, (const char *__restrict _name, const char *__restrict _type)); +int _EXFUN(sprintf, (char *__restrict, const char *__restrict, ...) _ATTRIBUTE ((__format__ (__printf__, 2, 3)))); int _EXFUN(remove, (const char *)); int _EXFUN(rename, (const char *, const char *)); +#ifdef _COMPILING_NEWLIB +int _EXFUN(_rename, (const char *, const char *)); +#endif #endif #if !defined(__STRICT_ANSI__) || defined(__USE_XOPEN2K) #ifdef _COMPILING_NEWLIB @@ -243,9 +237,9 @@ int _EXFUN(asiprintf, (char **, const char *, ...) _ATTRIBUTE ((__format__ (__printf__, 2, 3)))); char * _EXFUN(asniprintf, (char *, size_t *, const char *, ...) _ATTRIBUTE ((__format__ (__printf__, 3, 4)))); -char * _EXFUN(asnprintf, (char *, size_t *, const char *, ...) +char * _EXFUN(asnprintf, (char *__restrict, size_t *__restrict, const char *__restrict, ...) _ATTRIBUTE ((__format__ (__printf__, 3, 4)))); -int _EXFUN(asprintf, (char **, const char *, ...) +int _EXFUN(asprintf, (char **__restrict, const char *__restrict, ...) _ATTRIBUTE ((__format__ (__printf__, 2, 3)))); #ifndef diprintf int _EXFUN(diprintf, (int, const char *, ...) @@ -264,7 +258,7 @@ int _EXFUN(siprintf, (char *, const char *, ...) _ATTRIBUTE ((__format__ (__printf__, 2, 3)))); int _EXFUN(siscanf, (const char *, const char *, ...) _ATTRIBUTE ((__format__ (__scanf__, 2, 3)))); -int _EXFUN(snprintf, (char *, size_t, const char *, ...) +int _EXFUN(snprintf, (char *__restrict, size_t, const char *__restrict, ...) _ATTRIBUTE ((__format__ (__printf__, 3, 4)))); int _EXFUN(sniprintf, (char *, size_t, const char *, ...) _ATTRIBUTE ((__format__ (__printf__, 3, 4)))); @@ -283,7 +277,7 @@ int _EXFUN(vfiprintf, (FILE *, const char *, __VALIST) _ATTRIBUTE ((__format__ (__printf__, 2, 0)))); int _EXFUN(vfiscanf, (FILE *, const char *, __VALIST) _ATTRIBUTE ((__format__ (__scanf__, 2, 0)))); -int _EXFUN(vfscanf, (FILE *, const char *, __VALIST) +int _EXFUN(vfscanf, (FILE *__restrict, const char *__restrict, __VALIST) _ATTRIBUTE ((__format__ (__scanf__, 2, 0)))); int _EXFUN(viprintf, (const char *, __VALIST) _ATTRIBUTE ((__format__ (__printf__, 1, 0)))); @@ -297,9 +291,9 @@ int _EXFUN(vsiscanf, (const char *, const char *, __VALIST) _ATTRIBUTE ((__format__ (__scanf__, 2, 0)))); int _EXFUN(vsniprintf, (char *, size_t, const char *, __VALIST) _ATTRIBUTE ((__format__ (__printf__, 3, 0)))); -int _EXFUN(vsnprintf, (char *, size_t, const char *, __VALIST) +int _EXFUN(vsnprintf, (char *__restrict, size_t, const char *__restrict, __VALIST) _ATTRIBUTE ((__format__ (__printf__, 3, 0)))); -int _EXFUN(vsscanf, (const char *, const char *, __VALIST) +int _EXFUN(vsscanf, (const char *__restrict, const char *__restrict, __VALIST) _ATTRIBUTE ((__format__ (__scanf__, 2, 0)))); #endif /* !_REENT_ONLY */ #endif /* !__STRICT_ANSI__ */ @@ -335,17 +329,17 @@ int _EXFUN(putchar_unlocked, (int)); #ifndef __STRICT_ANSI__ # ifndef _REENT_ONLY # ifndef dprintf -int _EXFUN(dprintf, (int, const char *, ...) +int _EXFUN(dprintf, (int, const char *__restrict, ...) _ATTRIBUTE ((__format__ (__printf__, 2, 3)))); # endif -FILE * _EXFUN(fmemopen, (void *, size_t, const char *)); +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__) int _EXFUN(renameat, (int, const char *, int, const char *)); #endif -int _EXFUN(vdprintf, (int, const char *, __VALIST) +int _EXFUN(vdprintf, (int, const char *__restrict, __VALIST) _ATTRIBUTE ((__format__ (__printf__, 2, 0)))); # endif #endif @@ -358,22 +352,22 @@ int _EXFUN(_asiprintf_r, (struct _reent *, char **, const char *, ...) _ATTRIBUTE ((__format__ (__printf__, 3, 4)))); char * _EXFUN(_asniprintf_r, (struct _reent *, char *, size_t *, const char *, ...) _ATTRIBUTE ((__format__ (__printf__, 4, 5)))); -char * _EXFUN(_asnprintf_r, (struct _reent *, char *, size_t *, const char *, ...) +char * _EXFUN(_asnprintf_r, (struct _reent *, char *__restrict, size_t *__restrict, const char *__restrict, ...) _ATTRIBUTE ((__format__ (__printf__, 4, 5)))); -int _EXFUN(_asprintf_r, (struct _reent *, char **, const char *, ...) +int _EXFUN(_asprintf_r, (struct _reent *, char **__restrict, const char *__restrict, ...) _ATTRIBUTE ((__format__ (__printf__, 3, 4)))); int _EXFUN(_diprintf_r, (struct _reent *, int, const char *, ...) _ATTRIBUTE ((__format__ (__printf__, 3, 4)))); -int _EXFUN(_dprintf_r, (struct _reent *, int, const char *, ...) +int _EXFUN(_dprintf_r, (struct _reent *, int, const char *__restrict, ...) _ATTRIBUTE ((__format__ (__printf__, 3, 4)))); int _EXFUN(_fclose_r, (struct _reent *, FILE *)); 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 *)); -char * _EXFUN(_fgets_r, (struct _reent *, char *, int, FILE *)); +char * _EXFUN(_fgets_r, (struct _reent *, char *__restrict, int, FILE *__restrict)); #ifdef _COMPILING_NEWLIB -int _EXFUN(_fgetpos_r, (struct _reent *, FILE *, _fpos_t *)); +int _EXFUN(_fgetpos_r, (struct _reent *, FILE *__restrict, _fpos_t *__restrict)); int _EXFUN(_fsetpos_r, (struct _reent *, FILE *, const _fpos_t *)); #else int _EXFUN(_fgetpos_r, (struct _reent *, FILE *, fpos_t *)); @@ -383,23 +377,23 @@ int _EXFUN(_fiprintf_r, (struct _reent *, FILE *, const char *, ...) _ATTRIBUTE ((__format__ (__printf__, 3, 4)))); int _EXFUN(_fiscanf_r, (struct _reent *, FILE *, const char *, ...) _ATTRIBUTE ((__format__ (__scanf__, 3, 4)))); -FILE * _EXFUN(_fmemopen_r, (struct _reent *, void *, size_t, const char *)); -FILE * _EXFUN(_fopen_r, (struct _reent *, const char *, const char *)); -FILE * _EXFUN(_freopen_r, (struct _reent *, const char *, const char *, FILE *)); -int _EXFUN(_fprintf_r, (struct _reent *, FILE *, const char *, ...) +FILE * _EXFUN(_fmemopen_r, (struct _reent *, void *__restrict, size_t, const char *__restrict)); +FILE * _EXFUN(_fopen_r, (struct _reent *, const char *__restrict, const char *__restrict)); +FILE * _EXFUN(_freopen_r, (struct _reent *, const char *__restrict, const char *__restrict, FILE *__restrict)); +int _EXFUN(_fprintf_r, (struct _reent *, FILE *__restrict, const char *__restrict, ...) _ATTRIBUTE ((__format__ (__printf__, 3, 4)))); int _EXFUN(_fpurge_r, (struct _reent *, FILE *)); int _EXFUN(_fputc_r, (struct _reent *, int, FILE *)); -int _EXFUN(_fputs_r, (struct _reent *, const char *, FILE *)); -size_t _EXFUN(_fread_r, (struct _reent *, _PTR, size_t _size, size_t _n, FILE *)); -int _EXFUN(_fscanf_r, (struct _reent *, FILE *, const char *, ...) +int _EXFUN(_fputs_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)); +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)); int _EXFUN(_fseeko_r,(struct _reent *, FILE *, _off_t, int)); 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 , size_t _size, size_t _n, FILE *)); +size_t _EXFUN(_fwrite_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 *)); @@ -411,7 +405,7 @@ int _EXFUN(_iscanf_r, (struct _reent *, const char *, ...) _ATTRIBUTE ((__format__ (__scanf__, 2, 3)))); FILE * _EXFUN(_open_memstream_r, (struct _reent *, char **, size_t *)); void _EXFUN(_perror_r, (struct _reent *, const char *)); -int _EXFUN(_printf_r, (struct _reent *, const char *, ...) +int _EXFUN(_printf_r, (struct _reent *, const char *__restrict, ...) _ATTRIBUTE ((__format__ (__printf__, 2, 3)))); int _EXFUN(_putc_r, (struct _reent *, int, FILE *)); int _EXFUN(_putc_unlocked_r, (struct _reent *, int, FILE *)); @@ -421,7 +415,7 @@ int _EXFUN(_puts_r, (struct _reent *, const char *)); int _EXFUN(_remove_r, (struct _reent *, const char *)); int _EXFUN(_rename_r, (struct _reent *, const char *_old, const char *_new)); -int _EXFUN(_scanf_r, (struct _reent *, const char *, ...) +int _EXFUN(_scanf_r, (struct _reent *, const char *__restrict, ...) _ATTRIBUTE ((__format__ (__scanf__, 2, 3)))); int _EXFUN(_siprintf_r, (struct _reent *, char *, const char *, ...) _ATTRIBUTE ((__format__ (__printf__, 3, 4)))); @@ -429,11 +423,11 @@ int _EXFUN(_siscanf_r, (struct _reent *, const char *, const char *, ...) _ATTRIBUTE ((__format__ (__scanf__, 3, 4)))); int _EXFUN(_sniprintf_r, (struct _reent *, char *, size_t, const char *, ...) _ATTRIBUTE ((__format__ (__printf__, 4, 5)))); -int _EXFUN(_snprintf_r, (struct _reent *, char *, size_t, const char *, ...) +int _EXFUN(_snprintf_r, (struct _reent *, char *__restrict, size_t, const char *__restrict, ...) _ATTRIBUTE ((__format__ (__printf__, 4, 5)))); -int _EXFUN(_sprintf_r, (struct _reent *, char *, const char *, ...) +int _EXFUN(_sprintf_r, (struct _reent *, char *__restrict, const char *__restrict, ...) _ATTRIBUTE ((__format__ (__printf__, 3, 4)))); -int _EXFUN(_sscanf_r, (struct _reent *, const char *, const char *, ...) +int _EXFUN(_sscanf_r, (struct _reent *, const char *__restrict, const char *__restrict, ...) _ATTRIBUTE ((__format__ (__scanf__, 3, 4)))); char * _EXFUN(_tempnam_r, (struct _reent *, const char *, const char *)); FILE * _EXFUN(_tmpfile_r, (struct _reent *)); @@ -449,23 +443,23 @@ int _EXFUN(_vasprintf_r, (struct _reent *, char **, const char *, __VALIST) _ATTRIBUTE ((__format__ (__printf__, 3, 0)))); int _EXFUN(_vdiprintf_r, (struct _reent *, int, const char *, __VALIST) _ATTRIBUTE ((__format__ (__printf__, 3, 0)))); -int _EXFUN(_vdprintf_r, (struct _reent *, int, const char *, __VALIST) +int _EXFUN(_vdprintf_r, (struct _reent *, int, const char *__restrict, __VALIST) _ATTRIBUTE ((__format__ (__printf__, 3, 0)))); int _EXFUN(_vfiprintf_r, (struct _reent *, FILE *, const char *, __VALIST) _ATTRIBUTE ((__format__ (__printf__, 3, 0)))); int _EXFUN(_vfiscanf_r, (struct _reent *, FILE *, const char *, __VALIST) _ATTRIBUTE ((__format__ (__scanf__, 3, 0)))); -int _EXFUN(_vfprintf_r, (struct _reent *, FILE *, const char *, __VALIST) +int _EXFUN(_vfprintf_r, (struct _reent *, FILE *__restrict, const char *__restrict, __VALIST) _ATTRIBUTE ((__format__ (__printf__, 3, 0)))); -int _EXFUN(_vfscanf_r, (struct _reent *, FILE *, const char *, __VALIST) +int _EXFUN(_vfscanf_r, (struct _reent *, FILE *__restrict, const char *__restrict, __VALIST) _ATTRIBUTE ((__format__ (__scanf__, 3, 0)))); int _EXFUN(_viprintf_r, (struct _reent *, const char *, __VALIST) _ATTRIBUTE ((__format__ (__printf__, 2, 0)))); int _EXFUN(_viscanf_r, (struct _reent *, const char *, __VALIST) _ATTRIBUTE ((__format__ (__scanf__, 2, 0)))); -int _EXFUN(_vprintf_r, (struct _reent *, const char *, __VALIST) +int _EXFUN(_vprintf_r, (struct _reent *, const char *__restrict, __VALIST) _ATTRIBUTE ((__format__ (__printf__, 2, 0)))); -int _EXFUN(_vscanf_r, (struct _reent *, const char *, __VALIST) +int _EXFUN(_vscanf_r, (struct _reent *, const char *__restrict, __VALIST) _ATTRIBUTE ((__format__ (__scanf__, 2, 0)))); int _EXFUN(_vsiprintf_r, (struct _reent *, char *, const char *, __VALIST) _ATTRIBUTE ((__format__ (__printf__, 3, 0)))); @@ -473,11 +467,11 @@ int _EXFUN(_vsiscanf_r, (struct _reent *, const char *, const char *, __VALIST) _ATTRIBUTE ((__format__ (__scanf__, 3, 0)))); int _EXFUN(_vsniprintf_r, (struct _reent *, char *, size_t, const char *, __VALIST) _ATTRIBUTE ((__format__ (__printf__, 4, 0)))); -int _EXFUN(_vsnprintf_r, (struct _reent *, char *, size_t, const char *, __VALIST) +int _EXFUN(_vsnprintf_r, (struct _reent *, char *__restrict, size_t, const char *__restrict, __VALIST) _ATTRIBUTE ((__format__ (__printf__, 4, 0)))); -int _EXFUN(_vsprintf_r, (struct _reent *, char *, const char *, __VALIST) +int _EXFUN(_vsprintf_r, (struct _reent *, char *__restrict, const char *__restrict, __VALIST) _ATTRIBUTE ((__format__ (__printf__, 3, 0)))); -int _EXFUN(_vsscanf_r, (struct _reent *, const char *, const char *, __VALIST) +int _EXFUN(_vsscanf_r, (struct _reent *, const char *__restrict, const char *__restrict, __VALIST) _ATTRIBUTE ((__format__ (__scanf__, 3, 0)))); /* Other extensions. */ @@ -522,24 +516,32 @@ int _EXFUN(__swbuf_r, (struct _reent *, int, FILE *)); #ifndef __STRICT_ANSI__ # ifdef __LARGE64_FILES FILE *_EXFUN(funopen,(const _PTR __cookie, - int (*__readfn)(_PTR __c, char *__buf, int __n), - int (*__writefn)(_PTR __c, const char *__buf, int __n), + int (*__readfn)(_PTR __c, char *__buf, + _READ_WRITE_BUFSIZE_TYPE __n), + int (*__writefn)(_PTR __c, const char *__buf, + _READ_WRITE_BUFSIZE_TYPE __n), _fpos64_t (*__seekfn)(_PTR __c, _fpos64_t __off, int __whence), int (*__closefn)(_PTR __c))); FILE *_EXFUN(_funopen_r,(struct _reent *, const _PTR __cookie, - int (*__readfn)(_PTR __c, char *__buf, int __n), - int (*__writefn)(_PTR __c, const char *__buf, int __n), + int (*__readfn)(_PTR __c, char *__buf, + _READ_WRITE_BUFSIZE_TYPE __n), + int (*__writefn)(_PTR __c, const char *__buf, + _READ_WRITE_BUFSIZE_TYPE __n), _fpos64_t (*__seekfn)(_PTR __c, _fpos64_t __off, int __whence), int (*__closefn)(_PTR __c))); # else FILE *_EXFUN(funopen,(const _PTR __cookie, - int (*__readfn)(_PTR __cookie, char *__buf, int __n), - int (*__writefn)(_PTR __cookie, const char *__buf, int __n), + int (*__readfn)(_PTR __cookie, char *__buf, + _READ_WRITE_BUFSIZE_TYPE __n), + int (*__writefn)(_PTR __cookie, const char *__buf, + _READ_WRITE_BUFSIZE_TYPE __n), fpos_t (*__seekfn)(_PTR __cookie, fpos_t __off, int __whence), int (*__closefn)(_PTR __cookie))); FILE *_EXFUN(_funopen_r,(struct _reent *, const _PTR __cookie, - int (*__readfn)(_PTR __cookie, char *__buf, int __n), - int (*__writefn)(_PTR __cookie, const char *__buf, int __n), + int (*__readfn)(_PTR __cookie, char *__buf, + _READ_WRITE_BUFSIZE_TYPE __n), + int (*__writefn)(_PTR __cookie, const char *__buf, + _READ_WRITE_BUFSIZE_TYPE __n), fpos_t (*__seekfn)(_PTR __cookie, fpos_t __off, int __whence), int (*__closefn)(_PTR __cookie))); # endif /* !__LARGE64_FILES */ diff --git a/contrib/sdk/sources/newlib/libc/include/stdio_ext.h b/contrib/sdk/sources/newlib/libc/include/stdio_ext.h index fcfb662a04..a830c88159 100644 --- a/contrib/sdk/sources/newlib/libc/include/stdio_ext.h +++ b/contrib/sdk/sources/newlib/libc/include/stdio_ext.h @@ -17,6 +17,47 @@ _BEGIN_STD_C void _EXFUN(__fpurge,(FILE *)); +/* TODO: + + void _flushlbf (void); + int __fsetlocking (FILE *__fp, int __type); +*/ + +#ifdef __GNUC__ + +_ELIDABLE_INLINE inline size_t +__fbufsize (FILE *__fp) { return (size_t) __fp->_bf._size; } + +_ELIDABLE_INLINE inline int +__freading (FILE *__fp) { return (__fp->_flags & __SRD) != 0; } + +_ELIDABLE_INLINE inline int +__fwriting (FILE *__fp) { return (__fp->_flags & __SWR) != 0; } + +_ELIDABLE_INLINE 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 inline int +__flbf (FILE *__fp) { return (__fp->_flags & __SLBF) != 0; } + +_ELIDABLE_INLINE inline size_t +__fpending (FILE *__fp) { return __fp->_p - __fp->_bf._base; } + +#else + +#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 __flbf(__fp) (((__fp)->_flags & __SLBF) != 0) +#define __fpending(__fp) ((size_t) ((__fp)->_p - (__fp)->_bf._base)) + +#endif /* __GNUC__ */ + _END_STD_C #endif /* _STDIO_EXT_H_ */ diff --git a/contrib/sdk/sources/newlib/libc/include/stdlib.h b/contrib/sdk/sources/newlib/libc/include/stdlib.h index 9f55e286f8..901277f28e 100644 --- a/contrib/sdk/sources/newlib/libc/include/stdlib.h +++ b/contrib/sdk/sources/newlib/libc/include/stdlib.h @@ -12,6 +12,7 @@ #define __need_size_t #define __need_wchar_t +#define __need_NULL #include #include @@ -38,7 +39,9 @@ typedef struct long rem; /* remainder */ } ldiv_t; -#ifndef __STRICT_ANSI__ +#if !defined(__STRICT_ANSI__) || \ + (defined(__STDC_VERSION__) && __STDC_VERSION__ >= 199901L) || \ + (defined(__cplusplus) && __cplusplus >= 201103L) typedef struct { long long int quot; /* quotient */ @@ -46,8 +49,9 @@ typedef struct } lldiv_t; #endif -#ifndef NULL -#define NULL 0 +#ifndef __compar_fn_t_defined +#define __compar_fn_t_defined +typedef int (*__compar_fn_t) (const _PTR, const _PTR); #endif #define EXIT_FAILURE 1 @@ -74,7 +78,7 @@ _PTR _EXFUN(bsearch,(const _PTR __key, const _PTR __base, size_t __nmemb, size_t __size, - int _EXFNPTR(_compar,(const _PTR, const _PTR)))); + __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))); @@ -92,14 +96,14 @@ ldiv_t _EXFUN(ldiv,(long __numer, long __denom)); _PTR _EXFUN_NOTHROW(malloc,(size_t __size)); int _EXFUN(mblen,(const char *, size_t)); int _EXFUN(_mblen_r,(struct _reent *, const char *, size_t, _mbstate_t *)); -int _EXFUN(mbtowc,(wchar_t *, const char *, size_t)); -int _EXFUN(_mbtowc_r,(struct _reent *, wchar_t *, const char *, size_t, _mbstate_t *)); +int _EXFUN(mbtowc,(wchar_t *__restrict, const char *__restrict, size_t)); +int _EXFUN(_mbtowc_r,(struct _reent *, wchar_t *__restrict, const char *__restrict, size_t, _mbstate_t *)); int _EXFUN(wctomb,(char *, wchar_t)); int _EXFUN(_wctomb_r,(struct _reent *, char *, wchar_t, _mbstate_t *)); -size_t _EXFUN(mbstowcs,(wchar_t *, const char *, size_t)); -size_t _EXFUN(_mbstowcs_r,(struct _reent *, wchar_t *, const char *, size_t, _mbstate_t *)); -size_t _EXFUN(wcstombs,(char *, const wchar_t *, size_t)); -size_t _EXFUN(_wcstombs_r,(struct _reent *, char *, const wchar_t *, size_t, _mbstate_t *)); +size_t _EXFUN(mbstowcs,(wchar_t *__restrict, const char *__restrict, size_t)); +size_t _EXFUN(_mbstowcs_r,(struct _reent *, wchar_t *__restrict, const char *__restrict, size_t, _mbstate_t *)); +size_t _EXFUN(wcstombs,(char *__restrict, const wchar_t *__restrict, size_t)); +size_t _EXFUN(_wcstombs_r,(struct _reent *, char *__restrict, const wchar_t *__restrict, size_t, _mbstate_t *)); #ifndef __STRICT_ANSI__ #ifndef _REENT_ONLY char * _EXFUN(mkdtemp,(char *)); @@ -116,26 +120,29 @@ 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")))); #endif -_VOID _EXFUN(qsort,(_PTR __base, size_t __nmemb, size_t __size, int(*_compar)(const _PTR, const _PTR))); +_VOID _EXFUN(qsort,(_PTR __base, size_t __nmemb, size_t __size, __compar_fn_t _compar)); int _EXFUN(rand,(_VOID)); _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)); #endif _VOID _EXFUN(srand,(unsigned __seed)); -double _EXFUN(strtod,(const char *__n, char **__end_PTR)); -double _EXFUN(_strtod_r,(struct _reent *,const char *__n, char **__end_PTR)); -float _EXFUN(strtof,(const char *__n, char **__end_PTR)); +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) +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 # define strtodf strtof # endif #endif -long _EXFUN(strtol,(const char *__n, char **__end_PTR, int __base)); -long _EXFUN(_strtol_r,(struct _reent *,const char *__n, char **__end_PTR, int __base)); -unsigned long _EXFUN(strtoul,(const char *__n, char **__end_PTR, int __base)); -unsigned long _EXFUN(_strtoul_r,(struct _reent *,const char *__n, char **__end_PTR, int __base)); +long _EXFUN(strtol,(const char *__restrict __n, char **__restrict __end_PTR, int __base)); +long _EXFUN(_strtol_r,(struct _reent *,const char *__restrict __n, char **__restrict __end_PTR, int __base)); +unsigned long _EXFUN(strtoul,(const char *__restrict __n, char **__restrict __end_PTR, int __base)); +unsigned long _EXFUN(_strtoul_r,(struct _reent *,const char *__restrict __n, char **__restrict __end_PTR, int __base)); int _EXFUN(system,(const char *__string)); @@ -186,10 +193,18 @@ long long _EXFUN(atoll,(const char *__nptr)); long long _EXFUN(_atoll_r,(struct _reent *, const char *__nptr)); long long _EXFUN(llabs,(long long)); lldiv_t _EXFUN(lldiv,(long long __numer, long long __denom)); -long long _EXFUN(strtoll,(const char *__n, char **__end_PTR, int __base)); -long long _EXFUN(_strtoll_r,(struct _reent *, const char *__n, char **__end_PTR, int __base)); -unsigned long long _EXFUN(strtoull,(const char *__n, char **__end_PTR, int __base)); -unsigned long long _EXFUN(_strtoull_r,(struct _reent *, const char *__n, char **__end_PTR, int __base)); +#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) +unsigned long long _EXFUN(strtoull,(const char *__restrict __n, char **__restrict __end_PTR, int __base)); +#endif +#ifndef __STRICT_ANSI__ +unsigned long long _EXFUN(_strtoull_r,(struct _reent *, const char *__restrict __n, char **__restrict __end_PTR, int __base)); #ifndef __CYGWIN__ _VOID _EXFUN(cfree,(_PTR)); @@ -217,8 +232,9 @@ _VOID _EXFUN(__eprintf,(const char *, const char *, unsigned int, const char *)) /* On platforms where long double equals double. */ #ifdef _LDBL_EQ_DBL -extern long double strtold (const char *, char **); -extern long double wcstold (const wchar_t *, wchar_t **); +#if !defined(__STRICT_ANSI__) || (__STDC_VERSION__ >= 199901L) || (__cplusplus >= 201103L) +extern long double strtold (const char *__restrict, char **__restrict); +#endif #endif /* _LDBL_EQ_DBL */ _END_STD_C diff --git a/contrib/sdk/sources/newlib/libc/include/string.h b/contrib/sdk/sources/newlib/libc/include/string.h index 22a81ac769..752fff0d0c 100644 --- a/contrib/sdk/sources/newlib/libc/include/string.h +++ b/contrib/sdk/sources/newlib/libc/include/string.h @@ -10,63 +10,71 @@ #include "_ansi.h" #include #include +#include #define __need_size_t +#define __need_NULL #include -#ifndef NULL -#define NULL 0 -#endif - _BEGIN_STD_C _PTR _EXFUN(memchr,(const _PTR, int, size_t)); int _EXFUN(memcmp,(const _PTR, const _PTR, size_t)); -_PTR _EXFUN(memcpy,(_PTR, const _PTR, size_t)); +_PTR _EXFUN(memcpy,(_PTR __restrict, const _PTR __restrict, size_t)); _PTR _EXFUN(memmove,(_PTR, const _PTR, size_t)); _PTR _EXFUN(memset,(_PTR, int, size_t)); -char *_EXFUN(strcat,(char *, const char *)); +char *_EXFUN(strcat,(char *__restrict, const char *__restrict)); char *_EXFUN(strchr,(const char *, int)); int _EXFUN(strcmp,(const char *, const char *)); int _EXFUN(strcoll,(const char *, const char *)); -char *_EXFUN(strcpy,(char *, const char *)); +char *_EXFUN(strcpy,(char *__restrict, const char *__restrict)); size_t _EXFUN(strcspn,(const char *, const char *)); char *_EXFUN(strerror,(int)); size_t _EXFUN(strlen,(const char *)); -char *_EXFUN(strncat,(char *, const char *, size_t)); +char *_EXFUN(strncat,(char *__restrict, const char *__restrict, size_t)); int _EXFUN(strncmp,(const char *, const char *, size_t)); -char *_EXFUN(strncpy,(char *, const char *, size_t)); +char *_EXFUN(strncpy,(char *__restrict, const char *__restrict, size_t)); 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 *, const char *)); +char *_EXFUN(strtok,(char *__restrict, const char *__restrict)); #endif -size_t _EXFUN(strxfrm,(char *, const char *, size_t)); +size_t _EXFUN(strxfrm,(char *__restrict, const char *__restrict, size_t)); #ifndef __STRICT_ANSI__ -char *_EXFUN(strtok_r,(char *, const char *, char **)); +char *_EXFUN(strtok_r,(char *__restrict, const char *__restrict, char **__restrict)); 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)); -_PTR _EXFUN(memccpy,(_PTR, const _PTR, int, size_t)); +_PTR _EXFUN(memccpy,(_PTR __restrict, const _PTR __restrict, int, size_t)); _PTR _EXFUN(mempcpy,(_PTR, const _PTR, size_t)); _PTR _EXFUN(memmem, (const _PTR, size_t, const _PTR, size_t)); +_PTR _EXFUN(memrchr,(const _PTR, int, size_t)); +_PTR _EXFUN(rawmemchr,(const _PTR, int)); char *_EXFUN(rindex,(const char *, int)); -char *_EXFUN(stpcpy,(char *, const char *)); -char *_EXFUN(stpncpy,(char *, const char *, size_t)); +char *_EXFUN(stpcpy,(char *__restrict, const char *__restrict)); +char *_EXFUN(stpncpy,(char *__restrict, const char *__restrict, size_t)); int _EXFUN(strcasecmp,(const char *, const char *)); char *_EXFUN(strcasestr,(const char *, const char *)); char *_EXFUN(strchrnul,(const char *, int)); +#endif +#if !defined(__STRICT_ANSI__) || (_XOPEN_SOURCE - 0) >= 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 char *_EXFUN(strndup,(const char *, size_t)); +#endif +#ifndef __STRICT_ANSI__ char *_EXFUN(_strndup_r,(struct _reent *, const char *, size_t)); /* There are two common strerror_r variants. If you request _GNU_SOURCE, you get the GNU version; otherwise you get the POSIX 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 cf9c9be479..396208bbb0 100644 --- a/contrib/sdk/sources/newlib/libc/include/sys/_default_fcntl.h +++ b/contrib/sdk/sources/newlib/libc/include/sys/_default_fcntl.h @@ -42,15 +42,6 @@ extern "C" { /* O_NDELAY _FNBIO set in include/fcntl.h */ #define O_NONBLOCK _FNONBLOCK #define O_NOCTTY _FNOCTTY - -#define _FBINARY 0x10000 -#define _FTEXT 0x20000 -#define _FNOINHERIT 0x40000 - -#define O_BINARY _FBINARY -#define O_TEXT _FTEXT -#define O_NOINHERIT _FNOINHERIT - /* For machines which care - */ #if defined (_WIN32) || defined (__CYGWIN__) #define _FBINARY 0x10000 diff --git a/contrib/sdk/sources/newlib/libc/include/sys/_types.h b/contrib/sdk/sources/newlib/libc/include/sys/_types.h index be1c84530b..b18b206476 100644 --- a/contrib/sdk/sources/newlib/libc/include/sys/_types.h +++ b/contrib/sdk/sources/newlib/libc/include/sys/_types.h @@ -16,14 +16,9 @@ typedef long _off_t; #endif -#if defined(__rtems__) -/* device numbers are 32-bit major and and 32-bit minor */ -typedef unsigned long long __dev_t; -#else #ifndef __dev_t_defined typedef short __dev_t; #endif -#endif #ifndef __uid_t_defined typedef unsigned short __uid_t; @@ -52,12 +47,21 @@ typedef _off64_t _fpos64_t; #endif #ifndef __ssize_t_defined +#ifdef __SIZE_TYPE__ +/* If __SIZE_TYPE__ is defined (gcc) we define ssize_t based on size_t. + We simply change "unsigned" to "signed" for this single definition + to make sure ssize_t and size_t only differ by their signedness. */ +#define unsigned signed +typedef __SIZE_TYPE__ _ssize_t; +#undef unsigned +#else #if defined(__INT_MAX__) && __INT_MAX__ == 2147483647 typedef int _ssize_t; #else typedef long _ssize_t; #endif #endif +#endif #define __need_wint_t #include diff --git a/contrib/sdk/sources/newlib/libc/include/sys/cdefs.h b/contrib/sdk/sources/newlib/libc/include/sys/cdefs.h index 3857f51c44..4641263344 100644 --- a/contrib/sdk/sources/newlib/libc/include/sys/cdefs.h +++ b/contrib/sdk/sources/newlib/libc/include/sys/cdefs.h @@ -2,7 +2,7 @@ /* Written 2000 by Werner Almesberger */ -/* +/*- * Copyright (c) 1991, 1993 * The Regents of the University of California. All rights reserved. * @@ -17,10 +17,6 @@ * 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 * may be used to endorse or promote products derived from this software * without specific prior written permission. @@ -38,43 +34,20 @@ * SUCH DAMAGE. * * @(#)cdefs.h 8.8 (Berkeley) 1/9/95 - * $FreeBSD: src/sys/sys/cdefs.h,v 1.54 2002/05/11 03:58:24 alfred Exp $ + * $FreeBSD$ */ -#ifndef _SYS_CDEFS_H -#define _SYS_CDEFS_H +#ifndef _SYS_CDEFS_H_ +#define _SYS_CDEFS_H_ -#define __FBSDID(x) /* nothing */ -/* - * Note: the goal here is not compatibility to K&R C. Since we know that we - * have GCC which understands ANSI C perfectly well, we make use of this. - */ +#include +#include +#include -#define __P(args) args #define __PMT(args) args -#define __const const -#define __signed signed -#define __volatile volatile #define __DOTS , ... #define __THROW -/* - * The __CONCAT macro is used to concatenate parts of symbol names, e.g. - * with "#define OLD(foo) __CONCAT(old,foo)", OLD(foo) produces oldfoo. - * The __CONCAT macro is a bit tricky to use if it must work in non-ANSI - * mode -- there must be no spaces between its arguments, and for nested - * __CONCAT's, all the __CONCAT's must be at the left. __CONCAT can also - * concatenate double-quoted strings produced by the __STRING macro, but - * this only works with ANSI C. - * - * __XSTRING is like __STRING, but it expands any macros in its argument - * first. It is only available with 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 */ - #ifdef __GNUC__ # define __ASMNAME(cname) __XSTRING (__USER_LABEL_PREFIX__) cname #endif @@ -87,23 +60,452 @@ #define __attribute_format_strfmon__(a,b) #define __flexarr [0] -#ifdef __cplusplus -# define __BEGIN_DECLS extern "C" { -# define __END_DECLS } -#else -# define __BEGIN_DECLS -# define __END_DECLS -#endif - #ifndef __BOUNDED_POINTERS__ # define __bounded /* nothing */ # define __unbounded /* nothing */ # define __ptrvalue /* nothing */ #endif -#ifdef __GNUC__ +/* + * Testing against Clang-specific extensions. + */ + +#ifndef __has_extension +#define __has_extension __has_feature +#endif +#ifndef __has_feature +#define __has_feature(x) 0 +#endif +#ifndef __has_include +#define __has_include(x) 0 +#endif +#ifndef __has_builtin +#define __has_builtin(x) 0 +#endif + +#if defined(__cplusplus) +#define __BEGIN_DECLS extern "C" { +#define __END_DECLS } +#else +#define __BEGIN_DECLS +#define __END_DECLS +#endif + +/* + * This code has been put in place to help reduce the addition of + * compiler specific defines in FreeBSD code. It helps to aid in + * having a compiler-agnostic source tree. + */ + +#if defined(__GNUC__) || defined(__INTEL_COMPILER) + +#if __GNUC__ >= 3 || defined(__INTEL_COMPILER) +#define __GNUCLIKE_ASM 3 +#define __GNUCLIKE_MATH_BUILTIN_CONSTANTS +#else +#define __GNUCLIKE_ASM 2 +#endif +#define __GNUCLIKE___TYPEOF 1 +#define __GNUCLIKE___OFFSETOF 1 +#define __GNUCLIKE___SECTION 1 + +#ifndef __INTEL_COMPILER +# 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 + +#if (__GNUC_MINOR__ > 95 || __GNUC__ >= 3) && !defined(__INTEL_COMPILER) +# 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 +#endif + +/* + * Compiler memory barriers, specific to gcc and clang. + */ +#if defined(__GNUC__) +#define __compiler_membar() __asm __volatile(" " : : : "memory") +#endif + +#ifndef __INTEL_COMPILER +# define __GNUCLIKE_BUILTIN_NEXT_ARG 1 +# define __GNUCLIKE_MATH_BUILTIN_RELOPS +#endif + +#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___FUNC__ 1 +#define __CC_SUPPORTS_WARNING 1 + +#define __CC_SUPPORTS_VARADIC_XXX 1 /* see varargs.h */ + +#define __CC_SUPPORTS_DYNAMIC_ARRAY_INIT 1 + +#endif /* __GNUC__ || __INTEL_COMPILER */ + +/* + * The __CONCAT macro is used to concatenate parts of symbol names, e.g. + * with "#define OLD(foo) __CONCAT(old,foo)", OLD(foo) produces oldfoo. + * The __CONCAT macro is a bit tricky to use if it must work in non-ANSI + * mode -- there must be no spaces between its arguments, and for nested + * __CONCAT's, all the __CONCAT's must be at the left. __CONCAT can also + * concatenate double-quoted strings produced by the __STRING macro, but + * this only works with ANSI C. + * + * __XSTRING is like __STRING, but it expands any macros in its argument + * first. It is only available with ANSI C. + */ +#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 __const const /* define reserved names to standard */ +#define __signed signed +#define __volatile volatile +#if defined(__cplusplus) +#define __inline inline /* convert to C++ keyword */ +#else +#if !(defined(__CC_SUPPORTS___INLINE)) +#define __inline /* delete GCC keyword */ +#endif /* ! __CC_SUPPORTS___INLINE */ +#endif /* !__cplusplus */ + +#else /* !(__STDC__ || __cplusplus) */ +#define __P(protos) () /* traditional C preprocessor */ +#define __CONCAT(x,y) x/**/y +#define __STRING(x) "x" + +#if !defined(__CC_SUPPORTS___INLINE) +#define __const /* delete pseudo-ANSI C keywords */ +#define __inline +#define __signed +#define __volatile +/* + * In non-ANSI C environments, new programs will want ANSI-only C keywords + * deleted from the program and old programs will want them left alone. + * When using a compiler other than gcc, programs using the ANSI C keywords + * const, inline etc. as normal identifiers should define -DNO_ANSI_KEYWORDS. + * When using "gcc -traditional", we assume that this is the intent; if + * __GNUC__ is defined but __STDC__ is not, we leave the new keywords alone. + */ +#ifndef NO_ANSI_KEYWORDS +#define const /* delete ANSI C keywords */ +#define inline +#define signed +#define volatile +#endif /* !NO_ANSI_KEYWORDS */ +#endif /* !__CC_SUPPORTS___INLINE */ +#endif /* !(__STDC__ || __cplusplus) */ + +/* + * Compiler-dependent macros to help declare dead (non-returning) and + * pure (no side effects) functions, and unused variables. They are + * null except for versions of gcc that are known to support the features + * properly (old versions of gcc-2 supported the dead and pure features + * in a different (wrong) way). If we do not provide an implementation + * for a given compiler, let the compile fail if it is told to use + * a feature that we cannot live without. + */ +#ifdef lint +#define __dead2 +#define __pure2 +#define __unused +#define __packed +#define __aligned(x) +#define __section(x) +#else +#if !__GNUC_PREREQ__(2, 5) && !defined(__INTEL_COMPILER) +#define __dead2 +#define __pure2 +#define __unused +#endif +#if __GNUC__ == 2 && __GNUC_MINOR__ >= 5 && __GNUC_MINOR__ < 7 && !defined(__INTEL_COMPILER) +#define __dead2 __attribute__((__noreturn__)) +#define __pure2 __attribute__((__const__)) +#define __unused +/* XXX Find out what to do for __packed, __aligned and __section */ +#endif +#if __GNUC_PREREQ__(2, 7) +#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))) +#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))) +#endif +#endif + +#if !__GNUC_PREREQ__(2, 95) +#define __alignof(x) __offsetof(struct { char __a; x __b; }, __b) +#endif + +/* + * Keywords added in C11. + */ + +#if !defined(__STDC_VERSION__) || __STDC_VERSION__ < 201112L + +#if !__has_extension(c_alignas) +#if (defined(__cplusplus) && __cplusplus >= 201103L) || \ + __has_extension(cxx_alignas) +#define _Alignas(x) alignas(x) +#else +/* XXX: Only emulates _Alignas(constant-expression); not _Alignas(type-name). */ +#define _Alignas(x) __aligned(x) +#endif +#endif + +#if defined(__cplusplus) && __cplusplus >= 201103L +#define _Alignof(x) alignof(x) +#else +#define _Alignof(x) __alignof(x) +#endif + +#if !__has_extension(c_atomic) && !__has_extension(cxx_atomic) +/* + * No native support for _Atomic(). Place object in structure to prevent + * most forms of direct non-atomic access. + */ +#define _Atomic(T) struct { T volatile __val; } +#endif + +#if defined(__cplusplus) && __cplusplus >= 201103L +#define _Noreturn [[noreturn]] +#else +#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 (defined(__cplusplus) && __cplusplus >= 201103L) || \ + __has_extension(cxx_static_assert) +#define _Static_assert(x, y) static_assert(x, y) +#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] +#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. */ +#if /* (defined(__cplusplus) && __cplusplus >= 201103L) || */ \ + __has_extension(cxx_thread_local) +#define _Thread_local thread_local +#else +#define _Thread_local __thread +#endif +#endif + +#endif /* __STDC_VERSION__ || __STDC_VERSION__ < 201112L */ + +/* + * Emulation of C11 _Generic(). Unlike the previously defined C11 + * keywords, it is not possible to implement this using exactly the same + * syntax. Therefore implement something similar under the name + * __generic(). Unlike _Generic(), this macro can only distinguish + * between a single type, so it requires nested invocations to + * distinguish multiple cases. + */ + +#if defined(__STDC_VERSION__) && __STDC_VERSION__ >= 201112L +#define __generic(expr, t, yes, no) \ + _Generic(expr, t: yes, default: no) +#elif __GNUC_PREREQ__(3, 1) && !defined(__cplusplus) +#define __generic(expr, t, yes, no) \ + __builtin_choose_expr( \ + __builtin_types_compatible_p(__typeof(expr), t), yes, no) +#endif + +#if __GNUC_PREREQ__(2, 96) +#define __malloc_like __attribute__((__malloc__)) +#define __pure __attribute__((__pure__)) +#else +#define __malloc_like +#define __pure +#endif + +#if __GNUC_PREREQ__(3, 1) || (defined(__INTEL_COMPILER) && __INTEL_COMPILER >= 800) +#define __always_inline __attribute__((__always_inline__)) +#else +#define __always_inline +#endif + +#if __GNUC_PREREQ__(3, 1) +#define __noinline __attribute__ ((__noinline__)) +#else +#define __noinline +#endif + +#if __GNUC_PREREQ__(3, 3) +#define __nonnull(x) __attribute__((__nonnull__(x))) +#else +#define __nonnull(x) +#endif + +#if __GNUC_PREREQ__(3, 4) +#define __fastcall __attribute__((__fastcall__)) +#else +#define __fastcall +#endif + +#if __GNUC_PREREQ__(4, 1) +#define __returns_twice __attribute__((__returns_twice__)) +#else +#define __returns_twice +#endif + +/* XXX: should use `#if __STDC_VERSION__ < 199901'. */ +#if !__GNUC_PREREQ__(2, 7) && !defined(__INTEL_COMPILER) +#define __func__ NULL +#endif + +/* + * GCC 2.95 provides `__restrict' as an extension to C90 to support the + * C99-specific `restrict' type qualifier. We happen to use `__restrict' as + * a way to define the `restrict' type qualifier without disturbing older + * software that is unaware of C99 keywords. + */ +#if !(__GNUC__ == 2 && __GNUC_MINOR__ == 95) +#if !defined(__STDC_VERSION__) || __STDC_VERSION__ < 199901 || defined(lint) +#define __restrict +#else +#define __restrict restrict +#endif +#endif + +/* + * GNU C version 2.96 adds explicit branch prediction so that + * the CPU back-end can hint the processor and also so that + * code blocks can be reordered such that the predicted path + * sees a more linear flow, thus improving cache behavior, etc. + * + * The following two macros provide us with a way to utilize this + * compiler feature. Use __predict_true() if you expect the expression + * to evaluate to true, and __predict_false() if you expect the + * expression to evaluate to false. + * + * A few notes about usage: + * + * * Generally, __predict_false() error condition checks (unless + * you have some _strong_ reason to do otherwise, in which case + * document it), and/or __predict_true() `no-error' condition + * checks, assuming you want to optimize for the no-error case. + * + * * Other than that, if you don't know the likelihood of a test + * succeeding from empirical or other `hard' evidence, don't + * make predictions. + * + * * These are meant to be used in places that are run `a lot'. + * It is wasteful to make predictions in code that is run + * seldomly (e.g. at subsystem initialization time) as the + * basic block reordering that this affects can often generate + * larger code. + */ +#if __GNUC_PREREQ__(2, 96) +#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) +#endif + +#if __GNUC_PREREQ__(4, 2) +#define __hidden __attribute__((__visibility__("hidden"))) +#define __exported __attribute__((__visibility__("default"))) +#else +#define __hidden +#define __exported +#endif + +#define __offsetof(type, field) offsetof(type, field) +#define __rangeof(type, start, end) \ + (__offsetof(type, end) - __offsetof(type, start)) + +/* + * Given the pointer x to the member m of the struct s, return + * a pointer to the containing structure. When using GCC, we first + * assign pointer x to a local variable, to check that its type is + * compatible with member m. + */ +#if __GNUC_PREREQ__(3, 1) +#define __containerof(x, s, m) ({ \ + const volatile __typeof__(((s *)0)->m) *__x = (x); \ + __DEQUALIFY(s *, (const volatile char *)__x - __offsetof(s, m));\ +}) +#else +#define __containerof(x, s, m) \ + __DEQUALIFY(s *, (const volatile char *)(x) - __offsetof(s, m)) +#endif + +/* + * Compiler-dependent macros to declare that functions take printf-like + * or scanf-like arguments. They are null except for versions of gcc + * that are known to support the features properly (old versions of gcc-2 + * didn't permit keeping the keywords out of the application namespace). + */ +#if !__GNUC_PREREQ__(2, 7) && !defined(__INTEL_COMPILER) +#define __printflike(fmtarg, firstvararg) +#define __scanflike(fmtarg, firstvararg) +#define __format_arg(fmtarg) +#define __strfmonlike(fmtarg, firstvararg) +#define __strftimelike(fmtarg, firstvararg) +#else +#define __printflike(fmtarg, firstvararg) \ + __attribute__((__format__ (__printf__, fmtarg, firstvararg))) +#define __scanflike(fmtarg, firstvararg) \ + __attribute__((__format__ (__scanf__, fmtarg, firstvararg))) +#define __format_arg(fmtarg) __attribute__((__format_arg__ (fmtarg))) +#define __strfmonlike(fmtarg, firstvararg) \ + __attribute__((__format__ (__strfmon__, fmtarg, firstvararg))) +#define __strftimelike(fmtarg, firstvararg) \ + __attribute__((__format__ (__strftime__, fmtarg, firstvararg))) +#endif + +/* Compiler-dependent macros that rely on FreeBSD-specific extensions. */ +#if defined(__FreeBSD_cc_version) && __FreeBSD_cc_version >= 300001 && \ + defined(__GNUC__) && !defined(__INTEL_COMPILER) +#define __printf0like(fmtarg, firstvararg) \ + __attribute__((__format__ (__printf0__, fmtarg, firstvararg))) +#else +#define __printf0like(fmtarg, firstvararg) +#endif + +#if defined(__GNUC__) || defined(__INTEL_COMPILER) +#ifndef __INTEL_COMPILER #define __strong_reference(sym,aliassym) \ - extern __typeof (sym) aliassym __attribute__ ((__alias__ (#sym))); + extern __typeof (sym) aliassym __attribute__ ((__alias__ (#sym))) +#endif #ifdef __ELF__ #ifdef __STDC__ #define __weak_reference(sym,alias) \ @@ -113,6 +515,10 @@ __asm__(".section .gnu.warning." #sym); \ __asm__(".asciz \"" msg "\""); \ __asm__(".previous") +#define __sym_compat(sym,impl,verid) \ + __asm__(".symver " #impl ", " #sym "@" #verid) +#define __sym_default(sym,impl,verid) \ + __asm__(".symver " #impl ", " #sym "@@" #verid) #else #define __weak_reference(sym,alias) \ __asm__(".weak alias"); \ @@ -121,6 +527,10 @@ __asm__(".section .gnu.warning.sym"); \ __asm__(".asciz \"msg\""); \ __asm__(".previous") +#define __sym_compat(sym,impl,verid) \ + __asm__(".symver impl, sym@verid") +#define __sym_default(impl,sym,verid) \ + __asm__(".symver impl, sym@@verid") #endif /* __STDC__ */ #else /* !__ELF__ */ #ifdef __STDC__ @@ -139,6 +549,162 @@ __asm__(".stabs \"_/**/sym\",1,0,0,0") #endif /* __STDC__ */ #endif /* __ELF__ */ -#endif /* __GNUC__ */ +#endif /* __GNUC__ || __INTEL_COMPILER */ -#endif /* _SYS_CDEFS_H */ +#ifndef __FBSDID +#define __FBSDID(s) struct __hack +#endif + +#ifndef __RCSID +#define __RCSID(s) struct __hack +#endif + +#ifndef __RCSID_SOURCE +#define __RCSID_SOURCE(s) struct __hack +#endif + +#ifndef __SCCSID +#define __SCCSID(s) struct __hack +#endif + +#ifndef __COPYRIGHT +#define __COPYRIGHT(s) struct __hack +#endif + +#ifndef __DECONST +#define __DECONST(type, var) ((type)(__uintptr_t)(const void *)(var)) +#endif + +#ifndef __DEVOLATILE +#define __DEVOLATILE(type, var) ((type)(__uintptr_t)(volatile void *)(var)) +#endif + +#ifndef __DEQUALIFY +#define __DEQUALIFY(type, var) ((type)(__uintptr_t)(const volatile void *)(var)) +#endif + +/*- + * The following definitions are an extension of the behavior originally + * implemented in , but with a different level of granularity. + * POSIX.1 requires that the macros we test be defined before any standard + * header file is included. + * + * Here's a quick run-down of the versions: + * defined(_POSIX_SOURCE) 1003.1-1988 + * _POSIX_C_SOURCE == 1 1003.1-1990 + * _POSIX_C_SOURCE == 2 1003.2-1992 C Language Binding Option + * _POSIX_C_SOURCE == 199309 1003.1b-1993 + * _POSIX_C_SOURCE == 199506 1003.1c-1995, 1003.1i-1995, + * and the omnibus ISO/IEC 9945-1: 1996 + * _POSIX_C_SOURCE == 200112 1003.1-2001 + * _POSIX_C_SOURCE == 200809 1003.1-2008 + * + * In addition, the X/Open Portability Guide, which is now the Single UNIX + * Specification, defines a feature-test macro which indicates the version of + * that specification, and which subsumes _POSIX_C_SOURCE. + * + * Our macros begin with two underscores to avoid namespace screwage. + */ + +/* 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. */ +#define _POSIX_C_SOURCE 199009 +#endif + +/* Deal with IEEE Std. 1003.2-1992, in which _POSIX_C_SOURCE == 2. */ +#if defined(_POSIX_C_SOURCE) && _POSIX_C_SOURCE == 2 +#undef _POSIX_C_SOURCE +#define _POSIX_C_SOURCE 199209 +#endif + +/* Deal with various X/Open Portability Guides and Single UNIX Spec. */ +#ifdef _XOPEN_SOURCE +#if _XOPEN_SOURCE - 0 >= 700 +#define __XSI_VISIBLE 700 +#undef _POSIX_C_SOURCE +#define _POSIX_C_SOURCE 200809 +#elif _XOPEN_SOURCE - 0 >= 600 +#define __XSI_VISIBLE 600 +#undef _POSIX_C_SOURCE +#define _POSIX_C_SOURCE 200112 +#elif _XOPEN_SOURCE - 0 >= 500 +#define __XSI_VISIBLE 500 +#undef _POSIX_C_SOURCE +#define _POSIX_C_SOURCE 199506 +#endif +#endif + +/* + * Deal with all versions of POSIX. The ordering relative to the tests above is + * important. + */ +#if defined(_POSIX_SOURCE) && !defined(_POSIX_C_SOURCE) +#define _POSIX_C_SOURCE 198808 +#endif +#ifdef _POSIX_C_SOURCE +#if _POSIX_C_SOURCE >= 200809 +#define __POSIX_VISIBLE 200809 +#define __ISO_C_VISIBLE 1999 +#elif _POSIX_C_SOURCE >= 200112 +#define __POSIX_VISIBLE 200112 +#define __ISO_C_VISIBLE 1999 +#elif _POSIX_C_SOURCE >= 199506 +#define __POSIX_VISIBLE 199506 +#define __ISO_C_VISIBLE 1990 +#elif _POSIX_C_SOURCE >= 199309 +#define __POSIX_VISIBLE 199309 +#define __ISO_C_VISIBLE 1990 +#elif _POSIX_C_SOURCE >= 199209 +#define __POSIX_VISIBLE 199209 +#define __ISO_C_VISIBLE 1990 +#elif _POSIX_C_SOURCE >= 199009 +#define __POSIX_VISIBLE 199009 +#define __ISO_C_VISIBLE 1990 +#else +#define __POSIX_VISIBLE 198808 +#define __ISO_C_VISIBLE 0 +#endif /* _POSIX_C_SOURCE */ +#else +/*- + * Deal with _ANSI_SOURCE: + * If it is defined, and no other compilation environment is explicitly + * requested, then define our internal feature-test macros to zero. This + * makes no difference to the preprocessor (undefined symbols in preprocessing + * expressions are defined to have value zero), but makes it more convenient for + * a test program to print out the values. + * + * If a program mistakenly defines _ANSI_SOURCE and some other macro such as + * _POSIX_C_SOURCE, we will assume that it wants the broader compilation + * environment (and in fact we will never get here). + */ +#if defined(_ANSI_SOURCE) /* Hide almost everything. */ +#define __POSIX_VISIBLE 0 +#define __XSI_VISIBLE 0 +#define __BSD_VISIBLE 0 +#define __ISO_C_VISIBLE 1990 +#elif defined(_C99_SOURCE) /* Localism to specify strict C99 env. */ +#define __POSIX_VISIBLE 0 +#define __XSI_VISIBLE 0 +#define __BSD_VISIBLE 0 +#define __ISO_C_VISIBLE 1999 +#elif defined(_C11_SOURCE) /* Localism to specify strict C11 env. */ +#define __POSIX_VISIBLE 0 +#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 +#define __BSD_VISIBLE 1 +#define __ISO_C_VISIBLE 2011 +#endif +#endif + +#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 84db19e33e..70bae14724 100644 --- a/contrib/sdk/sources/newlib/libc/include/sys/config.h +++ b/contrib/sdk/sources/newlib/libc/include/sys/config.h @@ -4,6 +4,10 @@ #include /* floating point macros */ #include /* POSIX defs */ +#ifdef __aarch64__ +#define MALLOC_ALIGNMENT 16 +#endif + /* exceptions first */ #if defined(__H8500__) || defined(__W65__) #define __SMALL_BITFIELDS @@ -141,6 +145,21 @@ #define __BUFSIZ__ 16 #define _REENT_SMALL #endif + +#if defined __MSP430__ +#ifndef _REENT_SMALL +#define _REENT_SMALL +#endif + +#define __SMALL_BITFIELDS + +#ifdef __MSP430X_LARGE__ +#define _POINTER_INT long +#else +#define _POINTER_INT int +#endif +#endif + #ifdef __m32c__ #define __SMALL_BITFIELDS #undef INT_MAX @@ -213,6 +232,8 @@ #if defined(__rtems__) #define __FILENAME_MAX__ 255 #define _READ_WRITE_RETURN_TYPE _ssize_t +#define __DYNAMIC_REENT__ +#define _REENT_GLOBAL_ATEXIT #endif #ifndef __EXPORT @@ -229,6 +250,12 @@ #ifndef _READ_WRITE_RETURN_TYPE #define _READ_WRITE_RETURN_TYPE int #endif +/* Define `count' parameter of read/write routines. In POSIX, the `count' + parameter is "size_t" but legacy newlib code has been using "int" for some + time. If not specified, "int" is defaulted. */ +#ifndef _READ_WRITE_BUFSIZE_TYPE +#define _READ_WRITE_BUFSIZE_TYPE int +#endif #ifndef __WCHAR_MAX__ #if __INT_MAX__ == 32767 || defined (_WIN32) diff --git a/contrib/sdk/sources/newlib/libc/include/sys/features.h b/contrib/sdk/sources/newlib/libc/include/sys/features.h index 607d53fadf..74a2cb8e12 100644 --- a/contrib/sdk/sources/newlib/libc/include/sys/features.h +++ b/contrib/sdk/sources/newlib/libc/include/sys/features.h @@ -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.27 2011/07/20 19:41:15 yselkowitz Exp $ + * $Id: features.h,v 1.30 2013/04/23 09:42:25 corinna Exp $ */ #ifndef _SYS_FEATURES_H @@ -25,6 +25,18 @@ extern "C" { #endif +/* Macro to test version of GCC. Returns 0 for non-GCC or too old GCC. */ +#ifndef __GNUC_PREREQ +# if defined __GNUC__ && defined __GNUC_MINOR__ +# define __GNUC_PREREQ(maj, min) \ + ((__GNUC__ << 16) + __GNUC_MINOR__ >= ((maj) << 16) + (min)) +# else +# define __GNUC_PREREQ(maj, min) 0 +# endif +#endif /* __GNUC_PREREQ */ +/* Version with trailing underscores for BSD compatibility. */ +#define __GNUC_PREREQ__(ma, mi) __GNUC_PREREQ(ma, mi) + /* RTEMS adheres to POSIX -- 1003.1b with some features from annexes. */ #ifdef __rtems__ @@ -161,12 +173,18 @@ extern "C" { #define _POSIX2_SW_DEV 200112L #define _POSIX2_UPE 200112L #define _POSIX_V6_ILP32_OFF32 -1 -#define _XBS5_ILP32_OFF32 _POSIX_V6_ILP32_OFF32 +#ifdef __LP64__ +#define _POSIX_V6_ILP32_OFFBIG -1 +#define _POSIX_V6_LP64_OFF64 1 +#define _POSIX_V6_LPBIG_OFFBIG 1 +#else #define _POSIX_V6_ILP32_OFFBIG 1 -#define _XBS5_ILP32_OFFBIG _POSIX_V6_ILP32_OFFBIG #define _POSIX_V6_LP64_OFF64 -1 -#define _XBS5_LP64_OFF64 _POSIX_V6_LP64_OFF64 #define _POSIX_V6_LPBIG_OFFBIG -1 +#endif +#define _XBS5_ILP32_OFF32 _POSIX_V6_ILP32_OFF32 +#define _XBS5_ILP32_OFFBIG _POSIX_V6_ILP32_OFFBIG +#define _XBS5_LP64_OFF64 _POSIX_V6_LP64_OFF64 #define _XBS5_LPBIG_OFFBIG _POSIX_V6_LPBIG_OFFBIG #define _XOPEN_CRYPT 1 #define _XOPEN_ENH_I18N 1 diff --git a/contrib/sdk/sources/newlib/libc/include/sys/param.h b/contrib/sdk/sources/newlib/libc/include/sys/param.h index 0abf08b127..4eaf670353 100644 --- a/contrib/sdk/sources/newlib/libc/include/sys/param.h +++ b/contrib/sdk/sources/newlib/libc/include/sys/param.h @@ -6,6 +6,7 @@ # define _SYS_PARAM_H #include +#include #include #include @@ -19,6 +20,8 @@ # define PATHSIZE (1024) #endif +#define MAXPATHLEN PATH_MAX + #define MAX(a,b) ((a) > (b) ? (a) : (b)) #define MIN(a,b) ((a) < (b) ? (a) : (b)) diff --git a/contrib/sdk/sources/newlib/libc/include/sys/queue.h b/contrib/sdk/sources/newlib/libc/include/sys/queue.h index d221bb117d..1b19e92535 100644 --- a/contrib/sdk/sources/newlib/libc/include/sys/queue.h +++ b/contrib/sdk/sources/newlib/libc/include/sys/queue.h @@ -1,4 +1,4 @@ -/* +/*- * Copyright (c) 1991, 1993 * The Regents of the University of California. All rights reserved. * @@ -10,10 +10,6 @@ * 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 * may be used to endorse or promote products derived from this software * without specific prior written permission. @@ -31,13 +27,13 @@ * SUCH DAMAGE. * * @(#)queue.h 8.5 (Berkeley) 8/20/94 - * $FreeBSD: src/sys/sys/queue.h,v 1.48 2002/04/17 14:00:37 tmm Exp $ + * $FreeBSD$ */ #ifndef _SYS_QUEUE_H_ #define _SYS_QUEUE_H_ -#include /* for __offsetof */ +#include /* * This file defines four types of data structures: singly-linked lists, @@ -69,7 +65,7 @@ * so that an arbitrary element can be removed without a need to * traverse the list. New elements can be added to the list before * or after an existing element or at the head of the list. A list - * may only be traversed in the forward direction. + * may be traversed in either direction. * * A tail queue is headed by a pair of pointers, one to the head of the * list and the other to the tail of the list. The elements are doubly @@ -89,19 +85,59 @@ * _EMPTY + + + + * _FIRST + + + + * _NEXT + + + + - * _PREV - - - + + * _PREV - + - + * _LAST - - + + * _FOREACH + + + + + * _FOREACH_SAFE + + + + * _FOREACH_REVERSE - - - + + * _FOREACH_REVERSE_SAFE - - - + * _INSERT_HEAD + + + + * _INSERT_BEFORE - + - + * _INSERT_AFTER + + + + * _INSERT_TAIL - - + + * _CONCAT - - + + + * _REMOVE_AFTER + - + - * _REMOVE_HEAD + - + - * _REMOVE + + + + + * _SWAP + + + + * */ +#ifdef QUEUE_MACRO_DEBUG +/* Store the last 2 places the queue element or head was altered */ +struct qm_trace { + unsigned long lastline; + unsigned long prevline; + const char *lastfile; + const char *prevfile; +}; + +#define TRACEBUF struct qm_trace trace; +#define TRACEBUF_INITIALIZER { __FILE__, __LINE__, NULL, 0 } , +#define TRASHIT(x) do {(x) = (void *)-1;} while (0) +#define QMD_SAVELINK(name, link) void **name = (void *)&(link) + +#define QMD_TRACE_HEAD(head) do { \ + (head)->trace.prevline = (head)->trace.lastline; \ + (head)->trace.prevfile = (head)->trace.lastfile; \ + (head)->trace.lastline = __LINE__; \ + (head)->trace.lastfile = __FILE__; \ +} while (0) + +#define QMD_TRACE_ELEM(elem) do { \ + (elem)->trace.prevline = (elem)->trace.lastline; \ + (elem)->trace.prevfile = (elem)->trace.lastfile; \ + (elem)->trace.lastline = __LINE__; \ + (elem)->trace.lastfile = __FILE__; \ +} while (0) + +#else +#define QMD_TRACE_ELEM(elem) +#define QMD_TRACE_HEAD(head) +#define QMD_SAVELINK(name, link) +#define TRACEBUF +#define TRACEBUF_INITIALIZER +#define TRASHIT(x) +#endif /* QUEUE_MACRO_DEBUG */ /* * Singly-linked List declarations. @@ -131,6 +167,16 @@ struct { \ (var); \ (var) = SLIST_NEXT((var), field)) +#define SLIST_FOREACH_SAFE(var, head, field, tvar) \ + for ((var) = SLIST_FIRST((head)); \ + (var) && ((tvar) = SLIST_NEXT((var), field), 1); \ + (var) = (tvar)) + +#define SLIST_FOREACH_PREVPTR(var, varp, head, field) \ + for ((varp) = &SLIST_FIRST((head)); \ + ((var) = *(varp)) != NULL; \ + (varp) = &SLIST_NEXT((var), field)) + #define SLIST_INIT(head) do { \ SLIST_FIRST((head)) = NULL; \ } while (0) @@ -148,6 +194,7 @@ struct { \ #define SLIST_NEXT(elm, field) ((elm)->field.sle_next) #define SLIST_REMOVE(head, elm, type, field) do { \ + QMD_SAVELINK(oldnext, (elm)->field.sle_next); \ if (SLIST_FIRST((head)) == (elm)) { \ SLIST_REMOVE_HEAD((head), field); \ } \ @@ -155,15 +202,26 @@ struct { \ struct type *curelm = SLIST_FIRST((head)); \ while (SLIST_NEXT(curelm, field) != (elm)) \ curelm = SLIST_NEXT(curelm, field); \ - SLIST_NEXT(curelm, field) = \ - SLIST_NEXT(SLIST_NEXT(curelm, field), field); \ + SLIST_REMOVE_AFTER(curelm, field); \ } \ + TRASHIT(*oldnext); \ +} while (0) + +#define SLIST_REMOVE_AFTER(elm, field) do { \ + SLIST_NEXT(elm, field) = \ + SLIST_NEXT(SLIST_NEXT(elm, field), field); \ } while (0) #define SLIST_REMOVE_HEAD(head, field) do { \ SLIST_FIRST((head)) = SLIST_NEXT(SLIST_FIRST((head)), field); \ } while (0) +#define SLIST_SWAP(head1, head2, type) do { \ + struct type *swap_first = SLIST_FIRST(head1); \ + SLIST_FIRST(head1) = SLIST_FIRST(head2); \ + SLIST_FIRST(head2) = swap_first; \ +} while (0) + /* * Singly-linked Tail queue declarations. */ @@ -201,6 +259,12 @@ struct { \ (var); \ (var) = STAILQ_NEXT((var), field)) + +#define STAILQ_FOREACH_SAFE(var, head, field, tvar) \ + for ((var) = STAILQ_FIRST((head)); \ + (var) && ((tvar) = STAILQ_NEXT((var), field), 1); \ + (var) = (tvar)) + #define STAILQ_INIT(head) do { \ STAILQ_FIRST((head)) = NULL; \ (head)->stqh_last = &STAILQ_FIRST((head)); \ @@ -225,14 +289,13 @@ struct { \ } while (0) #define STAILQ_LAST(head, type, field) \ - (STAILQ_EMPTY((head)) ? \ - NULL : \ - ((struct type *) \ - ((char *)((head)->stqh_last) - __offsetof(struct type, field)))) + (STAILQ_EMPTY((head)) ? NULL : \ + __containerof((head)->stqh_last, struct type, field.stqe_next)) #define STAILQ_NEXT(elm, field) ((elm)->field.stqe_next) #define STAILQ_REMOVE(head, elm, type, field) do { \ + QMD_SAVELINK(oldnext, (elm)->field.stqe_next); \ if (STAILQ_FIRST((head)) == (elm)) { \ STAILQ_REMOVE_HEAD((head), field); \ } \ @@ -240,10 +303,15 @@ struct { \ struct type *curelm = STAILQ_FIRST((head)); \ while (STAILQ_NEXT(curelm, field) != (elm)) \ curelm = STAILQ_NEXT(curelm, field); \ - if ((STAILQ_NEXT(curelm, field) = \ - STAILQ_NEXT(STAILQ_NEXT(curelm, field), field)) == NULL)\ - (head)->stqh_last = &STAILQ_NEXT((curelm), field);\ + STAILQ_REMOVE_AFTER(head, curelm, field); \ } \ + TRASHIT(*oldnext); \ +} while (0) + +#define STAILQ_REMOVE_AFTER(head, elm, field) do { \ + if ((STAILQ_NEXT(elm, field) = \ + STAILQ_NEXT(STAILQ_NEXT(elm, field), field)) == NULL) \ + (head)->stqh_last = &STAILQ_NEXT((elm), field); \ } while (0) #define STAILQ_REMOVE_HEAD(head, field) do { \ @@ -257,6 +325,20 @@ struct { \ (head)->stqh_last = &STAILQ_FIRST((head)); \ } while (0) +#define STAILQ_SWAP(head1, head2, type) do { \ + struct type *swap_first = STAILQ_FIRST(head1); \ + struct type **swap_last = (head1)->stqh_last; \ + STAILQ_FIRST(head1) = STAILQ_FIRST(head2); \ + (head1)->stqh_last = (head2)->stqh_last; \ + STAILQ_FIRST(head2) = swap_first; \ + (head2)->stqh_last = swap_last; \ + if (STAILQ_EMPTY(head1)) \ + (head1)->stqh_last = &STAILQ_FIRST(head1); \ + if (STAILQ_EMPTY(head2)) \ + (head2)->stqh_last = &STAILQ_FIRST(head2); \ +} while (0) + + /* * List declarations. */ @@ -278,6 +360,31 @@ struct { \ * List functions. */ +#if (defined(_KERNEL) && defined(INVARIANTS)) +#define QMD_LIST_CHECK_HEAD(head, field) do { \ + if (LIST_FIRST((head)) != NULL && \ + LIST_FIRST((head))->field.le_prev != \ + &LIST_FIRST((head))) \ + panic("Bad list head %p first->prev != head", (head)); \ +} while (0) + +#define QMD_LIST_CHECK_NEXT(elm, field) do { \ + if (LIST_NEXT((elm), field) != NULL && \ + LIST_NEXT((elm), field)->field.le_prev != \ + &((elm)->field.le_next)) \ + panic("Bad link elm %p next->prev != elm", (elm)); \ +} while (0) + +#define QMD_LIST_CHECK_PREV(elm, field) do { \ + if (*(elm)->field.le_prev != (elm)) \ + panic("Bad link elm %p prev->next != elm", (elm)); \ +} while (0) +#else +#define QMD_LIST_CHECK_HEAD(head, field) +#define QMD_LIST_CHECK_NEXT(elm, field) +#define QMD_LIST_CHECK_PREV(elm, field) +#endif /* (_KERNEL && INVARIANTS) */ + #define LIST_EMPTY(head) ((head)->lh_first == NULL) #define LIST_FIRST(head) ((head)->lh_first) @@ -287,11 +394,17 @@ struct { \ (var); \ (var) = LIST_NEXT((var), field)) +#define LIST_FOREACH_SAFE(var, head, field, tvar) \ + for ((var) = LIST_FIRST((head)); \ + (var) && ((tvar) = LIST_NEXT((var), field), 1); \ + (var) = (tvar)) + #define LIST_INIT(head) do { \ LIST_FIRST((head)) = NULL; \ } while (0) #define LIST_INSERT_AFTER(listelm, elm, field) do { \ + QMD_LIST_CHECK_NEXT(listelm, field); \ if ((LIST_NEXT((elm), field) = LIST_NEXT((listelm), field)) != NULL)\ LIST_NEXT((listelm), field)->field.le_prev = \ &LIST_NEXT((elm), field); \ @@ -300,6 +413,7 @@ struct { \ } while (0) #define LIST_INSERT_BEFORE(listelm, elm, field) do { \ + QMD_LIST_CHECK_PREV(listelm, field); \ (elm)->field.le_prev = (listelm)->field.le_prev; \ LIST_NEXT((elm), field) = (listelm); \ *(listelm)->field.le_prev = (elm); \ @@ -307,6 +421,7 @@ struct { \ } while (0) #define LIST_INSERT_HEAD(head, elm, field) do { \ + QMD_LIST_CHECK_HEAD((head), field); \ if ((LIST_NEXT((elm), field) = LIST_FIRST((head))) != NULL) \ LIST_FIRST((head))->field.le_prev = &LIST_NEXT((elm), field);\ LIST_FIRST((head)) = (elm); \ @@ -315,11 +430,31 @@ struct { \ #define LIST_NEXT(elm, field) ((elm)->field.le_next) +#define LIST_PREV(elm, head, type, field) \ + ((elm)->field.le_prev == &LIST_FIRST((head)) ? NULL : \ + __containerof((elm)->field.le_prev, struct type, field.le_next)) + #define LIST_REMOVE(elm, field) do { \ + QMD_SAVELINK(oldnext, (elm)->field.le_next); \ + QMD_SAVELINK(oldprev, (elm)->field.le_prev); \ + QMD_LIST_CHECK_NEXT(elm, field); \ + QMD_LIST_CHECK_PREV(elm, field); \ if (LIST_NEXT((elm), field) != NULL) \ LIST_NEXT((elm), field)->field.le_prev = \ (elm)->field.le_prev; \ *(elm)->field.le_prev = LIST_NEXT((elm), field); \ + TRASHIT(*oldnext); \ + TRASHIT(*oldprev); \ +} while (0) + +#define LIST_SWAP(head1, head2, type, field) do { \ + struct type *swap_tmp = LIST_FIRST((head1)); \ + LIST_FIRST((head1)) = LIST_FIRST((head2)); \ + LIST_FIRST((head2)) = swap_tmp; \ + if ((swap_tmp = LIST_FIRST((head1))) != NULL) \ + swap_tmp->field.le_prev = &LIST_FIRST((head1)); \ + if ((swap_tmp = LIST_FIRST((head2))) != NULL) \ + swap_tmp->field.le_prev = &LIST_FIRST((head2)); \ } while (0) /* @@ -329,26 +464,61 @@ struct { \ struct name { \ struct type *tqh_first; /* first element */ \ struct type **tqh_last; /* addr of last next element */ \ + TRACEBUF \ } #define TAILQ_HEAD_INITIALIZER(head) \ - { NULL, &(head).tqh_first } + { NULL, &(head).tqh_first, TRACEBUF_INITIALIZER } #define TAILQ_ENTRY(type) \ struct { \ struct type *tqe_next; /* next element */ \ struct type **tqe_prev; /* address of previous next element */ \ + TRACEBUF \ } /* * Tail queue functions. */ +#if (defined(_KERNEL) && defined(INVARIANTS)) +#define QMD_TAILQ_CHECK_HEAD(head, field) do { \ + if (!TAILQ_EMPTY(head) && \ + TAILQ_FIRST((head))->field.tqe_prev != \ + &TAILQ_FIRST((head))) \ + panic("Bad tailq head %p first->prev != head", (head)); \ +} while (0) + +#define QMD_TAILQ_CHECK_TAIL(head, field) do { \ + if (*(head)->tqh_last != NULL) \ + panic("Bad tailq NEXT(%p->tqh_last) != NULL", (head)); \ +} while (0) + +#define QMD_TAILQ_CHECK_NEXT(elm, field) do { \ + if (TAILQ_NEXT((elm), field) != NULL && \ + TAILQ_NEXT((elm), field)->field.tqe_prev != \ + &((elm)->field.tqe_next)) \ + panic("Bad link elm %p next->prev != elm", (elm)); \ +} while (0) + +#define QMD_TAILQ_CHECK_PREV(elm, field) do { \ + if (*(elm)->field.tqe_prev != (elm)) \ + panic("Bad link elm %p prev->next != elm", (elm)); \ +} while (0) +#else +#define QMD_TAILQ_CHECK_HEAD(head, field) +#define QMD_TAILQ_CHECK_TAIL(head, headname) +#define QMD_TAILQ_CHECK_NEXT(elm, field) +#define QMD_TAILQ_CHECK_PREV(elm, field) +#endif /* (_KERNEL && INVARIANTS) */ + #define TAILQ_CONCAT(head1, head2, field) do { \ if (!TAILQ_EMPTY(head2)) { \ *(head1)->tqh_last = (head2)->tqh_first; \ (head2)->tqh_first->field.tqe_prev = (head1)->tqh_last; \ (head1)->tqh_last = (head2)->tqh_last; \ TAILQ_INIT((head2)); \ + QMD_TRACE_HEAD(head1); \ + QMD_TRACE_HEAD(head2); \ } \ } while (0) @@ -361,34 +531,54 @@ struct { \ (var); \ (var) = TAILQ_NEXT((var), field)) +#define TAILQ_FOREACH_SAFE(var, head, field, tvar) \ + for ((var) = TAILQ_FIRST((head)); \ + (var) && ((tvar) = TAILQ_NEXT((var), field), 1); \ + (var) = (tvar)) + #define TAILQ_FOREACH_REVERSE(var, head, headname, field) \ for ((var) = TAILQ_LAST((head), headname); \ (var); \ (var) = TAILQ_PREV((var), headname, field)) +#define TAILQ_FOREACH_REVERSE_SAFE(var, head, headname, field, tvar) \ + for ((var) = TAILQ_LAST((head), headname); \ + (var) && ((tvar) = TAILQ_PREV((var), headname, field), 1); \ + (var) = (tvar)) + #define TAILQ_INIT(head) do { \ TAILQ_FIRST((head)) = NULL; \ (head)->tqh_last = &TAILQ_FIRST((head)); \ + QMD_TRACE_HEAD(head); \ } while (0) #define TAILQ_INSERT_AFTER(head, listelm, elm, field) do { \ + QMD_TAILQ_CHECK_NEXT(listelm, field); \ if ((TAILQ_NEXT((elm), field) = TAILQ_NEXT((listelm), field)) != NULL)\ TAILQ_NEXT((elm), field)->field.tqe_prev = \ &TAILQ_NEXT((elm), field); \ - else \ + else { \ (head)->tqh_last = &TAILQ_NEXT((elm), field); \ + QMD_TRACE_HEAD(head); \ + } \ TAILQ_NEXT((listelm), field) = (elm); \ (elm)->field.tqe_prev = &TAILQ_NEXT((listelm), field); \ + QMD_TRACE_ELEM(&(elm)->field); \ + QMD_TRACE_ELEM(&listelm->field); \ } while (0) #define TAILQ_INSERT_BEFORE(listelm, elm, field) do { \ + QMD_TAILQ_CHECK_PREV(listelm, field); \ (elm)->field.tqe_prev = (listelm)->field.tqe_prev; \ TAILQ_NEXT((elm), field) = (listelm); \ *(listelm)->field.tqe_prev = (elm); \ (listelm)->field.tqe_prev = &TAILQ_NEXT((elm), field); \ + QMD_TRACE_ELEM(&(elm)->field); \ + QMD_TRACE_ELEM(&listelm->field); \ } while (0) #define TAILQ_INSERT_HEAD(head, elm, field) do { \ + QMD_TAILQ_CHECK_HEAD(head, field); \ if ((TAILQ_NEXT((elm), field) = TAILQ_FIRST((head))) != NULL) \ TAILQ_FIRST((head))->field.tqe_prev = \ &TAILQ_NEXT((elm), field); \ @@ -396,13 +586,18 @@ struct { \ (head)->tqh_last = &TAILQ_NEXT((elm), field); \ TAILQ_FIRST((head)) = (elm); \ (elm)->field.tqe_prev = &TAILQ_FIRST((head)); \ + QMD_TRACE_HEAD(head); \ + QMD_TRACE_ELEM(&(elm)->field); \ } while (0) #define TAILQ_INSERT_TAIL(head, elm, field) do { \ + QMD_TAILQ_CHECK_TAIL(head, field); \ TAILQ_NEXT((elm), field) = NULL; \ (elm)->field.tqe_prev = (head)->tqh_last; \ *(head)->tqh_last = (elm); \ (head)->tqh_last = &TAILQ_NEXT((elm), field); \ + QMD_TRACE_HEAD(head); \ + QMD_TRACE_ELEM(&(elm)->field); \ } while (0) #define TAILQ_LAST(head, headname) \ @@ -414,14 +609,39 @@ struct { \ (*(((struct headname *)((elm)->field.tqe_prev))->tqh_last)) #define TAILQ_REMOVE(head, elm, field) do { \ + QMD_SAVELINK(oldnext, (elm)->field.tqe_next); \ + QMD_SAVELINK(oldprev, (elm)->field.tqe_prev); \ + QMD_TAILQ_CHECK_NEXT(elm, field); \ + QMD_TAILQ_CHECK_PREV(elm, field); \ if ((TAILQ_NEXT((elm), field)) != NULL) \ TAILQ_NEXT((elm), field)->field.tqe_prev = \ (elm)->field.tqe_prev; \ - else \ + else { \ (head)->tqh_last = (elm)->field.tqe_prev; \ + QMD_TRACE_HEAD(head); \ + } \ *(elm)->field.tqe_prev = TAILQ_NEXT((elm), field); \ + TRASHIT(*oldnext); \ + TRASHIT(*oldprev); \ + QMD_TRACE_ELEM(&(elm)->field); \ } while (0) +#define TAILQ_SWAP(head1, head2, type, field) do { \ + struct type *swap_first = (head1)->tqh_first; \ + struct type **swap_last = (head1)->tqh_last; \ + (head1)->tqh_first = (head2)->tqh_first; \ + (head1)->tqh_last = (head2)->tqh_last; \ + (head2)->tqh_first = swap_first; \ + (head2)->tqh_last = swap_last; \ + if ((swap_first = (head1)->tqh_first) != NULL) \ + swap_first->field.tqe_prev = &(head1)->tqh_first; \ + else \ + (head1)->tqh_last = &(head1)->tqh_first; \ + if ((swap_first = (head2)->tqh_first) != NULL) \ + swap_first->field.tqe_prev = &(head2)->tqh_first; \ + else \ + (head2)->tqh_last = &(head2)->tqh_first; \ +} while (0) #ifdef _KERNEL diff --git a/contrib/sdk/sources/newlib/libc/include/sys/reent.h b/contrib/sdk/sources/newlib/libc/include/sys/reent.h index 3e51b0ab73..45b96aad9e 100644 --- a/contrib/sdk/sources/newlib/libc/include/sys/reent.h +++ b/contrib/sdk/sources/newlib/libc/include/sys/reent.h @@ -11,6 +11,7 @@ extern "C" { #define _SYS_REENT_H_ #include <_ansi.h> +#include #include #define _NULL 0 @@ -85,6 +86,7 @@ struct _atexit { void (*_fns[_ATEXIT_SIZE])(void); /* the table itself */ struct _on_exit_args * _on_exit_args_ptr; }; +# define _ATEXIT_INIT {_NULL, 0, {_NULL}, _NULL} #else struct _atexit { struct _atexit *_next; /* next in list */ @@ -93,6 +95,14 @@ struct _atexit { void (*_fns[_ATEXIT_SIZE])(void); /* the table itself */ struct _on_exit_args _on_exit_args; }; +# define _ATEXIT_INIT {_NULL, 0, {_NULL}, {{_NULL}, {_NULL}, 0, 0}} +#endif + +#ifdef _REENT_GLOBAL_ATEXIT +# define _REENT_INIT_ATEXIT +#else +# define _REENT_INIT_ATEXIT \ + _NULL, _ATEXIT_INIT, #endif /* @@ -183,9 +193,10 @@ struct __sFILE { _PTR _cookie; /* cookie passed to io functions */ _READ_WRITE_RETURN_TYPE _EXFNPTR(_read, (struct _reent *, _PTR, - char *, int)); + char *, _READ_WRITE_BUFSIZE_TYPE)); _READ_WRITE_RETURN_TYPE _EXFNPTR(_write, (struct _reent *, _PTR, - const char *, int)); + const char *, + _READ_WRITE_BUFSIZE_TYPE)); _fpos_t _EXFNPTR(_seek, (struct _reent *, _PTR, _fpos_t, int)); int _EXFNPTR(_close, (struct _reent *, _PTR)); @@ -203,7 +214,7 @@ struct __sFILE { /* Unix stdio files get aligned to block boundaries on fseek() */ int _blksize; /* stat.st_blksize (may be != _bf._size) */ - int _offset; /* current lseek offset */ + _off_t _offset; /* current lseek offset */ #ifndef _REENT_SMALL struct _reent *_data; /* Here for binary compatibility? Remove? */ @@ -238,9 +249,10 @@ struct __sFILE64 { _PTR _cookie; /* cookie passed to io functions */ _READ_WRITE_RETURN_TYPE _EXFNPTR(_read, (struct _reent *, _PTR, - char *, int)); + char *, _READ_WRITE_BUFSIZE_TYPE)); _READ_WRITE_RETURN_TYPE _EXFNPTR(_write, (struct _reent *, _PTR, - const char *, int)); + const char *, + _READ_WRITE_BUFSIZE_TYPE)); _fpos_t _EXFNPTR(_seek, (struct _reent *, _PTR, _fpos_t, int)); int _EXFNPTR(_close, (struct _reent *, _PTR)); @@ -353,7 +365,7 @@ struct _misc_reent _mbstate_t _wcsrtombs_state; }; -/* This version of _reent is layed our with "int"s in pairs, to help +/* This version of _reent is laid out with "int"s in pairs, to help * ports with 16-bit int's but 32-bit pointers, align nicely. */ struct _reent { @@ -392,9 +404,11 @@ struct _reent /* signal info */ void (**(_sig_func))(int); +# ifndef _REENT_GLOBAL_ATEXIT /* atexit stuff */ struct _atexit *_atexit; struct _atexit _atexit0; +# endif struct _glue __sglue; /* root of glue chain */ __FILE *__sf; /* file descriptors */ @@ -425,8 +439,7 @@ extern const struct __sFILE_fake __sf_fake_stderr; _NULL, \ _NULL, \ _NULL, \ - _NULL, \ - {_NULL, 0, {_NULL}, _NULL}, \ + _REENT_INIT_ATEXIT \ {_NULL, 0, _NULL}, \ _NULL, \ _NULL, \ @@ -434,35 +447,11 @@ extern const struct __sFILE_fake __sf_fake_stderr; } #define _REENT_INIT_PTR(var) \ - { (var)->_stdin = (__FILE *)&__sf_fake_stdin; \ + { memset((var), 0, sizeof(*(var))); \ + (var)->_stdin = (__FILE *)&__sf_fake_stdin; \ (var)->_stdout = (__FILE *)&__sf_fake_stdout; \ (var)->_stderr = (__FILE *)&__sf_fake_stderr; \ - (var)->_errno = 0; \ - (var)->_inc = 0; \ - (var)->_emergency = _NULL; \ - (var)->__sdidinit = 0; \ - (var)->_current_category = 0; \ (var)->_current_locale = "C"; \ - (var)->_mp = _NULL; \ - (var)->__cleanup = _NULL; \ - (var)->_gamma_signgam = 0; \ - (var)->_cvtlen = 0; \ - (var)->_cvtbuf = _NULL; \ - (var)->_r48 = _NULL; \ - (var)->_localtime_buf = _NULL; \ - (var)->_asctime_buf = _NULL; \ - (var)->_sig_func = _NULL; \ - (var)->_atexit = _NULL; \ - (var)->_atexit0._next = _NULL; \ - (var)->_atexit0._ind = 0; \ - (var)->_atexit0._fns[0] = _NULL; \ - (var)->_atexit0._on_exit_args_ptr = _NULL; \ - (var)->__sglue._next = _NULL; \ - (var)->__sglue._niobs = 0; \ - (var)->__sglue._iobs = _NULL; \ - (var)->__sf = 0; \ - (var)->_misc = _NULL; \ - (var)->_signal_buf = _NULL; \ } /* Only built the assert() calls if we are built with debugging. */ @@ -641,9 +630,11 @@ struct _reent } _unused; } _new; +# ifndef _REENT_GLOBAL_ATEXIT /* atexit stuff */ struct _atexit *_atexit; /* points to head of LIFO stack */ struct _atexit _atexit0; /* one guaranteed table, required by ANSI */ +# endif /* signal info */ void (**(_sig_func))(int); @@ -698,34 +689,17 @@ struct _reent {0, {0}} \ } \ }, \ - _NULL, \ - {_NULL, 0, {_NULL}, {{_NULL}, {_NULL}, 0, 0}}, \ + _REENT_INIT_ATEXIT \ _NULL, \ {_NULL, 0, _NULL} \ } #define _REENT_INIT_PTR(var) \ - { (var)->_errno = 0; \ + { memset((var), 0, sizeof(*(var))); \ (var)->_stdin = &(var)->__sf[0]; \ (var)->_stdout = &(var)->__sf[1]; \ (var)->_stderr = &(var)->__sf[2]; \ - (var)->_inc = 0; \ - memset(&(var)->_emergency, 0, sizeof((var)->_emergency)); \ - (var)->_current_category = 0; \ (var)->_current_locale = "C"; \ - (var)->__sdidinit = 0; \ - (var)->__cleanup = _NULL; \ - (var)->_result = _NULL; \ - (var)->_result_k = 0; \ - (var)->_p5s = _NULL; \ - (var)->_freelist = _NULL; \ - (var)->_cvtlen = 0; \ - (var)->_cvtbuf = _NULL; \ - (var)->_new._reent._unused_rand = 0; \ - (var)->_new._reent._strtok_last = _NULL; \ - (var)->_new._reent._asctime_buf[0] = 0; \ - memset(&(var)->_new._reent._localtime_buf, 0, sizeof((var)->_new._reent._localtime_buf)); \ - (var)->_new._reent._gamma_signgam = 0; \ (var)->_new._reent._rand_next = 1; \ (var)->_new._reent._r48._seed[0] = _RAND48_SEED_0; \ (var)->_new._reent._r48._seed[1] = _RAND48_SEED_1; \ @@ -734,36 +708,6 @@ struct _reent (var)->_new._reent._r48._mult[1] = _RAND48_MULT_1; \ (var)->_new._reent._r48._mult[2] = _RAND48_MULT_2; \ (var)->_new._reent._r48._add = _RAND48_ADD; \ - (var)->_new._reent._mblen_state.__count = 0; \ - (var)->_new._reent._mblen_state.__value.__wch = 0; \ - (var)->_new._reent._mbtowc_state.__count = 0; \ - (var)->_new._reent._mbtowc_state.__value.__wch = 0; \ - (var)->_new._reent._wctomb_state.__count = 0; \ - (var)->_new._reent._wctomb_state.__value.__wch = 0; \ - (var)->_new._reent._mbrlen_state.__count = 0; \ - (var)->_new._reent._mbrlen_state.__value.__wch = 0; \ - (var)->_new._reent._mbrtowc_state.__count = 0; \ - (var)->_new._reent._mbrtowc_state.__value.__wch = 0; \ - (var)->_new._reent._mbsrtowcs_state.__count = 0; \ - (var)->_new._reent._mbsrtowcs_state.__value.__wch = 0; \ - (var)->_new._reent._wcrtomb_state.__count = 0; \ - (var)->_new._reent._wcrtomb_state.__value.__wch = 0; \ - (var)->_new._reent._wcsrtombs_state.__count = 0; \ - (var)->_new._reent._wcsrtombs_state.__value.__wch = 0; \ - (var)->_new._reent._l64a_buf[0] = '\0'; \ - (var)->_new._reent._signal_buf[0] = '\0'; \ - (var)->_new._reent._getdate_err = 0; \ - (var)->_atexit = _NULL; \ - (var)->_atexit0._next = _NULL; \ - (var)->_atexit0._ind = 0; \ - (var)->_atexit0._fns[0] = _NULL; \ - (var)->_atexit0._on_exit_args._fntypes = 0; \ - (var)->_atexit0._on_exit_args._fnargs[0] = _NULL; \ - (var)->_sig_func = _NULL; \ - (var)->__sglue._next = _NULL; \ - (var)->__sglue._niobs = 0; \ - (var)->__sglue._iobs = _NULL; \ - memset(&(var)->__sf, 0, sizeof((var)->__sf)); \ } #define _REENT_CHECK_RAND48(ptr) /* nothing */ @@ -822,7 +766,8 @@ void _reclaim_reent _PARAMS ((struct _reent *)); /* #define _REENT_ONLY define this to get only reentrant routines */ - +#if defined(__DYNAMIC_REENT__) && !defined(__SINGLE_THREAD__) +#ifndef __getreent static inline struct _reent *__getreent(void) { struct _reent *ent; @@ -831,10 +776,21 @@ static inline struct _reent *__getreent(void) :"=r"(ent)); return ent; }; - +#endif # define _REENT (__getreent()) +#else /* __SINGLE_THREAD__ || !__DYNAMIC_REENT__ */ +# define _REENT _impure_ptr +#endif /* __SINGLE_THREAD__ || !__DYNAMIC_REENT__ */ + #define _GLOBAL_REENT _global_impure_ptr +#ifdef _REENT_GLOBAL_ATEXIT +extern struct _atexit *_global_atexit; /* points to head of LIFO stack */ +# define _GLOBAL_ATEXIT _global_atexit +#else +# define _GLOBAL_ATEXIT (_GLOBAL_REENT->_atexit) +#endif + #ifdef __cplusplus } #endif diff --git a/contrib/sdk/sources/newlib/libc/include/sys/signal.h b/contrib/sdk/sources/newlib/libc/include/sys/signal.h index 96525febac..ffce0b2ae3 100644 --- a/contrib/sdk/sources/newlib/libc/include/sys/signal.h +++ b/contrib/sdk/sources/newlib/libc/include/sys/signal.h @@ -12,7 +12,10 @@ extern "C" { /* #ifndef __STRICT_ANSI__*/ +/* Cygwin defines it's own sigset_t in include/cygwin/signal.h */ +#ifndef __CYGWIN__ typedef unsigned long sigset_t; +#endif #if defined(__rtems__) @@ -143,6 +146,9 @@ int _EXFUN(pthread_sigmask, (int how, const sigset_t *set, sigset_t *oset)); #undef sigfillset #undef sigismember +#ifdef _COMPILING_NEWLIB +int _EXFUN(_kill, (pid_t, int)); +#endif int _EXFUN(kill, (pid_t, int)); int _EXFUN(killpg, (pid_t, int)); int _EXFUN(sigaction, (int, const struct sigaction *, struct sigaction *)); diff --git a/contrib/sdk/sources/newlib/libc/include/sys/stat.h b/contrib/sdk/sources/newlib/libc/include/sys/stat.h index 59d5482b74..700e779f48 100644 --- a/contrib/sdk/sources/newlib/libc/include/sys/stat.h +++ b/contrib/sdk/sources/newlib/libc/include/sys/stat.h @@ -19,7 +19,7 @@ extern "C" { #ifdef __CYGWIN__ #include #ifdef _COMPILING_NEWLIB -#define stat64 __stat64 +#define stat64 stat #endif #else struct stat @@ -147,17 +147,17 @@ 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 )); -int _EXFUN(stat,( const char *__path, struct stat *__sbuf )); +int _EXFUN(stat,( const char *__restrict __path, struct stat *__restrict __sbuf )); mode_t _EXFUN(umask,( mode_t __mask )); #if defined (__SPU__) || defined(__rtems__) || defined(__CYGWIN__) && !defined(__INSIDE_CYGWIN__) -int _EXFUN(lstat,( const char *__path, struct stat *__buf )); +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__) int _EXFUN(fchmodat, (int, const char *, mode_t, int)); -int _EXFUN(fstatat, (int, const char *, struct stat *, int)); +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)); int _EXFUN(mknodat, (int, const char *, mode_t, dev_t)); @@ -169,9 +169,11 @@ int _EXFUN(futimens, (int, const struct timespec *)); provided in newlib for some compilers. */ #ifdef _COMPILING_NEWLIB int _EXFUN(_fstat,( int __fd, struct stat *__sbuf )); -int _EXFUN(_stat,( const char *__path, struct stat *__sbuf )); +int _EXFUN(_stat,( const char *__restrict __path, struct stat *__restrict __sbuf )); +int _EXFUN(_mkdir,( const char *_path, mode_t __mode )); #ifdef __LARGE64_FILES struct stat64; +int _EXFUN(_stat64,( const char *__restrict __path, struct stat64 *__restrict __sbuf )); int _EXFUN(_fstat64,( int __fd, struct stat64 *__sbuf )); #endif #endif diff --git a/contrib/sdk/sources/newlib/libc/include/sys/time.h b/contrib/sdk/sources/newlib/libc/include/sys/time.h index 2f15870749..81ee20c2e7 100644 --- a/contrib/sdk/sources/newlib/libc/include/sys/time.h +++ b/contrib/sdk/sources/newlib/libc/include/sys/time.h @@ -12,33 +12,13 @@ extern "C" { #endif -#ifndef _WINSOCK_H +#ifndef _TIMEVAL_DEFINED #define _TIMEVAL_DEFINED struct timeval { time_t tv_sec; suseconds_t tv_usec; }; -struct timezone { - int tz_minuteswest; - int tz_dsttime; -}; - -#ifdef __CYGWIN__ -#include -#endif /* __CYGWIN__ */ - -#endif /* _WINSOCK_H */ - -#define ITIMER_REAL 0 -#define ITIMER_VIRTUAL 1 -#define ITIMER_PROF 2 - -struct itimerval { - struct timeval it_interval; - struct timeval it_value; -}; - /* BSD time macros used by RTEMS code */ #if defined (__rtems__) || defined (__CYGWIN__) @@ -70,13 +50,37 @@ struct itimerval { } \ } while (0) #endif /* defined (__rtems__) || defined (__CYGWIN__) */ +#endif /* !_TIMEVAL_DEFINED */ -int _EXFUN(gettimeofday, (struct timeval *__p, void *__tz)); +struct timezone { + int tz_minuteswest; + int tz_dsttime; +}; + +#ifdef __CYGWIN__ +#include +#endif /* __CYGWIN__ */ + +#define ITIMER_REAL 0 +#define ITIMER_VIRTUAL 1 +#define ITIMER_PROF 2 + +struct itimerval { + struct timeval it_interval; + struct timeval it_value; +}; + +#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 *__value, - struct itimerval *__ovalue)); +int _EXFUN(setitimer, (int __which, const struct itimerval *__restrict __value, + struct itimerval *__restrict __ovalue)); #ifdef __cplusplus } diff --git a/contrib/sdk/sources/newlib/libc/include/sys/times.h b/contrib/sdk/sources/newlib/libc/include/sys/times.h index f87edb9ae1..a31d1c7206 100644 --- a/contrib/sdk/sources/newlib/libc/include/sys/times.h +++ b/contrib/sdk/sources/newlib/libc/include/sys/times.h @@ -21,6 +21,9 @@ struct tms { }; clock_t _EXFUN(times,(struct tms *)); +#ifdef _COMPILING_NEWLIB +clock_t _EXFUN(_times,(struct tms *)); +#endif #ifdef __cplusplus } diff --git a/contrib/sdk/sources/newlib/libc/include/sys/types.h b/contrib/sdk/sources/newlib/libc/include/sys/types.h index cf4972e845..32f66ab958 100644 --- a/contrib/sdk/sources/newlib/libc/include/sys/types.h +++ b/contrib/sdk/sources/newlib/libc/include/sys/types.h @@ -89,10 +89,22 @@ typedef quad_t * qaddr_t; #ifndef _BSDTYPES_DEFINED /* also defined in mingw/gmon.h and in w32api/winsock[2].h */ +#ifndef __u_char_defined typedef unsigned char u_char; +#define __u_char_defined +#endif +#ifndef __u_short_defined typedef unsigned short u_short; +#define __u_short_defined +#endif +#ifndef __u_int_defined typedef unsigned int u_int; +#define __u_int_defined +#endif +#ifndef __u_long_defined typedef unsigned long u_long; +#define __u_long_defined +#endif #define _BSDTYPES_DEFINED #endif @@ -109,22 +121,31 @@ typedef _CLOCK_T_ clock_t; #ifndef __time_t_defined 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 */ }; -#endif +#ifndef __daddr_t_defined typedef long daddr_t; +#define __daddr_t_defined +#endif +#ifndef __caddr_t_defined typedef char * caddr_t; +#define __caddr_t_defined +#endif #ifndef __CYGWIN__ #if defined(__MS_types__) || defined(__rtems__) || \ @@ -207,7 +228,7 @@ typedef unsigned short nlink_t; 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 (__USE_W32_SOCKETS)) +# 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 */ /* @@ -244,7 +265,7 @@ typedef struct _types_fd_set { *__tmp++ = 0; \ })) -# endif /* !(defined (_POSIX_SOURCE) || defined (_WINSOCK_H) || defined (__USE_W32_SOCKETS)) */ +# endif /* !(defined (_POSIX_SOURCE) || defined (_WINSOCK_H) || defined (_WINSOCKAPI_) || defined (__USE_W32_SOCKETS)) */ #undef __MS_types__ #undef _ST_INT32 @@ -301,38 +322,9 @@ typedef __uint32_t pthread_t; /* identify a thread */ #define PTHREAD_CREATE_DETACHED 0 #define PTHREAD_CREATE_JOINABLE 1 -#if defined(__XMK__) || defined(__rtems__) -/* The following defines are part of the X/Open System Interface (XSI). */ - -/* This type of mutex does not detect deadlock. A thread attempting to relock this mutex without first unlocking - * it shall deadlock. Attempting to unlock a mutex locked by a different thread results in undefined behavior. - * Attempting to unlock an unlocked mutex results in undefined behavior. - */ -#define PTHREAD_MUTEX_NORMAL 1 - -/* - * This type of mutex provides error checking. A thread attempting to relock this mutex without first unlocking - * it shall return with an error. A thread attempting to unlock a mutex which another thread has locked shall return - * with an error. A thread attempting to unlock an unlocked mutex shall return with an error. - */ -#define PTHREAD_MUTEX_ERRORCHECK 2 - -/* A thread attempting to relock this mutex without first unlocking it shall succeed in locking the mutex. - * The relocking deadlock which can occur with mutexes of type PTHREAD_MUTEX_NORMAL cannot occur with this type of mutex. - * Multiple locks of this mutex shall require the same number of unlocks to release the mutex before another thread can - * acquire the mutex. A thread attempting to unlock a mutex which another thread has locked shall return with an error. - * A thread attempting to unlock an unlocked mutex shall return with an error. - */ -#define PTHREAD_MUTEX_RECURSIVE 3 - -/* Attempting to recursively lock a mutex of this type results in undefined behavior. Attempting to unlock a - * mutex of this type which was not locked by the calling thread results in undefined behavior. Attempting to - * unlock a mutex of this type which is not locked results in undefined behavior. An implementation may map this - * mutex to one of the other mutex types. - */ -#define PTHREAD_MUTEX_DEFAULT 4 - -#endif /* defined(__XMK__) || defined(__rtems__) */ +#if defined(__rtems__) + #include +#endif #if defined(__XMK__) typedef struct pthread_attr_s { @@ -363,7 +355,11 @@ typedef struct { int cputime_clock_allowed; /* see time.h */ #endif int detachstate; - +#if defined(__rtems__) + size_t affinitysetsize; + cpu_set_t *affinityset; + cpu_set_t affinitysetpreallocated; +#endif } pthread_attr_t; #endif /* !defined(__XMK__) */ @@ -391,12 +387,49 @@ typedef struct { /* Values for mutex type */ +/* The following defines are part of the X/Open System Interface (XSI). */ + +/* + * This type of mutex does not detect deadlock. A thread attempting to + * relock this mutex without first unlocking it shall deadlock. Attempting + * to unlock a mutex locked by a different thread results in undefined + * behavior. Attempting to unlock an unlocked mutex results in undefined + * behavior. + */ #define PTHREAD_MUTEX_NORMAL 0 + +/* + * A thread attempting to relock this mutex without first unlocking + * it shall succeed in locking the mutex. The relocking deadlock which + * can occur with mutexes of type PTHREAD_MUTEX_NORMAL cannot occur with + * this type of mutex. Multiple locks of this mutex shall require the + * same number of unlocks to release the mutex before another thread can + * acquire the mutex. A thread attempting to unlock a mutex which another + * thread has locked shall return with an error. A thread attempting to + * unlock an unlocked mutex shall return with an error. + */ #define PTHREAD_MUTEX_RECURSIVE 1 + +/* + * This type of mutex provides error checking. A thread attempting + * to relock this mutex without first unlocking it shall return with an + * error. A thread attempting to unlock a mutex which another thread has + * locked shall return with an error. A thread attempting to unlock an + * unlocked mutex shall return with an error. + */ #define PTHREAD_MUTEX_ERRORCHECK 2 + +/* + * Attempting to recursively lock a mutex of this type results + * in undefined behavior. Attempting to unlock a mutex of this type + * which was not locked by the calling thread results in undefined + * behavior. Attempting to unlock a mutex of this type which is not locked + * results in undefined behavior. An implementation may map this mutex to + * one of the other mutex types. + */ #define PTHREAD_MUTEX_DEFAULT 3 -#endif +#endif /* !defined(_UNIX98_THREAD_MUTEX_ATTRIBUTES) */ #if defined(__XMK__) typedef unsigned int pthread_mutex_t; /* identify a mutex */ @@ -463,13 +496,13 @@ typedef struct { /* POSIX Spin Lock Types */ +#if !defined (__CYGWIN__) #if defined(_POSIX_SPIN_LOCKS) typedef __uint32_t pthread_spinlock_t; /* POSIX Spin Lock Object */ #endif /* defined(_POSIX_SPIN_LOCKS) */ /* POSIX Reader/Writer Lock Types */ -#if !defined (__CYGWIN__) #if defined(_POSIX_READER_WRITER_LOCKS) typedef __uint32_t pthread_rwlock_t; /* POSIX RWLock Object */ typedef struct { diff --git a/contrib/sdk/sources/newlib/libc/include/sys/unistd.h b/contrib/sdk/sources/newlib/libc/include/sys/unistd.h index 50303731b8..6a5719d309 100644 --- a/contrib/sdk/sources/newlib/libc/include/sys/unistd.h +++ b/contrib/sdk/sources/newlib/libc/include/sys/unistd.h @@ -71,6 +71,9 @@ pid_t _EXFUN(fork, (void )); long _EXFUN(fpathconf, (int __fd, int __name )); int _EXFUN(fsync, (int __fd)); int _EXFUN(fdatasync, (int __fd)); +#if defined(__CYGWIN__) +char * _EXFUN(get_current_dir_name, (void)); +#endif char * _EXFUN(getcwd, (char *__buf, size_t __size )); #if defined(__CYGWIN__) int _EXFUN(getdomainname ,(char *__name, size_t __len)); @@ -172,7 +175,7 @@ int _EXFUN(setuid, (uid_t __uid )); void _EXFUN(setusershell, (void)); #endif unsigned _EXFUN(sleep, (unsigned int __seconds )); -void _EXFUN(swab, (const void *, void *, ssize_t)); +void _EXFUN(swab, (const void *__restrict, void *__restrict, ssize_t)); long _EXFUN(sysconf, (int __name )); pid_t _EXFUN(tcgetpgrp, (int __fildes )); int _EXFUN(tcsetpgrp, (int __fildes, pid_t __pgrp_id )); @@ -219,7 +222,7 @@ _READ_WRITE_RETURN_TYPE _EXFUN(_write, (int __fd, const void *__buf, size_t __nb int _EXFUN(_execve, (const char *__path, char * const __argv[], char * const __envp[] )); #endif -#if defined(__CYGWIN__) || defined(__rtems__) || defined(__sh__) || defined(__SPU__) +#if defined(__CYGWIN__) || defined(__rtems__) || defined(__aarch64__) || defined (__arm__) || defined(__sh__) || defined(__SPU__) #if !defined(__INSIDE_CYGWIN__) int _EXFUN(ftruncate, (int __fd, off_t __length)); int _EXFUN(truncate, (const char *, off_t __length)); @@ -230,7 +233,7 @@ int _EXFUN(truncate, (const char *, off_t __length)); int _EXFUN(getdtablesize, (void)); int _EXFUN(setdtablesize, (int)); useconds_t _EXFUN(ualarm, (useconds_t __useconds, useconds_t __interval)); -#if !(defined (_WINSOCK_H) || defined (__USE_W32_SOCKETS)) +#if !(defined (_WINSOCK_H) || defined (_WINSOCKAPI_) || defined (__USE_W32_SOCKETS)) /* winsock[2].h defines as __stdcall, and with int as 2nd arg */ int _EXFUN(gethostname, (char *__name, size_t __len)); #endif @@ -241,9 +244,11 @@ char * _EXFUN(mktemp, (char *)); void _EXFUN(sync, (void)); #endif -ssize_t _EXFUN(readlink, (const char *__path, char *__buf, size_t __buflen)); +ssize_t _EXFUN(readlink, (const char *__restrict __path, + char *__restrict __buf, size_t __buflen)); #if defined(__CYGWIN__) -ssize_t _EXFUN(readlinkat, (int __dirfd1, const char *__path, char *__buf, size_t __buflen)); +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__) @@ -497,10 +502,6 @@ int _EXFUN(unlinkat, (int, const char *, int)); #define _CS_V6_ENV _CS_V7_ENV #endif -#ifndef __CYGWIN__ -# define MAXPATHLEN 1024 -#endif - #ifdef __cplusplus } #endif diff --git a/contrib/sdk/sources/newlib/libc/include/sys/wait.h b/contrib/sdk/sources/newlib/libc/include/sys/wait.h index 863c11ac0c..62a777ea20 100644 --- a/contrib/sdk/sources/newlib/libc/include/sys/wait.h +++ b/contrib/sdk/sources/newlib/libc/include/sys/wait.h @@ -29,6 +29,10 @@ extern "C" { pid_t wait (int *); pid_t waitpid (pid_t, int *, int); +#ifdef _COMPILING_NEWLIB +pid_t _wait (int *); +#endif + /* Provide prototypes for most of the _ names that are provided in newlib for some compilers. */ pid_t _wait (int *); diff --git a/contrib/sdk/sources/newlib/libc/include/tgmath.h b/contrib/sdk/sources/newlib/libc/include/tgmath.h new file mode 100644 index 0000000000..f9c8311cc3 --- /dev/null +++ b/contrib/sdk/sources/newlib/libc/include/tgmath.h @@ -0,0 +1,184 @@ +/* http://pubs.opengroup.org/onlinepubs/9699919799/basedefs/tgmath.h.html */ +/*- + * Copyright (c) 2004 Stefan Farfeleder. + * 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 _TGMATH_H_ +#define _TGMATH_H_ + +#include +#include + +#ifdef log2 +#undef log2 +#endif + +/* + * This implementation of requires two implementation-dependent + * macros to be defined: + * __tg_impl_simple(x, y, z, fn, fnf, fnl, ...) + * Invokes fnl() if the corresponding real type of x, y or z is long + * double, fn() if it is double or any has an integer type, and fnf() + * otherwise. + * __tg_impl_full(x, y, z, fn, fnf, fnl, cfn, cfnf, cfnl, ...) + * Invokes [c]fnl() if the corresponding real type of x, y or z is long + * double, [c]fn() if it is double or any has an integer type, and + * [c]fnf() otherwise. The function with the 'c' prefix is called if + * any of x, y or z is a complex number. + * Both macros call the chosen function with all additional arguments passed + * to them, as given by __VA_ARGS__. + * + * Note that these macros cannot be implemented with C's ?: operator, + * because the return type of the whole expression would incorrectly be long + * double complex regardless of the argument types. + */ + +/* requires GCC >= 3.1 */ +#if !__GNUC_PREREQ (3, 1) +#error " not implemented for this compiler" +#endif + +#define __tg_type(__e, __t) \ + __builtin_types_compatible_p(__typeof__(__e), __t) +#define __tg_type3(__e1, __e2, __e3, __t) \ + (__tg_type(__e1, __t) || __tg_type(__e2, __t) || \ + __tg_type(__e3, __t)) +#define __tg_type_corr(__e1, __e2, __e3, __t) \ + (__tg_type3(__e1, __e2, __e3, __t) || \ + __tg_type3(__e1, __e2, __e3, __t _Complex)) +#define __tg_integer(__e1, __e2, __e3) \ + (((__typeof__(__e1))1.5 == 1) || ((__typeof__(__e2))1.5 == 1) || \ + ((__typeof__(__e3))1.5 == 1)) +#define __tg_is_complex(__e1, __e2, __e3) \ + (__tg_type3(__e1, __e2, __e3, float _Complex) || \ + __tg_type3(__e1, __e2, __e3, double _Complex) || \ + __tg_type3(__e1, __e2, __e3, long double _Complex) || \ + __tg_type3(__e1, __e2, __e3, __typeof__(_Complex_I))) + +#ifdef _LDBL_EQ_DBL +#define __tg_impl_simple(x, y, z, fn, fnf, fnl, ...) \ + __builtin_choose_expr(__tg_type_corr(x, y, z, long double), \ + fnl(__VA_ARGS__), __builtin_choose_expr( \ + __tg_type_corr(x, y, z, double) || __tg_integer(x, y, z),\ + fn(__VA_ARGS__), fnf(__VA_ARGS__))) +#else +#define __tg_impl_simple(__x, __y, __z, __fn, __fnf, __fnl, ...) \ + (__tg_type_corr(__x, __y, __z, double) || __tg_integer(__x, __y, __z)) \ + ? __fn(__VA_ARGS__) : __fnf(__VA_ARGS__) +#endif + +#define __tg_impl_full(__x, __y, __z, __fn, __fnf, __fnl, __cfn, __cfnf, __cfnl, ...) \ + __builtin_choose_expr(__tg_is_complex(__x, __y, __z), \ + __tg_impl_simple(__x, __y, __z, __cfn, __cfnf, __cfnl, __VA_ARGS__), \ + __tg_impl_simple(__x, __y, __z, __fn, __fnf, __fnl, __VA_ARGS__)) + +/* Macros to save lots of repetition below */ +#define __tg_simple(__x, __fn) \ + __tg_impl_simple(__x, __x, __x, __fn, __fn##f, __fn##l, __x) +#define __tg_simple2(__x, __y, __fn) \ + __tg_impl_simple(__x, __x, __y, __fn, __fn##f, __fn##l, __x, __y) +#define __tg_simplev(__x, __fn, ...) \ + __tg_impl_simple(__x, __x, __x, __fn, __fn##f, __fn##l, __VA_ARGS__) +#define __tg_full(__x, __fn) \ + __tg_impl_full(__x, __x, __x, __fn, __fn##f, __fn##l, c##__fn, c##__fn##f, c##__fn##l, __x) + +/* 7.22#4 -- These macros expand to real or complex functions, depending on + * the type of their arguments. */ +#define acos(__x) __tg_full(__x, acos) +#define asin(__x) __tg_full(__x, asin) +#define atan(__x) __tg_full(__x, atan) +#define acosh(__x) __tg_full(__x, acosh) +#define asinh(__x) __tg_full(__x, asinh) +#define atanh(__x) __tg_full(__x, atanh) +#define cos(__x) __tg_full(__x, cos) +#define sin(__x) __tg_full(__x, sin) +#define tan(__x) __tg_full(__x, tan) +#define cosh(__x) __tg_full(__x, cosh) +#define sinh(__x) __tg_full(__x, sinh) +#define tanh(__x) __tg_full(__x, tanh) +#define exp(__x) __tg_full(__x, exp) +#define log(__x) __tg_full(__x, log) +#define pow(__x, __y) __tg_impl_full(__x, __x, __y, pow, powf, powl, \ + cpow, cpowf, cpowl, __x, __y) +#define sqrt(__x) __tg_full(__x, sqrt) + +/* "The corresponding type-generic macro for fabs and cabs is fabs." */ +#define fabs(__x) __tg_impl_full(__x, __x, __x, fabs, fabsf, fabsl, \ + cabs, cabsf, cabsl, __x) + +/* 7.22#5 -- These macros are only defined for arguments with real type. */ +#define atan2(__x, __y) __tg_simple2(__x, __y, atan2) +#define cbrt(__x) __tg_simple(__x, cbrt) +#define ceil(__x) __tg_simple(__x, ceil) +#define copysign(__x, __y) __tg_simple2(__x, __y, copysign) +#define erf(__x) __tg_simple(__x, erf) +#define erfc(__x) __tg_simple(__x, erfc) +#define exp2(__x) __tg_simple(__x, exp2) +#define expm1(__x) __tg_simple(__x, expm1) +#define fdim(__x, __y) __tg_simple2(__x, __y, fdim) +#define floor(__x) __tg_simple(__x, floor) +#define fma(__x, __y, __z) __tg_impl_simple(__x, __y, __z, fma, fmaf, fmal, \ + __x, __y, __z) +#define fmax(__x, __y) __tg_simple2(__x, __y, fmax) +#define fmin(__x, __y) __tg_simple2(__x, __y, fmin) +#define fmod(__x, __y) __tg_simple2(__x, __y, fmod) +#define frexp(__x, __y) __tg_simplev(__x, frexp, __x, __y) +#define hypot(__x, __y) __tg_simple2(__x, __y, hypot) +#define ilogb(__x) __tg_simple(__x, ilogb) +#define ldexp(__x, __y) __tg_simplev(__x, ldexp, __x, __y) +#define lgamma(__x) __tg_simple(__x, lgamma) +#define llrint(__x) __tg_simple(__x, llrint) +#define llround(__x) __tg_simple(__x, llround) +#define log10(__x) __tg_simple(__x, log10) +#define log1p(__x) __tg_simple(__x, log1p) +#define log2(__x) __tg_simple(__x, log2) +#define logb(__x) __tg_simple(__x, logb) +#define lrint(__x) __tg_simple(__x, lrint) +#define lround(__x) __tg_simple(__x, lround) +#define nearbyint(__x) __tg_simple(__x, nearbyint) +#define nextafter(__x, __y) __tg_simple2(__x, __y, nextafter) +/* not yet implemented even for _LDBL_EQ_DBL platforms +#define nexttoward(__x, __y) __tg_simplev(__x, nexttoward, __x, __y) +*/ +#define remainder(__x, __y) __tg_simple2(__x, __y, remainder) +#define remquo(__x, __y, __z) __tg_impl_simple(__x, __x, __y, remquo, remquof, \ + remquol, __x, __y, __z) +#define rint(__x) __tg_simple(__x, rint) +#define round(__x) __tg_simple(__x, round) +#define scalbn(__x, __y) __tg_simplev(__x, scalbn, __x, __y) +#define scalbln(__x, __y) __tg_simplev(__x, scalbln, __x, __y) +#define tgamma(__x) __tg_simple(__x, tgamma) +#define trunc(__x) __tg_simple(__x, trunc) + +/* 7.22#6 -- These macros always expand to complex functions. */ +#define carg(__x) __tg_simple(__x, carg) +#define cimag(__x) __tg_simple(__x, cimag) +#define conj(__x) __tg_simple(__x, conj) +#define cproj(__x) __tg_simple(__x, cproj) +#define creal(__x) __tg_simple(__x, creal) + +#endif /* !_TGMATH_H_ */ diff --git a/contrib/sdk/sources/newlib/libc/include/time.h b/contrib/sdk/sources/newlib/libc/include/time.h index d8072c7fee..67f8d61b6d 100644 --- a/contrib/sdk/sources/newlib/libc/include/time.h +++ b/contrib/sdk/sources/newlib/libc/include/time.h @@ -10,9 +10,9 @@ #include "_ansi.h" #include -#ifndef NULL -#define NULL 0 -#endif +#define __need_size_t +#define __need_NULL +#include /* Get _CLOCKS_PER_SEC_ */ #include @@ -23,8 +23,6 @@ #define CLOCKS_PER_SEC _CLOCKS_PER_SEC_ #define CLK_TCK CLOCKS_PER_SEC -#define __need_size_t -#include #include @@ -53,12 +51,17 @@ char *_EXFUN(ctime, (const time_t *_time)); struct tm *_EXFUN(gmtime, (const time_t *_timer)); struct tm *_EXFUN(localtime,(const time_t *_timer)); #endif -size_t _EXFUN(strftime, (char *_s, size_t _maxsize, const char *_fmt, const struct tm *_t)); +size_t _EXFUN(strftime, (char *__restrict _s, + size_t _maxsize, const char *__restrict _fmt, + const struct tm *__restrict _t)); -char *_EXFUN(asctime_r, (const struct tm *, char *)); +char *_EXFUN(asctime_r, (const struct tm *__restrict, + char *__restrict)); char *_EXFUN(ctime_r, (const time_t *, char *)); -struct tm *_EXFUN(gmtime_r, (const time_t *, struct tm *)); -struct tm *_EXFUN(localtime_r, (const time_t *, struct tm *)); +struct tm *_EXFUN(gmtime_r, (const time_t *__restrict, + struct tm *__restrict)); +struct tm *_EXFUN(localtime_r, (const time_t *__restrict, + struct tm *__restrict)); _END_STD_C @@ -67,7 +70,9 @@ extern "C" { #endif #ifndef __STRICT_ANSI__ -char *_EXFUN(strptime, (const char *, const char *, struct tm *)); +char *_EXFUN(strptime, (const char *__restrict, + const char *__restrict, + struct tm *__restrict)); _VOID _EXFUN(tzset, (_VOID)); _VOID _EXFUN(_tzset_r, (struct _reent *)); @@ -152,7 +157,9 @@ int _EXFUN(clock_getres, (clockid_t clock_id, struct timespec *res)); /* Create a Per-Process Timer, P1003.1b-1993, p. 264 */ int _EXFUN(timer_create, - (clockid_t clock_id, struct sigevent *evp, timer_t *timerid)); + (clockid_t clock_id, + struct sigevent *__restrict evp, + timer_t *__restrict timerid)); /* Delete a Per_process Timer, P1003.1b-1993, p. 266 */ @@ -161,8 +168,9 @@ int _EXFUN(timer_delete, (timer_t timerid)); /* Per-Process Timers, P1003.1b-1993, p. 267 */ int _EXFUN(timer_settime, - (timer_t timerid, int flags, const struct itimerspec *value, - struct itimerspec *ovalue)); + (timer_t timerid, int flags, + const struct itimerspec *__restrict value, + struct itimerspec *__restrict ovalue)); int _EXFUN(timer_gettime, (timer_t timerid, struct itimerspec *value)); int _EXFUN(timer_getoverrun, (timer_t timerid)); diff --git a/contrib/sdk/sources/newlib/libc/include/wchar.h b/contrib/sdk/sources/newlib/libc/include/wchar.h index 4aa62726fa..553641797f 100644 --- a/contrib/sdk/sources/newlib/libc/include/wchar.h +++ b/contrib/sdk/sources/newlib/libc/include/wchar.h @@ -8,6 +8,7 @@ #define __need_size_t #define __need_wchar_t #define __need_wint_t +#define __need_NULL #include #define __need___va_list @@ -19,28 +20,35 @@ /* For __STDC_ISO_10646__ */ #include -#ifndef NULL -#define NULL 0 -#endif - #ifndef WEOF # define WEOF ((wint_t)-1) #endif #ifndef WCHAR_MIN -#define WCHAR_MIN 0 +#ifdef __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 #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 0x7fffffffu +#define WCHAR_MAX (0x7fffffff + L'\0') #endif #endif _BEGIN_STD_C +/* As in stdio.h, defines __FILE. */ +typedef __FILE FILE; + /* As required by POSIX.1-2008, declare tm as incomplete type. The actual definition is in time.h. */ struct tm; @@ -52,77 +60,96 @@ typedef _mbstate_t mbstate_t; wint_t _EXFUN(btowc, (int)); int _EXFUN(wctob, (wint_t)); -size_t _EXFUN(mbrlen, (const char * , size_t, mbstate_t *)); -size_t _EXFUN(mbrtowc, (wchar_t * , const char * , size_t, mbstate_t *)); +size_t _EXFUN(mbrlen, (const char *__restrict, size_t, mbstate_t *__restrict)); +size_t _EXFUN(mbrtowc, (wchar_t *__restrict, const char *__restrict, size_t, + mbstate_t *__restrict)); size_t _EXFUN(_mbrtowc_r, (struct _reent *, wchar_t * , const char * , size_t, mbstate_t *)); int _EXFUN(mbsinit, (const mbstate_t *)); -size_t _EXFUN(mbsnrtowcs, (wchar_t * , const char ** , size_t, size_t, - mbstate_t *)); +size_t _EXFUN(mbsnrtowcs, (wchar_t *__restrict, const char **__restrict, + size_t, size_t, mbstate_t *__restrict)); size_t _EXFUN(_mbsnrtowcs_r, (struct _reent *, wchar_t * , const char ** , size_t, size_t, mbstate_t *)); -size_t _EXFUN(mbsrtowcs, (wchar_t * , const char ** , size_t, mbstate_t *)); +size_t _EXFUN(mbsrtowcs, (wchar_t *__restrict, const char **__restrict, size_t, + mbstate_t *__restrict)); size_t _EXFUN(_mbsrtowcs_r, (struct _reent *, wchar_t * , const char ** , size_t, mbstate_t *)); -size_t _EXFUN(wcrtomb, (char * , wchar_t, mbstate_t *)); +size_t _EXFUN(wcrtomb, (char *__restrict, wchar_t, mbstate_t *__restrict)); size_t _EXFUN(_wcrtomb_r, (struct _reent *, char * , wchar_t, mbstate_t *)); -size_t _EXFUN(wcsnrtombs, (char * , const wchar_t ** , size_t, size_t, - mbstate_t *)); +size_t _EXFUN(wcsnrtombs, (char *__restrict, const wchar_t **__restrict, + size_t, size_t, mbstate_t *__restrict)); size_t _EXFUN(_wcsnrtombs_r, (struct _reent *, char * , const wchar_t ** , size_t, size_t, mbstate_t *)); -size_t _EXFUN(wcsrtombs, (char * , const wchar_t ** , size_t, mbstate_t *)); +size_t _EXFUN(wcsrtombs, (char *__restrict, const wchar_t **__restrict, + size_t, mbstate_t *__restrict)); size_t _EXFUN(_wcsrtombs_r, (struct _reent *, char * , const wchar_t ** , size_t, mbstate_t *)); int _EXFUN(wcscasecmp, (const wchar_t *, const wchar_t *)); -wchar_t *_EXFUN(wcscat, (wchar_t * , const wchar_t *)); +wchar_t *_EXFUN(wcscat, (wchar_t *__restrict, const wchar_t *__restrict)); wchar_t *_EXFUN(wcschr, (const wchar_t *, wchar_t)); int _EXFUN(wcscmp, (const wchar_t *, const wchar_t *)); int _EXFUN(wcscoll, (const wchar_t *, const wchar_t *)); -wchar_t *_EXFUN(wcscpy, (wchar_t * , const wchar_t *)); -wchar_t *_EXFUN(wcpcpy, (wchar_t * , const wchar_t *)); +wchar_t *_EXFUN(wcscpy, (wchar_t *__restrict, const wchar_t *__restrict)); +wchar_t *_EXFUN(wcpcpy, (wchar_t *__restrict, + const wchar_t *__restrict)); wchar_t *_EXFUN(wcsdup, (const wchar_t *)); wchar_t *_EXFUN(_wcsdup_r, (struct _reent *, const wchar_t * )); size_t _EXFUN(wcscspn, (const wchar_t *, const wchar_t *)); -size_t _EXFUN(wcsftime, (wchar_t *, size_t, const wchar_t *, const struct tm *)); +size_t _EXFUN(wcsftime, (wchar_t *__restrict, size_t, + const wchar_t *__restrict, const struct tm *__restrict)); size_t _EXFUN(wcslcat, (wchar_t *, const wchar_t *, size_t)); size_t _EXFUN(wcslcpy, (wchar_t *, const wchar_t *, size_t)); size_t _EXFUN(wcslen, (const wchar_t *)); int _EXFUN(wcsncasecmp, (const wchar_t *, const wchar_t *, size_t)); -wchar_t *_EXFUN(wcsncat, (wchar_t * , const wchar_t * , size_t)); +wchar_t *_EXFUN(wcsncat, (wchar_t *__restrict, + const wchar_t *__restrict, size_t)); int _EXFUN(wcsncmp, (const wchar_t *, const wchar_t *, size_t)); -wchar_t *_EXFUN(wcsncpy, (wchar_t * , const wchar_t * , size_t)); -wchar_t *_EXFUN(wcpncpy, (wchar_t * , const wchar_t * , size_t)); +wchar_t *_EXFUN(wcsncpy, (wchar_t *__restrict, + const wchar_t *__restrict, size_t)); +wchar_t *_EXFUN(wcpncpy, (wchar_t *__restrict, + const wchar_t *__restrict, size_t)); size_t _EXFUN(wcsnlen, (const wchar_t *, size_t)); wchar_t *_EXFUN(wcspbrk, (const wchar_t *, const wchar_t *)); wchar_t *_EXFUN(wcsrchr, (const wchar_t *, wchar_t)); size_t _EXFUN(wcsspn, (const wchar_t *, const wchar_t *)); -wchar_t *_EXFUN(wcsstr, (const wchar_t *, const wchar_t *)); -wchar_t *_EXFUN(wcstok, (wchar_t *, const wchar_t *, wchar_t **)); -double _EXFUN(wcstod, (const wchar_t *, wchar_t **)); +wchar_t *_EXFUN(wcsstr, (const wchar_t *__restrict, + const wchar_t *__restrict)); +wchar_t *_EXFUN(wcstok, (wchar_t *__restrict, const wchar_t *__restrict, + wchar_t **__restrict)); +double _EXFUN(wcstod, (const wchar_t *__restrict, wchar_t **__restrict)); double _EXFUN(_wcstod_r, (struct _reent *, const wchar_t *, wchar_t **)); -float _EXFUN(wcstof, (const wchar_t *, wchar_t **)); +float _EXFUN(wcstof, (const wchar_t *__restrict, wchar_t **__restrict)); float _EXFUN(_wcstof_r, (struct _reent *, const wchar_t *, wchar_t **)); int _EXFUN(wcswidth, (const wchar_t *, size_t)); -size_t _EXFUN(wcsxfrm, (wchar_t *, const wchar_t *, size_t)); +size_t _EXFUN(wcsxfrm, (wchar_t *__restrict, const wchar_t *__restrict, + size_t)); int _EXFUN(wcwidth, (const wchar_t)); wchar_t *_EXFUN(wmemchr, (const wchar_t *, wchar_t, size_t)); int _EXFUN(wmemcmp, (const wchar_t *, const wchar_t *, size_t)); -wchar_t *_EXFUN(wmemcpy, (wchar_t * , const wchar_t * , size_t)); +wchar_t *_EXFUN(wmemcpy, (wchar_t *__restrict, const wchar_t *__restrict, + size_t)); wchar_t *_EXFUN(wmemmove, (wchar_t *, const wchar_t *, size_t)); wchar_t *_EXFUN(wmemset, (wchar_t *, wchar_t, size_t)); -long _EXFUN(wcstol, (const wchar_t *, wchar_t **, int)); -long long _EXFUN(wcstoll, (const wchar_t *, wchar_t **, int)); -unsigned long _EXFUN(wcstoul, (const wchar_t *, wchar_t **, int)); -unsigned long long _EXFUN(wcstoull, (const wchar_t *, wchar_t **, int)); +long _EXFUN(wcstol, (const wchar_t *__restrict, wchar_t **__restrict, int)); +long long _EXFUN(wcstoll, (const wchar_t *__restrict, wchar_t **__restrict, + int)); +unsigned long _EXFUN(wcstoul, (const wchar_t *__restrict, wchar_t **__restrict, + int)); +unsigned long long _EXFUN(wcstoull, (const wchar_t *__restrict, + wchar_t **__restrict, int)); 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 *, int, __FILE *)); +wchar_t *_EXFUN(fgetws, (wchar_t *__restrict, int, __FILE *__restrict)); wint_t _EXFUN(fputwc, (wchar_t, __FILE *)); -int _EXFUN(fputws, (const wchar_t *, __FILE *)); +int _EXFUN(fputws, (const wchar_t *__restrict, __FILE *__restrict)); int _EXFUN (fwide, (__FILE *, int)); wint_t _EXFUN (getwc, (__FILE *)); wint_t _EXFUN (getwchar, (void)); @@ -152,12 +179,15 @@ __FILE *_EXFUN (_open_wmemstream_r, (struct _reent *, wchar_t **, size_t *)); #endif #endif -int _EXFUN(fwprintf, (__FILE *, const wchar_t *, ...)); -int _EXFUN(swprintf, (wchar_t *, size_t, const wchar_t *, ...)); -int _EXFUN(vfwprintf, (__FILE *, const wchar_t *, __VALIST)); -int _EXFUN(vswprintf, (wchar_t *, size_t, const wchar_t *, __VALIST)); -int _EXFUN(vwprintf, (const wchar_t *, __VALIST)); -int _EXFUN(wprintf, (const wchar_t *, ...)); +int _EXFUN(fwprintf, (__FILE *__restrict, const wchar_t *__restrict, ...)); +int _EXFUN(swprintf, (wchar_t *__restrict, size_t, + const wchar_t *__restrict, ...)); +int _EXFUN(vfwprintf, (__FILE *__restrict, const wchar_t *__restrict, + __VALIST)); +int _EXFUN(vswprintf, (wchar_t *__restrict, size_t, + const wchar_t *__restrict, __VALIST)); +int _EXFUN(vwprintf, (const wchar_t *__restrict, __VALIST)); +int _EXFUN(wprintf, (const wchar_t *__restrict, ...)); int _EXFUN(_fwprintf_r, (struct _reent *, __FILE *, const wchar_t *, ...)); int _EXFUN(_swprintf_r, (struct _reent *, wchar_t *, size_t, const wchar_t *, ...)); @@ -166,12 +196,15 @@ int _EXFUN(_vswprintf_r, (struct _reent *, wchar_t *, size_t, const wchar_t *, _ int _EXFUN(_vwprintf_r, (struct _reent *, const wchar_t *, __VALIST)); int _EXFUN(_wprintf_r, (struct _reent *, const wchar_t *, ...)); -int _EXFUN(fwscanf, (__FILE *, const wchar_t *, ...)); -int _EXFUN(swscanf, (const wchar_t *, const wchar_t *, ...)); -int _EXFUN(vfwscanf, (__FILE *, const wchar_t *, __VALIST)); -int _EXFUN(vswscanf, (const wchar_t *, const wchar_t *, __VALIST)); -int _EXFUN(vwscanf, (const wchar_t *, __VALIST)); -int _EXFUN(wscanf, (const wchar_t *, ...)); +int _EXFUN(fwscanf, (__FILE *__restrict, const wchar_t *__restrict, ...)); +int _EXFUN(swscanf, (const wchar_t *__restrict, + const wchar_t *__restrict, ...)); +int _EXFUN(vfwscanf, (__FILE *__restrict, const wchar_t *__restrict, + __VALIST)); +int _EXFUN(vswscanf, (const wchar_t *__restrict, const wchar_t *__restrict, + __VALIST)); +int _EXFUN(vwscanf, (const wchar_t *__restrict, __VALIST)); +int _EXFUN(wscanf, (const wchar_t *__restrict, ...)); int _EXFUN(_fwscanf_r, (struct _reent *, __FILE *, const wchar_t *, ...)); int _EXFUN(_swscanf_r, (struct _reent *, const wchar_t *, const wchar_t *, ...)); @@ -182,13 +215,8 @@ int _EXFUN(_wscanf_r, (struct _reent *, const wchar_t *, ...)); #define getwc(fp) fgetwc(fp) #define putwc(wc,fp) fputwc((wc), (fp)) -#ifndef _REENT_ONLY #define getwchar() fgetwc(_REENT->_stdin) #define putwchar(wc) fputwc((wc), _REENT->_stdout) -#else -#define getwchar() fgetwc(_impure_ptr->_stdin) -#define putwchar(wc) fputwc((wc), _impure_ptr->_stdout) -#endif _END_STD_C diff --git a/contrib/sdk/sources/newlib/libc/include/wordexp.h b/contrib/sdk/sources/newlib/libc/include/wordexp.h index 9f3e88b4c2..f7454a444a 100644 --- a/contrib/sdk/sources/newlib/libc/include/wordexp.h +++ b/contrib/sdk/sources/newlib/libc/include/wordexp.h @@ -43,7 +43,7 @@ enum { /* Note: This implementation of wordexp requires a version of bash that supports the --wordexp and --protected arguments to be present on the system. It does not support the WRDE_UNDEF flag. */ -int wordexp(const char *, wordexp_t *, int); +int wordexp(const char *__restrict, wordexp_t *__restrict, int); void wordfree(wordexp_t *); #ifdef __cplusplus diff --git a/contrib/sdk/sources/newlib/libc/locale/ldpart.c b/contrib/sdk/sources/newlib/libc/locale/ldpart.c new file mode 100644 index 0000000000..595532298f --- /dev/null +++ b/contrib/sdk/sources/newlib/libc/locale/ldpart.c @@ -0,0 +1,191 @@ +/* + * Copyright (c) 2000, 2001 Alexey Zelkin + * 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. + */ + +#include + +#include +#include +#include +#include +#include +#include +#include + +#include "setlocale.h" +#include "ldpart.h" + +static int split_lines(char *, const char *); +static void set_from_buf(const char *, int, const char **); + +int +__part_load_locale(const char *name, + int *using_locale, + char *locale_buf, + const char *category_filename, + int locale_buf_size_max, + int locale_buf_size_min, + const char **dst_localebuf) { + + static char locale_buf_C[] = "C"; + static int num_lines; + + int fd; + char *lbuf; + char *p; + const char *plim; + char filename[PATH_MAX]; +#ifdef __USE_INTERNAL_STAT64 + struct stat64 st; +#else + struct stat st; +#endif + size_t namesize; + size_t bufsize; + int save_using_locale; + char *nptr; + + save_using_locale = *using_locale; + *using_locale = 0; + + if (name == NULL) + goto no_locale; + + if (!strcmp(name, "C") || !strcmp(name, "POSIX")) + return 0; + + /* + * If the locale name is the same as our cache, use the cache. + */ + lbuf = locale_buf; + if (lbuf != NULL && strcmp(name, lbuf) == 0) { + set_from_buf(lbuf, num_lines, dst_localebuf); + *using_locale = 1; + return 0; + } + + /* + * Slurp the locale file into the cache. + */ + namesize = strlen(name) + 1; + + if (!_PathLocale) + goto no_locale; + /* Range checking not needed, 'name' size is limited */ + strcpy(filename, _PathLocale); + strcat(filename, "/"); + strcat(filename, name); + strcat(filename, "/"); + strcat(filename, category_filename); + fd = open(filename, O_RDONLY); + if (fd < 0) + goto no_locale; +#ifdef __USE_INTERNAL_STAT64 + if (fstat64(fd, &st) != 0) +#else + if (fstat(fd, &st) != 0) +#endif + goto bad_locale; + if (st.st_size <= 0) + goto bad_locale; + bufsize = namesize + st.st_size; + locale_buf = NULL; + + if (lbuf == NULL || lbuf == locale_buf_C) + { + lbuf = malloc(bufsize); + } + else + { + nptr = realloc(lbuf, bufsize); + if (!nptr && lbuf) + free (lbuf); + lbuf = nptr; + } + + if (lbuf == NULL) + goto bad_locale; + (void) strcpy(lbuf, name); + p = lbuf + namesize; + plim = p + st.st_size; + if (read(fd, p, (size_t) st.st_size) != st.st_size) + goto bad_lbuf; + if (close(fd) != 0) + goto bad_lbuf; + /* + * Parse the locale file into localebuf. + */ + if (plim[-1] != '\n') + goto bad_lbuf; + num_lines = split_lines(p, plim); + if (num_lines >= locale_buf_size_max) + num_lines = locale_buf_size_max; + else if (num_lines >= locale_buf_size_min) + num_lines = locale_buf_size_min; + else + goto reset_locale; + set_from_buf(lbuf, num_lines, dst_localebuf); + /* + * Record the successful parse in the cache. + */ + locale_buf = lbuf; + + *using_locale = 1; + return 0; + +reset_locale: + locale_buf = locale_buf_C; + save_using_locale = 0; +bad_lbuf: + free(lbuf); +bad_locale: + (void)close(fd); +no_locale: + *using_locale = save_using_locale; + return -1; +} + +static int +split_lines(char *p, const char *plim) { + + int i; + + for (i = 0; p < plim; i++) { + p = strchr(p, '\n'); + *p++ = '\0'; + } + return i; +} + +static void +set_from_buf(const char *p, int num_lines, const char **dst_localebuf) { + + const char **ap; + int i; + + for (ap = dst_localebuf, i = 0; i < num_lines; ++ap, ++i) + *ap = p += strlen(p) + 1; +} + diff --git a/contrib/sdk/sources/newlib/libc/locale/locale.c b/contrib/sdk/sources/newlib/libc/locale/locale.c index 810f724c2f..2c5b65e2a6 100644 --- a/contrib/sdk/sources/newlib/libc/locale/locale.c +++ b/contrib/sdk/sources/newlib/libc/locale/locale.c @@ -188,7 +188,11 @@ No supporting OS subroutines are required. #define _LC_LAST 7 #define ENCODING_LEN 31 +#ifdef __CYGWIN__ /* Cygwin starts with LC_CTYPE set to "C.UTF-8". */ +int __EXPORT __mb_cur_max = 6; +#else int __EXPORT __mb_cur_max = 1; +#endif int __nlocale_changed = 0; int __mlocale_changed = 0; diff --git a/contrib/sdk/sources/newlib/libc/reent/closer.c b/contrib/sdk/sources/newlib/libc/reent/closer.c index 9c1f160e87..70a46e9a40 100644 --- a/contrib/sdk/sources/newlib/libc/reent/closer.c +++ b/contrib/sdk/sources/newlib/libc/reent/closer.c @@ -3,7 +3,6 @@ #include #include #include <_syslist.h> -#include /* Some targets provides their own versions of this functions. Those targets should define REENTRANT_SYSCALLS_PROVIDED in TARGET_CFLAGS. */ @@ -16,6 +15,9 @@ #ifndef REENTRANT_SYSCALLS_PROVIDED +/* We use the errno variable used by the system dependent layer. */ +#undef errno +extern int errno; /* FUNCTION @@ -39,49 +41,18 @@ DESCRIPTION takes a pointer to the global data block, which holds <>. */ -extern unsigned __NFiles; - - -#define __handle_check( __h, __r ) \ - if( (__h) < 0 || (__h) > __NFiles ) { \ - ptr->_errno = EBADF ; \ - return( __r ); \ - } - - - int -_DEFUN(_close_r, (ptr, fd), - struct _reent *ptr _AND - int fd) +_close_r (ptr, fd) + struct _reent *ptr; + int fd; { - int ret; - int h; + int ret; - __file_handle *fh; - - __handle_check( fd, -1 ); - - fh = (__file_handle*) __getOSHandle( fd ); - - if( fd > STDERR_FILENO ) - { - _free_r(ptr, fh->name); - _free_r(ptr, fh); - __freePOSIXHandle( fd ); - __SetIOMode_nogrow( fd, 0 ); - } - - return 0; -} - - -int -_DEFUN( close,(fd), - int fd) -{ - return _close_r(_REENT, fd); + errno = 0; + if ((ret = _close (fd)) == -1 && errno != 0) + ptr->_errno = errno; + return ret; } #endif /* ! defined (REENTRANT_SYSCALLS_PROVIDED) */ diff --git a/contrib/sdk/sources/newlib/libc/reent/fstatr.c b/contrib/sdk/sources/newlib/libc/reent/fstatr.c index c652e3f08e..7d4163d148 100644 --- a/contrib/sdk/sources/newlib/libc/reent/fstatr.c +++ b/contrib/sdk/sources/newlib/libc/reent/fstatr.c @@ -5,9 +5,6 @@ #include #include #include <_syslist.h> -#include -#include - /* Some targets provides their own versions of these functions. Those targets should define REENTRANT_SYSCALLS_PROVIDED in TARGET_CFLAGS. */ @@ -25,6 +22,8 @@ int _dummy_fstat_syscalls = 1; #else /* We use the errno variable used by the system dependent layer. */ +#undef errno +extern int errno; /* FUNCTION @@ -51,106 +50,18 @@ DESCRIPTION <>. */ -#pragma pack(push, 1) -typedef struct -{ - char sec; - char min; - char hour; - char rsv; -}detime_t; - -typedef struct -{ - char day; - char month; - short year; -}dedate_t; - -typedef struct -{ - unsigned attr; - unsigned flags; - union - { - detime_t ctime; - unsigned cr_time; - }; - union - { - dedate_t cdate; - unsigned cr_date; - }; - union - { - detime_t atime; - unsigned acc_time; - }; - union - { - dedate_t adate; - unsigned acc_date; - }; - union - { - detime_t mtime; - unsigned mod_time; - }; - union - { - dedate_t mdate; - unsigned mod_date; - }; - unsigned size; - unsigned size_high; -} FILEINFO; - -#pragma pack(pop) - -extern unsigned __NFiles; - -#define __handle_check( __h, __r ) \ - if( (__h) < 0 || (__h) > __NFiles ) { \ - ptr->_errno = EBADF ; \ - return( __r ); \ - } - int _fstat_r (ptr, fd, pstat) struct _reent *ptr; int fd; struct stat *pstat; { - FILEINFO info; - int ret; + int ret; - __file_handle *fh; - - __handle_check( fd, -1 ); - - if (fd < 3) - { - pstat->st_mode = S_IFCHR; - pstat->st_blksize = 0; - return 0; - } - - fh = (__file_handle*) __getOSHandle( fd ); - get_fileinfo(fh->name, &info); - - memset (pstat, 0, sizeof (* pstat)); - pstat->st_mode = S_IFREG; - pstat->st_blksize = 4096; - pstat->st_size = info.size; - return 0; -} - -int -_DEFUN (fstat, (fd, pstat), - int fd _AND - struct stat *pstat) -{ - return _fstat_r (_REENT, fd, pstat); + errno = 0; + if ((ret = _fstat (fd, pstat)) == -1 && errno != 0) + ptr->_errno = errno; + return ret; } #endif /* ! defined (REENTRANT_SYSCALLS_PROVIDED) */ diff --git a/contrib/sdk/sources/newlib/libc/reent/getreent.c b/contrib/sdk/sources/newlib/libc/reent/getreent.c index 30438cd00a..4079e30adf 100644 --- a/contrib/sdk/sources/newlib/libc/reent/getreent.c +++ b/contrib/sdk/sources/newlib/libc/reent/getreent.c @@ -19,7 +19,3 @@ void init_reent() ::"r"(ent)); __sinit(ent); } - - - - diff --git a/contrib/sdk/sources/newlib/libc/reent/gettimeofdayr.c b/contrib/sdk/sources/newlib/libc/reent/gettimeofdayr.c index 2b3bff9d54..5dbb76706d 100644 --- a/contrib/sdk/sources/newlib/libc/reent/gettimeofdayr.c +++ b/contrib/sdk/sources/newlib/libc/reent/gettimeofdayr.c @@ -8,7 +8,6 @@ #include #include #include <_syslist.h> -#include /* Some targets provides their own versions of these functions. Those targets should define REENTRANT_SYSCALLS_PROVIDED in TARGET_CFLAGS. */ @@ -27,7 +26,7 @@ int _dummy_gettimeofday_syscalls = 1; /* We use the errno variable used by the system dependent layer. */ #undef errno -static int errno; +extern int errno; /* FUNCTION @@ -74,40 +73,4 @@ _DEFUN (_gettimeofday_r, (ptr, ptimeval, ptimezone), return ret; } -#define BCD_TO_BIN(val) ((val)=((val)&15) + ((val)>>4)*10) - -int -_gettimeofday (struct timeval *tv, void *tz) -{ - unsigned int xtmp; - struct tm tmblk; - - if( tv ) - { - tv->tv_usec = 0; - - __asm__ __volatile__("int $0x40":"=a"(xtmp):"0"(3)); - tmblk.tm_sec = (xtmp>>16)&0xff; - tmblk.tm_min = (xtmp>>8)&0xff; - tmblk.tm_hour = xtmp&0xff; - BCD_TO_BIN(tmblk.tm_sec); - BCD_TO_BIN(tmblk.tm_min); - BCD_TO_BIN(tmblk.tm_hour); - __asm__ __volatile__("int $0x40":"=a"(xtmp):"0"(29)); - tmblk.tm_mday = (xtmp>>16)&0xff; - tmblk.tm_mon = ((xtmp>>8)&0xff)-1; - tmblk.tm_year = ((xtmp&0xff)+2000)-1900; - tmblk.tm_wday = tmblk.tm_yday = 0; - tmblk.tm_isdst = -1; - tv->tv_sec = mktime(&tmblk); - return 0; - } - else - { - errno = EINVAL; - return -1; - }; -} - - #endif /* ! defined (REENTRANT_SYSCALLS_PROVIDED) */ diff --git a/contrib/sdk/sources/newlib/libc/reent/isattyr.c b/contrib/sdk/sources/newlib/libc/reent/isattyr.c index 2685258d13..e59a0052b0 100644 --- a/contrib/sdk/sources/newlib/libc/reent/isattyr.c +++ b/contrib/sdk/sources/newlib/libc/reent/isattyr.c @@ -3,7 +3,6 @@ #include #include #include <_syslist.h> -#include /* Some targets provides their own versions of these functions. Those targets should define REENTRANT_SYSCALLS_PROVIDED in TARGET_CFLAGS. */ @@ -55,8 +54,10 @@ _isatty_r (ptr, fd) { int ret; - ptr->_errno = ENOTTY ; - return 0; + errno = 0; + if ((ret = _isatty (fd)) == -1 && errno != 0) + ptr->_errno = errno; + return ret; } #endif /* ! defined (REENTRANT_SYSCALLS_PROVIDED) */ diff --git a/contrib/sdk/sources/newlib/libc/reent/linkr.c b/contrib/sdk/sources/newlib/libc/reent/linkr.c new file mode 100644 index 0000000000..ded636af76 --- /dev/null +++ b/contrib/sdk/sources/newlib/libc/reent/linkr.c @@ -0,0 +1,66 @@ +/* Reentrant versions of file system calls. These implementations + just call the usual system calls. */ + +#include +#include +#include <_syslist.h> + +/* Some targets provides their own versions of these functions. Those + targets should define REENTRANT_SYSCALLS_PROVIDED in TARGET_CFLAGS. */ + +#ifdef _REENT_ONLY +#ifndef REENTRANT_SYSCALLS_PROVIDED +#define REENTRANT_SYSCALLS_PROVIDED +#endif +#endif + +#ifdef REENTRANT_SYSCALLS_PROVIDED + +int _dummy_link_syscalls = 1; + +#else + +/* We use the errno variable used by the system dependent layer. */ +#undef errno +extern int errno; + +/* +FUNCTION + <<_link_r>>---Reentrant version of link + +INDEX + _link_r + +ANSI_SYNOPSIS + #include + int _link_r(struct _reent *<[ptr]>, + const char *<[old]>, const char *<[new]>); + +TRAD_SYNOPSIS + #include + int _link_r(<[ptr]>, <[old]>, <[new]>) + struct _reent *<[ptr]>; + char *<[old]>; + char *<[new]>; + +DESCRIPTION + This is a reentrant version of <>. It + takes a pointer to the global data block, which holds + <>. +*/ + +int +_DEFUN (_link_r, (ptr, old, new), + struct _reent *ptr _AND + _CONST char *old _AND + _CONST char *new) +{ + int ret; + + errno = 0; + if ((ret = _link (old, new)) == -1 && errno != 0) + ptr->_errno = errno; + return ret; +} + +#endif /* ! defined (REENTRANT_SYSCALLS_PROVIDED) */ diff --git a/contrib/sdk/sources/newlib/libc/reent/lseekr.c b/contrib/sdk/sources/newlib/libc/reent/lseekr.c index 8af42f8eeb..355ceeaa97 100644 --- a/contrib/sdk/sources/newlib/libc/reent/lseekr.c +++ b/contrib/sdk/sources/newlib/libc/reent/lseekr.c @@ -3,7 +3,6 @@ #include #include #include <_syslist.h> -#include /* Some targets provides their own versions of this functions. Those targets should define REENTRANT_SYSCALLS_PROVIDED in TARGET_CFLAGS. */ @@ -16,71 +15,9 @@ #ifndef REENTRANT_SYSCALLS_PROVIDED -#pragma pack(push, 1) -typedef struct -{ - char sec; - char min; - char hour; - char rsv; -}detime_t; - -typedef struct -{ - char day; - char month; - short year; -}dedate_t; - -typedef struct -{ - unsigned attr; - unsigned flags; - union - { - detime_t ctime; - unsigned cr_time; - }; - union - { - dedate_t cdate; - unsigned cr_date; - }; - union - { - detime_t atime; - unsigned acc_time; - }; - union - { - dedate_t adate; - unsigned acc_date; - }; - union - { - detime_t mtime; - unsigned mod_time; - }; - union - { - dedate_t mdate; - unsigned mod_date; - }; - unsigned size; - unsigned size_high; -} FILEINFO; - -#pragma pack(pop) - - -extern unsigned __NFiles; - -#define __handle_check( __h, __r ) \ - if( (__h) < 0 || (__h) > __NFiles ) { \ - ptr->_errno = EBADF ; \ - return( __r ); \ - } - +/* We use the errno variable used by the system dependent layer. */ +#undef errno +extern int errno; /* FUNCTION @@ -115,45 +52,12 @@ _DEFUN (_lseek_r, (ptr, fd, pos, whence), _off_t pos _AND int whence) { - _off_t ret; - __file_handle *fh; + _off_t ret; - __handle_check( fd, -1 ); - fh = (__file_handle*) __getOSHandle( fd ); - - switch(whence) - { - case SEEK_SET: - ret = pos; - break; - case SEEK_CUR: - ret = fh->offset + pos; - break; - case SEEK_END: - { - FILEINFO info; - get_fileinfo(fh->name, &info); - ret = pos + info.size; - break; - } - default: - ptr->_errno = EINVAL; - return -1; - }; - - fh->offset = ret; - - return( ret ); + errno = 0; + if ((ret = _lseek (fd, pos, whence)) == (_off_t) -1 && errno != 0) + ptr->_errno = errno; + return ret; } -_off_t -_DEFUN (lseek, (fd, pos, whence), - int fd _AND - _off_t pos _AND - int whence) - -{ - return _lseek_r(_REENT, fd, pos, whence); -}; - #endif /* ! defined (REENTRANT_SYSCALLS_PROVIDED) */ diff --git a/contrib/sdk/sources/newlib/libc/reent/openr.c b/contrib/sdk/sources/newlib/libc/reent/openr.c index fd04dfc807..e120b68411 100644 --- a/contrib/sdk/sources/newlib/libc/reent/openr.c +++ b/contrib/sdk/sources/newlib/libc/reent/openr.c @@ -4,11 +4,6 @@ #include #include #include <_syslist.h> -#include -#include -#include -#include -#include /* Some targets provides their own versions of this functions. Those targets should define REENTRANT_SYSCALLS_PROVIDED in TARGET_CFLAGS. */ @@ -22,6 +17,8 @@ #ifndef REENTRANT_SYSCALLS_PROVIDED /* We use the errno variable used by the system dependent layer. */ +#undef errno +extern int errno; /* FUNCTION @@ -49,173 +46,20 @@ DESCRIPTION <>. */ - - -#define NULL_HANDLE (int)-1 -#define DUMMY_HANDLE (int)-2 - -#define _READ 0x0001 /* file opened for reading */ -#define _WRITE 0x0002 /* file opened for writing */ -#define _UNGET 0x0004 /* ungetc has been done */ -#define _BIGBUF 0x0008 /* big buffer allocated */ -#define _EOF 0x0010 /* EOF has occurred */ -#define _SFERR 0x0020 /* error has occurred on this file */ -#define _APPEND 0x0080 /* file opened for append */ -#define _BINARY 0x0040 /* file is binary, skip CRLF processing */ -#define _TMPFIL 0x0800 /* this is a temporary file */ -#define _DIRTY 0x1000 /* buffer has been modified */ -#define _ISTTY 0x2000 /* is console device */ -#define _DYNAMIC 0x4000 /* FILE is dynamically allocated */ -#define _FILEEXT 0x8000 /* lseek with positive offset has been done */ -#define _COMMIT 0x0001 /* extended flag: commit OS buffers on flush */ - -extern int _fmode; - - -static inline void debug_out(const char val) -{ - __asm__ __volatile__( - "int $0x40 \n\t" - ::"a"(63), "b"(1),"c"(val)); -} - -int debugwrite(const char *path, const void *buff, - size_t offset, size_t count, size_t *writes) -{ - int ret = count; - const char *p = buff; - - while (count--) - { - debug_out(*p++); - }; - *writes = ret; - return ret; -}; - -static int __openFileHandle(const char *path, int mode, int *err) -{ - fileinfo_t info; - __file_handle *handle; - -// path = getfullpath(name); - - *err = get_fileinfo(path, &info); - - if( mode & O_EXCL && mode & O_CREAT ) - { - if( ! *err) - { - *err = EEXIST; - return -1; - }; - } - - if( *err) - { - if(mode & O_CREAT) - *err=create_file(path); - - if( *err) - { - return -1; - }; - }; - if( mode & O_TRUNC ) - set_file_size(path, 0); - - if ( !(handle=(__file_handle*)malloc(sizeof( __file_handle) ))) - { - *err = ENOMEM; - return -1; - }; - - handle->name = strdup(path); - handle->offset = 0; - handle->write = write_file; - - *err = 0; - - return (int)handle; -}; - - - int -_DEFUN (_open_r, (ptr, file, flags, dmode), +_DEFUN (_open_r, (ptr, file, flags, mode), struct _reent *ptr _AND _CONST char *file _AND int flags _AND - int dmode) + int mode) { - int hid; - int handle; - int err = 0; - unsigned iomode_flags; - int rwmode; - -/* - if (flags & ~(O_RDONLY | O_WRONLY | O_RDWR | O_CREAT | O_APPEND | O_TRUNC)) - { - ptr->_errno = ENOSYS; - return -1; - } -*/ - - // First try to get the required slot. - // No point in creating a file only to not use it. JBS 99/10/26 - hid = __allocPOSIXHandle( DUMMY_HANDLE ); - if( hid == -1 ) - { - ptr->_errno = EMFILE; - return( -1 ); - } - - handle = __openFileHandle( file, flags, &err); - - if( handle == -1 ) - { - __freePOSIXHandle( hid ); - ptr->_errno = err; - return( -1 ); - } - - __setOSHandle( hid, handle ); // JBS 99/11/01 - - rwmode = flags & ( O_RDONLY | O_WRONLY | O_RDWR | O_NOINHERIT ); - - iomode_flags = 0; - - if( rwmode == O_RDWR ) iomode_flags |= _READ | _WRITE; - else if( rwmode == O_RDONLY) iomode_flags |= _READ; - else if( rwmode == O_WRONLY) iomode_flags |= _WRITE; - if( flags & O_APPEND ) iomode_flags |= _APPEND; - if( flags & (O_BINARY|O_TEXT) ) { - if( flags & O_BINARY ) iomode_flags |= _BINARY; - } else { - if( _fmode == O_BINARY ) iomode_flags |= _BINARY; - } - __SetIOMode( hid, iomode_flags ); - - ptr->_errno = 0; - - return (hid); -} - -int -_DEFUN (open, (file, flags, ...), - const char *file _AND - int flags _DOTS) -{ - va_list ap; int ret; - va_start (ap, flags); - ret = _open_r (_REENT, file, flags, va_arg (ap, int)); - va_end (ap); + errno = 0; + if ((ret = _open (file, flags, mode)) == -1 && errno != 0) + ptr->_errno = errno; return ret; } - #endif /* ! defined (REENTRANT_SYSCALLS_PROVIDED) */ diff --git a/contrib/sdk/sources/newlib/libc/reent/readr.c b/contrib/sdk/sources/newlib/libc/reent/readr.c index 3c0bd0e95a..ad64e5d561 100644 --- a/contrib/sdk/sources/newlib/libc/reent/readr.c +++ b/contrib/sdk/sources/newlib/libc/reent/readr.c @@ -3,7 +3,6 @@ #include #include #include <_syslist.h> -#include /* Some targets provides their own versions of this functions. Those targets should define REENTRANT_SYSCALLS_PROVIDED in TARGET_CFLAGS. */ @@ -17,6 +16,8 @@ #ifndef REENTRANT_SYSCALLS_PROVIDED /* We use the errno variable used by the system dependent layer. */ +#undef errno +extern int errno; /* FUNCTION @@ -44,29 +45,6 @@ DESCRIPTION <>. */ - -extern unsigned __NFiles; - -#define _READ 0x0001 /* file opened for reading */ -#define _BINARY 0x0040 /* file is binary, skip CRLF processing */ -#define _ISTTY 0x2000 /* is console device */ - -#define __handle_check( __h, __r ) \ - if( (__h) < 0 || (__h) > __NFiles ) { \ - ptr->_errno = EBADF; \ - return( __r ); \ - } - -_ssize_t -_DEFUN (_read, (fd, buf, cnt), - int fd _AND - _PTR buf _AND - size_t cnt) -{ - - return _read_r( _REENT, fd, buf, cnt); -} - _ssize_t _DEFUN (_read_r, (ptr, fd, buf, cnt), struct _reent *ptr _AND @@ -74,95 +52,12 @@ _DEFUN (_read_r, (ptr, fd, buf, cnt), _PTR buf _AND size_t cnt) { - _ssize_t ret; + _ssize_t ret; - _ssize_t read_len, total_len; - unsigned reduce_idx, finish_idx; - unsigned iomode_flags; - char *buffer = buf; - int rc; - int h; - unsigned amount_read; - int err; - - __file_handle *fh; - - __handle_check( fd, -1 ); - __ChkTTYIOMode( fd ); - iomode_flags = __GetIOMode( fd ); - if( iomode_flags == 0 ) - { - ptr->_errno = EBADF; - return( -1 ); - } - if( !(iomode_flags & _READ) ) - { - ptr->_errno = EACCES; /* changed from EBADF to EACCES 23-feb-89 */ - return( -1 ); - } - - fh = (__file_handle*) __getOSHandle( fd ); - - if( iomode_flags & _BINARY ) /* if binary mode */ - { - err = read_file(fh->name, buffer, fh->offset, cnt, &amount_read); - fh->offset+= amount_read; - total_len = amount_read; - - if(err) - if ( amount_read == 0) - return (-1); - } - else - { - total_len = 0; - read_len = cnt; - do - { - err=read_file(fh->name,buffer, fh->offset, cnt, &amount_read); - fh->offset+=amount_read; - - if( amount_read == 0 ) - break; /* EOF */ - - reduce_idx = 0; - finish_idx = reduce_idx; - for( ; reduce_idx < amount_read; ++reduce_idx ) - { - if( buffer[ reduce_idx ] == 0x1a ) /* EOF */ - { - _lseek_r(ptr, fd, ((long)reduce_idx - (long)amount_read)+1L, - SEEK_CUR ); - total_len += finish_idx; - return( total_len ); - } - if( buffer[ reduce_idx ] != '\r' ) - { - buffer[ finish_idx++ ] = buffer[ reduce_idx ]; - }; - } - - total_len += finish_idx; - buffer += finish_idx; - read_len -= finish_idx; - if( iomode_flags & _ISTTY ) - { - break; /* 04-feb-88, FWC */ - } - } while( read_len != 0 ); - } - return( total_len ); + errno = 0; + if ((ret = (_ssize_t)_read (fd, buf, cnt)) == -1 && errno != 0) + ptr->_errno = errno; + return ret; } - -_ssize_t -_DEFUN (read, (fd, buf, cnt), - int fd _AND - _PTR buf _AND - size_t cnt) -{ - - return _read_r(_REENT, fd, buf, cnt); -}; - #endif /* ! defined (REENTRANT_SYSCALLS_PROVIDED) */ diff --git a/contrib/sdk/sources/newlib/libc/reent/renamer.c b/contrib/sdk/sources/newlib/libc/reent/renamer.c new file mode 100644 index 0000000000..d3951a28dc --- /dev/null +++ b/contrib/sdk/sources/newlib/libc/reent/renamer.c @@ -0,0 +1,74 @@ +/* Reentrant version of rename system call. */ + +#include +#include +#include +#include +#include <_syslist.h> + +/* Some targets provides their own versions of these functions. Those + targets should define REENTRANT_SYSCALLS_PROVIDED in TARGET_CFLAGS. */ + +#ifdef _REENT_ONLY +#ifndef REENTRANT_SYSCALLS_PROVIDED +#define REENTRANT_SYSCALLS_PROVIDED +#endif +#endif + +#ifndef REENTRANT_SYSCALLS_PROVIDED + +/* We use the errno variable used by the system dependent layer. */ +#undef errno +extern int errno; + +/* +FUNCTION + <<_rename_r>>---Reentrant version of rename + +INDEX + _rename_r + +ANSI_SYNOPSIS + #include + int _rename_r(struct _reent *<[ptr]>, + const char *<[old]>, const char *<[new]>); + +TRAD_SYNOPSIS + #include + int _rename_r(<[ptr]>, <[old]>, <[new]>) + struct _reent *<[ptr]>; + char *<[old]>; + char *<[new]>; + +DESCRIPTION + This is a reentrant version of <>. It + takes a pointer to the global data block, which holds + <>. +*/ + +int +_DEFUN (_rename_r, (ptr, old, new), + struct _reent *ptr _AND + _CONST char *old _AND + _CONST char *new) +{ + int ret = 0; + +#ifdef HAVE_RENAME + errno = 0; + if ((ret = _rename (old, new)) == -1 && errno != 0) + ptr->_errno = errno; +#else + if (_link_r (ptr, old, new) == -1) + return -1; + + if (_unlink_r (ptr, old) == -1) + { + /* ??? Should we unlink new? (rhetorical question) */ + return -1; + } +#endif + return ret; +} + +#endif /* ! defined (REENTRANT_SYSCALLS_PROVIDED) */ diff --git a/contrib/sdk/sources/newlib/libc/reent/timesr.c b/contrib/sdk/sources/newlib/libc/reent/timesr.c new file mode 100644 index 0000000000..1881724bae --- /dev/null +++ b/contrib/sdk/sources/newlib/libc/reent/timesr.c @@ -0,0 +1,63 @@ +/* Reentrant versions of times system calls */ + +#include +#include +#include +#include +#include <_syslist.h> + +/* Some targets provides their own versions of these functions. Those + targets should define REENTRANT_SYSCALLS_PROVIDED in TARGET_CFLAGS. */ + +#ifdef _REENT_ONLY +#ifndef REENTRANT_SYSCALLS_PROVIDED +#define REENTRANT_SYSCALLS_PROVIDED +#endif +#endif + +#ifdef REENTRANT_SYSCALLS_PROVIDED + +int _dummy_times_syscalls = 1; + +#else + +/* We use the errno variable used by the system dependent layer. */ +#undef errno +extern int errno; + +/* +FUNCTION + <<_times_r>>---Reentrant version of times + +INDEX + _times_r + +ANSI_SYNOPSIS + #include + #include + clock_t _times_r(struct _reent *<[ptr]>, struct tms *<[ptms]>); + +TRAD_SYNOPSIS + #include + #include + clock_t _times_r(<[ptr]>, <[ptms]>) + struct _reent *<[ptr]>; + struct tms *<[ptms]>; + +DESCRIPTION + This is a reentrant version of <>. It + takes a pointer to the global data block, which holds + <>. +*/ + +clock_t +_DEFUN (_times_r, (ptr, ptms), + struct _reent *ptr _AND + struct tms *ptms) +{ + clock_t ret; + + ret = _times (ptms); + return ret; +} +#endif /* ! defined (REENTRANT_SYSCALLS_PROVIDED) */ diff --git a/contrib/sdk/sources/newlib/libc/reent/unlinkr.c b/contrib/sdk/sources/newlib/libc/reent/unlinkr.c new file mode 100644 index 0000000000..95b815f1be --- /dev/null +++ b/contrib/sdk/sources/newlib/libc/reent/unlinkr.c @@ -0,0 +1,59 @@ +/* Reentrant versions of file system calls. These implementations + just call the usual system calls. */ + +#include +#include +#include <_syslist.h> + +/* Some targets provides their own versions of these functions. Those + targets should define REENTRANT_SYSCALLS_PROVIDED in TARGET_CFLAGS. */ + +#ifdef _REENT_ONLY +#ifndef REENTRANT_SYSCALLS_PROVIDED +#define REENTRANT_SYSCALLS_PROVIDED +#endif +#endif + +#ifndef REENTRANT_SYSCALLS_PROVIDED + +/* We use the errno variable used by the system dependent layer. */ +#undef errno +extern int errno; + +/* +FUNCTION + <<_unlink_r>>---Reentrant version of unlink + +INDEX + _unlink_r + +ANSI_SYNOPSIS + #include + int _unlink_r(struct _reent *<[ptr]>, const char *<[file]>); + +TRAD_SYNOPSIS + #include + int _unlink_r(<[ptr]>, <[file]>) + struct _reent *<[ptr]>; + char *<[file]>; + +DESCRIPTION + This is a reentrant version of <>. It + takes a pointer to the global data block, which holds + <>. +*/ + +int +_DEFUN (_unlink_r, (ptr, file), + struct _reent *ptr _AND + _CONST char *file) +{ + int ret; + + errno = 0; + if ((ret = _unlink (file)) == -1 && errno != 0) + ptr->_errno = errno; + return ret; +} + +#endif /* ! defined (REENTRANT_SYSCALLS_PROVIDED) */ diff --git a/contrib/sdk/sources/newlib/libc/reent/writer.c b/contrib/sdk/sources/newlib/libc/reent/writer.c index 9b460546c5..639838564f 100644 --- a/contrib/sdk/sources/newlib/libc/reent/writer.c +++ b/contrib/sdk/sources/newlib/libc/reent/writer.c @@ -3,10 +3,6 @@ #include #include #include <_syslist.h> -#include -#include -#include - /* Some targets provides their own versions of this functions. Those targets should define REENTRANT_SYSCALLS_PROVIDED in TARGET_CFLAGS. */ @@ -20,6 +16,8 @@ #ifndef REENTRANT_SYSCALLS_PROVIDED /* We use the errno variable used by the system dependent layer. */ +#undef errno +extern int errno; /* FUNCTION @@ -47,211 +45,19 @@ DESCRIPTION <>. */ - -#define _WRITE 0x0002 /* file opened for writing */ -#define _APPEND 0x0080 /* file opened for append */ -#define _BINARY 0x0040 /* file is binary, skip CRLF processing */ -#define _ISTTY 0x2000 /* is console device */ -#define _FILEEXT 0x8000 /* lseek with positive offset has been done */ - -#define __handle_check( __h, __r ) \ - if( (__h) < 0 || (__h) > __NFiles ) { \ - ptr->_errno = EBADF; \ - return( __r ); \ - } - -extern unsigned __NFiles; - -#define PAD_SIZE 512 - -static int zero_pad(struct _reent *ptr, int handle ) /* 09-jan-95 */ -/*******************************/ -{ - int rc; - long curPos, eodPos; - long bytesToWrite; - unsigned writeAmt; - char zeroBuf[PAD_SIZE]; - - // Pad with zeros due to lseek() past EOF (POSIX) - curPos = _lseek_r( ptr, handle, 0L, SEEK_CUR ); /* current offset */ - if( curPos == -1 ) - return( -1 ); - eodPos = _lseek_r( ptr, handle, 0L, SEEK_END ); /* end of data offset */ - if( eodPos == -1 ) - return( -1 ); - - if( curPos > eodPos ) { - bytesToWrite = curPos - eodPos; /* amount to pad by */ - - if( bytesToWrite > 0 ) { /* only write if needed */ - memset( zeroBuf, 0x00, PAD_SIZE ); /* zero out a buffer */ - do { /* loop until done */ - if( bytesToWrite > PAD_SIZE ) - writeAmt = 512; - else - writeAmt = (unsigned)bytesToWrite; - rc = _write_r(ptr, handle, zeroBuf, writeAmt ); - if( rc < 0 ) - return( rc ); - bytesToWrite -= writeAmt; /* more bytes written */ - } while( bytesToWrite != 0 ); - } - } else { - curPos = _lseek_r( ptr, handle, curPos, SEEK_SET ); - if( curPos == -1 ) { - return( -1 ); - } - } - - return( 0 ); /* return success code */ -} - - -static int os_write(struct _reent *ptr, int handle, - const void *buffer, unsigned len, unsigned *amt ) -/********************************************************************************/ -{ - __file_handle *fh; - int rc; - - rc = 0; - *amt = 0; - - fh = (__file_handle*) __getOSHandle( handle ); - - rc = fh->write(fh->name,buffer,fh->offset,len,amt); - - fh->offset+= *amt; - - if( *amt != len ) - { - rc = ENOSPC; - ptr->_errno = ENOSPC; - } - return( rc ); -} _ssize_t -_DEFUN (_write_r, (ptr, fd, buffer, cnt), +_DEFUN (_write_r, (ptr, fd, buf, cnt), struct _reent *ptr _AND int fd _AND - _CONST _PTR buffer _AND + _CONST _PTR buf _AND size_t cnt) { - _ssize_t ret; - unsigned int iomode_flags; - unsigned len_written, i, j; - int rc2; - char *buf; - - __file_handle *fh; - - __handle_check( fd, -1 ); - - iomode_flags = __GetIOMode( fd ); - if( iomode_flags == 0 ) - { - ptr->_errno = EBADF; - return( -1 ); - } - - if( !(iomode_flags & _WRITE) ) { - ptr->_errno = EACCES ; /* changed from EBADF to EACCES 23-feb-89 */ - return( -1 ); - } - - if( (iomode_flags & _APPEND) && !(iomode_flags & _ISTTY) ) - { - fh->offset = _lseek_r(ptr, fd, 0L, SEEK_END ); /* end of data offset */ - } - - len_written = 0; - rc2 = 0; - - // Pad the file with zeros if necessary - if( iomode_flags & _FILEEXT ) - { - // turn off file extended flag - __SetIOMode_nogrow( fd, iomode_flags&(~_FILEEXT) ); - - // It is not required to pad a file with zeroes on an NTFS file system; - // unfortunately it is required on FAT (and probably FAT32). (JBS) - rc2 = zero_pad( ptr, fd ); - } - - if( rc2 == 0 ) - { - if( iomode_flags & _BINARY ) { /* if binary mode */ - rc2 = os_write(ptr, fd, buffer, cnt, &len_written ); - /* end of binary mode part */ - } else { /* text mode */ - - int buf_size = 512; - - buf = (char*)alloca( buf_size ); - - j = 0; - for( i = 0; i < cnt; ) - { - if( ((const char*)buffer)[i] == '\n' ) - { - buf[j] = '\r'; - ++j; - if( j == buf_size ) - { - rc2 = os_write(ptr, fd, buf, buf_size, &j ); - if( rc2 == -1 ) - break; - len_written += j; - if( rc2 == ENOSPC ) - break; - len_written = i; - j = 0; - } - } - buf[j] = ((const char*)buffer)[i]; - ++i; - ++j; - if( j == buf_size ) { - rc2 = os_write(ptr, fd, buf, buf_size, &j ); - if( rc2 == -1 ) - break; - len_written += j; - if( rc2 == ENOSPC ) - break; - len_written = i; - j = 0; - } - } - if( j ) { - rc2 = os_write(ptr, fd, buf, j, &i ); - if( rc2 == ENOSPC ) { - len_written += i; - } else { - len_written = cnt; - } - } - /* end of text mode part */ - } - } - - if( rc2 == -1 ) { - return( rc2 ); - } else { - return( len_written ); - } -} - -_ssize_t -_DEFUN (write, ( fd, buffer, cnt), - int fd _AND - _CONST _PTR buffer _AND - size_t cnt) - -{ - - return _write_r(_REENT, fd, buffer, cnt); + _ssize_t ret; + errno = 0; + if ((ret = (_ssize_t)_write (fd, buf, cnt)) == -1 && errno != 0) + ptr->_errno = errno; + return ret; } #endif /* ! defined (REENTRANT_SYSCALLS_PROVIDED) */ diff --git a/contrib/sdk/sources/newlib/libc/search/bsearch.c b/contrib/sdk/sources/newlib/libc/search/bsearch.c index 9fb0980e2e..ce384b1af5 100644 --- a/contrib/sdk/sources/newlib/libc/search/bsearch.c +++ b/contrib/sdk/sources/newlib/libc/search/bsearch.c @@ -61,8 +61,6 @@ PORTABILITY No supporting OS subroutines are required. */ -#include <_ansi.h> -#include #include _PTR diff --git a/contrib/sdk/sources/newlib/libc/stdio/asiprintf.c b/contrib/sdk/sources/newlib/libc/stdio/asiprintf.c new file mode 100644 index 0000000000..0c363d5ea5 --- /dev/null +++ b/contrib/sdk/sources/newlib/libc/stdio/asiprintf.c @@ -0,0 +1,80 @@ +/* + * 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. + */ +/* This code was copied from asprintf.c */ +/* doc in siprintf.c */ + +#include <_ansi.h> +#include +#include +#include +#include +#include "local.h" + +int +_DEFUN(_asiprintf_r, (ptr, strp, fmt), + struct _reent *ptr _AND + char **strp _AND + const char *fmt _DOTS) +{ + int ret; + va_list ap; + FILE f; + + /* mark a zero-length reallocatable buffer */ + f._flags = __SWR | __SSTR | __SMBF; + f._bf._base = f._p = NULL; + f._bf._size = f._w = 0; + f._file = -1; /* No file. */ + va_start (ap, fmt); + ret = _svfiprintf_r (ptr, &f, fmt, ap); + va_end (ap); + if (ret >= 0) + { + *f._p = 0; + *strp = (char *) f._bf._base; + } + return (ret); +} + +#ifndef _REENT_ONLY + +int +_DEFUN(asiprintf, (strp, fmt), + char **strp _AND + const char *fmt _DOTS) +{ + int ret; + va_list ap; + FILE f; + + /* mark a zero-length reallocatable buffer */ + f._flags = __SWR | __SSTR | __SMBF; + f._bf._base = f._p = NULL; + f._bf._size = f._w = 0; + f._file = -1; /* No file. */ + va_start (ap, fmt); + ret = _svfiprintf_r (_REENT, &f, fmt, ap); + va_end (ap); + if (ret >= 0) + { + *f._p = 0; + *strp = (char *) f._bf._base; + } + return (ret); +} + +#endif /* ! _REENT_ONLY */ diff --git a/contrib/sdk/sources/newlib/libc/stdio/asniprintf.c b/contrib/sdk/sources/newlib/libc/stdio/asniprintf.c new file mode 100644 index 0000000000..16ccfde636 --- /dev/null +++ b/contrib/sdk/sources/newlib/libc/stdio/asniprintf.c @@ -0,0 +1,108 @@ +/* Copyright (C) 2007, 2008 Eric Blake + * Permission to use, copy, modify, and distribute this software + * is freely granted, provided that this notice is preserved. + */ +/* This code was derived from asprintf.c */ +/* doc in siprintf.c */ + +#include <_ansi.h> +#include +#include +#include +#include +#include +#include "local.h" + +char * +_DEFUN(_asniprintf_r, (ptr, buf, lenp, fmt), + struct _reent *ptr _AND + char *buf _AND + size_t *lenp _AND + const char *fmt _DOTS) +{ + int ret; + va_list ap; + FILE f; + size_t len = *lenp; + + if (buf && len) + { + /* mark an existing buffer, but allow allocation of larger string */ + f._flags = __SWR | __SSTR | __SOPT; + } + else + { + /* mark a zero-length reallocatable buffer */ + f._flags = __SWR | __SSTR | __SMBF; + len = 0; + buf = NULL; + } + f._bf._base = f._p = (unsigned char *) buf; + /* For now, inherit the 32-bit signed limit of FILE._bf._size. + FIXME - it would be nice to rewrite sys/reent.h to support size_t + for _size. */ + if (len > INT_MAX) + { + ptr->_errno = EOVERFLOW; + return NULL; + } + f._bf._size = f._w = len; + f._file = -1; /* No file. */ + va_start (ap, fmt); + ret = _svfiprintf_r (ptr, &f, fmt, ap); + va_end (ap); + if (ret < 0) + return NULL; + *lenp = ret; + *f._p = '\0'; + return (char *) f._bf._base; +} + +#ifndef _REENT_ONLY + +char * +_DEFUN(asniprintf, (buf, lenp, fmt), + char *buf _AND + size_t *lenp _AND + const char *fmt _DOTS) +{ + int ret; + va_list ap; + FILE f; + size_t len = *lenp; + struct _reent *ptr = _REENT; + + if (buf && len) + { + /* mark an existing buffer, but allow allocation of larger string */ + f._flags = __SWR | __SSTR | __SOPT; + } + else + { + /* mark a zero-length reallocatable buffer */ + f._flags = __SWR | __SSTR | __SMBF; + len = 0; + buf = NULL; + } + f._bf._base = f._p = (unsigned char *) buf; + /* For now, inherit the 32-bit signed limit of FILE._bf._size. + FIXME - it would be nice to rewrite sys/reent.h to support size_t + for _size. */ + if (len > INT_MAX) + { + ptr->_errno = EOVERFLOW; + return NULL; + } + f._bf._size = f._w = len; + f._file = -1; /* No file. */ + va_start (ap, fmt); + ret = _svfiprintf_r (ptr, &f, fmt, ap); + va_end (ap); + if (ret < 0) + return NULL; + *lenp = ret; + *f._p = '\0'; + return (char *) f._bf._base; +} + +#endif /* ! _REENT_ONLY */ diff --git a/contrib/sdk/sources/newlib/libc/stdio/asnprintf.c b/contrib/sdk/sources/newlib/libc/stdio/asnprintf.c new file mode 100644 index 0000000000..a37c503588 --- /dev/null +++ b/contrib/sdk/sources/newlib/libc/stdio/asnprintf.c @@ -0,0 +1,108 @@ +/* Copyright (C) 2007, 2008 Eric Blake + * Permission to use, copy, modify, and distribute this software + * is freely granted, provided that this notice is preserved. + */ +/* This code was derived from asprintf.c */ +/* doc in sprintf.c */ + +#include <_ansi.h> +#include +#include +#include +#include +#include +#include "local.h" + +char * +_DEFUN(_asnprintf_r, (ptr, buf, lenp, fmt), + struct _reent *__restrict ptr _AND + char *buf _AND + size_t *lenp _AND + const char *__restrict fmt _DOTS) +{ + int ret; + va_list ap; + FILE f; + size_t len = *lenp; + + if (buf && len) + { + /* mark an existing buffer, but allow allocation of larger string */ + f._flags = __SWR | __SSTR | __SOPT; + } + else + { + /* mark a zero-length reallocatable buffer */ + f._flags = __SWR | __SSTR | __SMBF; + len = 0; + buf = NULL; + } + f._bf._base = f._p = (unsigned char *) buf; + /* For now, inherit the 32-bit signed limit of FILE._bf._size. + FIXME - it would be nice to rewrite sys/reent.h to support size_t + for _size. */ + if (len > INT_MAX) + { + ptr->_errno = EOVERFLOW; + return NULL; + } + f._bf._size = f._w = len; + f._file = -1; /* No file. */ + va_start (ap, fmt); + ret = _svfprintf_r (ptr, &f, fmt, ap); + va_end (ap); + if (ret < 0) + return NULL; + *lenp = ret; + *f._p = '\0'; + return (char *) f._bf._base; +} + +#ifndef _REENT_ONLY + +char * +_DEFUN(asnprintf, (buf, lenp, fmt), + char *__restrict buf _AND + size_t *__restrict lenp _AND + const char *__restrict fmt _DOTS) +{ + int ret; + va_list ap; + FILE f; + size_t len = *lenp; + struct _reent *ptr = _REENT; + + if (buf && len) + { + /* mark an existing buffer, but allow allocation of larger string */ + f._flags = __SWR | __SSTR | __SOPT; + } + else + { + /* mark a zero-length reallocatable buffer */ + f._flags = __SWR | __SSTR | __SMBF; + len = 0; + buf = NULL; + } + f._bf._base = f._p = (unsigned char *) buf; + /* For now, inherit the 32-bit signed limit of FILE._bf._size. + FIXME - it would be nice to rewrite sys/reent.h to support size_t + for _size. */ + if (len > INT_MAX) + { + ptr->_errno = EOVERFLOW; + return NULL; + } + f._bf._size = f._w = len; + f._file = -1; /* No file. */ + va_start (ap, fmt); + ret = _svfprintf_r (ptr, &f, fmt, ap); + va_end (ap); + if (ret < 0) + return NULL; + *lenp = ret; + *f._p = '\0'; + return (char *) f._bf._base; +} + +#endif /* ! _REENT_ONLY */ diff --git a/contrib/sdk/sources/newlib/libc/stdio/asprintf.c b/contrib/sdk/sources/newlib/libc/stdio/asprintf.c new file mode 100644 index 0000000000..d044112510 --- /dev/null +++ b/contrib/sdk/sources/newlib/libc/stdio/asprintf.c @@ -0,0 +1,80 @@ +/* + * Copyright (c) 1990, 2007 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. + */ +/* This code was copied from sprintf.c */ +/* doc in sprintf.c */ + +#include <_ansi.h> +#include +#include +#include +#include +#include "local.h" + +int +_DEFUN(_asprintf_r, (ptr, strp, fmt), + struct _reent *ptr _AND + char **__restrict strp _AND + const char *__restrict fmt _DOTS) +{ + int ret; + va_list ap; + FILE f; + + /* mark a zero-length reallocatable buffer */ + f._flags = __SWR | __SSTR | __SMBF; + f._bf._base = f._p = NULL; + f._bf._size = f._w = 0; + f._file = -1; /* No file. */ + va_start (ap, fmt); + ret = _svfprintf_r (ptr, &f, fmt, ap); + va_end (ap); + if (ret >= 0) + { + *f._p = 0; + *strp = (char *) f._bf._base; + } + return (ret); +} + +#ifndef _REENT_ONLY + +int +_DEFUN(asprintf, (strp, fmt), + char **__restrict strp _AND + const char *__restrict fmt _DOTS) +{ + int ret; + va_list ap; + FILE f; + + /* mark a zero-length reallocatable buffer */ + f._flags = __SWR | __SSTR | __SMBF; + f._bf._base = f._p = NULL; + f._bf._size = f._w = 0; + f._file = -1; /* No file. */ + va_start (ap, fmt); + ret = _svfprintf_r (_REENT, &f, fmt, ap); + va_end (ap); + if (ret >= 0) + { + *f._p = 0; + *strp = (char *) f._bf._base; + } + return (ret); +} + +#endif /* ! _REENT_ONLY */ diff --git a/contrib/sdk/sources/newlib/libc/stdio/clearerr.c b/contrib/sdk/sources/newlib/libc/stdio/clearerr.c index d3b620bed8..ed4603ba21 100644 --- a/contrib/sdk/sources/newlib/libc/stdio/clearerr.c +++ b/contrib/sdk/sources/newlib/libc/stdio/clearerr.c @@ -65,7 +65,7 @@ _DEFUN(clearerr, (fp), FILE * fp) { CHECK_INIT(_REENT, fp); - _flockfile (fp); + _newlib_flockfile_start (fp); __sclearerr (fp); - _funlockfile (fp); + _newlib_flockfile_end (fp); } diff --git a/contrib/sdk/sources/newlib/libc/stdio/dprintf.c b/contrib/sdk/sources/newlib/libc/stdio/dprintf.c index e2d8b36cab..2271f4b5c2 100644 --- a/contrib/sdk/sources/newlib/libc/stdio/dprintf.c +++ b/contrib/sdk/sources/newlib/libc/stdio/dprintf.c @@ -19,12 +19,13 @@ INDEX ANSI_SYNOPSIS #include #include - int dprintf(int <[fd]>, const char *<[format]>, ...); - int vdprintf(int <[fd]>, const char *<[format]>, va_list <[ap]>); + int dprintf(int <[fd]>, const char *restrict <[format]>, ...); + int vdprintf(int <[fd]>, const char *restrict <[format]>, + va_list <[ap]>); int _dprintf_r(struct _reent *<[ptr]>, int <[fd]>, - const char *<[format]>, ...); + const char *restrict <[format]>, ...); int _vdprintf_r(struct _reent *<[ptr]>, int <[fd]>, - const char *<[format]>, va_list <[ap]>); + const char *restrict <[format]>, va_list <[ap]>); DESCRIPTION <> and <> allow printing a format, similarly to @@ -55,7 +56,7 @@ int _DEFUN(_dprintf_r, (ptr, fd, format), struct _reent *ptr _AND int fd _AND - const char *format _DOTS) + const char *__restrict format _DOTS) { va_list ap; int n; @@ -71,7 +72,7 @@ _DEFUN(_dprintf_r, (ptr, fd, format), int _DEFUN(dprintf, (fd, format), int fd _AND - const char *format _DOTS) + const char *__restrict format _DOTS) { va_list ap; int n; diff --git a/contrib/sdk/sources/newlib/libc/stdio/fclose.c b/contrib/sdk/sources/newlib/libc/stdio/fclose.c index 5c4caf7116..6c88407802 100644 --- a/contrib/sdk/sources/newlib/libc/stdio/fclose.c +++ b/contrib/sdk/sources/newlib/libc/stdio/fclose.c @@ -76,11 +76,20 @@ _DEFUN(_fclose_r, (rptr, fp), CHECK_INIT (rptr, fp); + /* We can't use the _newlib_flockfile_XXX macros here due to the + interlocked locking with the sfp_lock. */ +#ifdef _STDIO_WITH_THREAD_CANCELLATION_SUPPORT + int __oldcancel; + pthread_setcancelstate (PTHREAD_CANCEL_DISABLE, &__oldcancel); +#endif _flockfile (fp); if (fp->_flags == 0) /* not open! */ { _funlockfile (fp); +#ifdef _STDIO_WITH_THREAD_CANCELLATION_SUPPORT + pthread_setcancelstate (__oldcancel, &__oldcancel); +#endif return (0); } /* Unconditionally flush to allow special handling for seekable read @@ -103,6 +112,9 @@ _DEFUN(_fclose_r, (rptr, fp), #endif __sfp_lock_release (); +#ifdef _STDIO_WITH_THREAD_CANCELLATION_SUPPORT + pthread_setcancelstate (__oldcancel, &__oldcancel); +#endif return (r); } diff --git a/contrib/sdk/sources/newlib/libc/stdio/fdopen.c b/contrib/sdk/sources/newlib/libc/stdio/fdopen.c index de0a249f24..88490f1f9a 100644 --- a/contrib/sdk/sources/newlib/libc/stdio/fdopen.c +++ b/contrib/sdk/sources/newlib/libc/stdio/fdopen.c @@ -93,7 +93,7 @@ _DEFUN(_fdopen_r, (ptr, fd, mode), if ((fp = __sfp (ptr)) == 0) return 0; - _flockfile (fp); + _newlib_flockfile_start (fp); fp->_flags = flags; /* POSIX recommends setting the O_APPEND bit on fd to match append @@ -127,7 +127,7 @@ _DEFUN(_fdopen_r, (ptr, fd, mode), fp->_flags |= __SCLE; #endif - _funlockfile (fp); + _newlib_flockfile_end (fp); return fp; } diff --git a/contrib/sdk/sources/newlib/libc/stdio/feof.c b/contrib/sdk/sources/newlib/libc/stdio/feof.c new file mode 100644 index 0000000000..c0216ffed4 --- /dev/null +++ b/contrib/sdk/sources/newlib/libc/stdio/feof.c @@ -0,0 +1,65 @@ +/* + * 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 +<>---test for end of file + +INDEX + feof + +ANSI_SYNOPSIS + #include + int feof(FILE *<[fp]>); + +TRAD_SYNOPSIS + #include + int feof(<[fp]>) + FILE *<[fp]>; + +DESCRIPTION +<> tests whether or not the end of the file identified by <[fp]> +has been reached. + +RETURNS +<> returns <<0>> if the end of file has not yet been reached; if +at end of file, the result is nonzero. + +PORTABILITY +<> is required by ANSI C. + +No supporting OS subroutines are required. +*/ + +#include +#include "local.h" + +/* A subroutine version of the macro feof. */ + +#undef feof + +int +_DEFUN(feof, (fp), + FILE * fp) +{ + int result; + CHECK_INIT(_REENT, fp); + _newlib_flockfile_start (fp); + result = __sfeof (fp); + _newlib_flockfile_end (fp); + return result; +} diff --git a/contrib/sdk/sources/newlib/libc/stdio/fflush.c b/contrib/sdk/sources/newlib/libc/stdio/fflush.c index 5cfd22c866..eab016174b 100644 --- a/contrib/sdk/sources/newlib/libc/stdio/fflush.c +++ b/contrib/sdk/sources/newlib/libc/stdio/fflush.c @@ -75,15 +75,19 @@ _DEFUN(__sflush_r, (ptr, fp), register FILE * fp) { register unsigned char *p; - register int n, t; + register _READ_WRITE_BUFSIZE_TYPE n; + register _READ_WRITE_RETURN_TYPE t; + short flags; - t = fp->_flags; - if ((t & __SWR) == 0) + flags = fp->_flags; + if ((flags & __SWR) == 0) { +#ifdef _FSEEK_OPTIMIZATION /* For a read stream, an fflush causes the next seek to be unoptimized (i.e. forces a system-level seek). This conforms to the POSIX and SUSv3 standards. */ fp->_flags |= __SNPT; +#endif /* For a seekable stream with buffered read characters, we will attempt a seek to the current position now. A subsequent read will then get @@ -152,7 +156,9 @@ _DEFUN(__sflush_r, (ptr, fp), { /* Seek successful or ignorable error condition. We can clear read buffer now. */ +#ifdef _FSEEK_OPTIMIZATION fp->_flags &= ~__SNPT; +#endif fp->_r = 0; fp->_p = fp->_bf._base; if ((fp->_flags & __SOFF) && (curoff != -1 || ptr->_errno == 0)) @@ -182,7 +188,7 @@ _DEFUN(__sflush_r, (ptr, fp), * write function. */ fp->_p = p; - fp->_w = t & (__SLBF | __SNBF) ? 0 : fp->_bf._size; + fp->_w = flags & (__SLBF | __SNBF) ? 0 : fp->_bf._size; while (n > 0) { @@ -226,9 +232,9 @@ _DEFUN(_fflush_r, (ptr, fp), if (!fp->_flags) return 0; - _flockfile (fp); + _newlib_flockfile_start (fp); ret = __sflush_r (ptr, fp); - _funlockfile (fp); + _newlib_flockfile_end (fp); return ret; } diff --git a/contrib/sdk/sources/newlib/libc/stdio/fgetc.c b/contrib/sdk/sources/newlib/libc/stdio/fgetc.c index e275cfeebe..20492d24ba 100644 --- a/contrib/sdk/sources/newlib/libc/stdio/fgetc.c +++ b/contrib/sdk/sources/newlib/libc/stdio/fgetc.c @@ -78,9 +78,9 @@ _DEFUN(_fgetc_r, (ptr, fp), { int result; CHECK_INIT(ptr, fp); - _flockfile (fp); + _newlib_flockfile_start (fp); result = __sgetc_r (ptr, fp); - _funlockfile (fp); + _newlib_flockfile_end (fp); return result; } @@ -92,10 +92,12 @@ _DEFUN(fgetc, (fp), { #if !defined(PREFER_SIZE_OVER_SPEED) && !defined(__OPTIMIZE_SIZE__) int result; - CHECK_INIT(_REENT, fp); - _flockfile (fp); - result = __sgetc_r (_REENT, fp); - _funlockfile (fp); + struct _reent *reent = _REENT; + + CHECK_INIT(reent, fp); + _newlib_flockfile_start (fp); + result = __sgetc_r (reent, fp); + _newlib_flockfile_end (fp); return result; #else return _fgetc_r (_REENT, fp); diff --git a/contrib/sdk/sources/newlib/libc/stdio/fgets.c b/contrib/sdk/sources/newlib/libc/stdio/fgets.c index 3561070a4d..5fe11914ee 100644 --- a/contrib/sdk/sources/newlib/libc/stdio/fgets.c +++ b/contrib/sdk/sources/newlib/libc/stdio/fgets.c @@ -26,10 +26,10 @@ INDEX ANSI_SYNOPSIS #include - char *fgets(char *<[buf]>, int <[n]>, FILE *<[fp]>); + char *fgets(char *restrict <[buf]>, int <[n]>, FILE *restrict <[fp]>); #include - char *_fgets_r(struct _reent *<[ptr]>, char *<[buf]>, int <[n]>, FILE *<[fp]>); + char *_fgets_r(struct _reent *<[ptr]>, char *restrict <[buf]>, int <[n]>, FILE *restrict <[fp]>); TRAD_SYNOPSIS #include @@ -83,9 +83,9 @@ Supporting OS subroutines required: <>, <>, <>, char * _DEFUN(_fgets_r, (ptr, buf, n, fp), struct _reent * ptr _AND - char *buf _AND + char *__restrict buf _AND int n _AND - FILE * fp) + FILE *__restrict fp) { size_t len; char *s; @@ -98,11 +98,11 @@ _DEFUN(_fgets_r, (ptr, buf, n, fp), CHECK_INIT(ptr, fp); - _flockfile (fp); + _newlib_flockfile_start (fp); #ifdef __SCLE if (fp->_flags & __SCLE) { - int c; + int c = 0; /* Sorry, have to do it the slow way */ while (--n > 0 && (c = __sgetc_r (ptr, fp)) != EOF) { @@ -112,11 +112,11 @@ _DEFUN(_fgets_r, (ptr, buf, n, fp), } if (c == EOF && s == buf) { - _funlockfile (fp); + _newlib_flockfile_exit (fp); return NULL; } *s = 0; - _funlockfile (fp); + _newlib_flockfile_exit (fp); return buf; } #endif @@ -134,7 +134,7 @@ _DEFUN(_fgets_r, (ptr, buf, n, fp), /* EOF: stop with partial or no line */ if (s == buf) { - _funlockfile (fp); + _newlib_flockfile_exit (fp); return 0; } break; @@ -159,7 +159,7 @@ _DEFUN(_fgets_r, (ptr, buf, n, fp), fp->_p = t; _CAST_VOID memcpy ((_PTR) s, (_PTR) p, len); s[len] = 0; - _funlockfile (fp); + _newlib_flockfile_exit (fp); return (buf); } fp->_r -= len; @@ -169,7 +169,7 @@ _DEFUN(_fgets_r, (ptr, buf, n, fp), } while ((n -= len) != 0); *s = 0; - _funlockfile (fp); + _newlib_flockfile_end (fp); return buf; } @@ -177,9 +177,9 @@ _DEFUN(_fgets_r, (ptr, buf, n, fp), char * _DEFUN(fgets, (buf, n, fp), - char *buf _AND + char *__restrict buf _AND int n _AND - FILE * fp) + FILE *__restrict fp) { return _fgets_r (_REENT, buf, n, fp); } diff --git a/contrib/sdk/sources/newlib/libc/stdio/fileno.c b/contrib/sdk/sources/newlib/libc/stdio/fileno.c index b66ca44631..b3d0950764 100644 --- a/contrib/sdk/sources/newlib/libc/stdio/fileno.c +++ b/contrib/sdk/sources/newlib/libc/stdio/fileno.c @@ -47,6 +47,7 @@ Supporting OS subroutines required: none. #include <_ansi.h> #include +#include #include "local.h" int @@ -55,8 +56,14 @@ _DEFUN(fileno, (f), { int result; CHECK_INIT (_REENT, f); - _flockfile (f); + _newlib_flockfile_start (f); + if (f->_flags) result = __sfileno (f); - _funlockfile (f); + else + { + result = -1; + _REENT->_errno = EBADF; + } + _newlib_flockfile_end (f); return result; } diff --git a/contrib/sdk/sources/newlib/libc/stdio/findfp.c b/contrib/sdk/sources/newlib/libc/stdio/findfp.c index 29b5672294..00d3880744 100644 --- a/contrib/sdk/sources/newlib/libc/stdio/findfp.c +++ b/contrib/sdk/sources/newlib/libc/stdio/findfp.c @@ -62,7 +62,11 @@ _DEFUN(std, (ptr, flags, file, data), ptr->_flags |= __SL64; #endif /* __LARGE64_FILES */ ptr->_seek = __sseek; +#ifdef _STDIO_CLOSE_PER_REENT_STD_STREAMS ptr->_close = __sclose; +#else /* _STDIO_CLOSE_STD_STREAMS */ + ptr->_close = NULL; +#endif /* _STDIO_CLOSE_STD_STREAMS */ #if !defined(__SINGLE_THREAD__) && !defined(_REENT_SMALL) __lock_init_recursive (ptr->_lock); /* @@ -77,23 +81,27 @@ _DEFUN(std, (ptr, flags, file, data), #endif } +struct glue_with_file { + struct _glue glue; + FILE file; +}; + struct _glue * _DEFUN(__sfmoreglue, (d, n), struct _reent *d _AND register int n) { - struct _glue *g; - FILE *p; + struct glue_with_file *g; - g = (struct _glue *) _malloc_r (d, sizeof (*g) + n * sizeof (FILE)); + g = (struct glue_with_file *) + _malloc_r (d, sizeof (*g) + (n - 1) * sizeof (FILE)); if (g == NULL) return NULL; - p = (FILE *) (g + 1); - g->_next = NULL; - g->_niobs = n; - g->_iobs = p; - memset (p, 0, n * sizeof (FILE)); - return g; + g->glue._next = NULL; + g->glue._niobs = n; + g->glue._iobs = &g->file; + memset (&g->file, 0, n * sizeof (FILE)); + return &g->glue; } /* @@ -108,7 +116,7 @@ _DEFUN(__sfp, (d), int n; struct _glue *g; - __sfp_lock_acquire (); + _newlib_sfp_lock_start (); if (!_GLOBAL_REENT->__sdidinit) __sinit (_GLOBAL_REENT); @@ -121,7 +129,7 @@ _DEFUN(__sfp, (d), (g->_next = __sfmoreglue (d, NDYNAMIC)) == NULL) break; } - __sfp_lock_release (); + _newlib_sfp_lock_exit (); d->_errno = ENOMEM; return NULL; @@ -132,7 +140,7 @@ found: #ifndef __SINGLE_THREAD__ __lock_init_recursive (fp->_lock); #endif - __sfp_lock_release (); + _newlib_sfp_lock_end (); fp->_p = NULL; /* no current pointer */ fp->_w = 0; /* nothing to read or write */ @@ -192,7 +200,6 @@ _DEFUN(__sinit, (s), /* make sure we clean up on exit */ s->__cleanup = _cleanup_r; /* conservative */ - s->__sdidinit = 1; s->__sglue._next = NULL; #ifndef _REENT_SMALL @@ -201,6 +208,11 @@ _DEFUN(__sinit, (s), #else s->__sglue._niobs = 0; s->__sglue._iobs = NULL; + /* Avoid infinite recursion when calling __sfp for _GLOBAL_REENT. The + problem is that __sfp checks for _GLOBAL_REENT->__sdidinit and calls + __sinit if it's 0. */ + if (s == _GLOBAL_REENT) + s->__sdidinit = 1; s->_stdin = __sfp(s); s->_stdout = __sfp(s); s->_stderr = __sfp(s); @@ -224,6 +236,8 @@ _DEFUN(__sinit, (s), when the underlying fd 2 is write-only. */ std (s->_stderr, __SRW | __SNBF, 2, s); + s->__sdidinit = 1; + __sinit_lock_release (); } @@ -235,25 +249,25 @@ __LOCK_INIT_RECURSIVE(static, __sinit_lock); _VOID _DEFUN_VOID(__sfp_lock_acquire) { - __lock_acquire_recursive (__sfp_lock); + //__lock_acquire_recursive (__sfp_lock); } _VOID _DEFUN_VOID(__sfp_lock_release) { - __lock_release_recursive (__sfp_lock); + //__lock_release_recursive (__sfp_lock); } _VOID _DEFUN_VOID(__sinit_lock_acquire) { - __lock_acquire_recursive (__sinit_lock); + //__lock_acquire_recursive (__sinit_lock); } _VOID _DEFUN_VOID(__sinit_lock_release) { - __lock_release_recursive (__sinit_lock); + //__lock_release_recursive (__sinit_lock); } /* Walkable file locking routine. */ diff --git a/contrib/sdk/sources/newlib/libc/stdio/flags.c b/contrib/sdk/sources/newlib/libc/stdio/flags.c index fbb7cdb1e7..b8892718c4 100644 --- a/contrib/sdk/sources/newlib/libc/stdio/flags.c +++ b/contrib/sdk/sources/newlib/libc/stdio/flags.c @@ -60,27 +60,40 @@ _DEFUN(__sflags, (ptr, mode, optr), ptr->_errno = EINVAL; return (0); } - if (mode[1] && (mode[1] == '+' || mode[2] == '+')) + while (*++mode) { + switch (*mode) + { + case '+': ret = (ret & ~(__SRD | __SWR)) | __SRW; - m = O_RDWR; - } - if (mode[1] && (mode[1] == 'b' || mode[2] == 'b')) - { + m = (m & ~O_ACCMODE) | O_RDWR; + break; + case 'b': #ifdef O_BINARY m |= O_BINARY; #endif - } + break; #ifdef __CYGWIN__ - else if (mode[1] && (mode[1] == 't' || mode[2] == 't')) -#else - else + case 't': + m |= O_TEXT; + break; #endif - { -#ifdef O_TEXT +#if defined (O_CLOEXEC) && defined (_GLIBC_EXTENSION) + case 'e': + m |= O_CLOEXEC; + break; +#endif + case 'x': + m |= O_EXCL; + break; + default: + break; + } + } +#if defined (O_TEXT) && !defined (__CYGWIN__) + if (!(m | O_BINARY)) m |= O_TEXT; #endif - } *optr = m | o; return ret; } diff --git a/contrib/sdk/sources/newlib/libc/stdio/fopen.c b/contrib/sdk/sources/newlib/libc/stdio/fopen.c index 54a6615d2a..1f65e61537 100644 --- a/contrib/sdk/sources/newlib/libc/stdio/fopen.c +++ b/contrib/sdk/sources/newlib/libc/stdio/fopen.c @@ -126,8 +126,8 @@ static char sccsid[] = "%W% (Berkeley) %G%"; FILE * _DEFUN(_fopen_r, (ptr, file, mode), struct _reent *ptr _AND - _CONST char *file _AND - _CONST char *mode) + _CONST char *__restrict file _AND + _CONST char *__restrict mode) { register FILE *fp; register int f; @@ -140,16 +140,16 @@ _DEFUN(_fopen_r, (ptr, file, mode), if ((f = _open_r (ptr, file, oflags, 0666)) < 0) { - __sfp_lock_acquire (); + _newlib_sfp_lock_start (); fp->_flags = 0; /* release */ #ifndef __SINGLE_THREAD__ __lock_close_recursive (fp->_lock); #endif - __sfp_lock_release (); + _newlib_sfp_lock_end (); return NULL; } - _flockfile (fp); + _newlib_flockfile_start (fp); fp->_file = f; fp->_flags = flags; @@ -167,7 +167,7 @@ _DEFUN(_fopen_r, (ptr, file, mode), fp->_flags |= __SCLE; #endif - _funlockfile (fp); + _newlib_flockfile_end (fp); return fp; } diff --git a/contrib/sdk/sources/newlib/libc/stdio/fprintf.c b/contrib/sdk/sources/newlib/libc/stdio/fprintf.c index 508de015cf..e0b760f80a 100644 --- a/contrib/sdk/sources/newlib/libc/stdio/fprintf.c +++ b/contrib/sdk/sources/newlib/libc/stdio/fprintf.c @@ -24,8 +24,8 @@ int _DEFUN(_fprintf_r, (ptr, fp, fmt), struct _reent *ptr _AND - FILE *fp _AND - const char *fmt _DOTS) + FILE *__restrict fp _AND + const char *__restrict fmt _DOTS) { int ret; va_list ap; @@ -40,8 +40,8 @@ _DEFUN(_fprintf_r, (ptr, fp, fmt), int _DEFUN(fprintf, (fp, fmt), - FILE *fp _AND - const char *fmt _DOTS) + FILE *__restrict fp _AND + const char *__restrict fmt _DOTS) { int ret; va_list ap; diff --git a/contrib/sdk/sources/newlib/libc/stdio/fputc.c b/contrib/sdk/sources/newlib/libc/stdio/fputc.c index 57f664d00f..796c3e3017 100644 --- a/contrib/sdk/sources/newlib/libc/stdio/fputc.c +++ b/contrib/sdk/sources/newlib/libc/stdio/fputc.c @@ -83,9 +83,9 @@ _DEFUN(_fputc_r, (ptr, ch, file), { int result; CHECK_INIT(ptr, file); - _flockfile (file); + _newlib_flockfile_start (file); result = _putc_r (ptr, ch, file); - _funlockfile (file); + _newlib_flockfile_end (file); return result; } @@ -97,10 +97,12 @@ _DEFUN(fputc, (ch, file), { #if !defined(__OPTIMIZE_SIZE__) && !defined(PREFER_SIZE_OVER_SPEED) int result; - CHECK_INIT(_REENT, file); - _flockfile (file); - result = _putc_r (_REENT, ch, file); - _funlockfile (file); + struct _reent *reent = _REENT; + + CHECK_INIT(reent, file); + _newlib_flockfile_start (file); + result = _putc_r (reent, ch, file); + _newlib_flockfile_end (file); return result; #else return _fputc_r (_REENT, ch, file); diff --git a/contrib/sdk/sources/newlib/libc/stdio/fputs.c b/contrib/sdk/sources/newlib/libc/stdio/fputs.c index 99162428bb..e4d2cc4459 100644 --- a/contrib/sdk/sources/newlib/libc/stdio/fputs.c +++ b/contrib/sdk/sources/newlib/libc/stdio/fputs.c @@ -26,10 +26,10 @@ INDEX ANSI_SYNOPSIS #include - int fputs(const char *<[s]>, FILE *<[fp]>); + int fputs(const char *restrict <[s]>, FILE *restrict <[fp]>); #include - int _fputs_r(struct _reent *<[ptr]>, const char *<[s]>, FILE *<[fp]>); + int _fputs_r(struct _reent *<[ptr]>, const char *restrict <[s]>, FILE *restrict <[fp]>); TRAD_SYNOPSIS #include @@ -74,9 +74,10 @@ Supporting OS subroutines required: <>, <>, <>, int _DEFUN(_fputs_r, (ptr, s, fp), struct _reent * ptr _AND - char _CONST * s _AND - FILE * fp) + char _CONST *__restrict s _AND + FILE *__restrict fp) { +#ifdef _FVWRITE_IN_STREAMIO int result; struct __suio uio; struct __siov iov; @@ -88,18 +89,41 @@ _DEFUN(_fputs_r, (ptr, s, fp), CHECK_INIT(ptr, fp); - _flockfile (fp); + _newlib_flockfile_start (fp); ORIENT (fp, -1); result = __sfvwrite_r (ptr, fp, &uio); - _funlockfile (fp); + _newlib_flockfile_end (fp); return result; +#else + _CONST char *p = s; + + CHECK_INIT(ptr, fp); + + _newlib_flockfile_start (fp); + ORIENT (fp, -1); + /* Make sure we can write. */ + if (cantwrite (ptr, fp)) + goto error; + + while (*p) + { + if (__sputc_r (ptr, *p++, fp) == EOF) + goto error; + } + _newlib_flockfile_exit (fp); + return 0; + +error: + _newlib_flockfile_end (fp); + return EOF; +#endif } #ifndef _REENT_ONLY int _DEFUN(fputs, (s, fp), - char _CONST * s _AND - FILE * fp) + char _CONST *__restrict s _AND + FILE *__restrict fp) { return _fputs_r (_REENT, s, fp); } diff --git a/contrib/sdk/sources/newlib/libc/stdio/fputwc.c b/contrib/sdk/sources/newlib/libc/stdio/fputwc.c index 17456a10a5..41d4119dce 100644 --- a/contrib/sdk/sources/newlib/libc/stdio/fputwc.c +++ b/contrib/sdk/sources/newlib/libc/stdio/fputwc.c @@ -160,10 +160,10 @@ _DEFUN(_fputwc_r, (ptr, wc, fp), { wint_t r; - _flockfile (fp); + _newlib_flockfile_start (fp); ORIENT(fp, 1); r = __fputwc(ptr, wc, fp); - _funlockfile (fp); + _newlib_flockfile_end (fp); return r; } @@ -172,6 +172,8 @@ _DEFUN(fputwc, (wc, fp), wchar_t wc _AND FILE *fp) { - CHECK_INIT(_REENT, fp); - return _fputwc_r (_REENT, wc, fp); + struct _reent *reent = _REENT; + + CHECK_INIT(reent, fp); + return _fputwc_r (reent, wc, fp); } diff --git a/contrib/sdk/sources/newlib/libc/stdio/fread.c b/contrib/sdk/sources/newlib/libc/stdio/fread.c index 89abe0750a..b937d25f00 100644 --- a/contrib/sdk/sources/newlib/libc/stdio/fread.c +++ b/contrib/sdk/sources/newlib/libc/stdio/fread.c @@ -26,12 +26,12 @@ INDEX ANSI_SYNOPSIS #include - size_t fread(void *<[buf]>, size_t <[size]>, size_t <[count]>, - FILE *<[fp]>); + size_t fread(void *restrict <[buf]>, size_t <[size]>, size_t <[count]>, + FILE *restrict <[fp]>); #include - size_t _fread_r(struct _reent *<[ptr]>, void *<[buf]>, - size_t <[size]>, size_t <[count]>, FILE *<[fp]>); + size_t _fread_r(struct _reent *<[ptr]>, void *restrict <[buf]>, + size_t <[size]>, size_t <[count]>, FILE *restrict <[fp]>); TRAD_SYNOPSIS #include @@ -131,10 +131,10 @@ _DEFUN(crlf_r, (ptr, fp, buf, count, eof), size_t _DEFUN(_fread_r, (ptr, buf, size, count, fp), struct _reent * ptr _AND - _PTR buf _AND + _PTR __restrict buf _AND size_t size _AND size_t count _AND - FILE * fp) + FILE * __restrict fp) { register size_t resid; register char *p; @@ -146,7 +146,7 @@ _DEFUN(_fread_r, (ptr, buf, size, count, fp), CHECK_INIT(ptr, fp); - _flockfile (fp); + _newlib_flockfile_start (fp); ORIENT (fp, -1); if (fp->_r < 0) fp->_r = 0; @@ -195,11 +195,11 @@ _DEFUN(_fread_r, (ptr, buf, size, count, fp), #ifdef __SCLE if (fp->_flags & __SCLE) { - _funlockfile (fp); + _newlib_flockfile_exit (fp); return crlf_r (ptr, fp, buf, total-resid, 1) / size; } #endif - _funlockfile (fp); + _newlib_flockfile_exit (fp); return (total - resid) / size; } } @@ -220,11 +220,11 @@ _DEFUN(_fread_r, (ptr, buf, size, count, fp), #ifdef __SCLE if (fp->_flags & __SCLE) { - _funlockfile (fp); + _newlib_flockfile_exit (fp); return crlf_r (ptr, fp, buf, total-resid, 1) / size; } #endif - _funlockfile (fp); + _newlib_flockfile_exit (fp); return (total - resid) / size; } } @@ -237,21 +237,21 @@ _DEFUN(_fread_r, (ptr, buf, size, count, fp), #ifdef __SCLE if (fp->_flags & __SCLE) { - _funlockfile (fp); + _newlib_flockfile_exit (fp); return crlf_r(ptr, fp, buf, total, 0) / size; } #endif - _funlockfile (fp); + _newlib_flockfile_end (fp); return count; } #ifndef _REENT_ONLY size_t _DEFUN(fread, (buf, size, count, fp), - _PTR buf _AND + _PTR __restrict buf _AND size_t size _AND size_t count _AND - FILE * fp) + FILE *__restrict fp) { return _fread_r (_REENT, buf, size, count, fp); } diff --git a/contrib/sdk/sources/newlib/libc/stdio/freopen.c b/contrib/sdk/sources/newlib/libc/stdio/freopen.c index a999af47f7..47bb790a9f 100644 --- a/contrib/sdk/sources/newlib/libc/stdio/freopen.c +++ b/contrib/sdk/sources/newlib/libc/stdio/freopen.c @@ -26,10 +26,10 @@ INDEX ANSI_SYNOPSIS #include - FILE *freopen(const char *<[file]>, const char *<[mode]>, - FILE *<[fp]>); - FILE *_freopen_r(struct _reent *<[ptr]>, const char *<[file]>, - const char *<[mode]>, FILE *<[fp]>); + FILE *freopen(const char *restrict <[file]>, const char *restrict <[mode]>, + FILE *restrict <[fp]>); + FILE *_freopen_r(struct _reent *<[ptr]>, const char *restrict <[file]>, + const char *restrict <[mode]>, FILE *restrict <[fp]>); TRAD_SYNOPSIS #include @@ -90,9 +90,9 @@ Supporting OS subroutines required: <>, <>, <>, FILE * _DEFUN(_freopen_r, (ptr, file, mode, fp), struct _reent *ptr _AND - const char *file _AND - const char *mode _AND - register FILE *fp) + const char *__restrict file _AND + const char *__restrict mode _AND + register FILE *__restrict fp) { register int f; int flags, oflags; @@ -100,11 +100,20 @@ _DEFUN(_freopen_r, (ptr, file, mode, fp), CHECK_INIT (ptr, fp); + /* We can't use the _newlib_flockfile_XXX macros here due to the + interlocked locking with the sfp_lock. */ +#ifdef _STDIO_WITH_THREAD_CANCELLATION_SUPPORT + int __oldcancel; + pthread_setcancelstate (PTHREAD_CANCEL_DISABLE, &__oldcancel); +#endif _flockfile (fp); if ((flags = __sflags (ptr, mode, &oflags)) == 0) { _funlockfile (fp); +#ifdef _STDIO_WITH_THREAD_CANCELLATION_SUPPORT + pthread_setcancelstate (__oldcancel, &__oldcancel); +#endif _fclose_r (ptr, fp); return NULL; } @@ -199,7 +208,7 @@ _DEFUN(_freopen_r, (ptr, file, mode, fp), if (HASLB (fp)) FREELB (ptr, fp); fp->_lb._size = 0; - fp->_flags & ~__SORD; + fp->_flags &= ~__SORD; fp->_flags2 = 0; memset (&fp->_mbstate, 0, sizeof (_mbstate_t)); @@ -213,6 +222,9 @@ _DEFUN(_freopen_r, (ptr, file, mode, fp), __lock_close_recursive (fp->_lock); #endif __sfp_lock_release (); +#ifdef _STDIO_WITH_THREAD_CANCELLATION_SUPPORT + pthread_setcancelstate (__oldcancel, &__oldcancel); +#endif return NULL; } @@ -230,6 +242,9 @@ _DEFUN(_freopen_r, (ptr, file, mode, fp), #endif _funlockfile (fp); +#ifdef _STDIO_WITH_THREAD_CANCELLATION_SUPPORT + pthread_setcancelstate (__oldcancel, &__oldcancel); +#endif return fp; } @@ -237,9 +252,9 @@ _DEFUN(_freopen_r, (ptr, file, mode, fp), FILE * _DEFUN(freopen, (file, mode, fp), - _CONST char *file _AND - _CONST char *mode _AND - register FILE *fp) + _CONST char *__restrict file _AND + _CONST char *__restrict mode _AND + register FILE *__restrict fp) { return _freopen_r (_REENT, file, mode, fp); } diff --git a/contrib/sdk/sources/newlib/libc/stdio/fscanf.c b/contrib/sdk/sources/newlib/libc/stdio/fscanf.c index 2555f0a28e..d94c3ade76 100644 --- a/contrib/sdk/sources/newlib/libc/stdio/fscanf.c +++ b/contrib/sdk/sources/newlib/libc/stdio/fscanf.c @@ -29,7 +29,7 @@ int #ifdef _HAVE_STDC -fscanf(FILE *fp, _CONST char *fmt, ...) +fscanf(FILE *__restrict fp, _CONST char *__restrict fmt, ...) #else fscanf(FILE *fp, fmt, va_alist) FILE *fp; @@ -54,7 +54,7 @@ fscanf(FILE *fp, fmt, va_alist) int #ifdef _HAVE_STDC -_fscanf_r(struct _reent *ptr, FILE *fp, _CONST char *fmt, ...) +_fscanf_r(struct _reent *ptr, FILE *__restrict fp, _CONST char *__restrict fmt, ...) #else _fscanf_r(ptr, FILE *fp, fmt, va_alist) struct _reent *ptr; diff --git a/contrib/sdk/sources/newlib/libc/stdio/fseek.c b/contrib/sdk/sources/newlib/libc/stdio/fseek.c index b037a33f31..16e42b0e6e 100644 --- a/contrib/sdk/sources/newlib/libc/stdio/fseek.c +++ b/contrib/sdk/sources/newlib/libc/stdio/fseek.c @@ -101,21 +101,9 @@ Supporting OS subroutines required: <>, <>, <>, #include <_ansi.h> #include #include -#include -#include -#include -#include #include -#include #include "local.h" -#define POS_ERR (-(_fpos_t)1) - -/* - * Seek the given file to the given offset. - * `Whence' must be one of the three SEEK_* macros. - */ - int _DEFUN(_fseek_r, (ptr, fp, offset, whence), struct _reent *ptr _AND @@ -123,264 +111,7 @@ _DEFUN(_fseek_r, (ptr, fp, offset, whence), long offset _AND int whence) { - _fpos_t _EXFNPTR(seekfn, (struct _reent *, _PTR, _fpos_t, int)); - _fpos_t target; - _fpos_t curoff = 0; - size_t n; -#ifdef __USE_INTERNAL_STAT64 - struct stat64 st; -#else - struct stat st; -#endif - int havepos; - - /* Make sure stdio is set up. */ - - CHECK_INIT (ptr, fp); - - _flockfile (fp); - - /* If we've been doing some writing, and we're in append mode - then we don't really know where the filepos is. */ - - if (fp->_flags & __SAPP && fp->_flags & __SWR) - { - /* So flush the buffer and seek to the end. */ - _fflush_r (ptr, fp); - } - - /* Have to be able to seek. */ - - if ((seekfn = fp->_seek) == NULL) - { - ptr->_errno = ESPIPE; /* ??? */ - _funlockfile (fp); - return EOF; - } - - /* - * Change any SEEK_CUR to SEEK_SET, and check `whence' argument. - * After this, whence is either SEEK_SET or SEEK_END. - */ - - switch (whence) - { - case SEEK_CUR: - /* - * In order to seek relative to the current stream offset, - * we have to first find the current stream offset a la - * ftell (see ftell for details). - */ - _fflush_r (ptr, fp); /* may adjust seek offset on append stream */ - if (fp->_flags & __SOFF) - curoff = fp->_offset; - else - { - curoff = seekfn (ptr, fp->_cookie, (_fpos_t) 0, SEEK_CUR); - if (curoff == -1L) - { - _funlockfile (fp); - return EOF; - } - } - if (fp->_flags & __SRD) - { - curoff -= fp->_r; - if (HASUB (fp)) - curoff -= fp->_ur; - } - else if (fp->_flags & __SWR && fp->_p != NULL) - curoff += fp->_p - fp->_bf._base; - - offset += curoff; - whence = SEEK_SET; - havepos = 1; - break; - - case SEEK_SET: - case SEEK_END: - havepos = 0; - break; - - default: - ptr->_errno = EINVAL; - _funlockfile (fp); - return (EOF); - } - - /* - * Can only optimise if: - * reading (and not reading-and-writing); - * not unbuffered; and - * this is a `regular' Unix file (and hence seekfn==__sseek). - * We must check __NBF first, because it is possible to have __NBF - * and __SOPT both set. - */ - - if (fp->_bf._base == NULL) - __smakebuf_r (ptr, fp); - if (fp->_flags & (__SWR | __SRW | __SNBF | __SNPT)) - goto dumb; - if ((fp->_flags & __SOPT) == 0) - { - if (seekfn != __sseek - || fp->_file < 0 -#ifdef __USE_INTERNAL_STAT64 - || _fstat64_r (ptr, fp->_file, &st) -#else - || _fstat_r (ptr, fp->_file, &st) -#endif - || (st.st_mode & S_IFMT) != S_IFREG) - { - fp->_flags |= __SNPT; - goto dumb; - } -#ifdef HAVE_BLKSIZE - fp->_blksize = st.st_blksize; -#else - fp->_blksize = 1024; -#endif - fp->_flags |= __SOPT; - } - - /* - * We are reading; we can try to optimise. - * Figure out where we are going and where we are now. - */ - - if (whence == SEEK_SET) - target = offset; - else - { -#ifdef __USE_INTERNAL_STAT64 - if (_fstat64_r (ptr, fp->_file, &st)) -#else - if (_fstat_r (ptr, fp->_file, &st)) -#endif - goto dumb; - target = st.st_size + offset; - } - if ((long)target != target) - { - ptr->_errno = EOVERFLOW; - _funlockfile (fp); - return EOF; - } - - if (!havepos) - { - if (fp->_flags & __SOFF) - curoff = fp->_offset; - else - { - curoff = seekfn (ptr, fp->_cookie, 0L, SEEK_CUR); - if (curoff == POS_ERR) - goto dumb; - } - curoff -= fp->_r; - if (HASUB (fp)) - curoff -= fp->_ur; - } - - /* - * Compute the number of bytes in the input buffer (pretending - * that any ungetc() input has been discarded). Adjust current - * offset backwards by this count so that it represents the - * file offset for the first byte in the current input buffer. - */ - - if (HASUB (fp)) - { - curoff += fp->_r; /* kill off ungetc */ - n = fp->_up - fp->_bf._base; - curoff -= n; - n += fp->_ur; - } - else - { - n = fp->_p - fp->_bf._base; - curoff -= n; - n += fp->_r; - } - - /* - * If the target offset is within the current buffer, - * simply adjust the pointers, clear EOF, undo ungetc(), - * and return. - */ - - if (target >= curoff && target < curoff + n) - { - register int o = target - curoff; - - fp->_p = fp->_bf._base + o; - fp->_r = n - o; - if (HASUB (fp)) - FREEUB (ptr, fp); - fp->_flags &= ~__SEOF; - memset (&fp->_mbstate, 0, sizeof (_mbstate_t)); - _funlockfile (fp); - return 0; - } - - /* - * The place we want to get to is not within the current buffer, - * but we can still be kind to the kernel copyout mechanism. - * By aligning the file offset to a block boundary, we can let - * the kernel use the VM hardware to map pages instead of - * copying bytes laboriously. Using a block boundary also - * ensures that we only read one block, rather than two. - */ - - curoff = target & ~(fp->_blksize - 1); - if (seekfn (ptr, fp->_cookie, curoff, SEEK_SET) == POS_ERR) - goto dumb; - fp->_r = 0; - fp->_p = fp->_bf._base; - if (HASUB (fp)) - FREEUB (ptr, fp); - fp->_flags &= ~__SEOF; - n = target - curoff; - if (n) - { - if (__srefill_r (ptr, fp) || fp->_r < n) - goto dumb; - fp->_p += n; - fp->_r -= n; - } - memset (&fp->_mbstate, 0, sizeof (_mbstate_t)); - _funlockfile (fp); - return 0; - - /* - * We get here if we cannot optimise the seek ... just - * do it. Allow the seek function to change fp->_bf._base. - */ - -dumb: - if (_fflush_r (ptr, fp) - || seekfn (ptr, fp->_cookie, offset, whence) == POS_ERR) - { - _funlockfile (fp); - return EOF; - } - /* success: clear EOF indicator and discard ungetc() data */ - if (HASUB (fp)) - FREEUB (ptr, fp); - fp->_p = fp->_bf._base; - fp->_r = 0; - /* fp->_w = 0; *//* unnecessary (I think...) */ - fp->_flags &= ~__SEOF; - /* Reset no-optimization flag after successful seek. The - no-optimization flag may be set in the case of a read - stream that is flushed which by POSIX/SUSv3 standards, - means that a corresponding seek must not optimize. The - optimization is then allowed if no subsequent flush - is performed. */ - fp->_flags &= ~__SNPT; - memset (&fp->_mbstate, 0, sizeof (_mbstate_t)); - _funlockfile (fp); - return 0; + return _fseeko_r (ptr, fp, offset, whence); } #ifndef _REENT_ONLY diff --git a/contrib/sdk/sources/newlib/libc/stdio/fseeko.c b/contrib/sdk/sources/newlib/libc/stdio/fseeko.c index 7d30ab66bc..6b3ca09d14 100644 --- a/contrib/sdk/sources/newlib/libc/stdio/fseeko.c +++ b/contrib/sdk/sources/newlib/libc/stdio/fseeko.c @@ -1,5 +1,5 @@ /* - * Copyright (c) 2002, Red Hat Inc. + * Copyright (c) 1990 The Regents of the University of California. * All rights reserved. * * Redistribution and use in source and binary forms are permitted @@ -15,9 +15,106 @@ * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. */ +/* +FUNCTION +<>, <>---set file position + +INDEX + fseek +INDEX + fseeko +INDEX + _fseek_r +INDEX + _fseeko_r + +ANSI_SYNOPSIS + #include + 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]>) + int _fseeko_r(struct _reent *<[ptr]>, FILE *<[fp]>, + off_t <[offset]>, int <[whence]>) + +TRAD_SYNOPSIS + #include + int fseek(<[fp]>, <[offset]>, <[whence]>) + FILE *<[fp]>; + long <[offset]>; + int <[whence]>; + + int fseeko(<[fp]>, <[offset]>, <[whence]>) + FILE *<[fp]>; + off_t <[offset]>; + int <[whence]>; + + int _fseek_r(<[ptr]>, <[fp]>, <[offset]>, <[whence]>) + struct _reent *<[ptr]>; + FILE *<[fp]>; + long <[offset]>; + int <[whence]>; + + int _fseeko_r(<[ptr]>, <[fp]>, <[offset]>, <[whence]>) + struct _reent *<[ptr]>; + FILE *<[fp]>; + off_t <[offset]>; + int <[whence]>; + +DESCRIPTION +Objects of type <> can have a ``position'' that records how much +of the file your program has already read. Many of the <> functions +depend on this position, and many change it as a side effect. + +You can use <>/<> to set the position for the file identified by +<[fp]>. The value of <[offset]> determines the new position, in one +of three ways selected by the value of <[whence]> (defined as macros +in `<>'): + +<>---<[offset]> is the absolute file position (an offset +from the beginning of the file) desired. <[offset]> must be positive. + +<>---<[offset]> is relative to the current file position. +<[offset]> can meaningfully be either positive or negative. + +<>---<[offset]> is relative to the current end of file. +<[offset]> can meaningfully be either positive (to increase the size +of the file) or negative. + +See <>/<> to determine the current file position. + +RETURNS +<>/<> return <<0>> when successful. On failure, the +result is <>. The reason for failure is indicated in <>: +either <> (the stream identified by <[fp]> doesn't support +repositioning) or <> (invalid file position). + +PORTABILITY +ANSI C requires <>. + +<> is defined by the Single Unix specification. + +Supporting OS subroutines required: <>, <>, <>, +<>, <>, <>, <>. +*/ + #include <_ansi.h> #include #include +#include +#include +#include +#include +#include +#include +#include "local.h" + +#define POS_ERR (-(_fpos_t)1) + +/* + * Seek the given file to the given offset. + * `Whence' must be one of the three SEEK_* macros. + */ int _DEFUN(_fseeko_r, (ptr, fp, offset, whence), @@ -26,7 +123,261 @@ _DEFUN(_fseeko_r, (ptr, fp, offset, whence), _off_t offset _AND int whence) { - return _fseek_r (ptr, fp, (long)offset, whence); + _fpos_t _EXFNPTR(seekfn, (struct _reent *, _PTR, _fpos_t, int)); + _fpos_t target; + _fpos_t curoff = 0; + size_t n; +#ifdef __USE_INTERNAL_STAT64 + struct stat64 st; +#else + struct stat st; +#endif + int havepos; + + /* Make sure stdio is set up. */ + + CHECK_INIT (ptr, fp); + + _newlib_flockfile_start (fp); + + /* If we've been doing some writing, and we're in append mode + then we don't really know where the filepos is. */ + + if (fp->_flags & __SAPP && fp->_flags & __SWR) + { + /* So flush the buffer and seek to the end. */ + _fflush_r (ptr, fp); + } + + /* Have to be able to seek. */ + + if ((seekfn = fp->_seek) == NULL) + { + ptr->_errno = ESPIPE; /* ??? */ + _newlib_flockfile_exit (fp); + return EOF; + } + + /* + * Change any SEEK_CUR to SEEK_SET, and check `whence' argument. + * After this, whence is either SEEK_SET or SEEK_END. + */ + + switch (whence) + { + case SEEK_CUR: + /* + * In order to seek relative to the current stream offset, + * we have to first find the current stream offset a la + * ftell (see ftell for details). + */ + _fflush_r (ptr, fp); /* may adjust seek offset on append stream */ + if (fp->_flags & __SOFF) + curoff = fp->_offset; + else + { + curoff = seekfn (ptr, fp->_cookie, (_fpos_t) 0, SEEK_CUR); + if (curoff == -1L) + { + _newlib_flockfile_exit (fp); + return EOF; + } + } + if (fp->_flags & __SRD) + { + curoff -= fp->_r; + if (HASUB (fp)) + curoff -= fp->_ur; + } + else if (fp->_flags & __SWR && fp->_p != NULL) + curoff += fp->_p - fp->_bf._base; + + offset += curoff; + whence = SEEK_SET; + havepos = 1; + break; + + case SEEK_SET: + case SEEK_END: + havepos = 0; + break; + + default: + ptr->_errno = EINVAL; + _newlib_flockfile_exit (fp); + return (EOF); + } + + /* + * Can only optimise if: + * reading (and not reading-and-writing); + * not unbuffered; and + * this is a `regular' Unix file (and hence seekfn==__sseek). + * We must check __NBF first, because it is possible to have __NBF + * and __SOPT both set. + */ + + if (fp->_bf._base == NULL) + __smakebuf_r (ptr, fp); + +#ifdef _FSEEK_OPTIMIZATION + if (fp->_flags & (__SWR | __SRW | __SNBF | __SNPT)) + goto dumb; + if ((fp->_flags & __SOPT) == 0) + { + if (seekfn != __sseek + || fp->_file < 0 +#ifdef __USE_INTERNAL_STAT64 + || _fstat64_r (ptr, fp->_file, &st) +#else + || _fstat_r (ptr, fp->_file, &st) +#endif + || (st.st_mode & S_IFMT) != S_IFREG) + { + fp->_flags |= __SNPT; + goto dumb; + } +#ifdef HAVE_BLKSIZE + fp->_blksize = st.st_blksize; +#else + fp->_blksize = 1024; +#endif + fp->_flags |= __SOPT; + } + + /* + * We are reading; we can try to optimise. + * Figure out where we are going and where we are now. + */ + + if (whence == SEEK_SET) + target = offset; + else + { +#ifdef __USE_INTERNAL_STAT64 + if (_fstat64_r (ptr, fp->_file, &st)) +#else + if (_fstat_r (ptr, fp->_file, &st)) +#endif + goto dumb; + target = st.st_size + offset; + } + + if (!havepos) + { + if (fp->_flags & __SOFF) + curoff = fp->_offset; + else + { + curoff = seekfn (ptr, fp->_cookie, 0L, SEEK_CUR); + if (curoff == POS_ERR) + goto dumb; + } + curoff -= fp->_r; + if (HASUB (fp)) + curoff -= fp->_ur; + } + + /* + * Compute the number of bytes in the input buffer (pretending + * that any ungetc() input has been discarded). Adjust current + * offset backwards by this count so that it represents the + * file offset for the first byte in the current input buffer. + */ + + if (HASUB (fp)) + { + curoff += fp->_r; /* kill off ungetc */ + n = fp->_up - fp->_bf._base; + curoff -= n; + n += fp->_ur; + } + else + { + n = fp->_p - fp->_bf._base; + curoff -= n; + n += fp->_r; + } + + /* + * If the target offset is within the current buffer, + * simply adjust the pointers, clear EOF, undo ungetc(), + * and return. + */ + + if (target >= curoff && target < curoff + n) + { + register int o = target - curoff; + + fp->_p = fp->_bf._base + o; + fp->_r = n - o; + if (HASUB (fp)) + FREEUB (ptr, fp); + fp->_flags &= ~__SEOF; + memset (&fp->_mbstate, 0, sizeof (_mbstate_t)); + _newlib_flockfile_exit (fp); + return 0; + } + + /* + * The place we want to get to is not within the current buffer, + * but we can still be kind to the kernel copyout mechanism. + * By aligning the file offset to a block boundary, we can let + * the kernel use the VM hardware to map pages instead of + * copying bytes laboriously. Using a block boundary also + * ensures that we only read one block, rather than two. + */ + + curoff = target & ~(fp->_blksize - 1); + if (seekfn (ptr, fp->_cookie, curoff, SEEK_SET) == POS_ERR) + goto dumb; + fp->_r = 0; + fp->_p = fp->_bf._base; + if (HASUB (fp)) + FREEUB (ptr, fp); + fp->_flags &= ~__SEOF; + n = target - curoff; + if (n) + { + if (__srefill_r (ptr, fp) || fp->_r < n) + goto dumb; + fp->_p += n; + fp->_r -= n; + } + memset (&fp->_mbstate, 0, sizeof (_mbstate_t)); + _newlib_flockfile_exit (fp); + return 0; + + /* + * We get here if we cannot optimise the seek ... just + * do it. Allow the seek function to change fp->_bf._base. + */ +#endif + +dumb: + if (_fflush_r (ptr, fp) + || seekfn (ptr, fp->_cookie, offset, whence) == POS_ERR) + { + _newlib_flockfile_exit (fp); + return EOF; + } + /* success: clear EOF indicator and discard ungetc() data */ + if (HASUB (fp)) + FREEUB (ptr, fp); + fp->_p = fp->_bf._base; + fp->_r = 0; + /* fp->_w = 0; *//* unnecessary (I think...) */ + fp->_flags &= ~__SEOF; + /* Reset no-optimization flag after successful seek. The + no-optimization flag may be set in the case of a read + stream that is flushed which by POSIX/SUSv3 standards, + means that a corresponding seek must not optimize. The + optimization is then allowed if no subsequent flush + is performed. */ + fp->_flags &= ~__SNPT; + memset (&fp->_mbstate, 0, sizeof (_mbstate_t)); + _newlib_flockfile_end (fp); + return 0; } #ifndef _REENT_ONLY @@ -37,8 +388,7 @@ _DEFUN(fseeko, (fp, offset, whence), _off_t offset _AND int whence) { - /* for now we simply cast since off_t should be long */ - return _fseek_r (_REENT, fp, (long)offset, whence); + return _fseeko_r (_REENT, fp, offset, whence); } #endif /* !_REENT_ONLY */ diff --git a/contrib/sdk/sources/newlib/libc/stdio/ftell.c b/contrib/sdk/sources/newlib/libc/stdio/ftell.c index c2c80f991a..69eee57da6 100644 --- a/contrib/sdk/sources/newlib/libc/stdio/ftell.c +++ b/contrib/sdk/sources/newlib/libc/stdio/ftell.c @@ -105,64 +105,13 @@ _DEFUN(_ftell_r, (ptr, fp), { _fpos_t pos; - /* Ensure stdio is set up. */ - - CHECK_INIT (ptr, fp); - - _flockfile (fp); - - if (fp->_seek == NULL) - { - ptr->_errno = ESPIPE; - _funlockfile (fp); - return -1L; - } - - /* Find offset of underlying I/O object, then adjust for buffered - bytes. Flush a write stream, since the offset may be altered if - the stream is appending. Do not flush a read stream, since we - must not lose the ungetc buffer. */ - if (fp->_flags & __SWR) - _fflush_r (ptr, fp); - if (fp->_flags & __SOFF) - pos = fp->_offset; - else - { - pos = fp->_seek (ptr, fp->_cookie, (_fpos_t) 0, SEEK_CUR); - if (pos == -1L) - { - _funlockfile (fp); - return pos; - } - } - if (fp->_flags & __SRD) - { - /* - * Reading. Any unread characters (including - * those from ungetc) cause the position to be - * smaller than that in the underlying object. - */ - pos -= fp->_r; - if (HASUB (fp)) - pos -= fp->_ur; - } - else if ((fp->_flags & __SWR) && fp->_p != NULL) - { - /* - * Writing. Any buffered characters cause the - * position to be greater than that in the - * underlying object. - */ - pos += fp->_p - fp->_bf._base; - } - - _funlockfile (fp); + pos = _ftello_r (ptr, fp); if ((long)pos != pos) { pos = -1; ptr->_errno = EOVERFLOW; } - return pos; + return (long)pos; } #ifndef _REENT_ONLY diff --git a/contrib/sdk/sources/newlib/libc/stdio/ftello.c b/contrib/sdk/sources/newlib/libc/stdio/ftello.c index 3976524811..e7fc2360e0 100644 --- a/contrib/sdk/sources/newlib/libc/stdio/ftello.c +++ b/contrib/sdk/sources/newlib/libc/stdio/ftello.c @@ -1,5 +1,5 @@ /* - * Copyright (c) 2002, Red Hat Inc. + * Copyright (c) 1990 The Regents of the University of California. * All rights reserved. * * Redistribution and use in source and binary forms are permitted @@ -15,17 +15,149 @@ * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. */ +/* +FUNCTION +<>, <>---return position in a stream or file + +INDEX + ftell +INDEX + ftello +INDEX + _ftell_r +INDEX + _ftello_r + +ANSI_SYNOPSIS + #include + long ftell(FILE *<[fp]>); + off_t ftello(FILE *<[fp]>); + long _ftell_r(struct _reent *<[ptr]>, FILE *<[fp]>); + off_t _ftello_r(struct _reent *<[ptr]>, FILE *<[fp]>); + +TRAD_SYNOPSIS + #include + long ftell(<[fp]>) + FILE *<[fp]>; + + off_t ftello(<[fp]>) + FILE *<[fp]>; + + long _ftell_r(<[ptr]>, <[fp]>) + struct _reent *<[ptr]>; + FILE *<[fp]>; + + off_t _ftello_r(<[ptr]>, <[fp]>) + struct _reent *<[ptr]>; + FILE *<[fp]>; + +DESCRIPTION +Objects of type <> can have a ``position'' that records how much +of the file your program has already read. Many of the <> functions +depend on this position, and many change it as a side effect. + +The result of <>/<> is the current position for a file +identified by <[fp]>. If you record this result, you can later +use it with <>/<> to return the file to this +position. The difference between <> and <> is that +<> returns <> and <> returns <>. + +In the current implementation, <>/<> simply uses a character +count to represent the file position; this is the same number that +would be recorded by <>. + +RETURNS +<>/<> return the file position, if possible. If they cannot do +this, they return <<-1L>>. Failure occurs on streams that do not support +positioning; the global <> indicates this condition with the +value <>. + +PORTABILITY +<> is required by the ANSI C standard, but the meaning of its +result (when successful) is not specified beyond requiring that it be +acceptable as an argument to <>. In particular, other +conforming C implementations may return a different result from +<> than what <> records. + +<> is defined by the Single Unix specification. + +No supporting OS subroutines are required. +*/ + +#if defined(LIBC_SCCS) && !defined(lint) +static char sccsid[] = "%W% (Berkeley) %G%"; +#endif /* LIBC_SCCS and not lint */ + +/* + * ftello: return current offset. + */ + #include <_ansi.h> #include #include +#include +#include "local.h" _off_t _DEFUN(_ftello_r, (ptr, fp), struct _reent * ptr _AND register FILE * fp) { - /* for now we simply cast since off_t should be long */ - return (_off_t)_ftell_r (ptr, fp); + _fpos_t pos; + + /* Ensure stdio is set up. */ + + CHECK_INIT (ptr, fp); + + _newlib_flockfile_start (fp); + + if (fp->_seek == NULL) + { + ptr->_errno = ESPIPE; + _newlib_flockfile_exit (fp); + return -1L; + } + + /* Find offset of underlying I/O object, then adjust for buffered + bytes. Flush a write stream, since the offset may be altered if + the stream is appending. Do not flush a read stream, since we + must not lose the ungetc buffer. */ + if (fp->_flags & __SWR) + _fflush_r (ptr, fp); + if (fp->_flags & __SOFF) + pos = fp->_offset; + else + { + pos = fp->_seek (ptr, fp->_cookie, (_fpos_t) 0, SEEK_CUR); + if (pos == -1L) + { + _newlib_flockfile_exit (fp); + return pos; + } + } + if (fp->_flags & __SRD) + { + /* + * Reading. Any unread characters (including + * those from ungetc) cause the position to be + * smaller than that in the underlying object. + */ + pos -= fp->_r; + if (HASUB (fp)) + pos -= fp->_ur; + } + else if ((fp->_flags & __SWR) && fp->_p != NULL) + { + /* + * Writing. Any buffered characters cause the + * position to be greater than that in the + * underlying object. + */ + pos += fp->_p - fp->_bf._base; + } + + _newlib_flockfile_end (fp); + return pos; } #ifndef _REENT_ONLY @@ -34,7 +166,7 @@ _off_t _DEFUN(ftello, (fp), register FILE * fp) { - return (_off_t)_ftell_r (_REENT, fp); + return _ftello_r (_REENT, fp); } #endif /* !_REENT_ONLY */ diff --git a/contrib/sdk/sources/newlib/libc/stdio/fvwrite.c b/contrib/sdk/sources/newlib/libc/stdio/fvwrite.c index 107e553de5..82ad985f5c 100644 --- a/contrib/sdk/sources/newlib/libc/stdio/fvwrite.c +++ b/contrib/sdk/sources/newlib/libc/stdio/fvwrite.c @@ -21,6 +21,7 @@ #include #include #include +#include #include "local.h" #include "fvwrite.h" @@ -52,7 +53,7 @@ _DEFUN(__sfvwrite_r, (ptr, fp, uio), register size_t len; register _CONST char *p = NULL; register struct __siov *iov; - register int w, s; + register _READ_WRITE_RETURN_TYPE w, s; char *nl; int nlknown, nldist; @@ -89,12 +90,14 @@ _DEFUN(__sfvwrite_r, (ptr, fp, uio), if (fp->_flags & __SNBF) { /* - * Unbuffered: write up to BUFSIZ bytes at a time. + * Unbuffered: Split buffer in the largest multiple of BUFSIZ < INT_MAX + * as some legacy code may expect int instead of size_t. */ do { GETIOV (;); - w = fp->_write (ptr, fp->_cookie, p, MIN (len, BUFSIZ)); + w = fp->_write (ptr, fp->_cookie, p, + MIN (len, INT_MAX - INT_MAX % BUFSIZ)); if (w <= 0) goto err; p += w; @@ -155,8 +158,10 @@ _DEFUN(__sfvwrite_r, (ptr, fp, uio), newsize); if (!str) { - /* Free buffer which is no longer used. */ + /* Free buffer which is no longer used and clear + __SMBF flag to avoid double free in fclose. */ _free_r (ptr, fp->_bf._base); + fp->_flags &= ~__SMBF; /* Ensure correct errno, even if free changed it. */ ptr->_errno = ENOMEM; goto err; @@ -175,29 +180,23 @@ _DEFUN(__sfvwrite_r, (ptr, fp, uio), fp->_p += w; w = len; /* but pretend copied all */ } - else if (fp->_p > fp->_bf._base && len > w) + else if (fp->_p > fp->_bf._base || len < fp->_bf._size) { - /* fill and flush */ + /* pass through the buffer */ + w = MIN (len, w); COPY (w); - /* fp->_w -= w; *//* unneeded */ + fp->_w -= w; fp->_p += w; - if (_fflush_r (ptr, fp)) - goto err; - } - else if (len >= (w = fp->_bf._size)) - { - /* write directly */ - w = fp->_write (ptr, fp->_cookie, p, w); - if (w <= 0) + if (fp->_w == 0 && _fflush_r (ptr, fp)) goto err; } else { - /* fill and done */ - w = len; - COPY (w); - fp->_w -= w; - fp->_p += w; + /* write directly */ + w = ((int)MIN (len, INT_MAX)) / fp->_bf._size * fp->_bf._size; + w = fp->_write (ptr, fp->_cookie, p, w); + if (w <= 0) + goto err; } p += w; len -= w; diff --git a/contrib/sdk/sources/newlib/libc/stdio/fvwrite.h b/contrib/sdk/sources/newlib/libc/stdio/fvwrite.h index af597556d5..d4d519ec7f 100644 --- a/contrib/sdk/sources/newlib/libc/stdio/fvwrite.h +++ b/contrib/sdk/sources/newlib/libc/stdio/fvwrite.h @@ -28,7 +28,7 @@ struct __siov { struct __suio { struct __siov *uio_iov; int uio_iovcnt; - int uio_resid; + size_t uio_resid; }; diff --git a/contrib/sdk/sources/newlib/libc/stdio/fwalk.c b/contrib/sdk/sources/newlib/libc/stdio/fwalk.c index f11e89977b..749f1c9541 100644 --- a/contrib/sdk/sources/newlib/libc/stdio/fwalk.c +++ b/contrib/sdk/sources/newlib/libc/stdio/fwalk.c @@ -46,11 +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) - { if (fp->_flags != 0 && fp->_flags != 1 && fp->_file != -1) ret |= (*function) (fp); - } return ret; } diff --git a/contrib/sdk/sources/newlib/libc/stdio/fwrite.c b/contrib/sdk/sources/newlib/libc/stdio/fwrite.c index 66f260b0de..01cf5e6353 100644 --- a/contrib/sdk/sources/newlib/libc/stdio/fwrite.c +++ b/contrib/sdk/sources/newlib/libc/stdio/fwrite.c @@ -26,12 +26,12 @@ INDEX ANSI_SYNOPSIS #include - size_t fwrite(const void *<[buf]>, size_t <[size]>, - size_t <[count]>, FILE *<[fp]>); + size_t fwrite(const void *restrict <[buf]>, size_t <[size]>, + size_t <[count]>, FILE *restrict <[fp]>); #include - size_t _fwrite_r(struct _reent *<[ptr]>, const void *<[buf]>, size_t <[size]>, - size_t <[count]>, FILE *<[fp]>); + size_t _fwrite_r(struct _reent *<[ptr]>, const void *restrict <[buf]>, size_t <[size]>, + size_t <[count]>, FILE *restrict <[fp]>); TRAD_SYNOPSIS #include @@ -97,12 +97,13 @@ static char sccsid[] = "%W% (Berkeley) %G%"; size_t _DEFUN(_fwrite_r, (ptr, buf, size, count, fp), struct _reent * ptr _AND - _CONST _PTR buf _AND + _CONST _PTR __restrict buf _AND size_t size _AND size_t count _AND - FILE * fp) + FILE * __restrict fp) { size_t n; +#ifdef _FVWRITE_IN_STREAMIO struct __suio uio; struct __siov iov; @@ -119,21 +120,45 @@ _DEFUN(_fwrite_r, (ptr, buf, size, count, fp), CHECK_INIT(ptr, fp); - _flockfile (fp); + _newlib_flockfile_start (fp); ORIENT (fp, -1); if (__sfvwrite_r (ptr, fp, &uio) == 0) { - _funlockfile (fp); + _newlib_flockfile_exit (fp); return count; } - _funlockfile (fp); + _newlib_flockfile_end (fp); return (n - uio.uio_resid) / size; +#else + size_t i = 0; + _CONST char *p = buf; + n = count * size; + CHECK_INIT (ptr, fp); + + _newlib_flockfile_start (fp); + ORIENT (fp, -1); + /* Make sure we can write. */ + if (cantwrite (ptr, fp)) + goto ret; + + while (i < n) + { + if (__sputc_r (ptr, p[i], fp) == EOF) + break; + + i++; + } + +ret: + _newlib_flockfile_end (fp); + return i / size; +#endif } #ifndef _REENT_ONLY size_t _DEFUN(fwrite, (buf, size, count, fp), - _CONST _PTR buf _AND + _CONST _PTR __restrict buf _AND size_t size _AND size_t count _AND FILE * fp) diff --git a/contrib/sdk/sources/newlib/libc/stdio/local.h b/contrib/sdk/sources/newlib/libc/stdio/local.h index 8e24ebfda9..4345fa8f19 100644 --- a/contrib/sdk/sources/newlib/libc/stdio/local.h +++ b/contrib/sdk/sources/newlib/libc/stdio/local.h @@ -32,6 +32,98 @@ # include #endif +/* The following define determines if the per-reent stdin, stdout and stderr + streams are closed during _reclaim_reent(). The stdin, stdout and stderr + streams are initialized to use file descriptors 0, 1 and 2 respectively. In + 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__ +#define _STDIO_CLOSE_PER_REENT_STD_STREAMS +#endif + +/* The following macros are supposed to replace calls to _flockfile/_funlockfile + and __sfp_lock_acquire/__sfp_lock_release. In case of multi-threaded + environments using pthreads, it's not sufficient to lock the stdio functions + against concurrent threads accessing the same data, the locking must also be + secured against thread cancellation. + + The below macros have to be used in pairs. The _newlib_XXX_start macro + starts with a opening curly brace, the _newlib_XXX_end macro ends with a + closing curly brace, so the start macro and the end macro mark the code + start and end of a critical section. In case the code leaves the critical + section before reaching the end of the critical section's code end, use + the appropriate _newlib_XXX_exit macro. */ + +#if !defined (__SINGLE_THREAD__) && defined (_POSIX_THREADS) \ + && !defined (__rtems__) +#define _STDIO_WITH_THREAD_CANCELLATION_SUPPORT +#endif + +#ifdef _STDIO_WITH_THREAD_CANCELLATION_SUPPORT +#include + +/* Start a stream oriented critical section: */ +# define _newlib_flockfile_start(_fp) \ + { \ + int __oldfpcancel; \ + pthread_setcancelstate (PTHREAD_CANCEL_DISABLE, &__oldfpcancel); \ + _flockfile (_fp) + +/* Exit from a stream oriented critical section prematurely: */ +# define _newlib_flockfile_exit(_fp) \ + _funlockfile (_fp); \ + pthread_setcancelstate (__oldfpcancel, &__oldfpcancel); + +/* End a stream oriented critical section: */ +# define _newlib_flockfile_end(_fp) \ + _funlockfile (_fp); \ + pthread_setcancelstate (__oldfpcancel, &__oldfpcancel); \ + } + +/* Start a stream list oriented critical section: */ +# define _newlib_sfp_lock_start() \ + { \ + int __oldsfpcancel; \ + pthread_setcancelstate (PTHREAD_CANCEL_DISABLE, &__oldsfpcancel); \ + __sfp_lock_acquire () + +/* Exit from a stream list oriented critical section prematurely: */ +# define _newlib_sfp_lock_exit() \ + __sfp_lock_release (); \ + pthread_setcancelstate (__oldsfpcancel, &__oldsfpcancel); + +/* End a stream list oriented critical section: */ +# define _newlib_sfp_lock_end() \ + __sfp_lock_release (); \ + pthread_setcancelstate (__oldsfpcancel, &__oldsfpcancel); \ + } + +#else /* !_STDIO_WITH_THREAD_CANCELLATION_SUPPORT */ + +# define _newlib_flockfile_start(_fp) \ + { \ + _flockfile(_fp) + +# define _newlib_flockfile_exit(_fp) \ + _funlockfile(_fp); \ + +# define _newlib_flockfile_end(_fp) \ + _funlockfile(_fp); \ + } + +# define _newlib_sfp_lock_start() \ + { \ + __sfp_lock_acquire () + +# define _newlib_sfp_lock_exit() \ + __sfp_lock_release (); + +# define _newlib_sfp_lock_end() \ + __sfp_lock_release (); \ + } + +#endif /* _STDIO_WITH_THREAD_CANCELLATION_SUPPORT */ extern u_char *_EXFUN(__sccl, (char *, u_char *fmt)); extern int _EXFUN(__svfscanf_r,(struct _reent *,FILE *, _CONST char *,va_list)); @@ -42,26 +134,28 @@ 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 *)); extern int _EXFUN(__srefill_r,(struct _reent *,FILE *)); extern _READ_WRITE_RETURN_TYPE _EXFUN(__sread,(struct _reent *, void *, char *, - int)); + _READ_WRITE_BUFSIZE_TYPE)); extern _READ_WRITE_RETURN_TYPE _EXFUN(__seofread,(struct _reent *, void *, - char *, int)); + char *, + _READ_WRITE_BUFSIZE_TYPE)); extern _READ_WRITE_RETURN_TYPE _EXFUN(__swrite,(struct _reent *, void *, - const char *, int)); + const char *, + _READ_WRITE_BUFSIZE_TYPE)); extern _fpos_t _EXFUN(__sseek,(struct _reent *, void *, _fpos_t, int)); extern int _EXFUN(__sclose,(struct _reent *, void *)); extern int _EXFUN(__stextmode,(int)); @@ -76,7 +170,8 @@ extern int _EXFUN(__submore, (struct _reent *, FILE *)); #ifdef __LARGE64_FILES extern _fpos64_t _EXFUN(__sseek64,(struct _reent *, void *, _fpos64_t, int)); extern _READ_WRITE_RETURN_TYPE _EXFUN(__swrite64,(struct _reent *, void *, - const char *, int)); + const char *, + _READ_WRITE_BUFSIZE_TYPE)); #endif /* Called by the main entry point fns to ensure stdio has been initialized. */ @@ -85,22 +180,24 @@ extern _READ_WRITE_RETURN_TYPE _EXFUN(__swrite64,(struct _reent *, void *, #define CHECK_INIT(ptr, fp) \ do \ { \ - if ((ptr) && !(ptr)->__sdidinit) \ - __sinit (ptr); \ + struct _reent *_check_init_ptr = (ptr); \ + if ((_check_init_ptr) && !(_check_init_ptr)->__sdidinit) \ + __sinit (_check_init_ptr); \ if ((fp) == (FILE *)&__sf_fake_stdin) \ - (fp) = _stdin_r(ptr); \ + (fp) = _stdin_r(_check_init_ptr); \ else if ((fp) == (FILE *)&__sf_fake_stdout) \ - (fp) = _stdout_r(ptr); \ + (fp) = _stdout_r(_check_init_ptr); \ else if ((fp) == (FILE *)&__sf_fake_stderr) \ - (fp) = _stderr_r(ptr); \ + (fp) = _stderr_r(_check_init_ptr); \ } \ while (0) #else /* !_REENT_SMALL */ #define CHECK_INIT(ptr, fp) \ do \ { \ - if ((ptr) && !(ptr)->__sdidinit) \ - __sinit (ptr); \ + struct _reent *_check_init_ptr = (ptr); \ + if ((_check_init_ptr) && !(_check_init_ptr)->__sdidinit) \ + __sinit (_check_init_ptr); \ } \ while (0) #endif /* !_REENT_SMALL */ @@ -108,8 +205,9 @@ extern _READ_WRITE_RETURN_TYPE _EXFUN(__swrite64,(struct _reent *, void *, #define CHECK_STD_INIT(ptr) \ do \ { \ - if ((ptr) && !(ptr)->__sdidinit) \ - __sinit (ptr); \ + struct _reent *_check_init_ptr = (ptr); \ + if ((_check_init_ptr) && !(_check_init_ptr)->__sdidinit) \ + __sinit (_check_init_ptr); \ } \ while (0) @@ -136,6 +234,7 @@ extern _READ_WRITE_RETURN_TYPE _EXFUN(__swrite64,(struct _reent *, void *, #define FREELB(ptr, fp) { _free_r(ptr,(char *)(fp)->_lb._base); \ (fp)->_lb._base = NULL; } +#ifdef _WIDE_ORIENT /* * Set the orientation for a stream. If o > 0, the stream has wide- * orientation. If o < 0, the stream has byte-orientation. @@ -153,6 +252,9 @@ extern _READ_WRITE_RETURN_TYPE _EXFUN(__swrite64,(struct _reent *, void *, } \ } \ while (0) +#else +#define ORIENT(fp,ori) +#endif /* WARNING: _dcvt is defined in the stdlib directory, not here! */ diff --git a/contrib/sdk/sources/newlib/libc/stdio/makebuf.c b/contrib/sdk/sources/newlib/libc/stdio/makebuf.c index 02cf7c9fa8..d3abf5ac3c 100644 --- a/contrib/sdk/sources/newlib/libc/stdio/makebuf.c +++ b/contrib/sdk/sources/newlib/libc/stdio/makebuf.c @@ -65,8 +65,10 @@ _DEFUN(__smakebuf_r, (ptr, fp), size = _DEFAULT_ASPRINTF_BUFSIZE; else size = BUFSIZ; +#ifdef _FSEEK_OPTIMIZATION /* do not try to optimise fseek() */ fp->_flags |= __SNPT; +#endif } else { @@ -76,6 +78,7 @@ _DEFUN(__smakebuf_r, (ptr, fp), #else size = BUFSIZ; #endif +#ifdef _FSEEK_OPTIMIZATION /* * Optimize fseek() only if it is a regular file. * (The test for __sseek is mainly paranoia.) @@ -91,6 +94,7 @@ _DEFUN(__smakebuf_r, (ptr, fp), } else fp->_flags |= __SNPT; +#endif } if ((p = _malloc_r (ptr, size)) == NULL) { diff --git a/contrib/sdk/sources/newlib/libc/stdio/printf.c b/contrib/sdk/sources/newlib/libc/stdio/printf.c index 8d522e9733..3327856071 100644 --- a/contrib/sdk/sources/newlib/libc/stdio/printf.c +++ b/contrib/sdk/sources/newlib/libc/stdio/printf.c @@ -25,7 +25,7 @@ int _DEFUN(_printf_r, (ptr, fmt), struct _reent *ptr _AND - const char *fmt _DOTS) + const char *__restrict fmt _DOTS) { int ret; va_list ap; @@ -41,7 +41,7 @@ _DEFUN(_printf_r, (ptr, fmt), int _DEFUN(printf, (fmt), - const char *fmt _DOTS) + const char *__restrict fmt _DOTS) { int ret; va_list ap; diff --git a/contrib/sdk/sources/newlib/libc/stdio/putc.c b/contrib/sdk/sources/newlib/libc/stdio/putc.c index c71b23eca7..00a4bc7b1a 100644 --- a/contrib/sdk/sources/newlib/libc/stdio/putc.c +++ b/contrib/sdk/sources/newlib/libc/stdio/putc.c @@ -97,9 +97,9 @@ _DEFUN(_putc_r, (ptr, c, fp), { int result; CHECK_INIT (ptr, fp); - _flockfile (fp); + _newlib_flockfile_start (fp); result = __sputc_r (ptr, c, fp); - _funlockfile (fp); + _newlib_flockfile_end (fp); return result; } @@ -111,10 +111,12 @@ _DEFUN(putc, (c, fp), { #if !defined(PREFER_SIZE_OVER_SPEED) && !defined(__OPTIMIZE_SIZE__) int result; - CHECK_INIT (_REENT, fp); - _flockfile (fp); - result = __sputc_r (_REENT, c, fp); - _funlockfile (fp); + struct _reent *reent = _REENT; + + CHECK_INIT (reent, fp); + _newlib_flockfile_start (fp); + result = __sputc_r (reent, c, fp); + _newlib_flockfile_end (fp); return result; #else return _putc_r (_REENT, c, fp); diff --git a/contrib/sdk/sources/newlib/libc/stdio/putchar.c b/contrib/sdk/sources/newlib/libc/stdio/putchar.c index d4af25cafc..0f553430ae 100644 --- a/contrib/sdk/sources/newlib/libc/stdio/putchar.c +++ b/contrib/sdk/sources/newlib/libc/stdio/putchar.c @@ -90,8 +90,10 @@ int _DEFUN(putchar, (c), int c) { - _REENT_SMALL_CHECK_INIT (_REENT); - return _putc_r (_REENT, c, _stdout_r (_REENT)); + struct _reent *reent = _REENT; + + _REENT_SMALL_CHECK_INIT (reent); + return _putc_r (reent, c, _stdout_r (reent)); } #endif diff --git a/contrib/sdk/sources/newlib/libc/stdio/puts.c b/contrib/sdk/sources/newlib/libc/stdio/puts.c index 080010dede..f498e37b69 100644 --- a/contrib/sdk/sources/newlib/libc/stdio/puts.c +++ b/contrib/sdk/sources/newlib/libc/stdio/puts.c @@ -78,9 +78,12 @@ _DEFUN(_puts_r, (ptr, s), struct _reent *ptr _AND _CONST char * s) { +#ifdef _FVWRITE_IN_STREAMIO + int result; size_t c = strlen (s); struct __suio uio; struct __siov iov[2]; + FILE *fp; iov[0].iov_base = s; iov[0].iov_len = c; @@ -89,9 +92,41 @@ _DEFUN(_puts_r, (ptr, s), uio.uio_resid = c + 1; uio.uio_iov = &iov[0]; uio.uio_iovcnt = 2; + _REENT_SMALL_CHECK_INIT (ptr); - ORIENT (stdout, -1); - return (__sfvwrite_r (ptr, _stdout_r (ptr), &uio) ? EOF : '\n'); + fp = _stdout_r (ptr); + _newlib_flockfile_start (fp); + ORIENT (fp, -1); + result = (__sfvwrite_r (ptr, fp, &uio) ? EOF : '\n'); + _newlib_flockfile_end (fp); + return result; +#else + int result = EOF; + const char *p = s; + FILE *fp; + _REENT_SMALL_CHECK_INIT (ptr); + + fp = _stdout_r (ptr); + _newlib_flockfile_start (fp); + ORIENT (fp, -1); + /* Make sure we can write. */ + if (cantwrite (ptr, fp)) + goto err; + + while (*p) + { + if (__sputc_r (ptr, *p++, fp) == EOF) + goto err; + } + if (__sputc_r (ptr, '\n', fp) == EOF) + goto err; + + result = '\n'; + +err: + _newlib_flockfile_end (fp); + return result; +#endif } #ifndef _REENT_ONLY diff --git a/contrib/sdk/sources/newlib/libc/stdio/remove.c b/contrib/sdk/sources/newlib/libc/stdio/remove.c index f5dc19c2fa..77ce359156 100644 --- a/contrib/sdk/sources/newlib/libc/stdio/remove.c +++ b/contrib/sdk/sources/newlib/libc/stdio/remove.c @@ -66,15 +66,16 @@ Supporting OS subroutine required: <>. #include <_ansi.h> #include #include -#include - int _DEFUN(_remove_r, (ptr, filename), struct _reent *ptr _AND _CONST char *filename) { - return delete_file(filename)==0 ? 0: -1; + if (_unlink_r (ptr, filename) == -1) + return -1; + + return 0; } #ifndef _REENT_ONLY @@ -83,9 +84,7 @@ int _DEFUN(remove, (filename), _CONST char *filename) { - - return delete_file(filename)==0 ? 0: -1; - + return _remove_r (_REENT, filename); } #endif diff --git a/contrib/sdk/sources/newlib/libc/stdio/rename.c b/contrib/sdk/sources/newlib/libc/stdio/rename.c index b341cb200c..7bab82c31d 100644 --- a/contrib/sdk/sources/newlib/libc/stdio/rename.c +++ b/contrib/sdk/sources/newlib/libc/stdio/rename.c @@ -57,16 +57,6 @@ Supporting OS subroutines required: <>, <>, or <>. #include #include -int -_DEFUN (_rename_r, (ptr, old, new), - struct _reent *ptr _AND - _CONST char *old _AND - _CONST char *new) -{ - return -1; -} - - #ifndef _REENT_ONLY int @@ -74,7 +64,7 @@ _DEFUN(rename, (old, new), _CONST char *old _AND _CONST char *new) { - return -1; + return _rename_r (_REENT, old, new); } #endif diff --git a/contrib/sdk/sources/newlib/libc/stdio/setvbuf.c b/contrib/sdk/sources/newlib/libc/stdio/setvbuf.c index 537a1a3f8e..9f9aa881e6 100644 --- a/contrib/sdk/sources/newlib/libc/stdio/setvbuf.c +++ b/contrib/sdk/sources/newlib/libc/stdio/setvbuf.c @@ -103,10 +103,11 @@ _DEFUN(setvbuf, (fp, buf, mode, size), register size_t size) { int ret = 0; + struct _reent *reent = _REENT; - CHECK_INIT (_REENT, fp); + CHECK_INIT (reent, fp); - _flockfile (fp); + _newlib_flockfile_start (fp); /* * Verify arguments. The `int' limit on `size' is due to this @@ -115,7 +116,7 @@ _DEFUN(setvbuf, (fp, buf, mode, size), if ((mode != _IOFBF && mode != _IOLBF && mode != _IONBF) || (int)(_POINTER_INT) size < 0) { - _funlockfile (fp); + _newlib_flockfile_exit (fp); return (EOF); } @@ -126,11 +127,11 @@ _DEFUN(setvbuf, (fp, buf, mode, size), * non buffer flags, and clear malloc flag. */ - _fflush_r (_REENT, fp); + _fflush_r (reent, fp); fp->_r = 0; fp->_lbfsize = 0; if (fp->_flags & __SMBF) - _free_r (_REENT, (_PTR) fp->_bf._base); + _free_r (reent, (_PTR) fp->_bf._base); fp->_flags &= ~(__SLBF | __SNBF | __SMBF); if (mode == _IONBF) @@ -158,7 +159,7 @@ nbf: fp->_w = 0; fp->_bf._base = fp->_p = fp->_nbuf; fp->_bf._size = 1; - _funlockfile (fp); + _newlib_flockfile_exit (fp); return (ret); } fp->_flags |= __SMBF; @@ -180,7 +181,7 @@ nbf: case _IOFBF: /* no flag */ - _REENT->__cleanup = _cleanup_r; + reent->__cleanup = _cleanup_r; fp->_bf._base = fp->_p = (unsigned char *) buf; fp->_bf._size = size; break; @@ -193,6 +194,6 @@ nbf: if (fp->_flags & __SWR) fp->_w = fp->_flags & (__SLBF | __SNBF) ? 0 : size; - _funlockfile (fp); + _newlib_flockfile_end (fp); return 0; } diff --git a/contrib/sdk/sources/newlib/libc/stdio/snprintf.c b/contrib/sdk/sources/newlib/libc/stdio/snprintf.c index b15631acad..3b8d79ccf5 100644 --- a/contrib/sdk/sources/newlib/libc/stdio/snprintf.c +++ b/contrib/sdk/sources/newlib/libc/stdio/snprintf.c @@ -33,9 +33,9 @@ int #ifdef _HAVE_STDC _DEFUN(_snprintf_r, (ptr, str, size, fmt), struct _reent *ptr _AND - char *str _AND + char *__restrict str _AND size_t size _AND - _CONST char *fmt _DOTS) + _CONST char *__restrict fmt _DOTS) #else _snprintf_r(ptr, str, size, fmt, va_alist) struct _reent *ptr; @@ -77,9 +77,9 @@ _snprintf_r(ptr, str, size, fmt, va_alist) int #ifdef _HAVE_STDC _DEFUN(snprintf, (str, size, fmt), - char *str _AND + char *__restrict str _AND size_t size _AND - _CONST char *fmt _DOTS) + _CONST char *__restrict fmt _DOTS) #else snprintf(str, size, fmt, va_alist) char *str; diff --git a/contrib/sdk/sources/newlib/libc/stdio/sprintf.c b/contrib/sdk/sources/newlib/libc/stdio/sprintf.c index ecd99d1e27..3b0d1b43ca 100644 --- a/contrib/sdk/sources/newlib/libc/stdio/sprintf.c +++ b/contrib/sdk/sources/newlib/libc/stdio/sprintf.c @@ -47,26 +47,26 @@ INDEX ANSI_SYNOPSIS #include - int printf(const char *<[format]>, ...); - int fprintf(FILE *<[fd]>, const char *<[format]>, ...); - int sprintf(char *<[str]>, const char *<[format]>, ...); - int snprintf(char *<[str]>, size_t <[size]>, const char *<[format]>, + int printf(const char *restrict <[format]>, ...); + int fprintf(FILE *restrict <[fd]>, const char *restrict <[format]>, ...); + int sprintf(char *restrict <[str]>, const char *restrict <[format]>, ...); + int snprintf(char *restrict <[str]>, size_t <[size]>, const char *restrict <[format]>, ...); - int asprintf(char **<[strp]>, const char *<[format]>, ...); - char *asnprintf(char *<[str]>, size_t *<[size]>, const char *<[format]>, + int asprintf(char **restrict <[strp]>, const char *restrict <[format]>, ...); + char *asnprintf(char *restrict <[str]>, size_t *restrict <[size]>, const char *restrict <[format]>, ...); - int _printf_r(struct _reent *<[ptr]>, const char *<[format]>, ...); - int _fprintf_r(struct _reent *<[ptr]>, FILE *<[fd]>, - const char *<[format]>, ...); - int _sprintf_r(struct _reent *<[ptr]>, char *<[str]>, - const char *<[format]>, ...); - int _snprintf_r(struct _reent *<[ptr]>, char *<[str]>, size_t <[size]>, - const char *<[format]>, ...); - int _asprintf_r(struct _reent *<[ptr]>, char **<[strp]>, - const char *<[format]>, ...); - char *_asnprintf_r(struct _reent *<[ptr]>, char *<[str]>, - size_t *<[size]>, const char *<[format]>, ...); + int _printf_r(struct _reent *<[ptr]>, const char *restrict <[format]>, ...); + int _fprintf_r(struct _reent *<[ptr]>, FILE *restrict <[fd]>, + const char *restrict <[format]>, ...); + int _sprintf_r(struct _reent *<[ptr]>, char *restrict <[str]>, + const char *restrict <[format]>, ...); + int _snprintf_r(struct _reent *<[ptr]>, char *restrict <[str]>, size_t <[size]>, + const char *restrict <[format]>, ...); + int _asprintf_r(struct _reent *<[ptr]>, char **restrict <[strp]>, + const char *restrict <[format]>, ...); + char *_asnprintf_r(struct _reent *<[ptr]>, char *restrict <[str]>, + size_t *restrict <[size]>, const char *restrict <[format]>, ...); DESCRIPTION <> accepts a series of arguments, applies to each a @@ -518,6 +518,10 @@ DESCRIPTION implementation is similar to <<%#tx>>), except that <<0x>> appears even for the NULL pointer. + o m + Prints the output of <>; no + argument is required. A GNU extension. + o- O- @@ -575,13 +579,13 @@ int #ifdef _HAVE_STDC _DEFUN(_sprintf_r, (ptr, str, fmt), struct _reent *ptr _AND - char *str _AND - _CONST char *fmt _DOTS) + char *__restrict str _AND + _CONST char *__restrict fmt _DOTS) #else _sprintf_r(ptr, str, fmt, va_alist) struct _reent *ptr; - char *str; - _CONST char *fmt; + char *__restrict str; + _CONST char *__restrict fmt; va_dcl #endif { @@ -609,8 +613,8 @@ _sprintf_r(ptr, str, fmt, va_alist) int #ifdef _HAVE_STDC _DEFUN(sprintf, (str, fmt), - char *str _AND - _CONST char *fmt _DOTS) + char *__restrict str _AND + _CONST char *__restrict fmt _DOTS) #else sprintf(str, fmt, va_alist) char *str; diff --git a/contrib/sdk/sources/newlib/libc/stdio/sscanf.c b/contrib/sdk/sources/newlib/libc/stdio/sscanf.c index 1a16a7d64e..c5d6c9c58d 100644 --- a/contrib/sdk/sources/newlib/libc/stdio/sscanf.c +++ b/contrib/sdk/sources/newlib/libc/stdio/sscanf.c @@ -35,15 +35,15 @@ INDEX ANSI_SYNOPSIS #include - int scanf(const char *<[format]>, ...); - int fscanf(FILE *<[fd]>, const char *<[format]>, ...); - int sscanf(const char *<[str]>, const char *<[format]>, ...); + int scanf(const char *restrict <[format]>, ...); + int fscanf(FILE *restrict <[fd]>, const char *restrict <[format]>, ...); + int sscanf(const char *restrict <[str]>, const char *restrict <[format]>, ...); - int _scanf_r(struct _reent *<[ptr]>, const char *<[format]>, ...); - int _fscanf_r(struct _reent *<[ptr]>, FILE *<[fd]>, - const char *<[format]>, ...); - int _sscanf_r(struct _reent *<[ptr]>, const char *<[str]>, - const char *<[format]>, ...); + int _scanf_r(struct _reent *<[ptr]>, const char *restrict <[format]>, ...); + int _fscanf_r(struct _reent *<[ptr]>, FILE *restrict <[fd]>, + const char *restrict <[format]>, ...); + int _sscanf_r(struct _reent *<[ptr]>, const char *restrict <[str]>, + const char *restrict <[format]>, ...); TRAD_SYNOPSIS @@ -399,8 +399,8 @@ Supporting OS subroutines required: <>, <>, <>, #ifdef _HAVE_STDC int _DEFUN(sscanf, (str, fmt), - _CONST char *str _AND - _CONST char *fmt _DOTS) + _CONST char *__restrict str _AND + _CONST char * fmt _DOTS) #else int sscanf(str, fmt, va_alist) @@ -436,14 +436,14 @@ sscanf(str, fmt, va_alist) int _DEFUN(_sscanf_r, (ptr, str, fmt), struct _reent *ptr _AND - _CONST char *str _AND - _CONST char *fmt _DOTS) + _CONST char *__restrict str _AND + _CONST char *__restrict fmt _DOTS) #else int _sscanf_r(ptr, str, fmt, va_alist) struct _reent *ptr; - _CONST char *str; - _CONST char *fmt; + _CONST char *__restrict str; + _CONST char *__restrict fmt; va_dcl #endif { diff --git a/contrib/sdk/sources/newlib/libc/stdio/stdio.c b/contrib/sdk/sources/newlib/libc/stdio/stdio.c index 6c43f97901..473b839ecb 100644 --- a/contrib/sdk/sources/newlib/libc/stdio/stdio.c +++ b/contrib/sdk/sources/newlib/libc/stdio/stdio.c @@ -34,10 +34,10 @@ _DEFUN(__sread, (ptr, cookie, buf, n), struct _reent *ptr _AND void *cookie _AND char *buf _AND - int n) + _READ_WRITE_BUFSIZE_TYPE n) { register FILE *fp = (FILE *) cookie; - register int ret; + register ssize_t ret; #ifdef __SCLE int oldmode = 0; @@ -67,7 +67,7 @@ _DEFUN(__seofread, (ptr, cookie, buf, len), struct _reent *_ptr _AND _PTR cookie _AND char *buf _AND - int len) + _READ_WRITE_BUFSIZE_TYPE len) { return 0; } @@ -77,10 +77,10 @@ _DEFUN(__swrite, (ptr, cookie, buf, n), struct _reent *ptr _AND void *cookie _AND char const *buf _AND - int n) + _READ_WRITE_BUFSIZE_TYPE n) { register FILE *fp = (FILE *) cookie; - int w; + ssize_t w; #ifdef __SCLE int oldmode=0; #endif diff --git a/contrib/sdk/sources/newlib/libc/stdio/ungetc.c b/contrib/sdk/sources/newlib/libc/stdio/ungetc.c index aafce3ebab..8ef8ba21e4 100644 --- a/contrib/sdk/sources/newlib/libc/stdio/ungetc.c +++ b/contrib/sdk/sources/newlib/libc/stdio/ungetc.c @@ -125,7 +125,7 @@ _DEFUN(_ungetc_r, (rptr, c, fp), CHECK_INIT (rptr, fp); - _flockfile (fp); + _newlib_flockfile_start (fp); ORIENT (fp, -1); @@ -140,14 +140,14 @@ _DEFUN(_ungetc_r, (rptr, c, fp), */ if ((fp->_flags & __SRW) == 0) { - _funlockfile (fp); + _newlib_flockfile_exit (fp); return EOF; } if (fp->_flags & __SWR) { if (_fflush_r (rptr, fp)) { - _funlockfile (fp); + _newlib_flockfile_exit (fp); return EOF; } fp->_flags &= ~__SWR; @@ -167,12 +167,12 @@ _DEFUN(_ungetc_r, (rptr, c, fp), { if (fp->_r >= fp->_ub._size && __submore (rptr, fp)) { - _funlockfile (fp); + _newlib_flockfile_exit (fp); return EOF; } *--fp->_p = c; fp->_r++; - _funlockfile (fp); + _newlib_flockfile_exit (fp); return c; } @@ -186,7 +186,7 @@ _DEFUN(_ungetc_r, (rptr, c, fp), { fp->_p--; fp->_r++; - _funlockfile (fp); + _newlib_flockfile_exit (fp); return c; } @@ -202,7 +202,7 @@ _DEFUN(_ungetc_r, (rptr, c, fp), fp->_ubuf[sizeof (fp->_ubuf) - 1] = c; fp->_p = &fp->_ubuf[sizeof (fp->_ubuf) - 1]; fp->_r = 1; - _funlockfile (fp); + _newlib_flockfile_end (fp); return c; } diff --git a/contrib/sdk/sources/newlib/libc/stdio/vdprintf.c b/contrib/sdk/sources/newlib/libc/stdio/vdprintf.c index bfb19c95b7..7e875ac325 100644 --- a/contrib/sdk/sources/newlib/libc/stdio/vdprintf.c +++ b/contrib/sdk/sources/newlib/libc/stdio/vdprintf.c @@ -16,7 +16,7 @@ int _DEFUN(_vdprintf_r, (ptr, fd, format, ap), struct _reent *ptr _AND int fd _AND - const char *format _AND + const char *__restrict format _AND va_list ap) { char *p; @@ -38,7 +38,7 @@ _DEFUN(_vdprintf_r, (ptr, fd, format, ap), int _DEFUN(vdprintf, (fd, format, ap), int fd _AND - const char *format _AND + const char *__restrict format _AND va_list ap) { return _vdprintf_r (_REENT, fd, format, ap); diff --git a/contrib/sdk/sources/newlib/libc/stdio/vfieeefp.h b/contrib/sdk/sources/newlib/libc/stdio/vfieeefp.h index 85632fc74c..37a7270188 100644 --- a/contrib/sdk/sources/newlib/libc/stdio/vfieeefp.h +++ b/contrib/sdk/sources/newlib/libc/stdio/vfieeefp.h @@ -131,7 +131,7 @@ struct ldieee unsigned manh:32; unsigned manl:32; unsigned manl2:32; - unsigned manl3;16; + unsigned manl3:16; }; #endif /* LDBL_MANT_DIG */ #endif /* !IEEE_8087 */ diff --git a/contrib/sdk/sources/newlib/libc/stdio/vfprintf.c b/contrib/sdk/sources/newlib/libc/stdio/vfprintf.c index 5e2adef98f..4536245e3f 100644 --- a/contrib/sdk/sources/newlib/libc/stdio/vfprintf.c +++ b/contrib/sdk/sources/newlib/libc/stdio/vfprintf.c @@ -178,9 +178,17 @@ static char *rcsid = "$Id: vfprintf.c,v 1.43 2002/08/13 02:40:06 fitzsim Exp $"; #endif #ifdef STRING_ONLY -#define __SPRINT __ssprint_r +# ifdef _FVWRITE_IN_STREAMIO +# define __SPRINT __ssprint_r +# else +# define __SPRINT __ssputs_r +# endif #else -#define __SPRINT __sprint_r +# ifdef _FVWRITE_IN_STREAMIO +# define __SPRINT __sprint_r +# else +# define __SPRINT __sfputs_r +# endif #endif /* The __sprint_r/__ssprint_r functions are shared between all versions of @@ -188,6 +196,76 @@ static char *rcsid = "$Id: vfprintf.c,v 1.43 2002/08/13 02:40:06 fitzsim Exp $"; the INTEGER_ONLY versions here. */ #ifdef STRING_ONLY #ifdef INTEGER_ONLY +#ifndef _FVWRITE_IN_STREAMIO +int +_DEFUN(__ssputs_r, (ptr, fp, buf, len), + struct _reent *ptr _AND + FILE *fp _AND + _CONST char *buf _AND + size_t len) +{ + register int w; + + w = fp->_w; + if (len >= w && fp->_flags & (__SMBF | __SOPT)) { + /* must be asprintf family */ + unsigned char *str; + int curpos = (fp->_p - fp->_bf._base); + /* Choose a geometric growth factor to avoid + * quadratic realloc behavior, but use a rate less + * than (1+sqrt(5))/2 to accomodate malloc + * overhead. asprintf EXPECTS us to overallocate, so + * that it can add a trailing \0 without + * reallocating. The new allocation should thus be + * max(prev_size*1.5, curpos+len+1). */ + int newsize = fp->_bf._size * 3 / 2; + if (newsize < curpos + len + 1) + newsize = curpos + len + 1; + if (fp->_flags & __SOPT) + { + /* asnprintf leaves original buffer alone. */ + str = (unsigned char *)_malloc_r (ptr, newsize); + if (!str) + { + ptr->_errno = ENOMEM; + goto err; + } + memcpy (str, fp->_bf._base, curpos); + fp->_flags = (fp->_flags & ~__SOPT) | __SMBF; + } + else + { + str = (unsigned char *)_realloc_r (ptr, fp->_bf._base, + newsize); + if (!str) { + /* Free unneeded buffer. */ + _free_r (ptr, fp->_bf._base); + /* Ensure correct errno, even if free + * changed it. */ + ptr->_errno = ENOMEM; + goto err; + } + } + fp->_bf._base = str; + fp->_p = str + curpos; + fp->_bf._size = newsize; + w = len; + fp->_w = newsize - curpos; + } + if (len < w) + w = len; + (void)memmove ((_PTR) fp->_p, (_PTR) buf, (size_t) (w)); + fp->_w -= w; + fp->_p += w; + + return 0; + +err: + fp->_flags |= __SERR; + return EOF; +} +#endif + int _DEFUN(__ssprint_r, (ptr, fp, uio), struct _reent *ptr _AND @@ -280,11 +358,46 @@ err: return EOF; } #else /* !INTEGER_ONLY */ +#ifndef _FVWRITE_IN_STREAMIO +int __ssputs_r (struct _reent *, FILE *, _CONST char *, size_t); +#endif int __ssprint_r (struct _reent *, FILE *, register struct __suio *); #endif /* !INTEGER_ONLY */ #else /* !STRING_ONLY */ #ifdef INTEGER_ONLY + +#ifndef _FVWRITE_IN_STREAMIO +int +_DEFUN(__sfputs_r, (ptr, fp, buf, len), + struct _reent *ptr _AND + FILE *fp _AND + _CONST char *buf _AND + size_t len) +{ + register int i; + +#ifdef _WIDE_ORIENT + if (fp->_flags2 & __SWID) { + wchar_t *p; + + p = (wchar_t *) buf; + for (i = 0; i < (len / sizeof (wchar_t)); i++) { + if (_fputwc_r (ptr, p[i], fp) == WEOF) + return -1; + } + } else { +#else + { +#endif + for (i = 0; i < len; i++) { + if (_fputc_r (ptr, buf[i], fp) == EOF) + return -1; + } + } + return (0); +} +#endif /* * Flush out all the vectors defined by the given uio, * then reset it so that it can be reused. @@ -301,6 +414,7 @@ _DEFUN(__sprint_r, (ptr, fp, uio), uio->uio_iovcnt = 0; return (0); } +#ifdef _WIDE_ORIENT if (fp->_flags2 & __SWID) { struct __siov *iov; wchar_t *p; @@ -319,6 +433,7 @@ _DEFUN(__sprint_r, (ptr, fp, uio), } } } else +#endif err = __sfvwrite_r(ptr, fp, uio); out: uio->uio_resid = 0; @@ -326,15 +441,21 @@ out: return (err); } #else /* !INTEGER_ONLY */ +#ifndef _FVWRITE_IN_STREAMIO +int __sfputs_r (struct _reent *, FILE *, _CONST char *buf, size_t); +#endif int __sprint_r (struct _reent *, FILE *, register struct __suio *); #endif /* !INTEGER_ONLY */ +#ifdef _UNBUF_STREAM_OPT /* * Helper function for `fprintf to unbuffered unix file': creates a * temporary buffer. We only work on write-only files; this avoids * worries about ungetc buffers and so forth. + * + * Make sure to avoid inlining. */ -static int +_NOINLINE_STATIC int _DEFUN(__sbprintf, (rptr, fp, fmt, ap), struct _reent *rptr _AND register FILE *fp _AND @@ -372,6 +493,7 @@ _DEFUN(__sbprintf, (rptr, fp, fmt, ap), #endif return (ret); } +#endif /* _UNBUF_STREAM_OPT */ #endif /* !STRING_ONLY */ @@ -548,7 +670,6 @@ _DEFUN(_VFPRINTF_R, (data, fp, fmt0, ap), register int ch; /* character from fmt */ register int n, m; /* handy integers (short term usage) */ register char *cp; /* handy char pointer (short term usage) */ - register struct __siov *iovp;/* for PRINT macro */ register int flags; /* flags as above */ char *fmt_anchor; /* current format spec being processed */ #ifndef _NO_POS_ARGS @@ -567,9 +688,9 @@ _DEFUN(_VFPRINTF_R, (data, fp, fmt0, ap), char sign; /* sign prefix (' ', '+', '-', or \0) */ #ifdef _WANT_IO_C99_FORMATS /* locale specific numeric grouping */ - char *thousands_sep; - size_t thsnd_len; - const char *grouping; + char *thousands_sep = NULL; + size_t thsnd_len = 0; + const char *grouping = NULL; #endif #ifdef FLOATING_POINT char *decimal_point = _localeconv_r (data)->decimal_point; @@ -585,7 +706,7 @@ _DEFUN(_VFPRINTF_R, (data, fp, fmt0, ap), #if defined (FLOATING_POINT) || defined (_WANT_IO_C99_FORMATS) int ndig = 0; /* actual number of digits returned by cvt */ #endif -#ifdef _WANT_IO_C99_FORMATS +#if defined (FLOATING_POINT) && defined (_WANT_IO_C99_FORMATS) int nseps; /* number of group separators with ' */ int nrepeats; /* number of repeats of the last group */ #endif @@ -595,9 +716,12 @@ _DEFUN(_VFPRINTF_R, (data, fp, fmt0, ap), int realsz; /* field size expanded by dprec */ int size; /* size of converted field or string */ char *xdigs = NULL; /* digits for [xX] conversion */ +#ifdef _FVWRITE_IN_STREAMIO #define NIOV 8 struct __suio uio; /* output information: summary */ struct __siov iov[NIOV];/* ... and individual io vectors */ + register struct __siov *iovp;/* for PRINT macro */ +#endif char buf[BUF]; /* space for %c, %S, %[diouxX], %[aA] */ char ox[2]; /* space for 0x hex-prefix */ #ifdef _MB_CAPABLE @@ -623,6 +747,7 @@ _DEFUN(_VFPRINTF_R, (data, fp, fmt0, ap), /* * BEWARE, these `goto error' on error, and PAD uses `n'. */ +#ifdef _FVWRITE_IN_STREAMIO #define PRINT(ptr, len) { \ iovp->iov_base = (ptr); \ iovp->iov_len = (len); \ @@ -657,6 +782,30 @@ _DEFUN(_VFPRINTF_R, (data, fp, fmt0, ap), uio.uio_iovcnt = 0; \ iovp = iov; \ } +#else +#define PRINT(ptr, len) { \ + if (__SPRINT (data, fp, (ptr), (len)) == EOF) \ + goto error; \ +} +#define PAD(howmany, with) { \ + if ((n = (howmany)) > 0) { \ + while (n > PADSIZE) { \ + PRINT (with, PADSIZE); \ + n -= PADSIZE; \ + } \ + PRINT (with, n); \ + } \ +} +#define PRINTANDPAD(p, ep, len, with) { \ + int n = (ep) - (p); \ + if (n > (len)) \ + n = (len); \ + if (n > 0) \ + PRINT((p), n); \ + PAD((len) - (n > 0 ? n : 0), (with)); \ +} +#define FLUSH() +#endif /* Macros to support positional arguments */ #ifndef _NO_POS_ARGS @@ -708,22 +857,24 @@ _DEFUN(_VFPRINTF_R, (data, fp, fmt0, ap), #ifndef STRING_ONLY /* Initialize std streams if not dealing with sprintf family. */ CHECK_INIT (data, fp); - _flockfile (fp); + _newlib_flockfile_start (fp); ORIENT(fp, -1); /* sorry, fprintf(read_only_file, "") returns EOF, not 0 */ if (cantwrite (data, fp)) { - _funlockfile (fp); + _newlib_flockfile_exit (fp); return (EOF); } +#ifdef _UNBUF_STREAM_OPT /* optimise fprintf(stderr) (and other unbuffered Unix files) */ if ((fp->_flags & (__SNBF|__SWR|__SRW)) == (__SNBF|__SWR) && fp->_file >= 0) { - _funlockfile (fp); + _newlib_flockfile_exit (fp); return (__sbprintf (data, fp, fmt0, ap)); } +#endif #else /* STRING_ONLY */ /* Create initial buffer if we are called by asprintf family. */ if (fp->_flags & __SMBF && !fp->_bf._base) @@ -739,9 +890,11 @@ _DEFUN(_VFPRINTF_R, (data, fp, fmt0, ap), #endif /* STRING_ONLY */ fmt = (char *)fmt0; +#ifdef _FVWRITE_IN_STREAMIO uio.uio_iov = iovp = iov; uio.uio_resid = 0; uio.uio_iovcnt = 0; +#endif ret = 0; #ifndef _NO_POS_ARGS arg_index = 0; @@ -793,10 +946,10 @@ _DEFUN(_VFPRINTF_R, (data, fp, fmt0, ap), sign = '\0'; #ifdef FLOATING_POINT lead = 0; -#endif #ifdef _WANT_IO_C99_FORMATS nseps = nrepeats = 0; #endif +#endif #ifndef _NO_POS_ARGS N = arg_index; is_pos_arg = 0; @@ -1225,6 +1378,15 @@ reswitch: switch (ch) { sign = '-'; break; #endif /* FLOATING_POINT */ +#ifdef _GLIBC_EXTENSION + case 'm': /* extension */ + { + int dummy; + cp = _strerror_r (data, data->_errno, 1, &dummy); + } + flags &= ~LONGINT; + goto string; +#endif case 'n': #ifndef _NO_LONGLONG if (flags & QUADINT) @@ -1272,8 +1434,11 @@ reswitch: switch (ch) { #ifdef _WANT_IO_C99_FORMATS case 'S': #endif - sign = '\0'; cp = GET_ARG (N, ap, char_ptr_t); +#ifdef _GLIBC_EXTENSION +string: +#endif + sign = '\0'; #ifndef __OPTIMIZE_SIZE__ /* Behavior is undefined if the user passed a NULL string when precision is not 0. @@ -1621,7 +1786,7 @@ error: if (malloc_buf != NULL) _free_r (data, malloc_buf); #ifndef STRING_ONLY - _funlockfile (fp); + _newlib_flockfile_end (fp); #endif return (__sferror (fp) ? EOF : ret); /* NOTREACHED */ diff --git a/contrib/sdk/sources/newlib/libc/stdio/vfscanf.c b/contrib/sdk/sources/newlib/libc/stdio/vfscanf.c index b7d686c95b..593eddaf13 100644 --- a/contrib/sdk/sources/newlib/libc/stdio/vfscanf.c +++ b/contrib/sdk/sources/newlib/libc/stdio/vfscanf.c @@ -148,10 +148,12 @@ Supporting OS subroutines required: #endif #ifdef STRING_ONLY -#undef _flockfile -#undef _funlockfile -#define _flockfile(x) {} -#define _funlockfile(x) {} +#undef _newlib_flockfile_start +#undef _newlib_flockfile_exit +#undef _newlib_flockfile_end +#define _newlib_flockfile_start(x) {} +#define _newlib_flockfile_exit(x) {} +#define _newlib_flockfile_end(x) {} #define _ungetc_r _sungetc_r #define __srefill_r __ssrefill_r #define _fread_r _sfread_r @@ -160,6 +162,7 @@ Supporting OS subroutines required: #ifdef FLOATING_POINT #include #include +#include /* Currently a test is made to see if long double processing is warranted. This could be changed in the future should the _ldtoa_r code be @@ -172,11 +175,7 @@ extern _LONG_DOUBLE _strtold _PARAMS((char *s, char **sptr)); #include "floatio.h" -#if ((MAXEXP+MAXFRACT+3) > MB_LEN_MAX) -# define BUF (MAXEXP+MAXFRACT+3) /* 3 = sign + decimal point + NUL */ -#else -# define BUF MB_LEN_MAX -#endif +#define BUF (MAXEXP+MAXFRACT+MB_LEN_MAX+2) /* decimal point + sign + NUL */ /* An upper bound for how long a long prints in decimal. 4 / 13 approximates log (2). Add one char for roundoff compensation and one for the sign. */ @@ -241,10 +240,7 @@ static void * get_arg (int, va_list *, int *, void **); #define CT_INT 3 /* integer, i.e., strtol or strtoul */ #define CT_FLOAT 4 /* floating, i.e., strtod */ -#if 0 #define u_char unsigned char -#endif -#define u_char char #define u_long unsigned long #ifndef _NO_LONGLONG @@ -267,8 +263,10 @@ _DEFUN(VFSCANF, (fp, fmt, ap), _CONST char *fmt _AND va_list ap) { - CHECK_INIT(_REENT, fp); - return __SVFSCANF_R (_REENT, fp, fmt, ap); + struct _reent *reent = _REENT; + + CHECK_INIT(reent, fp); + return __SVFSCANF_R (reent, fp, fmt, ap); } int @@ -496,7 +494,7 @@ _DEFUN(__SVFSCANF_R, (rptr, fp, fmt0, ap), # define GET_ARG(n, ap, type) (va_arg (ap, type)) #endif - _flockfile (fp); + _newlib_flockfile_start (fp); ORIENT (fp, -1); @@ -511,8 +509,8 @@ _DEFUN(__SVFSCANF_R, (rptr, fp, fmt0, ap), #ifndef _MB_CAPABLE wc = *fmt; #else - nbytes = __mbtowc (rptr, &wc, fmt, MB_CUR_MAX, __locale_charset (), - &state); + nbytes = __mbtowc (rptr, &wc, (char *) fmt, MB_CUR_MAX, + __locale_charset (), &state); if (nbytes < 0) { wc = 0xFFFD; /* Unicode replacement character */ nbytes = 1; @@ -795,7 +793,7 @@ _DEFUN(__SVFSCANF_R, (rptr, fp, fmt0, ap), * Disgusting backwards compatibility hacks. XXX */ case '\0': /* compat */ - _funlockfile (fp); + _newlib_flockfile_exit (fp); return EOF; default: /* compat */ @@ -1287,6 +1285,10 @@ _DEFUN(__SVFSCANF_R, (rptr, fp, fmt0, ap), unsigned width_left = 0; char nancount = 0; char infcount = 0; + const char *decpt = _localeconv_r (rptr)->decimal_point; +#ifdef _MB_CAPABLE + int decptpos = 0; +#endif #ifdef hardway if (width == 0 || width > sizeof (buf) - 1) #else @@ -1415,14 +1417,6 @@ _DEFUN(__SVFSCANF_R, (rptr, fp, fmt0, ap), goto fok; } break; - case '.': - if (flags & DPTOK) - { - flags &= ~(SIGNOK | DPTOK); - leading_zeroes = zeroes; - goto fok; - } - break; case 'e': case 'E': /* no exponent without some digits */ @@ -1441,6 +1435,53 @@ _DEFUN(__SVFSCANF_R, (rptr, fp, fmt0, ap), goto fok; } break; + default: +#ifndef _MB_CAPABLE + if ((unsigned char) c == (unsigned char) decpt[0] + && (flags & DPTOK)) + { + flags &= ~(SIGNOK | DPTOK); + leading_zeroes = zeroes; + goto fok; + } + break; +#else + if (flags & DPTOK) + { + while ((unsigned char) c + == (unsigned char) decpt[decptpos]) + { + if (decpt[++decptpos] == '\0') + { + /* We read the complete decpt seq. */ + flags &= ~(SIGNOK | DPTOK); + leading_zeroes = zeroes; + p = stpncpy (p, decpt, decptpos); + decptpos = 0; + goto fskip; + } + ++nread; + if (--fp->_r > 0) + fp->_p++; + else if (__srefill_r (rptr, fp)) + break; /* EOF */ + c = *fp->_p; + } + if (decptpos > 0) + { + /* We read part of a multibyte decimal point, + but the rest is invalid or we're at EOF, + so back off. */ + while (decptpos-- > 0) + { + _ungetc_r (rptr, (unsigned char) decpt[decptpos], + fp); + --nread; + } + } + } + break; +#endif } break; fok: @@ -1595,12 +1636,12 @@ input_failure: should have been set prior to here. On EOF failure (including invalid format string), return EOF if no matches yet, else number of matches made prior to failure. */ - _funlockfile (fp); + _newlib_flockfile_exit (fp); return nassigned && !(fp->_flags & __SERR) ? nassigned : EOF; match_failure: all_done: /* Return number of matches, which can be 0 on match failure. */ - _funlockfile (fp); + _newlib_flockfile_end (fp); return nassigned; } diff --git a/contrib/sdk/sources/newlib/libc/stdio/vscanf.c b/contrib/sdk/sources/newlib/libc/stdio/vscanf.c index e6e0d22ed0..ec842b19f6 100644 --- a/contrib/sdk/sources/newlib/libc/stdio/vscanf.c +++ b/contrib/sdk/sources/newlib/libc/stdio/vscanf.c @@ -34,8 +34,10 @@ _DEFUN(vscanf, (fmt, ap), _CONST char *fmt _AND va_list ap) { - _REENT_SMALL_CHECK_INIT (_REENT); - return __svfscanf_r (_REENT, _stdin_r (_REENT), fmt, ap); + struct _reent *reent = _REENT; + + _REENT_SMALL_CHECK_INIT (reent); + return __svfscanf_r (reent, _stdin_r (reent), fmt, ap); } #endif /* !_REENT_ONLY */ @@ -43,7 +45,7 @@ _DEFUN(vscanf, (fmt, ap), int _DEFUN(_vscanf_r, (ptr, fmt, ap), struct _reent *ptr _AND - _CONST char *fmt _AND + _CONST char *__restrict fmt _AND va_list ap) { _REENT_SMALL_CHECK_INIT (ptr); diff --git a/contrib/sdk/sources/newlib/libc/stdio/vsnprintf.c b/contrib/sdk/sources/newlib/libc/stdio/vsnprintf.c index af26dbc89e..00a772b0ed 100644 --- a/contrib/sdk/sources/newlib/libc/stdio/vsnprintf.c +++ b/contrib/sdk/sources/newlib/libc/stdio/vsnprintf.c @@ -33,9 +33,9 @@ static char sccsid[] = "%W% (Berkeley) %G%"; int _DEFUN(vsnprintf, (str, size, fmt, ap), - char *str _AND + char *__restrict str _AND size_t size _AND - const char *fmt _AND + const char *__restrict fmt _AND va_list ap) { return _vsnprintf_r (_REENT, str, size, fmt, ap); @@ -46,9 +46,9 @@ _DEFUN(vsnprintf, (str, size, fmt, ap), int _DEFUN(_vsnprintf_r, (ptr, str, size, fmt, ap), struct _reent *ptr _AND - char *str _AND + char *__restrict str _AND size_t size _AND - const char *fmt _AND + const char *__restrict fmt _AND va_list ap) { int ret; diff --git a/contrib/sdk/sources/newlib/libc/stdio/vsprintf.c b/contrib/sdk/sources/newlib/libc/stdio/vsprintf.c index 1a978c0eae..be5ff1c5f2 100644 --- a/contrib/sdk/sources/newlib/libc/stdio/vsprintf.c +++ b/contrib/sdk/sources/newlib/libc/stdio/vsprintf.c @@ -32,8 +32,8 @@ static char sccsid[] = "%W% (Berkeley) %G%"; int _DEFUN(vsprintf, (str, fmt, ap), - char *str _AND - const char *fmt _AND + char *__restrict str _AND + const char *__restrict fmt _AND va_list ap) { return _vsprintf_r (_REENT, str, fmt, ap); @@ -44,8 +44,8 @@ _DEFUN(vsprintf, (str, fmt, ap), int _DEFUN(_vsprintf_r, (ptr, str, fmt, ap), struct _reent *ptr _AND - char *str _AND - const char *fmt _AND + char *__restrict str _AND + const char *__restrict fmt _AND va_list ap) { int ret; diff --git a/contrib/sdk/sources/newlib/libc/stdio/vsscanf.c b/contrib/sdk/sources/newlib/libc/stdio/vsscanf.c index c19bbeee72..6eff8d39f7 100644 --- a/contrib/sdk/sources/newlib/libc/stdio/vsscanf.c +++ b/contrib/sdk/sources/newlib/libc/stdio/vsscanf.c @@ -36,8 +36,8 @@ int _DEFUN(vsscanf, (str, fmt, ap), - _CONST char *str _AND - _CONST char *fmt _AND + _CONST char *__restrict str _AND + _CONST char *__restrict fmt _AND va_list ap) { return _vsscanf_r (_REENT, str, fmt, ap); @@ -48,8 +48,8 @@ _DEFUN(vsscanf, (str, fmt, ap), int _DEFUN(_vsscanf_r, (ptr, str, fmt, ap), struct _reent *ptr _AND - _CONST char *str _AND - _CONST char *fmt _AND + _CONST char *__restrict str _AND + _CONST char *__restrict fmt _AND va_list ap) { FILE f; diff --git a/contrib/sdk/sources/newlib/libc/stdlib/_Exit.c b/contrib/sdk/sources/newlib/libc/stdlib/_Exit.c new file mode 100644 index 0000000000..3f189a21fc --- /dev/null +++ b/contrib/sdk/sources/newlib/libc/stdlib/_Exit.c @@ -0,0 +1,46 @@ +/* +FUNCTION +<<_Exit>>---end program execution with no cleanup processing + +INDEX + _Exit + +ANSI_SYNOPSIS + #include + void _Exit(int <[code]>); + +TRAD_SYNOPSIS + #include + void _Exit(<[code]>) + int <[code]>; + +DESCRIPTION +Use <<_Exit>> to return control from a program to the host operating +environment. Use the argument <[code]> to pass an exit status to the +operating environment: two particular values, <> and +<>, are defined in `<>' to indicate success or +failure in a portable fashion. + +<<_Exit>> differs from <> in that it does not run any +application-defined cleanup functions registered with <> and +it does not clean up files and streams. It is identical to <<_exit>>. + +RETURNS +<<_Exit>> does not return to its caller. + +PORTABILITY +<<_Exit>> is defined by the C99 standard. + +Supporting OS subroutines required: <<_exit>>. +*/ + +#include +#include /* for _exit() declaration */ +#include + +void +_DEFUN (_Exit, (code), + int code) +{ + _exit (code); +} diff --git a/contrib/sdk/sources/newlib/libc/stdlib/__adjust.c b/contrib/sdk/sources/newlib/libc/stdlib/__adjust.c new file mode 100644 index 0000000000..d5c70758b1 --- /dev/null +++ b/contrib/sdk/sources/newlib/libc/stdlib/__adjust.c @@ -0,0 +1,44 @@ +/* + * return (*acc) scaled by 10**dexp. + */ + +#include <_ansi.h> +#include +#include "std.h" + +#define abs(x) (((x) < 0) ? -(x) : (x)) + +double +_DEFUN (__adjust, (ptr, acc, dexp, sign), + struct _reent *ptr _AND + double *acc _AND + int dexp _AND + int sign) + /* *acc the 64 bit accumulator */ + /* dexp decimal exponent */ + /* sign sign flag */ +{ + double r; + + if (dexp > MAXE) + { + ptr->_errno = ERANGE; + return (sign) ? -HUGE_VAL : HUGE_VAL; + } + else if (dexp < MINE) + { + ptr->_errno = ERANGE; + return 0.0; + } + + r = *acc; + if (sign) + r = -r; + if (dexp == 0) + return r; + + if (dexp < 0) + return r / __exp10 (abs (dexp)); + else + return r * __exp10 (dexp); +} diff --git a/contrib/sdk/sources/newlib/libc/stdlib/__atexit.c b/contrib/sdk/sources/newlib/libc/stdlib/__atexit.c index ba7e81620e..47898b827a 100644 --- a/contrib/sdk/sources/newlib/libc/stdlib/__atexit.c +++ b/contrib/sdk/sources/newlib/libc/stdlib/__atexit.c @@ -1,5 +1,35 @@ /* * Common routine to implement atexit-like functionality. + * + * This is also the key function to be configured as lite exit, a size-reduced + * implementation of exit that doesn't invoke clean-up functions such as _fini + * or global destructors. + * + * Default (without lite exit) call graph is like: + * _start -> atexit -> __register_exitproc + * _start -> __libc_init_array -> __cxa_atexit -> __register_exitproc + * on_exit -> __register_exitproc + * _start -> exit -> __call_exitprocs + * + * Here an -> means arrow tail invokes arrow head. All invocations here + * are non-weak reference in current newlib/libgloss. + * + * Lite exit makes some of above calls as weak reference, so that size expansive + * functions __register_exitproc and __call_exitprocs may not be linked. These + * calls are: + * _start w-> atexit + * __cxa_atexit w-> __register_exitproc + * exit w-> __call_exitprocs + * + * Lite exit also makes sure that __call_exitprocs will be referenced as non-weak + * whenever __register_exitproc is referenced as non-weak. + * + * Thus with lite exit libs, a program not explicitly calling atexit or on_exit + * will escape from the burden of cleaning up code. A program with atexit or on_exit + * will work consistently to normal libs. + * + * Lite exit is enabled with --enable-lite-exit, and is controlled with macro + * _LITE_EXIT. */ #include @@ -10,7 +40,23 @@ /* Make this a weak reference to avoid pulling in malloc. */ void * malloc(size_t) _ATTRIBUTE((__weak__)); -__LOCK_INIT_RECURSIVE(, __atexit_lock); + +#ifdef _LITE_EXIT +/* As __call_exitprocs is weak reference in lite exit, make a + non-weak reference to it here. */ +const void * __atexit_dummy = &__call_exitprocs; +#endif + +#ifndef __SINGLE_THREAD__ +extern _LOCK_RECURSIVE_T __atexit_lock; +#endif + +#ifdef _REENT_GLOBAL_ATEXIT +static struct _atexit _global_atexit0 = _ATEXIT_INIT; +# define _GLOBAL_ATEXIT0 (&_global_atexit0) +#else +# define _GLOBAL_ATEXIT0 (&_GLOBAL_REENT->_atexit0) +#endif /* * Register a function to be performed at exit or on shared library unload. @@ -31,9 +77,9 @@ _DEFUN (__register_exitproc, __lock_acquire_recursive(__atexit_lock); #endif - p = _GLOBAL_REENT->_atexit; + p = _GLOBAL_ATEXIT; if (p == NULL) - _GLOBAL_REENT->_atexit = p = &_GLOBAL_REENT->_atexit0; + _GLOBAL_ATEXIT = p = _GLOBAL_ATEXIT0; if (p->_ind >= _ATEXIT_SIZE) { #ifndef _ATEXIT_DYNAMIC_ALLOC @@ -53,11 +99,13 @@ _DEFUN (__register_exitproc, return -1; } p->_ind = 0; - p->_next = _GLOBAL_REENT->_atexit; - _GLOBAL_REENT->_atexit = p; + p->_next = _GLOBAL_ATEXIT; + _GLOBAL_ATEXIT = p; #ifndef _REENT_SMALL p->_on_exit_args._fntypes = 0; p->_on_exit_args._is_cxa = 0; +#else + p->_on_exit_args_ptr = NULL; #endif #endif } @@ -74,7 +122,7 @@ _DEFUN (__register_exitproc, if (args == NULL) { #ifndef __SINGLE_THREAD__ - __lock_release(lock); + __lock_release(__atexit_lock); #endif return -1; } diff --git a/contrib/sdk/sources/newlib/libc/stdlib/__call_atexit.c b/contrib/sdk/sources/newlib/libc/stdlib/__call_atexit.c index 86410e2b62..10b5b8f0b5 100644 --- a/contrib/sdk/sources/newlib/libc/stdlib/__call_atexit.c +++ b/contrib/sdk/sources/newlib/libc/stdlib/__call_atexit.c @@ -11,8 +11,10 @@ /* Make this a weak reference to avoid pulling in free. */ void free(void *) _ATTRIBUTE((__weak__)); -#ifndef __SINGLE_THREAD__ -extern _LOCK_RECURSIVE_T __atexit_lock; +__LOCK_INIT_RECURSIVE(, __atexit_lock); + +#ifdef _REENT_GLOBAL_ATEXIT +struct _atexit *_global_atexit = _NULL; #endif #ifdef _WANT_REGISTER_FINI @@ -78,8 +80,8 @@ _DEFUN (__call_exitprocs, (code, d), restart: - p = _GLOBAL_REENT->_atexit; - lastp = &_GLOBAL_REENT->_atexit; + p = _GLOBAL_ATEXIT; + lastp = &_GLOBAL_ATEXIT; while (p) { #ifdef _REENT_SMALL diff --git a/contrib/sdk/sources/newlib/libc/stdlib/__exp10.c b/contrib/sdk/sources/newlib/libc/stdlib/__exp10.c new file mode 100644 index 0000000000..4e368b830d --- /dev/null +++ b/contrib/sdk/sources/newlib/libc/stdlib/__exp10.c @@ -0,0 +1,30 @@ +/* + * compute 10**x by successive squaring. + */ + +#include <_ansi.h> +#include "std.h" + +double +_DEFUN (__exp10, (x), + unsigned x) +{ + static _CONST double powtab[] = + {1.0, + 10.0, + 100.0, + 1000.0, + 10000.0}; + + if (x < (sizeof (powtab) / sizeof (double))) + return powtab[x]; + else if (x & 1) + { + return 10.0 * __exp10 (x - 1); + } + else + { + double n = __exp10 (x / 2); + return n * n; + } +} diff --git a/contrib/sdk/sources/newlib/libc/stdlib/__ten_mu.c b/contrib/sdk/sources/newlib/libc/stdlib/__ten_mu.c new file mode 100644 index 0000000000..637197be2a --- /dev/null +++ b/contrib/sdk/sources/newlib/libc/stdlib/__ten_mu.c @@ -0,0 +1,24 @@ +/* + * [atw] multiply 64 bit accumulator by 10 and add digit. + * The KA/CA way to do this should be to use + * a 64-bit integer internally and use "adjust" to + * convert it to float at the end of processing. + */ + +#include <_ansi.h> +#include "std.h" + +int +_DEFUN (__ten_mul, (acc, digit), + double *acc _AND + int digit) +{ + /* + * [atw] Crude, but effective (at least on a KB)... + */ + + *acc *= 10; + *acc += digit; + + return 0; /* no overflow */ +} diff --git a/contrib/sdk/sources/newlib/libc/stdlib/a64l.c b/contrib/sdk/sources/newlib/libc/stdlib/a64l.c new file mode 100644 index 0000000000..ee3d40d49b --- /dev/null +++ b/contrib/sdk/sources/newlib/libc/stdlib/a64l.c @@ -0,0 +1,197 @@ +/* +FUNCTION +<>, <>---convert between radix-64 ASCII string and long + +INDEX + a64l +INDEX + l64a + +ANSI_SYNOPSIS + #include + long a64l(const char *<[input]>); + char *l64a(long <[input]>); + +TRAD_SYNOPSIS + #include + long a64l(<[input]>) + const char *<[input]>; + + char *l64a(<[input]>) + long <[input]>; + +DESCRIPTION +Conversion is performed between long and radix-64 characters. The +<> routine transforms up to 32 bits of input value starting from +least significant bits to the most significant bits. The input value +is split up into a maximum of 5 groups of 6 bits and possibly one +group of 2 bits (bits 31 and 30). + +Each group of 6 bits forms a value from 0--63 which is translated into +a character as follows: + +O+ +o 0 = '.' +o 1 = '/' +o 2--11 = '0' to '9' +o 12--37 = 'A' to 'Z' +o 38--63 = 'a' to 'z' +O- + +When the remaining bits are zero or all bits have been translated, a +null terminator is appended to the string. An input value of 0 +results in the empty string. + +The <> function performs the reverse translation. Each +character is used to generate a 6-bit value for up to 30 bits and then +a 2-bit value to complete a 32-bit result. The null terminator means +that the remaining digits are 0. An empty input string or NULL string +results in 0L. An invalid string results in undefined behavior. If +the size of a long is greater than 32 bits, the result is sign-extended. + +RETURNS +<> returns a null-terminated string of 0 to 6 characters. +<> returns the 32-bit translated value from the input character string. + +PORTABILITY +<> and <> are non-ANSI and are defined by the Single Unix Specification. + +Supporting OS subroutines required: None. +*/ + +#include <_ansi.h> +#include +#include + +long +_DEFUN (a64l, (input), + const char *input) +{ + const char *ptr; + char ch; + int i, digit; + unsigned long result = 0; + + if (input == NULL) + return 0; + + ptr = input; + + /* it easiest to go from most significant digit to least so find end of input or up + to 6 characters worth */ + for (i = 0; i < 6; ++i) + { + if (*ptr) + ++ptr; + } + + while (ptr > input) + { + ch = *(--ptr); + +#if defined(PREFER_SIZE_OVER_SPEED) || defined(__OPTIMIZE_SIZE__) + if (ch >= 'a') + digit = (ch - 'a') + 38; + else if (ch >= 'A') + digit = (ch - 'A') + 12; + else if (ch >= '0') + digit = (ch - '0') + 2; + else if (ch == '/') + digit = 1; + else + digit = 0; +#else /* !defined(PREFER_SIZE_OVER_SPEED) && !defined(__OPTIMIZE_SIZE__) */ + switch (ch) + { + case '/': + digit = 1; + break; + case '0': + case '1': + case '2': + case '3': + case '4': + case '5': + case '6': + case '7': + case '8': + case '9': + digit = (ch - '0') + 2; + break; + case 'A': + case 'B': + case 'C': + case 'D': + case 'E': + case 'F': + case 'G': + case 'H': + case 'I': + case 'J': + case 'K': + case 'L': + case 'M': + case 'N': + case 'O': + case 'P': + case 'Q': + case 'R': + case 'S': + case 'T': + case 'U': + case 'V': + case 'W': + case 'X': + case 'Y': + case 'Z': + digit = (ch - 'A') + 12; + break; + case 'a': + case 'b': + case 'c': + case 'd': + case 'e': + case 'f': + case 'g': + case 'h': + case 'i': + case 'j': + case 'k': + case 'l': + case 'm': + case 'n': + case 'o': + case 'p': + case 'q': + case 'r': + case 's': + case 't': + case 'u': + case 'v': + case 'w': + case 'x': + case 'y': + case 'z': + digit = (ch - 'a') + 38; + break; + default: + digit = 0; + break; + } +#endif /* !defined(PREFER_SIZE_OVER_SPEED) && !defined(__OPTIMIZE_SIZE__) */ + + result = (result << 6) + digit; + } + +#if LONG_MAX > 2147483647 + /* for implementations where long is > 32 bits, the result must be sign-extended */ + if (result & 0x80000000) + return (((long)-1 >> 32) << 32) + result; +#endif + + return result; +} + + + + diff --git a/contrib/sdk/sources/newlib/libc/stdlib/abort.c b/contrib/sdk/sources/newlib/libc/stdlib/abort.c index bc0cf99638..dda267bdf3 100644 --- a/contrib/sdk/sources/newlib/libc/stdlib/abort.c +++ b/contrib/sdk/sources/newlib/libc/stdlib/abort.c @@ -59,7 +59,7 @@ _DEFUN_VOID (abort) while (1) { -// raise (SIGABRT); + raise (SIGABRT); _exit (1); } } diff --git a/contrib/sdk/sources/newlib/libc/stdlib/atoff.c b/contrib/sdk/sources/newlib/libc/stdlib/atoff.c new file mode 100644 index 0000000000..c97b78fb1f --- /dev/null +++ b/contrib/sdk/sources/newlib/libc/stdlib/atoff.c @@ -0,0 +1,9 @@ +#include +#include <_ansi.h> + +float +_DEFUN (atoff, (s), + _CONST char *s) +{ + return strtof (s, NULL); +} diff --git a/contrib/sdk/sources/newlib/libc/stdlib/atoll.c b/contrib/sdk/sources/newlib/libc/stdlib/atoll.c new file mode 100644 index 0000000000..a6abd95959 --- /dev/null +++ b/contrib/sdk/sources/newlib/libc/stdlib/atoll.c @@ -0,0 +1,94 @@ +/* +FUNCTION +<>---convert a string to a long long integer + +INDEX + atoll +INDEX + _atoll_r + +ANSI_SYNOPSIS + #include + long long atoll(const char *<[str]>); + long long _atoll_r(struct _reent *<[ptr]>, const char *<[str]>); + +TRAD_SYNOPSIS + #include + long long atoll(<[str]>) + const char *<[str]>; + + long long _atoll_r(<[ptr]>, <[str]>) + struct _reent *<[ptr]>; + const char *<[str]>; + +DESCRIPTION +The function <> converts the initial portion of the string +pointed to by <<*<[str]>>> to a type <>. A call to +atoll(str) in this implementation is equivalent to +strtoll(str, (char **)NULL, 10) including behavior on error. + +The alternate function <<_atoll_r>> is a reentrant version. The +extra argument <[reent]> is a pointer to a reentrancy structure. + + +RETURNS +The converted value. + +PORTABILITY +<> is ISO 9899 (C99) and POSIX 1003.1-2001 compatable. + +No supporting OS subroutines are required. +*/ + +/* + * Copyright (c) 1988, 1993 + * The Regents of the University of California. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * 3. 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 + * may be used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + */ + +#include +#include + +#ifndef _REENT_ONLY +long long +_DEFUN(atoll, (str), + _CONST char *str) +{ + return strtoll(str, (char **)NULL, 10); +} +#endif /* !_REENT_ONLY */ + +long long +_DEFUN(_atoll_r, (ptr, str), + struct _reent *ptr _AND + _CONST char *str) +{ + return _strtoll_r(ptr, str, (char **)NULL, 10); +} diff --git a/contrib/sdk/sources/newlib/libc/stdlib/exit.c b/contrib/sdk/sources/newlib/libc/stdlib/exit.c index fb235af78c..39c8a00479 100644 --- a/contrib/sdk/sources/newlib/libc/stdlib/exit.c +++ b/contrib/sdk/sources/newlib/libc/stdlib/exit.c @@ -58,6 +58,11 @@ void _DEFUN (exit, (code), int code) { +#ifdef _LITE_EXIT + /* Refer to comments in __atexit.c for more details of lite exit. */ + void __call_exitprocs _PARAMS ((int, _PTR)) __attribute__((weak)); + if (__call_exitprocs) +#endif __call_exitprocs (code, NULL); if (_GLOBAL_REENT->__cleanup) diff --git a/contrib/sdk/sources/newlib/libc/stdlib/gdtoa-gethex.c b/contrib/sdk/sources/newlib/libc/stdlib/gdtoa-gethex.c index 9cd9e0d40f..66292140ec 100644 --- a/contrib/sdk/sources/newlib/libc/stdlib/gdtoa-gethex.c +++ b/contrib/sdk/sources/newlib/libc/stdlib/gdtoa-gethex.c @@ -37,27 +37,37 @@ THIS SOFTWARE. #include "gd_qnan.h" #include "locale.h" -unsigned char hexdig[256]; - -static void -_DEFUN (htinit, (h, s, inc), - unsigned char *h _AND - unsigned char *s _AND - int inc) +#if !defined(PREFER_SIZE_OVER_SPEED) && !defined(__OPTIMIZE_SIZE__) && !defined(_SMALL_HEXDIG) +_CONST unsigned char __hexdig[256]= { - int i, j; - for(i = 0; (j = s[i]) !=0; i++) - h[j] = i + inc; -} - -void -_DEFUN_VOID (hexdig_init) + 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, + 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, + 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, + 16,17,18,19,20,21,22,23,24,25,0,0,0,0,0,0, + 0,26,27,28,29,30,31,0,0,0,0,0,0,0,0,0, + 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, + 0,26,27,28,29,30,31,0,0,0,0,0,0,0,0,0, + 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, + 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, + 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, + 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, + 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, + 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, + 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, + 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, + 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0 +}; +#else /* !defined(PREFER_SIZE_OVER_SPEED) && !defined(__OPTIMIZE_SIZE__) && !defined(_SMALL_HEXDIG) */ +unsigned char +_DEFUN (__hexdig_fun, (c), + unsigned char c) { -#define USC (unsigned char *) - htinit(hexdig, USC "0123456789", 0x10); - htinit(hexdig, USC "abcdef", 0x10 + 10); - htinit(hexdig, USC "ABCDEF", 0x10 + 10); + if(c>='0' && c<='9') return c-'0'+0x10; + else if(c>='a' && c<='f') return c-'a'+0x10+10; + else if(c>='A' && c<='F') return c-'A'+0x10+10; + else return 0; } +#endif /* !defined(PREFER_SIZE_OVER_SPEED) && !defined(__OPTIMIZE_SIZE__) && !defined(_SMALL_HEXDIG) */ static void _DEFUN(rshift, (b, k), @@ -138,7 +148,7 @@ int _DEFUN(gethex, (ptr, sp, fpi, exp, bp, sign), struct _reent *ptr _AND _CONST char **sp _AND - FPI *fpi _AND + _CONST FPI *fpi _AND Long *exp _AND _Bigint **bp _AND int sign) @@ -153,8 +163,6 @@ _DEFUN(gethex, (ptr, sp, fpi, exp, bp, sign), size_t decp_len = strlen ((const char *) decimalpoint); unsigned char decp_end = decimalpoint[decp_len - 1]; - if (!hexdig['0']) - hexdig_init(); havedig = 0; s0 = *(_CONST unsigned char **)sp + 2; while(s0[havedig] == '0') @@ -164,28 +172,28 @@ _DEFUN(gethex, (ptr, sp, fpi, exp, bp, sign), decpt = 0; zret = 0; e = 0; - if (!hexdig[*s]) { + if (!__get_hexdig(*s)) { zret = 1; if (strncmp ((const char *) s, (const char *) decimalpoint, decp_len) != 0) goto pcheck; decpt = (s += decp_len); - if (!hexdig[*s]) + if (!__get_hexdig(*s)) goto pcheck; while(*s == '0') s++; - if (hexdig[*s]) + if (__get_hexdig(*s)) zret = 0; havedig = 1; s0 = s; } - while(hexdig[*s]) + while(__get_hexdig(*s)) s++; if (strncmp ((const char *) s, (const char *) decimalpoint, decp_len) == 0 && !decpt) { decpt = (s += decp_len); - while(hexdig[*s]) + while(__get_hexdig(*s)) s++; } if (decpt) @@ -203,12 +211,12 @@ _DEFUN(gethex, (ptr, sp, fpi, exp, bp, sign), case '+': s++; } - if ((n = hexdig[*s]) == 0 || n > 0x19) { + if ((n = __get_hexdig(*s)) == 0 || n > 0x19) { s = s1; break; } e1 = n - 0x10; - while((n = hexdig[*++s]) !=0 && n <= 0x19) + while((n = __get_hexdig(*++s)) !=0 && n <= 0x19) e1 = 10*e1 + n - 0x10; if (esign) e1 = -e1; @@ -236,7 +244,7 @@ _DEFUN(gethex, (ptr, sp, fpi, exp, bp, sign), L = 0; n = 0; } - L |= (hexdig[*s1] & 0x0f) << n; + L |= (__get_hexdig(*s1) & 0x0f) << n; n += 4; } *x++ = L; diff --git a/contrib/sdk/sources/newlib/libc/stdlib/gdtoa-hexnan.c b/contrib/sdk/sources/newlib/libc/stdlib/gdtoa-hexnan.c index 49d472ff61..43459fedc0 100644 --- a/contrib/sdk/sources/newlib/libc/stdlib/gdtoa-hexnan.c +++ b/contrib/sdk/sources/newlib/libc/stdlib/gdtoa-hexnan.c @@ -64,15 +64,13 @@ _DEFUN (L_shift, (x, x1, i), int _DEFUN (hexnan, (sp, fpi, x0), _CONST char **sp _AND - FPI *fpi _AND + _CONST FPI *fpi _AND __ULong *x0) { __ULong c, h, *x, *x1, *xe; _CONST char *s; int havedig, hd0, i, nbits; - if (!hexdig['0']) - hexdig_init(); nbits = fpi->nbits; x = x0 + (nbits >> kshift); if (nbits & kmask) @@ -82,7 +80,7 @@ _DEFUN (hexnan, (sp, fpi, x0), havedig = hd0 = i = 0; s = *sp; while((c = *(_CONST unsigned char*)++s)) { - if (!(h = hexdig[c])) { + if (!(h = __get_hexdig(c))) { if (c <= ' ') { if (hd0 < havedig) { if (x < x1 && i < 8) diff --git a/contrib/sdk/sources/newlib/libc/stdlib/ldiv.c b/contrib/sdk/sources/newlib/libc/stdlib/ldiv.c new file mode 100644 index 0000000000..d7508f1c5f --- /dev/null +++ b/contrib/sdk/sources/newlib/libc/stdlib/ldiv.c @@ -0,0 +1,109 @@ +/* +FUNCTION +<>---divide two long integers + +INDEX + ldiv + +ANSI_SYNOPSIS + #include + ldiv_t ldiv(long <[n]>, long <[d]>); + +TRAD_SYNOPSIS + #include + ldiv_t ldiv(<[n]>, <[d]>) + long <[n]>, <[d]>; + +DESCRIPTION +Divide +@tex +$n/d$, +@end tex +@ifnottex +<[n]>/<[d]>, +@end ifnottex +returning quotient and remainder as two long integers in a structure <>. + +RETURNS +The result is represented with the structure + +. typedef struct +. { +. long quot; +. long rem; +. } ldiv_t; + +where the <> field represents the quotient, and <> the +remainder. For nonzero <[d]>, if `<<<[r]> = ldiv(<[n]>,<[d]>);>>' then +<[n]> equals `<<<[r]>.rem + <[d]>*<[r]>.quot>>'. + +To divide <> rather than <> values, use the similar +function <
>. + +PORTABILITY +<> is ANSI. + +No supporting OS subroutines are required. +*/ + + +/* + * Copyright (c) 1990 Regents of the University of California. + * All rights reserved. + * + * This code is derived from software contributed to Berkeley by + * Chris Torek. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * 3. 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 + * may be used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + */ + +#include <_ansi.h> +#include /* ldiv_t */ + +ldiv_t +_DEFUN (ldiv, (num, denom), + long num _AND + long denom) +{ + ldiv_t r; + + /* see div.c for comments */ + + r.quot = num / denom; + r.rem = num % denom; + if (num >= 0 && r.rem < 0) { + ++r.quot; + r.rem -= denom; + } + else if (num < 0 && r.rem > 0) { + --r.quot; + r.rem += denom; + } + return (r); +} diff --git a/contrib/sdk/sources/newlib/libc/stdlib/lrand48.c b/contrib/sdk/sources/newlib/libc/stdlib/lrand48.c new file mode 100644 index 0000000000..bfc693b752 --- /dev/null +++ b/contrib/sdk/sources/newlib/libc/stdlib/lrand48.c @@ -0,0 +1,32 @@ +/* + * Copyright (c) 1993 Martin Birgmeier + * All rights reserved. + * + * You may redistribute unmodified or modified versions of this source + * code provided that the above copyright notice and this and the + * following conditions are retained. + * + * This software is provided ``as is'', and comes with no warranties + * of any kind. I shall in no event be liable for anything that happens + * to anyone/anything when using this software. + */ + +#include "rand48.h" + +long +_DEFUN (_lrand48_r, (r), + struct _reent *r) +{ + _REENT_CHECK_RAND48(r); + __dorand48(r, __rand48_seed); + return (long)((unsigned long) __rand48_seed[2] << 15) + + ((unsigned long) __rand48_seed[1] >> 1); +} + +#ifndef _REENT_ONLY +long +_DEFUN_VOID (lrand48) +{ + return _lrand48_r (_REENT); +} +#endif /* !_REENT_ONLY */ diff --git a/contrib/sdk/sources/newlib/libc/stdlib/mbrtowc.c b/contrib/sdk/sources/newlib/libc/stdlib/mbrtowc.c index 04fcaf6514..bc76e5f794 100644 --- a/contrib/sdk/sources/newlib/libc/stdlib/mbrtowc.c +++ b/contrib/sdk/sources/newlib/libc/stdlib/mbrtowc.c @@ -43,33 +43,34 @@ _DEFUN (_mbrtowc_r, (ptr, pwc, s, n, ps), #ifndef _REENT_ONLY size_t _DEFUN (mbrtowc, (pwc, s, n, ps), - wchar_t *pwc _AND - const char *s _AND + wchar_t *__restrict pwc _AND + const char *__restrict s _AND size_t n _AND - mbstate_t *ps) + mbstate_t *__restrict ps) { #if defined(PREFER_SIZE_OVER_SPEED) || defined(__OPTIMIZE_SIZE__) return _mbrtowc_r (_REENT, pwc, s, n, ps); #else int retval = 0; + struct _reent *reent = _REENT; #ifdef _MB_CAPABLE if (ps == NULL) { - _REENT_CHECK_MISC(_REENT); - ps = &(_REENT_MBRTOWC_STATE(_REENT)); + _REENT_CHECK_MISC(reent); + ps = &(_REENT_MBRTOWC_STATE(reent)); } #endif if (s == NULL) - retval = __mbtowc (_REENT, NULL, "", 1, __locale_charset (), ps); + retval = __mbtowc (reent, NULL, "", 1, __locale_charset (), ps); else - retval = __mbtowc (_REENT, pwc, s, n, __locale_charset (), ps); + retval = __mbtowc (reent, pwc, s, n, __locale_charset (), ps); if (retval == -1) { ps->__count = 0; - _REENT->_errno = EILSEQ; + reent->_errno = EILSEQ; return (size_t)(-1); } else diff --git a/contrib/sdk/sources/newlib/libc/stdlib/mbtowc.c b/contrib/sdk/sources/newlib/libc/stdlib/mbtowc.c index ac14f59016..a5a7c7420d 100644 --- a/contrib/sdk/sources/newlib/libc/stdlib/mbtowc.c +++ b/contrib/sdk/sources/newlib/libc/stdlib/mbtowc.c @@ -7,7 +7,7 @@ INDEX ANSI_SYNOPSIS #include - int mbtowc(wchar_t *<[pwc]>, const char *<[s]>, size_t <[n]>); + int mbtowc(wchar_t *restrict <[pwc]>, const char *restrict <[s]>, size_t <[n]>); TRAD_SYNOPSIS #include @@ -58,18 +58,19 @@ effects vary with the locale. int _DEFUN (mbtowc, (pwc, s, n), - wchar_t *pwc _AND - const char *s _AND + wchar_t *__restrict pwc _AND + const char *__restrict s _AND size_t n) { #ifdef _MB_CAPABLE int retval = 0; + struct _reent *reent = _REENT; mbstate_t *ps; - _REENT_CHECK_MISC(_REENT); - ps = &(_REENT_MBTOWC_STATE(_REENT)); + _REENT_CHECK_MISC(reent); + ps = &(_REENT_MBTOWC_STATE(reent)); - retval = __mbtowc (_REENT, pwc, s, n, __locale_charset (), ps); + retval = __mbtowc (reent, pwc, s, n, __locale_charset (), ps); if (retval < 0) { diff --git a/contrib/sdk/sources/newlib/libc/stdlib/mbtowc_r.c b/contrib/sdk/sources/newlib/libc/stdlib/mbtowc_r.c index 6270e4ea1d..c36b49ddc0 100644 --- a/contrib/sdk/sources/newlib/libc/stdlib/mbtowc_r.c +++ b/contrib/sdk/sources/newlib/libc/stdlib/mbtowc_r.c @@ -19,8 +19,8 @@ int (*__mbtowc) (struct _reent *, wchar_t *, const char *, size_t, int _DEFUN (_mbtowc_r, (r, pwc, s, n, state), struct _reent *r _AND - wchar_t *pwc _AND - const char *s _AND + wchar_t *__restrict pwc _AND + const char *__restrict s _AND size_t n _AND mbstate_t *state) { @@ -78,6 +78,7 @@ typedef enum { COPY_A, COPY_J1, COPY_J2, MAKE_A, NOOP, EMPTY, ERROR } JIS_ACTION * is 2 (switch to JIS) + 2 (JIS characters) + 2 (switch back to ASCII) = 6. *************************************************************************************/ +#ifndef __CYGWIN__ static JIS_STATE JIS_state_table[JIS_S_NUM][JIS_C_NUM] = { /* ESCAPE DOLLAR BRACKET AT B J NUL JIS_CHAR OTHER */ /* ASCII */ { A_ESC, ASCII, ASCII, ASCII, ASCII, ASCII, ASCII, ASCII, ASCII }, @@ -99,6 +100,7 @@ static JIS_ACTION JIS_action_table[JIS_S_NUM][JIS_C_NUM] = { /* J_ESC */ { ERROR, ERROR, NOOP, ERROR, ERROR, ERROR, ERROR, ERROR, ERROR }, /* J_ESC_BR */{ ERROR, ERROR, ERROR, ERROR, MAKE_A, MAKE_A, ERROR, ERROR, ERROR }, }; +#endif /* !__CYGWIN__ */ /* we override the mbstate_t __count field for more complex encodings and use it store a state value */ #define __state __count diff --git a/contrib/sdk/sources/newlib/libc/stdlib/mlock.c b/contrib/sdk/sources/newlib/libc/stdlib/mlock.c index 4437171f61..34ca2be331 100644 --- a/contrib/sdk/sources/newlib/libc/stdlib/mlock.c +++ b/contrib/sdk/sources/newlib/libc/stdlib/mlock.c @@ -1,3 +1,4 @@ +#ifndef MALLOC_PROVIDED /* FUNCTION <<__malloc_lock>>, <<__malloc_unlock>>---lock malloc pool @@ -38,19 +39,26 @@ that it already holds. #include #include +#ifndef __SINGLE_THREAD__ __LOCK_INIT_RECURSIVE(static, __malloc_lock_object); +#endif void __malloc_lock (ptr) struct _reent *ptr; { +#ifndef __SINGLE_THREAD__ __lock_acquire_recursive (__malloc_lock_object); +#endif } void __malloc_unlock (ptr) struct _reent *ptr; { +#ifndef __SINGLE_THREAD__ __lock_release_recursive (__malloc_lock_object); +#endif } +#endif diff --git a/contrib/sdk/sources/newlib/libc/stdlib/mprec.h b/contrib/sdk/sources/newlib/libc/stdlib/mprec.h index 9b8ea99bee..b5e4ae83d1 100644 --- a/contrib/sdk/sources/newlib/libc/stdlib/mprec.h +++ b/contrib/sdk/sources/newlib/libc/stdlib/mprec.h @@ -98,7 +98,7 @@ typedef union { double d; __ULong i[2]; } U; #define SI 0 #endif -#define Storeinc(a,b,c) (*(a)++ = (b) << 16 | (c) & 0xffff) +#define Storeinc(a,b,c) (*(a)++ = ((b) << 16) | ((c) & 0xffff)) /* #define P DBL_MANT_DIG */ /* Ten_pmax = floor(P*log(2)/log(5)) */ @@ -370,9 +370,12 @@ typedef struct _Bigint _Bigint; #define gethex __gethex #define copybits __copybits #define hexnan __hexnan -#define hexdig_init __hexdig_init -#define hexdig __hexdig +#if !defined(PREFER_SIZE_OVER_SPEED) && !defined(__OPTIMIZE_SIZE__) && !defined(_SMALL_HEXDIG) +#define __get_hexdig(x) __hexdig[x] /* NOTE: must evaluate arg only once */ +#else /* !defined(PREFER_SIZE_OVER_SPEED) && !defined(__OPTIMIZE_SIZE__) && !defined(_SMALL_HEXDIG) */ +#define __get_hexdig(x) __hexdig_fun(x) +#endif /* !defined(PREFER_SIZE_OVER_SPEED) && !defined(__OPTIMIZE_SIZE__) && !defined(_SMALL_HEXDIG) */ #define tens __mprec_tens #define bigtens __mprec_bigtens @@ -395,13 +398,15 @@ _Bigint * _EXFUN(d2b,(struct _reent *p, double d, int *e, int *bits)); _Bigint * _EXFUN(lshift,(struct _reent *p, _Bigint *b, int k)); _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, struct FPI *fpi, Long *exp, _Bigint **bp, int sign)); +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)); -void _EXFUN(hexdig_init,(void)); +#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) */ #ifdef INFNAN_CHECK -int _EXFUN(hexnan,(_CONST char **sp, struct FPI *fpi, __ULong *x0)); +int _EXFUN(hexnan,(_CONST char **sp, _CONST struct FPI *fpi, __ULong *x0)); #endif #define Bcopy(x,y) memcpy((char *)&x->_sign, (char *)&y->_sign, y->_wds*sizeof(__Long) + 2*sizeof(int)) @@ -409,7 +414,9 @@ int _EXFUN(hexnan,(_CONST char **sp, struct FPI *fpi, __ULong *x0)); extern _CONST double tinytens[]; extern _CONST double bigtens[]; extern _CONST double tens[]; -extern unsigned char hexdig[]; +#if !defined(PREFER_SIZE_OVER_SPEED) && !defined(__OPTIMIZE_SIZE__) && !defined(_SMALL_HEXDIG) +extern _CONST unsigned char __hexdig[]; +#endif /* !defined(PREFER_SIZE_OVER_SPEED) && !defined(__OPTIMIZE_SIZE__) && !defined(_SMALL_HEXDIG) */ double _EXFUN(_mprec_log10,(int)); diff --git a/contrib/sdk/sources/newlib/libc/stdlib/rand.c b/contrib/sdk/sources/newlib/libc/stdlib/rand.c index 024237d106..bce78fcb85 100644 --- a/contrib/sdk/sources/newlib/libc/stdlib/rand.c +++ b/contrib/sdk/sources/newlib/libc/stdlib/rand.c @@ -72,20 +72,24 @@ on two different systems. void _DEFUN (srand, (seed), unsigned int seed) { - _REENT_CHECK_RAND48(_REENT); - _REENT_RAND_NEXT(_REENT) = seed; + struct _reent *reent = _REENT; + + _REENT_CHECK_RAND48(reent); + _REENT_RAND_NEXT(reent) = seed; } int _DEFUN_VOID (rand) { + struct _reent *reent = _REENT; + /* This multiplier was obtained from Knuth, D.E., "The Art of Computer Programming," Vol 2, Seminumerical Algorithms, Third Edition, Addison-Wesley, 1998, p. 106 (line 26) & p. 108 */ - _REENT_CHECK_RAND48(_REENT); - _REENT_RAND_NEXT(_REENT) = - _REENT_RAND_NEXT(_REENT) * __extension__ 6364136223846793005LL + 1; - return (int)((_REENT_RAND_NEXT(_REENT) >> 32) & RAND_MAX); + _REENT_CHECK_RAND48(reent); + _REENT_RAND_NEXT(reent) = + _REENT_RAND_NEXT(reent) * __extension__ 6364136223846793005LL + 1; + return (int)((_REENT_RAND_NEXT(reent) >> 32) & RAND_MAX); } #endif /* _REENT_ONLY */ diff --git a/contrib/sdk/sources/newlib/libc/stdlib/strtod.c b/contrib/sdk/sources/newlib/libc/stdlib/strtod.c index d417418511..7dc3f8aece 100644 --- a/contrib/sdk/sources/newlib/libc/stdlib/strtod.c +++ b/contrib/sdk/sources/newlib/libc/stdlib/strtod.c @@ -11,11 +11,11 @@ INDEX ANSI_SYNOPSIS #include - double strtod(const char *<[str]>, char **<[tail]>); - float strtof(const char *<[str]>, char **<[tail]>); + double strtod(const char *restrict <[str]>, char **restrict <[tail]>); + float strtof(const char *restrict <[str]>, char **restrict <[tail]>); double _strtod_r(void *<[reent]>, - const char *<[str]>, char **<[tail]>); + const char *restrict <[str]>, char **restrict <[tail]>); TRAD_SYNOPSIS #include @@ -128,11 +128,17 @@ THIS SOFTWARE. #ifndef NO_IEEE_Scale #define Avoid_Underflow #undef tinytens -/* The factor of 2^53 in tinytens[4] helps us avoid setting the underflow */ +/* The factor of 2^106 in tinytens[4] helps us avoid setting the underflow */ /* flag unnecessarily. It leads to a song and dance at the end of strtod. */ -static _CONST double tinytens[] = { 1e-16, 1e-32, 1e-64, 1e-128, - 9007199254740992.e-256 +static _CONST double tinytens[] = { 1e-16, 1e-32, +#ifdef _DOUBLE_IS_32BITS + 0.0, 0.0, 0.0 +#else + 1e-64, 1e-128, + 9007199254740992. * 9007199254740992.e-256 +#endif }; + #endif #endif @@ -144,6 +150,28 @@ static _CONST double tinytens[] = { 1e-16, 1e-32, 1e-64, 1e-128, #define Rounding Flt_Rounds #endif +#ifdef Avoid_Underflow /*{*/ + static double +_DEFUN (sulp, (x, scale), + U x _AND + int scale) +{ + U u; + double rv; + int i; + + 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); +#ifndef _DOUBLE_IS_32BITS + dword1(u) = 0; +#endif + return rv * u.d; + } +#endif /*}*/ + + #ifndef NO_HEX_FP static void @@ -208,8 +236,8 @@ _DEFUN (match, (sp, t), double _DEFUN (_strtod_r, (ptr, s00, se), struct _reent *ptr _AND - _CONST char *s00 _AND - char **se) + _CONST char *__restrict s00 _AND + char **__restrict se) { #ifdef Avoid_Underflow int scale; @@ -221,7 +249,10 @@ _DEFUN (_strtod_r, (ptr, s00, se), U aadj1, rv, rv0; Long L; __ULong y, z; - _Bigint *bb, *bb1, *bd, *bd0, *bs, *delta; + _Bigint *bb = NULL, *bb1, *bd = NULL, *bd0, *bs = NULL, *delta = NULL; +#ifdef Avoid_Underflow + __ULong Lsb, Lsb1; +#endif #ifdef SET_INEXACT int inexact, oldinexact; #endif @@ -256,7 +287,7 @@ _DEFUN (_strtod_r, (ptr, s00, se), if (*s == '0') { #ifndef NO_HEX_FP { - static FPI fpi = { 53, 1-1023-53+1, 2046-1023-53+1, 1, SI }; + static _CONST FPI fpi = { 53, 1-1023-53+1, 2046-1023-53+1, 1, SI }; Long exp; __ULong bits[2]; switch(s[1]) { @@ -279,6 +310,8 @@ _DEFUN (_strtod_r, (ptr, s00, se), switch((i = gethex(ptr, &s, &fpi1, &exp, &bb, sign)) & STRTOG_Retmask) { case STRTOG_NoNumber: s = s00; + sign = 0; + /* FALLTHROUGH */ case STRTOG_Zero: break; default: @@ -299,17 +332,15 @@ _DEFUN (_strtod_r, (ptr, s00, se), } s0 = s; y = z = 0; - for(nd = nf = 0; (c = *s) >= '0' && c <= '9'; nd++, s++) { - if (nd < DBL_DIG + 1) { + 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'; - } - } nd0 = nd; if (strncmp (s, _localeconv_r (ptr)->decimal_point, - strlen (_localeconv_r (ptr)->decimal_point)) == 0) { + strlen (_localeconv_r (ptr)->decimal_point)) == 0) + { decpt = 1; c = *(s += strlen (_localeconv_r (ptr)->decimal_point)); if (!nd) { @@ -327,24 +358,16 @@ _DEFUN (_strtod_r, (ptr, s00, se), have_dig: nz++; if (c -= '0') { - for(i = 1; i < nz; i++) { - if (nd <= DBL_DIG + 1) { - if (nd + i < 10) + nf += nz; + for(i = 1; i < nz; i++) + if (nd++ < 9) y *= 10; - else + else if (nd <= DBL_DIG + 1) z *= 10; - } - } - if (nd <= DBL_DIG + 1) { - if (nd + i < 10) + if (nd++ < 9) y = 10*y + c; - else + else if (nd <= DBL_DIG + 1) z = 10*z + c; - } - if (nd <= DBL_DIG + 1) { - nf += nz; - nd += nz; - } nz = 0; } } @@ -392,7 +415,7 @@ _DEFUN (_strtod_r, (ptr, s00, se), #ifdef INFNAN_CHECK /* Check for Nan and Infinity */ __ULong bits[2]; - static FPI fpinan = /* only 52 explicit bits */ + static _CONST FPI fpinan = /* only 52 explicit bits */ { 52, 1-1023-53+1, 2046-1023-53+1, 1, SI }; if (!decpt) switch(c) { @@ -693,12 +716,20 @@ _DEFUN (_strtod_r, (ptr, s00, se), /* Put digits into bd: true value = bd * 10^e */ bd0 = s2b(ptr, s0, nd0, nd, y); + if (bd0 == NULL) + goto ovfl; for(;;) { bd = Balloc(ptr,bd0->_k); + if (bd == NULL) + goto ovfl; Bcopy(bd, bd0); bb = d2b(ptr,dval(rv), &bbe, &bbbits); /* rv = bb * 2^bbe */ + if (bb == NULL) + goto ovfl; bs = i2b(ptr,1); + if (bs == NULL) + goto ovfl; if (e >= 0) { bb2 = bb5 = 0; @@ -718,12 +749,19 @@ _DEFUN (_strtod_r, (ptr, s00, se), bs2++; #endif #ifdef Avoid_Underflow + Lsb = LSB; + Lsb1 = 0; j = bbe - scale; i = j + bbbits - 1; /* logb(rv) */ - if (i < Emin) /* denormal */ - j += P - Emin; + j = P + 1 - bbbits; + if (i < Emin) { /* denormal */ + i = Emin - i; + j -= i; + if (i < 32) + Lsb <<= i; else - j = P + 1 - bbbits; + Lsb1 = Lsb << (i-32); + } #else /*Avoid_Underflow*/ #ifdef Sudden_Underflow #ifdef IBM @@ -755,19 +793,37 @@ _DEFUN (_strtod_r, (ptr, s00, se), } if (bb5 > 0) { bs = pow5mult(ptr, bs, bb5); + if (bs == NULL) + goto ovfl; bb1 = mult(ptr, bs, bb); + if (bb1 == NULL) + goto ovfl; Bfree(ptr, bb); bb = bb1; } - if (bb2 > 0) + if (bb2 > 0) { bb = lshift(ptr, bb, bb2); - if (bd5 > 0) + if (bb == NULL) + goto ovfl; + } + if (bd5 > 0) { bd = pow5mult(ptr, bd, bd5); - if (bd2 > 0) + if (bd == NULL) + goto ovfl; + } + if (bd2 > 0) { bd = lshift(ptr, bd, bd2); - if (bs2 > 0) + if (bd == NULL) + goto ovfl; + } + if (bs2 > 0) { bs = lshift(ptr, bs, bs2); + if (bs == NULL) + goto ovfl; + } delta = diff(ptr, bb, bd); + if (delta == NULL) + goto ovfl; dsign = delta->_sign; delta->_sign = 0; i = cmp(delta, bs); @@ -854,7 +910,9 @@ _DEFUN (_strtod_r, (ptr, s00, se), #endif /*Sudden_Underflow*/ #endif /*Avoid_Underflow*/ adj *= ulp(dval(rv)); - if (dsign) + if (dsign) { + if (dword0(rv) == Big0 && dword1(rv) == Big1) + goto ovfl; dval(rv) += adj; else dval(rv) -= adj; @@ -904,6 +962,8 @@ _DEFUN (_strtod_r, (ptr, s00, se), #endif 0xffffffff)) { /*boundary case -- increment exponent*/ + if (dword0(rv) == Big0 && dword1(rv) == Big1) + goto ovfl; dword0(rv) = (dword0(rv) & Exp_mask) + Exp_msk1 #ifdef IBM @@ -962,14 +1022,31 @@ _DEFUN (_strtod_r, (ptr, s00, se), #endif } #ifndef ROUND_BIASED +#ifdef Avoid_Underflow + if (Lsb1) { + if (!(dword0(rv) & Lsb1)) + break; + } + else if (!(dword1(rv) & Lsb)) + break; +#else if (!(dword1(rv) & LSB)) break; +#endif #endif if (dsign) +#ifdef Avoid_Underflow + dval(rv) += sulp(rv, scale); +#else dval(rv) += ulp(dval(rv)); +#endif #ifndef ROUND_BIASED else { +#ifdef Avoid_Underflow + dval(rv) -= sulp(rv, scale); +#else dval(rv) -= ulp(dval(rv)); +#endif #ifndef Sudden_Underflow if (!dval(rv)) goto undfl; @@ -1046,7 +1123,7 @@ _DEFUN (_strtod_r, (ptr, s00, se), #ifdef Avoid_Underflow if (scale && y <= 2*P*Exp_msk1) { if (aadj <= 0x7fffffff) { - if ((z = aadj) <= 0) + if ((z = aadj) == 0) z = 1; aadj = z; dval(aadj1) = dsign ? aadj : -aadj; @@ -1178,15 +1255,15 @@ _DEFUN (_strtod_r, (ptr, s00, se), double _DEFUN (strtod, (s00, se), - _CONST char *s00 _AND char **se) + _CONST char *__restrict s00 _AND char **__restrict se) { return _strtod_r (_REENT, s00, se); } float _DEFUN (strtof, (s00, se), - _CONST char *s00 _AND - char **se) + _CONST char *__restrict s00 _AND + char **__restrict se) { double retval = _strtod_r (_REENT, s00, se); if (isnan (retval)) diff --git a/contrib/sdk/sources/newlib/libc/stdlib/strtol.c b/contrib/sdk/sources/newlib/libc/stdlib/strtol.c index 1f2c6453a2..23cc6510ed 100644 --- a/contrib/sdk/sources/newlib/libc/stdlib/strtol.c +++ b/contrib/sdk/sources/newlib/libc/stdlib/strtol.c @@ -9,10 +9,10 @@ INDEX ANSI_SYNOPSIS #include - long strtol(const char *<[s]>, char **<[ptr]>,int <[base]>); + long strtol(const char *restrict <[s]>, char **restrict <[ptr]>,int <[base]>); long _strtol_r(void *<[reent]>, - const char *<[s]>, char **<[ptr]>,int <[base]>); + const char *restrict <[s]>, char **restrict <[ptr]>,int <[base]>); TRAD_SYNOPSIS #include @@ -133,8 +133,8 @@ No supporting OS subroutines are required. long _DEFUN (_strtol_r, (rptr, nptr, endptr, base), struct _reent *rptr _AND - _CONST char *nptr _AND - char **endptr _AND + _CONST char *__restrict nptr _AND + char **__restrict endptr _AND int base) { register const unsigned char *s = (const unsigned char *)nptr; @@ -216,8 +216,8 @@ _DEFUN (_strtol_r, (rptr, nptr, endptr, base), long _DEFUN (strtol, (s, ptr, base), - _CONST char *s _AND - char **ptr _AND + _CONST char *__restrict s _AND + char **__restrict ptr _AND int base) { return _strtol_r (_REENT, s, ptr, base); diff --git a/contrib/sdk/sources/newlib/libc/stdlib/strtold.c b/contrib/sdk/sources/newlib/libc/stdlib/strtold.c index 1e648b0b50..64f15fe40a 100644 --- a/contrib/sdk/sources/newlib/libc/stdlib/strtold.c +++ b/contrib/sdk/sources/newlib/libc/stdlib/strtold.c @@ -34,7 +34,7 @@ POSSIBILITY OF SUCH DAMAGE. /* On platforms where long double is as wide as double. */ #ifdef _LDBL_EQ_DBL long double -strtold (const char *s00, char **se) +strtold (const char *__restrict s00, char **__restrict se) { return strtod(s00, se); } diff --git a/contrib/sdk/sources/newlib/libc/stdlib/strtoll.c b/contrib/sdk/sources/newlib/libc/stdlib/strtoll.c index b184f1eaa4..6d9354c7f0 100644 --- a/contrib/sdk/sources/newlib/libc/stdlib/strtoll.c +++ b/contrib/sdk/sources/newlib/libc/stdlib/strtoll.c @@ -9,10 +9,10 @@ INDEX ANSI_SYNOPSIS #include - long long strtoll(const char *<[s]>, char **<[ptr]>,int <[base]>); + long long strtoll(const char *restrict <[s]>, char **restrict <[ptr]>,int <[base]>); long long _strtoll_r(void *<[reent]>, - const char *<[s]>, char **<[ptr]>,int <[base]>); + const char *restrict <[s]>, char **restrict <[ptr]>,int <[base]>); TRAD_SYNOPSIS #include @@ -128,8 +128,8 @@ No supporting OS subroutines are required. long long _DEFUN (strtoll, (s, ptr, base), - _CONST char *s _AND - char **ptr _AND + _CONST char *__restrict s _AND + char **__restrict ptr _AND int base) { return _strtoll_r (_REENT, s, ptr, base); diff --git a/contrib/sdk/sources/newlib/libc/stdlib/strtoll_r.c b/contrib/sdk/sources/newlib/libc/stdlib/strtoll_r.c index 5ee2f5031d..87a7fee909 100644 --- a/contrib/sdk/sources/newlib/libc/stdlib/strtoll_r.c +++ b/contrib/sdk/sources/newlib/libc/stdlib/strtoll_r.c @@ -58,8 +58,8 @@ long long _DEFUN (_strtoll_r, (rptr, nptr, endptr, base), struct _reent *rptr _AND - _CONST char *nptr _AND - char **endptr _AND + _CONST char *__restrict nptr _AND + char **__restrict endptr _AND int base) { register const unsigned char *s = (const unsigned char *)nptr; diff --git a/contrib/sdk/sources/newlib/libc/stdlib/strtoul.c b/contrib/sdk/sources/newlib/libc/stdlib/strtoul.c index 02db4bf35b..518daf119f 100644 --- a/contrib/sdk/sources/newlib/libc/stdlib/strtoul.c +++ b/contrib/sdk/sources/newlib/libc/stdlib/strtoul.c @@ -9,11 +9,11 @@ INDEX ANSI_SYNOPSIS #include - unsigned long strtoul(const char *<[s]>, char **<[ptr]>, + unsigned long strtoul(const char *restrict <[s]>, char **restrict <[ptr]>, int <[base]>); - unsigned long _strtoul_r(void *<[reent]>, const char *<[s]>, - char **<[ptr]>, int <[base]>); + unsigned long _strtoul_r(void *<[reent]>, const char *restrict <[s]>, + char **restrict <[ptr]>, int <[base]>); TRAD_SYNOPSIS #include @@ -134,8 +134,8 @@ PORTABILITY unsigned long _DEFUN (_strtoul_r, (rptr, nptr, endptr, base), struct _reent *rptr _AND - _CONST char *nptr _AND - char **endptr _AND + _CONST char *__restrict nptr _AND + char **__restrict endptr _AND int base) { register const unsigned char *s = (const unsigned char *)nptr; @@ -196,8 +196,8 @@ _DEFUN (_strtoul_r, (rptr, nptr, endptr, base), unsigned long _DEFUN (strtoul, (s, ptr, base), - _CONST char *s _AND - char **ptr _AND + _CONST char *__restrict s _AND + char **__restrict ptr _AND int base) { return _strtoul_r (_REENT, s, ptr, base); diff --git a/contrib/sdk/sources/newlib/libc/stdlib/strtoull.c b/contrib/sdk/sources/newlib/libc/stdlib/strtoull.c index d95fc57b6f..aa80b51854 100644 --- a/contrib/sdk/sources/newlib/libc/stdlib/strtoull.c +++ b/contrib/sdk/sources/newlib/libc/stdlib/strtoull.c @@ -9,11 +9,11 @@ INDEX ANSI_SYNOPSIS #include - unsigned long long strtoull(const char *<[s]>, char **<[ptr]>, + unsigned long long strtoull(const char *restrict <[s]>, char **restrict <[ptr]>, int <[base]>); - unsigned long long _strtoull_r(void *<[reent]>, const char *<[s]>, - char **<[ptr]>, int <[base]>); + unsigned long long _strtoull_r(void *<[reent]>, const char *restrict <[s]>, + char **restrict <[ptr]>, int <[base]>); TRAD_SYNOPSIS #include @@ -129,8 +129,8 @@ PORTABILITY unsigned long long _DEFUN (strtoull, (s, ptr, base), - _CONST char *s _AND - char **ptr _AND + _CONST char *__restrict s _AND + char **__restrict ptr _AND int base) { return _strtoull_r (_REENT, s, ptr, base); diff --git a/contrib/sdk/sources/newlib/libc/stdlib/strtoull_r.c b/contrib/sdk/sources/newlib/libc/stdlib/strtoull_r.c index 6fcc976555..6c687da443 100644 --- a/contrib/sdk/sources/newlib/libc/stdlib/strtoull_r.c +++ b/contrib/sdk/sources/newlib/libc/stdlib/strtoull_r.c @@ -59,8 +59,8 @@ unsigned long long _DEFUN (_strtoull_r, (rptr, nptr, endptr, base), struct _reent *rptr _AND - _CONST char *nptr _AND - char **endptr _AND + _CONST char *__restrict nptr _AND + char **__restrict endptr _AND int base) { register const unsigned char *s = (const unsigned char *)nptr; diff --git a/contrib/sdk/sources/newlib/libc/stdlib/system.c b/contrib/sdk/sources/newlib/libc/stdlib/system.c index 5d26fbfa80..49cf82a233 100644 --- a/contrib/sdk/sources/newlib/libc/stdlib/system.c +++ b/contrib/sdk/sources/newlib/libc/stdlib/system.c @@ -61,16 +61,42 @@ Supporting OS subroutines required: <<_exit>>, <<_execve>>, <<_fork_r>>, #include <_syslist.h> #include +#if defined (unix) || defined (__CYGWIN__) +static int _EXFUN(do_system, (struct _reent *ptr _AND _CONST char *s)); +#endif int _DEFUN(_system_r, (ptr, s), struct _reent *ptr _AND _CONST char *s) { +#if defined(HAVE_SYSTEM) + return _system (s); + ptr = ptr; +#elif defined(NO_EXEC) if (s == NULL) return 0; errno = ENOSYS; return -1; +#else + + /* ??? How to handle (s == NULL) here is not exactly clear. + If _fork_r fails, that's not really a justification for returning 0. + For now we always return 0 and leave it to each target to explicitly + handle otherwise (this can always be relaxed in the future). */ + +#if defined (unix) || defined (__CYGWIN__) + if (s == NULL) + return 1; + return do_system (ptr, s); +#else + if (s == NULL) + return 0; + errno = ENOSYS; + return -1; +#endif + +#endif } #ifndef _REENT_ONLY @@ -83,3 +109,83 @@ _DEFUN(system, (s), } #endif + +#if defined (unix) && !defined (__CYGWIN__) && !defined(__rtems__) +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; + +static int +_DEFUN(do_system, (ptr, s), + struct _reent *ptr _AND + _CONST char *s) +{ + char *argv[4]; + int pid, status; + + argv[0] = "sh"; + argv[1] = "-c"; + argv[2] = (char *) s; + argv[3] = NULL; + + if ((pid = _fork_r (ptr)) == 0) + { + _execve ("/bin/sh", argv, *p_environ); + exit (100); + } + else if (pid == -1) + return -1; + else + { + int rc = _wait_r (ptr, &status); + if (rc == -1) + return -1; + status = (status >> 8) & 0xff; + return status; + } +} +#endif + +#if defined (__CYGWIN__) +static int +_DEFUN(do_system, (ptr, s), + struct _reent *ptr _AND + _CONST char *s) +{ + char *argv[4]; + int pid, status; + + argv[0] = "sh"; + argv[1] = "-c"; + argv[2] = (char *) s; + argv[3] = NULL; + + if ((pid = vfork ()) == 0) + { + /* ??? It's not clear what's the right path to take (pun intended :-). + There won't be an "sh" in any fixed location so we need each user + to be able to say where to find "sh". That suggests using an + environment variable, but after a few more such situations we may + have too many of them. */ + char *sh = getenv ("SH_PATH"); + if (sh == NULL) + sh = "/bin/sh"; + _execve (sh, argv, environ); + exit (100); + } + else if (pid == -1) + return -1; + else + { + extern int _wait (int *); + int rc = _wait (&status); + if (rc == -1) + return -1; + status = (status >> 8) & 0xff; + return status; + } +} +#endif diff --git a/contrib/sdk/sources/newlib/libc/stdlib/wcrtomb.c b/contrib/sdk/sources/newlib/libc/stdlib/wcrtomb.c index b699708ee3..4f30068140 100644 --- a/contrib/sdk/sources/newlib/libc/stdlib/wcrtomb.c +++ b/contrib/sdk/sources/newlib/libc/stdlib/wcrtomb.c @@ -1,78 +1,79 @@ -#include -#include -#include -#include -#include -#include -#include "local.h" - -size_t -_DEFUN (_wcrtomb_r, (ptr, s, wc, ps), - struct _reent *ptr _AND - char *s _AND - wchar_t wc _AND - mbstate_t *ps) -{ - int retval = 0; - char buf[10]; - -#ifdef _MB_CAPABLE - if (ps == NULL) - { - _REENT_CHECK_MISC(ptr); - ps = &(_REENT_WCRTOMB_STATE(ptr)); - } -#endif - - if (s == NULL) - retval = __wctomb (ptr, buf, L'\0', __locale_charset (), ps); - else - retval = __wctomb (ptr, s, wc, __locale_charset (), ps); - - if (retval == -1) - { - ps->__count = 0; - ptr->_errno = EILSEQ; - return (size_t)(-1); - } - else - return (size_t)retval; -} - -#ifndef _REENT_ONLY -size_t -_DEFUN (wcrtomb, (s, wc, ps), - char *s _AND - wchar_t wc _AND - mbstate_t *ps) -{ -#if defined(PREFER_SIZE_OVER_SPEED) || defined(__OPTIMIZE_SIZE__) - return _wcrtomb_r (_REENT, s, wc, ps); -#else - int retval = 0; - char buf[10]; - -#ifdef _MB_CAPABLE - if (ps == NULL) - { - _REENT_CHECK_MISC(_REENT); - ps = &(_REENT_WCRTOMB_STATE(_REENT)); - } -#endif - - if (s == NULL) - retval = __wctomb (_REENT, buf, L'\0', __locale_charset (), ps); - else - retval = __wctomb (_REENT, s, wc, __locale_charset (), ps); - - if (retval == -1) - { - ps->__count = 0; - _REENT->_errno = EILSEQ; - return (size_t)(-1); - } - else - return (size_t)retval; -#endif /* not PREFER_SIZE_OVER_SPEED */ -} -#endif /* !_REENT_ONLY */ +#include +#include +#include +#include +#include +#include +#include "local.h" + +size_t +_DEFUN (_wcrtomb_r, (ptr, s, wc, ps), + struct _reent *ptr _AND + char *s _AND + wchar_t wc _AND + mbstate_t *ps) +{ + int retval = 0; + char buf[10]; + +#ifdef _MB_CAPABLE + if (ps == NULL) + { + _REENT_CHECK_MISC(ptr); + ps = &(_REENT_WCRTOMB_STATE(ptr)); + } +#endif + + if (s == NULL) + retval = __wctomb (ptr, buf, L'\0', __locale_charset (), ps); + else + retval = __wctomb (ptr, s, wc, __locale_charset (), ps); + + if (retval == -1) + { + ps->__count = 0; + ptr->_errno = EILSEQ; + return (size_t)(-1); + } + else + return (size_t)retval; +} + +#ifndef _REENT_ONLY +size_t +_DEFUN (wcrtomb, (s, wc, ps), + char *__restrict s _AND + wchar_t wc _AND + mbstate_t *__restrict ps) +{ +#if defined(PREFER_SIZE_OVER_SPEED) || defined(__OPTIMIZE_SIZE__) + return _wcrtomb_r (_REENT, s, wc, ps); +#else + int retval = 0; + struct _reent *reent = _REENT; + char buf[10]; + +#ifdef _MB_CAPABLE + if (ps == NULL) + { + _REENT_CHECK_MISC(reent); + ps = &(_REENT_WCRTOMB_STATE(reent)); + } +#endif + + if (s == NULL) + retval = __wctomb (reent, buf, L'\0', __locale_charset (), ps); + else + retval = __wctomb (reent, s, wc, __locale_charset (), ps); + + if (retval == -1) + { + ps->__count = 0; + reent->_errno = EILSEQ; + return (size_t)(-1); + } + else + return (size_t)retval; +#endif /* not PREFER_SIZE_OVER_SPEED */ +} +#endif /* !_REENT_ONLY */ diff --git a/contrib/sdk/sources/newlib/libc/stdlib/wctomb_r.c b/contrib/sdk/sources/newlib/libc/stdlib/wctomb_r.c index 2f1439525d..13e1e4c36f 100644 --- a/contrib/sdk/sources/newlib/libc/stdlib/wctomb_r.c +++ b/contrib/sdk/sources/newlib/libc/stdlib/wctomb_r.c @@ -1,376 +1,376 @@ -#include -#include -#include -#include -#include -#include "mbctype.h" -#include "local.h" - -int (*__wctomb) (struct _reent *, char *, wchar_t, const char *charset, - mbstate_t *) -#ifdef __CYGWIN__ - /* Cygwin starts up in UTF-8 mode. */ - = __utf8_wctomb; -#else - = __ascii_wctomb; -#endif - -int -_DEFUN (_wctomb_r, (r, s, wchar, state), - struct _reent *r _AND - char *s _AND - wchar_t _wchar _AND - mbstate_t *state) -{ - return __wctomb (r, s, _wchar, __locale_charset (), state); -} - -int -_DEFUN (__ascii_wctomb, (r, s, wchar, charset, state), - struct _reent *r _AND - char *s _AND - wchar_t _wchar _AND - const char *charset _AND - mbstate_t *state) -{ - /* Avoids compiler warnings about comparisons that are always false - due to limited range when sizeof(wchar_t) is 2 but sizeof(wint_t) - is 4, as is the case on cygwin. */ - wint_t wchar = _wchar; - - if (s == NULL) - return 0; - -#ifdef __CYGWIN__ - if ((size_t)wchar >= 0x80) -#else - if ((size_t)wchar >= 0x100) -#endif - { - r->_errno = EILSEQ; - return -1; - } - - *s = (char) wchar; - return 1; -} - -#ifdef _MB_CAPABLE -/* for some conversions, we use the __count field as a place to store a state value */ -#define __state __count - -int -_DEFUN (__utf8_wctomb, (r, s, wchar, charset, state), - struct _reent *r _AND - char *s _AND - wchar_t _wchar _AND - const char *charset _AND - mbstate_t *state) -{ - wint_t wchar = _wchar; - int ret = 0; - - if (s == NULL) - return 0; /* UTF-8 encoding is not state-dependent */ - - if (sizeof (wchar_t) == 2 && state->__count == -4 - && (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 - to return extra 3 bytes. */ - wchar_t tmp; - tmp = (state->__value.__wchb[0] << 16 | state->__value.__wchb[1] << 8) - - 0x10000 >> 10 | 0xd80d; - *s++ = 0xe0 | ((tmp & 0xf000) >> 12); - *s++ = 0x80 | ((tmp & 0xfc0) >> 6); - *s++ = 0x80 | (tmp & 0x3f); - state->__count = 0; - ret = 3; - } - if (wchar <= 0x7f) - { - *s = wchar; - return ret + 1; - } - if (wchar >= 0x80 && wchar <= 0x7ff) - { - *s++ = 0xc0 | ((wchar & 0x7c0) >> 6); - *s = 0x80 | (wchar & 0x3f); - return ret + 2; - } - if (wchar >= 0x800 && wchar <= 0xffff) - { - /* No UTF-16 surrogate handling in UCS-4 */ - if (sizeof (wchar_t) == 2 && wchar >= 0xd800 && wchar <= 0xdfff) - { - wint_t tmp; - if (wchar <= 0xdbff) - { - /* First half of a surrogate pair. Store the state and - return ret + 0. */ - tmp = ((wchar & 0x3ff) << 10) + 0x10000; - state->__value.__wchb[0] = (tmp >> 16) & 0xff; - state->__value.__wchb[1] = (tmp >> 8) & 0xff; - state->__count = -4; - *s = (0xf0 | ((tmp & 0x1c0000) >> 18)); - return ret; - } - if (state->__count == -4) - { - /* Second half of a surrogate pair. Reconstruct the full - Unicode value and return the trailing three bytes of the - UTF-8 character. */ - tmp = (state->__value.__wchb[0] << 16) - | (state->__value.__wchb[1] << 8) - | (wchar & 0x3ff); - state->__count = 0; - *s++ = 0xf0 | ((tmp & 0x1c0000) >> 18); - *s++ = 0x80 | ((tmp & 0x3f000) >> 12); - *s++ = 0x80 | ((tmp & 0xfc0) >> 6); - *s = 0x80 | (tmp & 0x3f); - return 4; - } - /* Otherwise translate into CESU-8 value. */ - } - *s++ = 0xe0 | ((wchar & 0xf000) >> 12); - *s++ = 0x80 | ((wchar & 0xfc0) >> 6); - *s = 0x80 | (wchar & 0x3f); - return ret + 3; - } - if (wchar >= 0x10000 && wchar <= 0x10ffff) - { - *s++ = 0xf0 | ((wchar & 0x1c0000) >> 18); - *s++ = 0x80 | ((wchar & 0x3f000) >> 12); - *s++ = 0x80 | ((wchar & 0xfc0) >> 6); - *s = 0x80 | (wchar & 0x3f); - return 4; - } - - r->_errno = EILSEQ; - return -1; -} - -/* Cygwin defines its own doublebyte charset conversion functions - because the underlying OS requires wchar_t == UTF-16. */ -#ifndef __CYGWIN__ -int -_DEFUN (__sjis_wctomb, (r, s, wchar, charset, state), - struct _reent *r _AND - char *s _AND - wchar_t _wchar _AND - const char *charset _AND - mbstate_t *state) -{ - wint_t wchar = _wchar; - - unsigned char char2 = (unsigned char)wchar; - unsigned char char1 = (unsigned char)(wchar >> 8); - - if (s == NULL) - return 0; /* not state-dependent */ - - if (char1 != 0x00) - { - /* first byte is non-zero..validate multi-byte char */ - if (_issjis1(char1) && _issjis2(char2)) - { - *s++ = (char)char1; - *s = (char)char2; - return 2; - } - else - { - r->_errno = EILSEQ; - return -1; - } - } - *s = (char) wchar; - return 1; -} - -int -_DEFUN (__eucjp_wctomb, (r, s, wchar, charset, state), - struct _reent *r _AND - char *s _AND - wchar_t _wchar _AND - const char *charset _AND - mbstate_t *state) -{ - wint_t wchar = _wchar; - unsigned char char2 = (unsigned char)wchar; - unsigned char char1 = (unsigned char)(wchar >> 8); - - if (s == NULL) - return 0; /* not state-dependent */ - - if (char1 != 0x00) - { - /* first byte is non-zero..validate multi-byte char */ - if (_iseucjp1 (char1) && _iseucjp2 (char2)) - { - *s++ = (char)char1; - *s = (char)char2; - return 2; - } - else if (_iseucjp2 (char1) && _iseucjp2 (char2 | 0x80)) - { - *s++ = (char)0x8f; - *s++ = (char)char1; - *s = (char)(char2 | 0x80); - return 3; - } - else - { - r->_errno = EILSEQ; - return -1; - } - } - *s = (char) wchar; - return 1; -} - -int -_DEFUN (__jis_wctomb, (r, s, wchar, charset, state), - struct _reent *r _AND - char *s _AND - wchar_t _wchar _AND - const char *charset _AND - mbstate_t *state) -{ - wint_t wchar = _wchar; - int cnt = 0; - unsigned char char2 = (unsigned char)wchar; - unsigned char char1 = (unsigned char)(wchar >> 8); - - if (s == NULL) - return 1; /* state-dependent */ - - if (char1 != 0x00) - { - /* first byte is non-zero..validate multi-byte char */ - if (_isjis (char1) && _isjis (char2)) - { - if (state->__state == 0) - { - /* must switch from ASCII to JIS state */ - state->__state = 1; - *s++ = ESC_CHAR; - *s++ = '$'; - *s++ = 'B'; - cnt = 3; - } - *s++ = (char)char1; - *s = (char)char2; - return cnt + 2; - } - r->_errno = EILSEQ; - return -1; - } - if (state->__state != 0) - { - /* must switch from JIS to ASCII state */ - state->__state = 0; - *s++ = ESC_CHAR; - *s++ = '('; - *s++ = 'B'; - cnt = 3; - } - *s = (char)char2; - return cnt + 1; -} -#endif /* !__CYGWIN__ */ - -#ifdef _MB_EXTENDED_CHARSETS_ISO -int -_DEFUN (__iso_wctomb, (r, s, wchar, charset, state), - struct _reent *r _AND - char *s _AND - wchar_t _wchar _AND - const char *charset _AND - mbstate_t *state) -{ - wint_t wchar = _wchar; - - if (s == NULL) - return 0; - - /* wchars <= 0x9f translate to all ISO charsets directly. */ - if (wchar >= 0xa0) - { - int iso_idx = __iso_8859_index (charset + 9); - if (iso_idx >= 0) - { - unsigned char mb; - - if (s == NULL) - return 0; - - for (mb = 0; mb < 0x60; ++mb) - if (__iso_8859_conv[iso_idx][mb] == wchar) - { - *s = (char) (mb + 0xa0); - return 1; - } - r->_errno = EILSEQ; - return -1; - } - } - - if ((size_t)wchar >= 0x100) - { - r->_errno = EILSEQ; - return -1; - } - - *s = (char) wchar; - return 1; -} -#endif /* _MB_EXTENDED_CHARSETS_ISO */ - -#ifdef _MB_EXTENDED_CHARSETS_WINDOWS -int -_DEFUN (__cp_wctomb, (r, s, wchar, charset, state), - struct _reent *r _AND - char *s _AND - wchar_t _wchar _AND - const char *charset _AND - mbstate_t *state) -{ - wint_t wchar = _wchar; - - if (s == NULL) - return 0; - - if (wchar >= 0x80) - { - int cp_idx = __cp_index (charset + 2); - if (cp_idx >= 0) - { - unsigned char mb; - - if (s == NULL) - return 0; - - for (mb = 0; mb < 0x80; ++mb) - if (__cp_conv[cp_idx][mb] == wchar) - { - *s = (char) (mb + 0x80); - return 1; - } - r->_errno = EILSEQ; - return -1; - } - } - - if ((size_t)wchar >= 0x100) - { - r->_errno = EILSEQ; - return -1; - } - - *s = (char) wchar; - return 1; -} -#endif /* _MB_EXTENDED_CHARSETS_WINDOWS */ -#endif /* _MB_CAPABLE */ +#include +#include +#include +#include +#include +#include "mbctype.h" +#include "local.h" + +int (*__wctomb) (struct _reent *, char *, wchar_t, const char *charset, + mbstate_t *) +#ifdef __CYGWIN__ + /* Cygwin starts up in UTF-8 mode. */ + = __utf8_wctomb; +#else + = __ascii_wctomb; +#endif + +int +_DEFUN (_wctomb_r, (r, s, wchar, state), + struct _reent *r _AND + char *s _AND + wchar_t _wchar _AND + mbstate_t *state) +{ + return __wctomb (r, s, _wchar, __locale_charset (), state); +} + +int +_DEFUN (__ascii_wctomb, (r, s, wchar, charset, state), + struct _reent *r _AND + char *s _AND + wchar_t _wchar _AND + const char *charset _AND + mbstate_t *state) +{ + /* Avoids compiler warnings about comparisons that are always false + due to limited range when sizeof(wchar_t) is 2 but sizeof(wint_t) + is 4, as is the case on cygwin. */ + wint_t wchar = _wchar; + + if (s == NULL) + return 0; + +#ifdef __CYGWIN__ + if ((size_t)wchar >= 0x80) +#else + if ((size_t)wchar >= 0x100) +#endif + { + r->_errno = EILSEQ; + return -1; + } + + *s = (char) wchar; + return 1; +} + +#ifdef _MB_CAPABLE +/* for some conversions, we use the __count field as a place to store a state value */ +#define __state __count + +int +_DEFUN (__utf8_wctomb, (r, s, wchar, charset, state), + struct _reent *r _AND + char *s _AND + wchar_t _wchar _AND + const char *charset _AND + mbstate_t *state) +{ + wint_t wchar = _wchar; + int ret = 0; + + if (s == NULL) + return 0; /* UTF-8 encoding is not state-dependent */ + + if (sizeof (wchar_t) == 2 && state->__count == -4 + && (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 + to return extra 3 bytes. */ + wchar_t tmp; + tmp = (state->__value.__wchb[0] << 16 | state->__value.__wchb[1] << 8) + - (0x10000 >> 10 | 0xd80d); + *s++ = 0xe0 | ((tmp & 0xf000) >> 12); + *s++ = 0x80 | ((tmp & 0xfc0) >> 6); + *s++ = 0x80 | (tmp & 0x3f); + state->__count = 0; + ret = 3; + } + if (wchar <= 0x7f) + { + *s = wchar; + return ret + 1; + } + if (wchar >= 0x80 && wchar <= 0x7ff) + { + *s++ = 0xc0 | ((wchar & 0x7c0) >> 6); + *s = 0x80 | (wchar & 0x3f); + return ret + 2; + } + if (wchar >= 0x800 && wchar <= 0xffff) + { + /* No UTF-16 surrogate handling in UCS-4 */ + if (sizeof (wchar_t) == 2 && wchar >= 0xd800 && wchar <= 0xdfff) + { + wint_t tmp; + if (wchar <= 0xdbff) + { + /* First half of a surrogate pair. Store the state and + return ret + 0. */ + tmp = ((wchar & 0x3ff) << 10) + 0x10000; + state->__value.__wchb[0] = (tmp >> 16) & 0xff; + state->__value.__wchb[1] = (tmp >> 8) & 0xff; + state->__count = -4; + *s = (0xf0 | ((tmp & 0x1c0000) >> 18)); + return ret; + } + if (state->__count == -4) + { + /* Second half of a surrogate pair. Reconstruct the full + Unicode value and return the trailing three bytes of the + UTF-8 character. */ + tmp = (state->__value.__wchb[0] << 16) + | (state->__value.__wchb[1] << 8) + | (wchar & 0x3ff); + state->__count = 0; + *s++ = 0xf0 | ((tmp & 0x1c0000) >> 18); + *s++ = 0x80 | ((tmp & 0x3f000) >> 12); + *s++ = 0x80 | ((tmp & 0xfc0) >> 6); + *s = 0x80 | (tmp & 0x3f); + return 4; + } + /* Otherwise translate into CESU-8 value. */ + } + *s++ = 0xe0 | ((wchar & 0xf000) >> 12); + *s++ = 0x80 | ((wchar & 0xfc0) >> 6); + *s = 0x80 | (wchar & 0x3f); + return ret + 3; + } + if (wchar >= 0x10000 && wchar <= 0x10ffff) + { + *s++ = 0xf0 | ((wchar & 0x1c0000) >> 18); + *s++ = 0x80 | ((wchar & 0x3f000) >> 12); + *s++ = 0x80 | ((wchar & 0xfc0) >> 6); + *s = 0x80 | (wchar & 0x3f); + return 4; + } + + r->_errno = EILSEQ; + return -1; +} + +/* Cygwin defines its own doublebyte charset conversion functions + because the underlying OS requires wchar_t == UTF-16. */ +#ifndef __CYGWIN__ +int +_DEFUN (__sjis_wctomb, (r, s, wchar, charset, state), + struct _reent *r _AND + char *s _AND + wchar_t _wchar _AND + const char *charset _AND + mbstate_t *state) +{ + wint_t wchar = _wchar; + + unsigned char char2 = (unsigned char)wchar; + unsigned char char1 = (unsigned char)(wchar >> 8); + + if (s == NULL) + return 0; /* not state-dependent */ + + if (char1 != 0x00) + { + /* first byte is non-zero..validate multi-byte char */ + if (_issjis1(char1) && _issjis2(char2)) + { + *s++ = (char)char1; + *s = (char)char2; + return 2; + } + else + { + r->_errno = EILSEQ; + return -1; + } + } + *s = (char) wchar; + return 1; +} + +int +_DEFUN (__eucjp_wctomb, (r, s, wchar, charset, state), + struct _reent *r _AND + char *s _AND + wchar_t _wchar _AND + const char *charset _AND + mbstate_t *state) +{ + wint_t wchar = _wchar; + unsigned char char2 = (unsigned char)wchar; + unsigned char char1 = (unsigned char)(wchar >> 8); + + if (s == NULL) + return 0; /* not state-dependent */ + + if (char1 != 0x00) + { + /* first byte is non-zero..validate multi-byte char */ + if (_iseucjp1 (char1) && _iseucjp2 (char2)) + { + *s++ = (char)char1; + *s = (char)char2; + return 2; + } + else if (_iseucjp2 (char1) && _iseucjp2 (char2 | 0x80)) + { + *s++ = (char)0x8f; + *s++ = (char)char1; + *s = (char)(char2 | 0x80); + return 3; + } + else + { + r->_errno = EILSEQ; + return -1; + } + } + *s = (char) wchar; + return 1; +} + +int +_DEFUN (__jis_wctomb, (r, s, wchar, charset, state), + struct _reent *r _AND + char *s _AND + wchar_t _wchar _AND + const char *charset _AND + mbstate_t *state) +{ + wint_t wchar = _wchar; + int cnt = 0; + unsigned char char2 = (unsigned char)wchar; + unsigned char char1 = (unsigned char)(wchar >> 8); + + if (s == NULL) + return 1; /* state-dependent */ + + if (char1 != 0x00) + { + /* first byte is non-zero..validate multi-byte char */ + if (_isjis (char1) && _isjis (char2)) + { + if (state->__state == 0) + { + /* must switch from ASCII to JIS state */ + state->__state = 1; + *s++ = ESC_CHAR; + *s++ = '$'; + *s++ = 'B'; + cnt = 3; + } + *s++ = (char)char1; + *s = (char)char2; + return cnt + 2; + } + r->_errno = EILSEQ; + return -1; + } + if (state->__state != 0) + { + /* must switch from JIS to ASCII state */ + state->__state = 0; + *s++ = ESC_CHAR; + *s++ = '('; + *s++ = 'B'; + cnt = 3; + } + *s = (char)char2; + return cnt + 1; +} +#endif /* !__CYGWIN__ */ + +#ifdef _MB_EXTENDED_CHARSETS_ISO +int +_DEFUN (__iso_wctomb, (r, s, wchar, charset, state), + struct _reent *r _AND + char *s _AND + wchar_t _wchar _AND + const char *charset _AND + mbstate_t *state) +{ + wint_t wchar = _wchar; + + if (s == NULL) + return 0; + + /* wchars <= 0x9f translate to all ISO charsets directly. */ + if (wchar >= 0xa0) + { + int iso_idx = __iso_8859_index (charset + 9); + if (iso_idx >= 0) + { + unsigned char mb; + + if (s == NULL) + return 0; + + for (mb = 0; mb < 0x60; ++mb) + if (__iso_8859_conv[iso_idx][mb] == wchar) + { + *s = (char) (mb + 0xa0); + return 1; + } + r->_errno = EILSEQ; + return -1; + } + } + + if ((size_t)wchar >= 0x100) + { + r->_errno = EILSEQ; + return -1; + } + + *s = (char) wchar; + return 1; +} +#endif /* _MB_EXTENDED_CHARSETS_ISO */ + +#ifdef _MB_EXTENDED_CHARSETS_WINDOWS +int +_DEFUN (__cp_wctomb, (r, s, wchar, charset, state), + struct _reent *r _AND + char *s _AND + wchar_t _wchar _AND + const char *charset _AND + mbstate_t *state) +{ + wint_t wchar = _wchar; + + if (s == NULL) + return 0; + + if (wchar >= 0x80) + { + int cp_idx = __cp_index (charset + 2); + if (cp_idx >= 0) + { + unsigned char mb; + + if (s == NULL) + return 0; + + for (mb = 0; mb < 0x80; ++mb) + if (__cp_conv[cp_idx][mb] == wchar) + { + *s = (char) (mb + 0x80); + return 1; + } + r->_errno = EILSEQ; + return -1; + } + } + + if ((size_t)wchar >= 0x100) + { + r->_errno = EILSEQ; + return -1; + } + + *s = (char) wchar; + return 1; +} +#endif /* _MB_EXTENDED_CHARSETS_WINDOWS */ +#endif /* _MB_CAPABLE */ diff --git a/contrib/sdk/sources/newlib/libc/string/local.h b/contrib/sdk/sources/newlib/libc/string/local.h index e9aff40b4c..909cbbe4e5 100644 --- a/contrib/sdk/sources/newlib/libc/string/local.h +++ b/contrib/sdk/sources/newlib/libc/string/local.h @@ -7,3 +7,18 @@ 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 + + diff --git a/contrib/sdk/sources/newlib/libc/string/memcpy.c b/contrib/sdk/sources/newlib/libc/string/memcpy.c index 20bb178916..5f27bca727 100644 --- a/contrib/sdk/sources/newlib/libc/string/memcpy.c +++ b/contrib/sdk/sources/newlib/libc/string/memcpy.c @@ -1,110 +1,111 @@ -/* -FUNCTION - <>---copy memory regions - -ANSI_SYNOPSIS - #include - void* memcpy(void *<[out]>, const void *<[in]>, size_t <[n]>); - -TRAD_SYNOPSIS - #include - void *memcpy(<[out]>, <[in]>, <[n]> - void *<[out]>; - void *<[in]>; - size_t <[n]>; - -DESCRIPTION - This function copies <[n]> bytes from the memory region - pointed to by <[in]> to the memory region pointed to by - <[out]>. - - If the regions overlap, the behavior is undefined. - -RETURNS - <> returns a pointer to the first byte of the <[out]> - region. - -PORTABILITY -<> is ANSI C. - -<> requires no supporting OS subroutines. - -QUICKREF - memcpy ansi pure - */ - -#include <_ansi.h> -#include - -/* Nonzero if either X or Y is not aligned on a "long" boundary. */ -#define UNALIGNED(X, Y) \ - (((long)X & (sizeof (long) - 1)) | ((long)Y & (sizeof (long) - 1))) - -/* How many bytes are copied each iteration of the 4X unrolled loop. */ -#define BIGBLOCKSIZE (sizeof (long) << 2) - -/* How many bytes are copied each iteration of the word copy loop. */ -#define LITTLEBLOCKSIZE (sizeof (long)) - -/* Threshhold for punting to the byte copier. */ -#define TOO_SMALL(LEN) ((LEN) < BIGBLOCKSIZE) - -_PTR -_DEFUN (memcpy, (dst0, src0, len0), - _PTR dst0 _AND - _CONST _PTR src0 _AND - size_t len0) -{ -#if defined(PREFER_SIZE_OVER_SPEED) || defined(__OPTIMIZE_SIZE__) - char *dst = (char *) dst0; - char *src = (char *) src0; - - _PTR save = dst0; - - while (len0--) - { - *dst++ = *src++; - } - - return save; -#else - char *dst = dst0; - _CONST char *src = src0; - long *aligned_dst; - _CONST long *aligned_src; - - /* If the size is small, or either SRC or DST is unaligned, - then punt into the byte copy loop. This should be rare. */ - if (!TOO_SMALL(len0) && !UNALIGNED (src, dst)) - { - aligned_dst = (long*)dst; - aligned_src = (long*)src; - - /* Copy 4X long words at a time if possible. */ - while (len0 >= BIGBLOCKSIZE) - { - *aligned_dst++ = *aligned_src++; - *aligned_dst++ = *aligned_src++; - *aligned_dst++ = *aligned_src++; - *aligned_dst++ = *aligned_src++; - len0 -= BIGBLOCKSIZE; - } - - /* Copy one long word at a time if possible. */ - while (len0 >= LITTLEBLOCKSIZE) - { - *aligned_dst++ = *aligned_src++; - len0 -= LITTLEBLOCKSIZE; - } - - /* Pick up any residual with a byte copier. */ - dst = (char*)aligned_dst; - src = (char*)aligned_src; - } - - while (len0--) - *dst++ = *src++; - - return dst0; -#endif /* not PREFER_SIZE_OVER_SPEED */ -} +/* +FUNCTION + <>---copy memory regions + +ANSI_SYNOPSIS + #include + void* memcpy(void *restrict <[out]>, const void *restrict <[in]>, + size_t <[n]>); + +TRAD_SYNOPSIS + #include + void *memcpy(<[out]>, <[in]>, <[n]> + void *<[out]>; + void *<[in]>; + size_t <[n]>; + +DESCRIPTION + This function copies <[n]> bytes from the memory region + pointed to by <[in]> to the memory region pointed to by + <[out]>. + + If the regions overlap, the behavior is undefined. + +RETURNS + <> returns a pointer to the first byte of the <[out]> + region. + +PORTABILITY +<> is ANSI C. + +<> requires no supporting OS subroutines. + +QUICKREF + memcpy ansi pure + */ + +#include <_ansi.h> +#include + +/* Nonzero if either X or Y is not aligned on a "long" boundary. */ +#define UNALIGNED(X, Y) \ + (((long)X & (sizeof (long) - 1)) | ((long)Y & (sizeof (long) - 1))) + +/* How many bytes are copied each iteration of the 4X unrolled loop. */ +#define BIGBLOCKSIZE (sizeof (long) << 2) + +/* How many bytes are copied each iteration of the word copy loop. */ +#define LITTLEBLOCKSIZE (sizeof (long)) + +/* Threshhold for punting to the byte copier. */ +#define TOO_SMALL(LEN) ((LEN) < BIGBLOCKSIZE) + +_PTR +_DEFUN (memcpy, (dst0, src0, len0), + _PTR __restrict dst0 _AND + _CONST _PTR __restrict src0 _AND + size_t len0) +{ +#if defined(PREFER_SIZE_OVER_SPEED) || defined(__OPTIMIZE_SIZE__) + char *dst = (char *) dst0; + char *src = (char *) src0; + + _PTR save = dst0; + + while (len0--) + { + *dst++ = *src++; + } + + return save; +#else + char *dst = dst0; + _CONST char *src = src0; + long *aligned_dst; + _CONST long *aligned_src; + + /* If the size is small, or either SRC or DST is unaligned, + then punt into the byte copy loop. This should be rare. */ + if (!TOO_SMALL(len0) && !UNALIGNED (src, dst)) + { + aligned_dst = (long*)dst; + aligned_src = (long*)src; + + /* Copy 4X long words at a time if possible. */ + while (len0 >= BIGBLOCKSIZE) + { + *aligned_dst++ = *aligned_src++; + *aligned_dst++ = *aligned_src++; + *aligned_dst++ = *aligned_src++; + *aligned_dst++ = *aligned_src++; + len0 -= BIGBLOCKSIZE; + } + + /* Copy one long word at a time if possible. */ + while (len0 >= LITTLEBLOCKSIZE) + { + *aligned_dst++ = *aligned_src++; + len0 -= LITTLEBLOCKSIZE; + } + + /* Pick up any residual with a byte copier. */ + dst = (char*)aligned_dst; + src = (char*)aligned_src; + } + + while (len0--) + *dst++ = *src++; + + return dst0; +#endif /* not PREFER_SIZE_OVER_SPEED */ +} diff --git a/contrib/sdk/sources/newlib/libc/string/memmove.c b/contrib/sdk/sources/newlib/libc/string/memmove.c index 221d260e4a..a037c7c2ff 100644 --- a/contrib/sdk/sources/newlib/libc/string/memmove.c +++ b/contrib/sdk/sources/newlib/libc/string/memmove.c @@ -1,142 +1,144 @@ -/* -FUNCTION - <>---move possibly overlapping memory - -INDEX - memmove - -ANSI_SYNOPSIS - #include - void *memmove(void *<[dst]>, const void *<[src]>, size_t <[length]>); - -TRAD_SYNOPSIS - #include - void *memmove(<[dst]>, <[src]>, <[length]>) - void *<[dst]>; - void *<[src]>; - size_t <[length]>; - -DESCRIPTION - This function moves <[length]> characters from the block of - memory starting at <<*<[src]>>> to the memory starting at - <<*<[dst]>>>. <> reproduces the characters correctly - at <<*<[dst]>>> even if the two areas overlap. - - -RETURNS - The function returns <[dst]> as passed. - -PORTABILITY -<> is ANSI C. - -<> requires no supporting OS subroutines. - -QUICKREF - memmove ansi pure -*/ - -#include -#include <_ansi.h> -#include -#include - -/* Nonzero if either X or Y is not aligned on a "long" boundary. */ -#define UNALIGNED(X, Y) \ - (((long)X & (sizeof (long) - 1)) | ((long)Y & (sizeof (long) - 1))) - -/* How many bytes are copied each iteration of the 4X unrolled loop. */ -#define BIGBLOCKSIZE (sizeof (long) << 2) - -/* How many bytes are copied each iteration of the word copy loop. */ -#define LITTLEBLOCKSIZE (sizeof (long)) - -/* Threshhold for punting to the byte copier. */ -#define TOO_SMALL(LEN) ((LEN) < BIGBLOCKSIZE) - -/*SUPPRESS 20*/ -_PTR -_DEFUN (memmove, (dst_void, src_void, length), - _PTR dst_void _AND - _CONST _PTR src_void _AND - size_t length) -{ -#if defined(PREFER_SIZE_OVER_SPEED) || defined(__OPTIMIZE_SIZE__) - char *dst = dst_void; - _CONST char *src = src_void; - - if (src < dst && dst < src + length) - { - /* Have to copy backwards */ - src += length; - dst += length; - while (length--) - { - *--dst = *--src; - } - } - else - { - while (length--) - { - *dst++ = *src++; - } - } - - return dst_void; -#else - char *dst = dst_void; - _CONST char *src = src_void; - long *aligned_dst; - _CONST long *aligned_src; - - if (src < dst && dst < src + length) - { - /* Destructive overlap...have to copy backwards */ - src += length; - dst += length; - while (length--) - { - *--dst = *--src; - } - } - else - { - /* Use optimizing algorithm for a non-destructive copy to closely - match memcpy. If the size is small or either SRC or DST is unaligned, - then punt into the byte copy loop. This should be rare. */ - if (!TOO_SMALL(length) && !UNALIGNED (src, dst)) - { - aligned_dst = (long*)dst; - aligned_src = (long*)src; - - /* Copy 4X long words at a time if possible. */ - while (length >= BIGBLOCKSIZE) - { - *aligned_dst++ = *aligned_src++; - *aligned_dst++ = *aligned_src++; - *aligned_dst++ = *aligned_src++; - *aligned_dst++ = *aligned_src++; - length -= BIGBLOCKSIZE; - } - - /* Copy one long word at a time if possible. */ - while (length >= LITTLEBLOCKSIZE) - { - *aligned_dst++ = *aligned_src++; - length -= LITTLEBLOCKSIZE; - } - - /* Pick up any residual with a byte copier. */ - dst = (char*)aligned_dst; - src = (char*)aligned_src; - } - - while (length--) - { - *dst++ = *src++; - } - } - - return dst_void; -#endif /* not PREFER_SIZE_OVER_SPEED */ -} +/* +FUNCTION + <>---move possibly overlapping memory + +INDEX + memmove + +ANSI_SYNOPSIS + #include + void *memmove(void *<[dst]>, const void *<[src]>, size_t <[length]>); + +TRAD_SYNOPSIS + #include + void *memmove(<[dst]>, <[src]>, <[length]>) + void *<[dst]>; + void *<[src]>; + size_t <[length]>; + +DESCRIPTION + This function moves <[length]> characters from the block of + memory starting at <<*<[src]>>> to the memory starting at + <<*<[dst]>>>. <> reproduces the characters correctly + at <<*<[dst]>>> even if the two areas overlap. + + +RETURNS + The function returns <[dst]> as passed. + +PORTABILITY +<> is ANSI C. + +<> requires no supporting OS subroutines. + +QUICKREF + memmove ansi pure +*/ + +#include +#include <_ansi.h> +#include +#include +#include "local.h" + +/* Nonzero if either X or Y is not aligned on a "long" boundary. */ +#define UNALIGNED(X, Y) \ + (((long)X & (sizeof (long) - 1)) | ((long)Y & (sizeof (long) - 1))) + +/* How many bytes are copied each iteration of the 4X unrolled loop. */ +#define BIGBLOCKSIZE (sizeof (long) << 2) + +/* How many bytes are copied each iteration of the word copy loop. */ +#define LITTLEBLOCKSIZE (sizeof (long)) + +/* Threshhold for punting to the byte copier. */ +#define TOO_SMALL(LEN) ((LEN) < BIGBLOCKSIZE) + +/*SUPPRESS 20*/ +_PTR +__inhibit_loop_to_libcall +_DEFUN (memmove, (dst_void, src_void, length), + _PTR dst_void _AND + _CONST _PTR src_void _AND + size_t length) +{ +#if defined(PREFER_SIZE_OVER_SPEED) || defined(__OPTIMIZE_SIZE__) + char *dst = dst_void; + _CONST char *src = src_void; + + if (src < dst && dst < src + length) + { + /* Have to copy backwards */ + src += length; + dst += length; + while (length--) + { + *--dst = *--src; + } + } + else + { + while (length--) + { + *dst++ = *src++; + } + } + + return dst_void; +#else + char *dst = dst_void; + _CONST char *src = src_void; + long *aligned_dst; + _CONST long *aligned_src; + + if (src < dst && dst < src + length) + { + /* Destructive overlap...have to copy backwards */ + src += length; + dst += length; + while (length--) + { + *--dst = *--src; + } + } + else + { + /* Use optimizing algorithm for a non-destructive copy to closely + match memcpy. If the size is small or either SRC or DST is unaligned, + then punt into the byte copy loop. This should be rare. */ + if (!TOO_SMALL(length) && !UNALIGNED (src, dst)) + { + aligned_dst = (long*)dst; + aligned_src = (long*)src; + + /* Copy 4X long words at a time if possible. */ + while (length >= BIGBLOCKSIZE) + { + *aligned_dst++ = *aligned_src++; + *aligned_dst++ = *aligned_src++; + *aligned_dst++ = *aligned_src++; + *aligned_dst++ = *aligned_src++; + length -= BIGBLOCKSIZE; + } + + /* Copy one long word at a time if possible. */ + while (length >= LITTLEBLOCKSIZE) + { + *aligned_dst++ = *aligned_src++; + length -= LITTLEBLOCKSIZE; + } + + /* Pick up any residual with a byte copier. */ + dst = (char*)aligned_dst; + src = (char*)aligned_src; + } + + while (length--) + { + *dst++ = *src++; + } + } + + return dst_void; +#endif /* not PREFER_SIZE_OVER_SPEED */ +} diff --git a/contrib/sdk/sources/newlib/libc/string/memset.c b/contrib/sdk/sources/newlib/libc/string/memset.c index 9ff8024931..734bec2684 100644 --- a/contrib/sdk/sources/newlib/libc/string/memset.c +++ b/contrib/sdk/sources/newlib/libc/string/memset.c @@ -34,12 +34,14 @@ QUICKREF */ #include +#include "local.h" #define LBLOCKSIZE (sizeof(long)) #define UNALIGNED(X) ((long)X & (LBLOCKSIZE - 1)) #define TOO_SMALL(LEN) ((LEN) < LBLOCKSIZE) _PTR +__inhibit_loop_to_libcall _DEFUN (memset, (m, c, n), _PTR m _AND int c _AND diff --git a/contrib/sdk/sources/newlib/libc/string/stpcpy.c b/contrib/sdk/sources/newlib/libc/string/stpcpy.c index 62fe79997d..bc58f47718 100644 --- a/contrib/sdk/sources/newlib/libc/string/stpcpy.c +++ b/contrib/sdk/sources/newlib/libc/string/stpcpy.c @@ -7,7 +7,7 @@ INDEX ANSI_SYNOPSIS #include - char *stpcpy(char *<[dst]>, const char *<[src]>); + char *stpcpy(char *restrict <[dst]>, const char *restrict <[src]>); TRAD_SYNOPSIS #include @@ -60,8 +60,8 @@ QUICKREF char* _DEFUN (stpcpy, (dst, src), - char *dst _AND - _CONST char *src) + char *__restrict dst _AND + _CONST char *__restrict src) { #if !defined(PREFER_SIZE_OVER_SPEED) && !defined(__OPTIMIZE_SIZE__) long *aligned_dst; diff --git a/contrib/sdk/sources/newlib/libc/string/stpncpy.c b/contrib/sdk/sources/newlib/libc/string/stpncpy.c index fca10d3985..abd9bbdbf6 100644 --- a/contrib/sdk/sources/newlib/libc/string/stpncpy.c +++ b/contrib/sdk/sources/newlib/libc/string/stpncpy.c @@ -7,7 +7,8 @@ INDEX ANSI_SYNOPSIS #include - char *stpncpy(char *<[dst]>, const char *<[src]>, size_t <[length]>); + char *stpncpy(char *restrict <[dst]>, const char *restrict <[src]>, + size_t <[length]>); TRAD_SYNOPSIS #include @@ -68,8 +69,8 @@ QUICKREF char * _DEFUN (stpncpy, (dst, src), - char *dst _AND - _CONST char *src _AND + char *__restrict dst _AND + _CONST char *__restrict src _AND size_t count) { char *ret = NULL; diff --git a/contrib/sdk/sources/newlib/libc/string/strcasestr.c b/contrib/sdk/sources/newlib/libc/string/strcasestr.c index 9c8e4e6df6..1bde1cdbfb 100644 --- a/contrib/sdk/sources/newlib/libc/string/strcasestr.c +++ b/contrib/sdk/sources/newlib/libc/string/strcasestr.c @@ -1,148 +1,152 @@ -/* -FUNCTION - <>---case-insensitive character string search - -INDEX - strcasestr - -ANSI_SYNOPSIS - #include - char *strcasestr(const char *<[s]>, const char *<[find]>); - -TRAD_SYNOPSIS - #include - int strcasecmp(<[s]>, <[find]>) - char *<[s]>; - char *<[find]>; - -DESCRIPTION - <> searchs the string <[s]> for - the first occurrence of the sequence <[find]>. <> - is identical to <> except the search is - case-insensitive. - -RETURNS - - A pointer to the first case-insensitive occurrence of the sequence - <[find]> or <> if no match was found. - -PORTABILITY -<> is in the Berkeley Software Distribution. - -<> requires no supporting OS subroutines. It uses -tolower() from elsewhere in this library. - -QUICKREF - strcasestr -*/ - -/*- - * Copyright (c) 1990, 1993 - * The Regents of the University of California. All rights reserved. - * - * The quadratic code is derived from software contributed to Berkeley by - * Chris Torek. - * - * 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. - */ -/* Linear algorithm Copyright (C) 2008 Eric Blake - * Permission to use, copy, modify, and distribute the linear portion of - * software is freely granted, provided that this notice is preserved. - */ - -#include - -#include -#include -#include - -#if !defined(PREFER_SIZE_OVER_SPEED) && !defined(__OPTIMIZE_SIZE__) -# define RETURN_TYPE char * -# define AVAILABLE(h, h_l, j, n_l) \ - (!memchr ((h) + (h_l), '\0', (j) + (n_l) - (h_l)) \ - && ((h_l) = (j) + (n_l))) -# define CANON_ELEMENT(c) tolower (c) -# define CMP_FUNC strncasecmp -# include "str-two-way.h" -#endif - -/* - * Find the first occurrence of find in s, ignore case. - */ -char * -strcasestr(s, find) - const char *s, *find; -{ -#if defined(PREFER_SIZE_OVER_SPEED) || defined(__OPTIMIZE_SIZE__) - - /* Less code size, but quadratic performance in the worst case. */ - char c, sc; - size_t len; - - if ((c = *find++) != 0) { - c = tolower((unsigned char)c); - len = strlen(find); - do { - do { - if ((sc = *s++) == 0) - return (NULL); - } while ((char)tolower((unsigned char)sc) != c); - } while (strncasecmp(s, find, len) != 0); - s--; - } - return ((char *)s); - -#else /* compilation for speed */ - - /* Larger code size, but guaranteed linear performance. */ - const char *haystack = s; - const char *needle = find; - size_t needle_len; /* Length of NEEDLE. */ - size_t haystack_len; /* Known minimum length of HAYSTACK. */ - int ok = 1; /* True if NEEDLE is prefix of HAYSTACK. */ - - /* Determine length of NEEDLE, and in the process, make sure - HAYSTACK is at least as long (no point processing all of a long - NEEDLE if HAYSTACK is too short). */ - while (*haystack && *needle) - ok &= (tolower ((unsigned char) *haystack++) - == tolower ((unsigned char) *needle++)); - if (*needle) - return NULL; - if (ok) - return (char *) s; - needle_len = needle - find; - haystack = s + 1; - haystack_len = needle_len - 1; - - /* Perform the search. */ - if (needle_len < LONG_NEEDLE_THRESHOLD) - return two_way_short_needle ((const unsigned char *) haystack, - haystack_len, - (const unsigned char *) find, needle_len); - return two_way_long_needle ((const unsigned char *) haystack, haystack_len, - (const unsigned char *) find, needle_len); -#endif /* compilation for speed */ -} +/* +FUNCTION + <>---case-insensitive character string search + +INDEX + strcasestr + +ANSI_SYNOPSIS + #include + char *strcasestr(const char *<[s]>, const char *<[find]>); + +TRAD_SYNOPSIS + #include + int strcasecmp(<[s]>, <[find]>) + char *<[s]>; + char *<[find]>; + +DESCRIPTION + <> searchs the string <[s]> for + the first occurrence of the sequence <[find]>. <> + is identical to <> except the search is + case-insensitive. + +RETURNS + + A pointer to the first case-insensitive occurrence of the sequence + <[find]> or <> if no match was found. + +PORTABILITY +<> is in the Berkeley Software Distribution. + +<> requires no supporting OS subroutines. It uses +tolower() from elsewhere in this library. + +QUICKREF + strcasestr +*/ + +/*- + * Copyright (c) 1990, 1993 + * The Regents of the University of California. All rights reserved. + * + * The quadratic code is derived from software contributed to Berkeley by + * Chris Torek. + * + * 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. + */ +/* Linear algorithm Copyright (C) 2008 Eric Blake + * Permission to use, copy, modify, and distribute the linear portion of + * software is freely granted, provided that this notice is preserved. + */ + +#include + +#include +#include +#include + +#if !defined(PREFER_SIZE_OVER_SPEED) && !defined(__OPTIMIZE_SIZE__) +# define RETURN_TYPE char * +# define AVAILABLE(h, h_l, j, n_l) \ + (!memchr ((h) + (h_l), '\0', (j) + (n_l) - (h_l)) \ + && ((h_l) = (j) + (n_l))) +# define CANON_ELEMENT(c) tolower (c) +#if __GNUC_PREREQ (4, 2) +/* strncasecmp uses signed char, CMP_FUNC is expected to use unsigned char. */ +#pragma GCC diagnostic ignored "-Wpointer-sign" +#endif +# define CMP_FUNC strncasecmp +# include "str-two-way.h" +#endif + +/* + * Find the first occurrence of find in s, ignore case. + */ +char * +strcasestr(s, find) + const char *s, *find; +{ +#if defined(PREFER_SIZE_OVER_SPEED) || defined(__OPTIMIZE_SIZE__) + + /* Less code size, but quadratic performance in the worst case. */ + char c, sc; + size_t len; + + if ((c = *find++) != 0) { + c = tolower((unsigned char)c); + len = strlen(find); + do { + do { + if ((sc = *s++) == 0) + return (NULL); + } while ((char)tolower((unsigned char)sc) != c); + } while (strncasecmp(s, find, len) != 0); + s--; + } + return ((char *)s); + +#else /* compilation for speed */ + + /* Larger code size, but guaranteed linear performance. */ + const char *haystack = s; + const char *needle = find; + size_t needle_len; /* Length of NEEDLE. */ + size_t haystack_len; /* Known minimum length of HAYSTACK. */ + int ok = 1; /* True if NEEDLE is prefix of HAYSTACK. */ + + /* Determine length of NEEDLE, and in the process, make sure + HAYSTACK is at least as long (no point processing all of a long + NEEDLE if HAYSTACK is too short). */ + while (*haystack && *needle) + ok &= (tolower ((unsigned char) *haystack++) + == tolower ((unsigned char) *needle++)); + if (*needle) + return NULL; + if (ok) + return (char *) s; + needle_len = needle - find; + haystack = s + 1; + haystack_len = needle_len - 1; + + /* Perform the search. */ + if (needle_len < LONG_NEEDLE_THRESHOLD) + return two_way_short_needle ((const unsigned char *) haystack, + haystack_len, + (const unsigned char *) find, needle_len); + return two_way_long_needle ((const unsigned char *) haystack, haystack_len, + (const unsigned char *) find, needle_len); +#endif /* compilation for speed */ +} diff --git a/contrib/sdk/sources/newlib/libc/string/strcat.c b/contrib/sdk/sources/newlib/libc/string/strcat.c index ba8ee394ef..1e4614991a 100644 --- a/contrib/sdk/sources/newlib/libc/string/strcat.c +++ b/contrib/sdk/sources/newlib/libc/string/strcat.c @@ -1,104 +1,104 @@ -/* -FUNCTION - <>---concatenate strings - -INDEX - strcat - -ANSI_SYNOPSIS - #include - char *strcat(char *<[dst]>, const char *<[src]>); - -TRAD_SYNOPSIS - #include - char *strcat(<[dst]>, <[src]>) - char *<[dst]>; - char *<[src]>; - -DESCRIPTION - <> appends a copy of the string pointed to by <[src]> - (including the terminating null character) to the end of the - string pointed to by <[dst]>. The initial character of - <[src]> overwrites the null character at the end of <[dst]>. - -RETURNS - This function returns the initial value of <[dst]> - -PORTABILITY -<> is ANSI C. - -<> requires no supporting OS subroutines. - -QUICKREF - strcat ansi pure -*/ - -#include -#include - -/* Nonzero if X is aligned on a "long" boundary. */ -#define ALIGNED(X) \ - (((long)X & (sizeof (long) - 1)) == 0) - -#if LONG_MAX == 2147483647L -#define DETECTNULL(X) (((X) - 0x01010101) & ~(X) & 0x80808080) -#else -#if LONG_MAX == 9223372036854775807L -/* Nonzero if X (a long int) contains a NULL byte. */ -#define DETECTNULL(X) (((X) - 0x0101010101010101) & ~(X) & 0x8080808080808080) -#else -#error long int is not a 32bit or 64bit type. -#endif -#endif - -#ifndef DETECTNULL -#error long int is not a 32bit or 64bit byte -#endif - - -/*SUPPRESS 560*/ -/*SUPPRESS 530*/ - -char * -_DEFUN (strcat, (s1, s2), - char *s1 _AND - _CONST char *s2) -{ -#if defined(PREFER_SIZE_OVER_SPEED) || defined(__OPTIMIZE_SIZE__) - char *s = s1; - - while (*s1) - s1++; - - while (*s1++ = *s2++) - ; - return s; -#else - char *s = s1; - - - /* Skip over the data in s1 as quickly as possible. */ - if (ALIGNED (s1)) - { - unsigned long *aligned_s1 = (unsigned long *)s1; - while (!DETECTNULL (*aligned_s1)) - aligned_s1++; - - s1 = (char *)aligned_s1; - } - - while (*s1) - s1++; - - /* s1 now points to the its trailing null character, we can - just use strcpy to do the work for us now. - - ?!? We might want to just include strcpy here. - Also, this will cause many more unaligned string copies because - s1 is much less likely to be aligned. I don't know if its worth - tweaking strcpy to handle this better. */ - strcpy (s1, s2); - - return s; -#endif /* not PREFER_SIZE_OVER_SPEED */ -} +/* +FUNCTION + <>---concatenate strings + +INDEX + strcat + +ANSI_SYNOPSIS + #include + char *strcat(char *restrict <[dst]>, const char *restrict <[src]>); + +TRAD_SYNOPSIS + #include + char *strcat(<[dst]>, <[src]>) + char *<[dst]>; + char *<[src]>; + +DESCRIPTION + <> appends a copy of the string pointed to by <[src]> + (including the terminating null character) to the end of the + string pointed to by <[dst]>. The initial character of + <[src]> overwrites the null character at the end of <[dst]>. + +RETURNS + This function returns the initial value of <[dst]> + +PORTABILITY +<> is ANSI C. + +<> requires no supporting OS subroutines. + +QUICKREF + strcat ansi pure +*/ + +#include +#include + +/* Nonzero if X is aligned on a "long" boundary. */ +#define ALIGNED(X) \ + (((long)X & (sizeof (long) - 1)) == 0) + +#if LONG_MAX == 2147483647L +#define DETECTNULL(X) (((X) - 0x01010101) & ~(X) & 0x80808080) +#else +#if LONG_MAX == 9223372036854775807L +/* Nonzero if X (a long int) contains a NULL byte. */ +#define DETECTNULL(X) (((X) - 0x0101010101010101) & ~(X) & 0x8080808080808080) +#else +#error long int is not a 32bit or 64bit type. +#endif +#endif + +#ifndef DETECTNULL +#error long int is not a 32bit or 64bit byte +#endif + + +/*SUPPRESS 560*/ +/*SUPPRESS 530*/ + +char * +_DEFUN (strcat, (s1, s2), + char *__restrict s1 _AND + _CONST char *__restrict s2) +{ +#if defined(PREFER_SIZE_OVER_SPEED) || defined(__OPTIMIZE_SIZE__) + char *s = s1; + + while (*s1) + s1++; + + while (*s1++ = *s2++) + ; + return s; +#else + char *s = s1; + + + /* Skip over the data in s1 as quickly as possible. */ + if (ALIGNED (s1)) + { + unsigned long *aligned_s1 = (unsigned long *)s1; + while (!DETECTNULL (*aligned_s1)) + aligned_s1++; + + s1 = (char *)aligned_s1; + } + + while (*s1) + s1++; + + /* s1 now points to the its trailing null character, we can + just use strcpy to do the work for us now. + + ?!? We might want to just include strcpy here. + Also, this will cause many more unaligned string copies because + s1 is much less likely to be aligned. I don't know if its worth + tweaking strcpy to handle this better. */ + strcpy (s1, s2); + + return s; +#endif /* not PREFER_SIZE_OVER_SPEED */ +} diff --git a/contrib/sdk/sources/newlib/libc/string/strncat.c b/contrib/sdk/sources/newlib/libc/string/strncat.c index c61f4d5139..2f5a061bf4 100644 --- a/contrib/sdk/sources/newlib/libc/string/strncat.c +++ b/contrib/sdk/sources/newlib/libc/string/strncat.c @@ -1,114 +1,115 @@ -/* -FUNCTION - <>---concatenate strings - -INDEX - strncat - -ANSI_SYNOPSIS - #include - char *strncat(char *<[dst]>, const char *<[src]>, size_t <[length]>); - -TRAD_SYNOPSIS - #include - char *strncat(<[dst]>, <[src]>, <[length]>) - char *<[dst]>; - char *<[src]>; - size_t <[length]>; - -DESCRIPTION - <> appends not more than <[length]> characters from - the string pointed to by <[src]> (including the terminating - null character) to the end of the string pointed to by - <[dst]>. The initial character of <[src]> overwrites the null - character at the end of <[dst]>. A terminating null character - is always appended to the result - -WARNINGS - Note that a null is always appended, so that if the copy is - limited by the <[length]> argument, the number of characters - appended to <[dst]> is <>. - -RETURNS - This function returns the initial value of <[dst]> - -PORTABILITY -<> is ANSI C. - -<> requires no supporting OS subroutines. - -QUICKREF - strncat ansi pure -*/ - -#include -#include - -/* Nonzero if X is aligned on a "long" boundary. */ -#define ALIGNED(X) \ - (((long)X & (sizeof (long) - 1)) == 0) - -#if LONG_MAX == 2147483647L -#define DETECTNULL(X) (((X) - 0x01010101) & ~(X) & 0x80808080) -#else -#if LONG_MAX == 9223372036854775807L -/* Nonzero if X (a long int) contains a NULL byte. */ -#define DETECTNULL(X) (((X) - 0x0101010101010101) & ~(X) & 0x8080808080808080) -#else -#error long int is not a 32bit or 64bit type. -#endif -#endif - -#ifndef DETECTNULL -#error long int is not a 32bit or 64bit byte -#endif - -char * -_DEFUN (strncat, (s1, s2, n), - char *s1 _AND - _CONST char *s2 _AND - size_t n) -{ -#if defined(PREFER_SIZE_OVER_SPEED) || defined(__OPTIMIZE_SIZE__) - char *s = s1; - - while (*s1) - s1++; - while (n-- != 0 && (*s1++ = *s2++)) - { - if (n == 0) - *s1 = '\0'; - } - - return s; -#else - char *s = s1; - - /* Skip over the data in s1 as quickly as possible. */ - if (ALIGNED (s1)) - { - unsigned long *aligned_s1 = (unsigned long *)s1; - while (!DETECTNULL (*aligned_s1)) - aligned_s1++; - - s1 = (char *)aligned_s1; - } - - while (*s1) - s1++; - - /* s1 now points to the its trailing null character, now copy - up to N bytes from S2 into S1 stopping if a NULL is encountered - in S2. - - It is not safe to use strncpy here since it copies EXACTLY N - characters, NULL padding if necessary. */ - while (n-- != 0 && (*s1++ = *s2++)) - { - if (n == 0) - *s1 = '\0'; - } - - return s; -#endif /* not PREFER_SIZE_OVER_SPEED */ -} +/* +FUNCTION + <>---concatenate strings + +INDEX + strncat + +ANSI_SYNOPSIS + #include + char *strncat(char *restrict <[dst]>, const char *restrict <[src]>, + size_t <[length]>); + +TRAD_SYNOPSIS + #include + char *strncat(<[dst]>, <[src]>, <[length]>) + char *<[dst]>; + char *<[src]>; + size_t <[length]>; + +DESCRIPTION + <> appends not more than <[length]> characters from + the string pointed to by <[src]> (including the terminating + null character) to the end of the string pointed to by + <[dst]>. The initial character of <[src]> overwrites the null + character at the end of <[dst]>. A terminating null character + is always appended to the result + +WARNINGS + Note that a null is always appended, so that if the copy is + limited by the <[length]> argument, the number of characters + appended to <[dst]> is <>. + +RETURNS + This function returns the initial value of <[dst]> + +PORTABILITY +<> is ANSI C. + +<> requires no supporting OS subroutines. + +QUICKREF + strncat ansi pure +*/ + +#include +#include + +/* Nonzero if X is aligned on a "long" boundary. */ +#define ALIGNED(X) \ + (((long)X & (sizeof (long) - 1)) == 0) + +#if LONG_MAX == 2147483647L +#define DETECTNULL(X) (((X) - 0x01010101) & ~(X) & 0x80808080) +#else +#if LONG_MAX == 9223372036854775807L +/* Nonzero if X (a long int) contains a NULL byte. */ +#define DETECTNULL(X) (((X) - 0x0101010101010101) & ~(X) & 0x8080808080808080) +#else +#error long int is not a 32bit or 64bit type. +#endif +#endif + +#ifndef DETECTNULL +#error long int is not a 32bit or 64bit byte +#endif + +char * +_DEFUN (strncat, (s1, s2, n), + char *__restrict s1 _AND + _CONST char *__restrict s2 _AND + size_t n) +{ +#if defined(PREFER_SIZE_OVER_SPEED) || defined(__OPTIMIZE_SIZE__) + char *s = s1; + + while (*s1) + s1++; + while (n-- != 0 && (*s1++ = *s2++)) + { + if (n == 0) + *s1 = '\0'; + } + + return s; +#else + char *s = s1; + + /* Skip over the data in s1 as quickly as possible. */ + if (ALIGNED (s1)) + { + unsigned long *aligned_s1 = (unsigned long *)s1; + while (!DETECTNULL (*aligned_s1)) + aligned_s1++; + + s1 = (char *)aligned_s1; + } + + while (*s1) + s1++; + + /* s1 now points to the its trailing null character, now copy + up to N bytes from S2 into S1 stopping if a NULL is encountered + in S2. + + It is not safe to use strncpy here since it copies EXACTLY N + characters, NULL padding if necessary. */ + while (n-- != 0 && (*s1++ = *s2++)) + { + if (n == 0) + *s1 = '\0'; + } + + return s; +#endif /* not PREFER_SIZE_OVER_SPEED */ +} diff --git a/contrib/sdk/sources/newlib/libc/string/strncpy.c b/contrib/sdk/sources/newlib/libc/string/strncpy.c index 52e54ce8e3..ff5d0d409f 100644 --- a/contrib/sdk/sources/newlib/libc/string/strncpy.c +++ b/contrib/sdk/sources/newlib/libc/string/strncpy.c @@ -1,125 +1,126 @@ -/* -FUNCTION - <>---counted copy string - -INDEX - strncpy - -ANSI_SYNOPSIS - #include - char *strncpy(char *<[dst]>, const char *<[src]>, size_t <[length]>); - -TRAD_SYNOPSIS - #include - char *strncpy(<[dst]>, <[src]>, <[length]>) - char *<[dst]>; - char *<[src]>; - size_t <[length]>; - -DESCRIPTION - <> copies not more than <[length]> characters from the - the string pointed to by <[src]> (including the terminating - null character) to the array pointed to by <[dst]>. If the - string pointed to by <[src]> is shorter than <[length]> - characters, null characters are appended to the destination - array until a total of <[length]> characters have been - written. - -RETURNS - This function returns the initial value of <[dst]>. - -PORTABILITY -<> is ANSI C. - -<> requires no supporting OS subroutines. - -QUICKREF - strncpy ansi pure -*/ - -#include -#include - -/*SUPPRESS 560*/ -/*SUPPRESS 530*/ - -/* Nonzero if either X or Y is not aligned on a "long" boundary. */ -#define UNALIGNED(X, Y) \ - (((long)X & (sizeof (long) - 1)) | ((long)Y & (sizeof (long) - 1))) - -#if LONG_MAX == 2147483647L -#define DETECTNULL(X) (((X) - 0x01010101) & ~(X) & 0x80808080) -#else -#if LONG_MAX == 9223372036854775807L -/* Nonzero if X (a long int) contains a NULL byte. */ -#define DETECTNULL(X) (((X) - 0x0101010101010101) & ~(X) & 0x8080808080808080) -#else -#error long int is not a 32bit or 64bit type. -#endif -#endif - -#ifndef DETECTNULL -#error long int is not a 32bit or 64bit byte -#endif - -#define TOO_SMALL(LEN) ((LEN) < sizeof (long)) - -char * -_DEFUN (strncpy, (dst0, src0), - char *dst0 _AND - _CONST char *src0 _AND - size_t count) -{ -#if defined(PREFER_SIZE_OVER_SPEED) || defined(__OPTIMIZE_SIZE__) - char *dscan; - _CONST char *sscan; - - dscan = dst0; - sscan = src0; - while (count > 0) - { - --count; - if ((*dscan++ = *sscan++) == '\0') - break; - } - while (count-- > 0) - *dscan++ = '\0'; - - return dst0; -#else - char *dst = dst0; - _CONST char *src = src0; - long *aligned_dst; - _CONST long *aligned_src; - - /* If SRC and DEST is aligned and count large enough, then copy words. */ - if (!UNALIGNED (src, dst) && !TOO_SMALL (count)) - { - aligned_dst = (long*)dst; - aligned_src = (long*)src; - - /* SRC and DEST are both "long int" aligned, try to do "long int" - sized copies. */ - while (count >= sizeof (long int) && !DETECTNULL(*aligned_src)) - { - count -= sizeof (long int); - *aligned_dst++ = *aligned_src++; - } - - dst = (char*)aligned_dst; - src = (char*)aligned_src; - } - - while (count > 0) - { - --count; - if ((*dst++ = *src++) == '\0') - break; - } - - while (count-- > 0) - *dst++ = '\0'; - - return dst0; -#endif /* not PREFER_SIZE_OVER_SPEED */ -} +/* +FUNCTION + <>---counted copy string + +INDEX + strncpy + +ANSI_SYNOPSIS + #include + char *strncpy(char *restrict <[dst]>, const char *restrict <[src]>, + size_t <[length]>); + +TRAD_SYNOPSIS + #include + char *strncpy(<[dst]>, <[src]>, <[length]>) + char *<[dst]>; + char *<[src]>; + size_t <[length]>; + +DESCRIPTION + <> copies not more than <[length]> characters from the + the string pointed to by <[src]> (including the terminating + null character) to the array pointed to by <[dst]>. If the + string pointed to by <[src]> is shorter than <[length]> + characters, null characters are appended to the destination + array until a total of <[length]> characters have been + written. + +RETURNS + This function returns the initial value of <[dst]>. + +PORTABILITY +<> is ANSI C. + +<> requires no supporting OS subroutines. + +QUICKREF + strncpy ansi pure +*/ + +#include +#include + +/*SUPPRESS 560*/ +/*SUPPRESS 530*/ + +/* Nonzero if either X or Y is not aligned on a "long" boundary. */ +#define UNALIGNED(X, Y) \ + (((long)X & (sizeof (long) - 1)) | ((long)Y & (sizeof (long) - 1))) + +#if LONG_MAX == 2147483647L +#define DETECTNULL(X) (((X) - 0x01010101) & ~(X) & 0x80808080) +#else +#if LONG_MAX == 9223372036854775807L +/* Nonzero if X (a long int) contains a NULL byte. */ +#define DETECTNULL(X) (((X) - 0x0101010101010101) & ~(X) & 0x8080808080808080) +#else +#error long int is not a 32bit or 64bit type. +#endif +#endif + +#ifndef DETECTNULL +#error long int is not a 32bit or 64bit byte +#endif + +#define TOO_SMALL(LEN) ((LEN) < sizeof (long)) + +char * +_DEFUN (strncpy, (dst0, src0), + char *__restrict dst0 _AND + _CONST char *__restrict src0 _AND + size_t count) +{ +#if defined(PREFER_SIZE_OVER_SPEED) || defined(__OPTIMIZE_SIZE__) + char *dscan; + _CONST char *sscan; + + dscan = dst0; + sscan = src0; + while (count > 0) + { + --count; + if ((*dscan++ = *sscan++) == '\0') + break; + } + while (count-- > 0) + *dscan++ = '\0'; + + return dst0; +#else + char *dst = dst0; + _CONST char *src = src0; + long *aligned_dst; + _CONST long *aligned_src; + + /* If SRC and DEST is aligned and count large enough, then copy words. */ + if (!UNALIGNED (src, dst) && !TOO_SMALL (count)) + { + aligned_dst = (long*)dst; + aligned_src = (long*)src; + + /* SRC and DEST are both "long int" aligned, try to do "long int" + sized copies. */ + while (count >= sizeof (long int) && !DETECTNULL(*aligned_src)) + { + count -= sizeof (long int); + *aligned_dst++ = *aligned_src++; + } + + dst = (char*)aligned_dst; + src = (char*)aligned_src; + } + + while (count > 0) + { + --count; + if ((*dst++ = *src++) == '\0') + break; + } + + while (count-- > 0) + *dst++ = '\0'; + + return dst0; +#endif /* not PREFER_SIZE_OVER_SPEED */ +} diff --git a/contrib/sdk/sources/newlib/libc/string/strtok.c b/contrib/sdk/sources/newlib/libc/string/strtok.c index 1e07ea315a..35460ba044 100644 --- a/contrib/sdk/sources/newlib/libc/string/strtok.c +++ b/contrib/sdk/sources/newlib/libc/string/strtok.c @@ -1,101 +1,105 @@ -/* -FUNCTION - <>, <>, <>---get next token from a string - -INDEX - strtok - -INDEX - strtok_r - -INDEX - strsep - -ANSI_SYNOPSIS - #include - char *strtok(char *<[source]>, const char *<[delimiters]>) - char *strtok_r(char *<[source]>, const char *<[delimiters]>, - char **<[lasts]>) - char *strsep(char **<[source_ptr]>, const char *<[delimiters]>) - -TRAD_SYNOPSIS - #include - char *strtok(<[source]>, <[delimiters]>) - char *<[source]>; - char *<[delimiters]>; - - char *strtok_r(<[source]>, <[delimiters]>, <[lasts]>) - char *<[source]>; - char *<[delimiters]>; - char **<[lasts]>; - - char *strsep(<[source_ptr]>, <[delimiters]>) - char **<[source_ptr]>; - char *<[delimiters]>; - -DESCRIPTION - The <> function is used to isolate sequential tokens in a - null-terminated string, <<*<[source]>>>. These tokens are delimited - in the string by at least one of the characters in <<*<[delimiters]>>>. - The first time that <> is called, <<*<[source]>>> should be - specified; subsequent calls, wishing to obtain further tokens from - the same string, should pass a null pointer instead. The separator - string, <<*<[delimiters]>>>, must be supplied each time and may - change between calls. - - The <> function returns a pointer to the beginning of each - subsequent token in the string, after replacing the separator - character itself with a null character. When no more tokens remain, - a null pointer is returned. - - The <> function has the same behavior as <>, except - a pointer to placeholder <<*<[lasts]>>> must be supplied by the caller. - - The <> function is similar in behavior to <>, except - a pointer to the string pointer must be supplied <<<[source_ptr]>>> and - the function does not skip leading delimiters. When the string starts - with a delimiter, the delimiter is changed to the null character and - the empty string is returned. Like <> and <>, the - <<*<[source_ptr]>>> is updated to the next character following the - last delimiter found or NULL if the end of string is reached with - no more delimiters. - -RETURNS - <>, <>, and <> all return a pointer to the - next token, or <> if no more tokens can be found. For - <>, a token may be the empty string. - -NOTES - <> is unsafe for multi-threaded applications. <> - and <> are thread-safe and should be used instead. - -PORTABILITY -<> is ANSI C. -<> is POSIX. -<> is a BSD extension. - -<>, <>, and <> require no supporting OS subroutines. - -QUICKREF - strtok ansi impure -*/ - -/* undef STRICT_ANSI so that strtok_r prototype will be defined */ -#undef __STRICT_ANSI__ -#include -#include <_ansi.h> -#include - -#ifndef _REENT_ONLY - -extern char *__strtok_r (char *, const char *, char **, int); - -char * -_DEFUN (strtok, (s, delim), - register char *s _AND - register const char *delim) -{ - _REENT_CHECK_MISC(_REENT); - return __strtok_r (s, delim, &(_REENT_STRTOK_LAST(_REENT)), 1); -} -#endif +/* +FUNCTION + <>, <>, <>---get next token from a string + +INDEX + strtok + +INDEX + strtok_r + +INDEX + strsep + +ANSI_SYNOPSIS + #include + char *strtok(char *restrict <[source]>, + const char *restrict <[delimiters]>) + char *strtok_r(char *restrict <[source]>, + const char *restrict <[delimiters]>, + char **<[lasts]>) + char *strsep(char **<[source_ptr]>, const char *<[delimiters]>) + +TRAD_SYNOPSIS + #include + char *strtok(<[source]>, <[delimiters]>) + char *<[source]>; + char *<[delimiters]>; + + char *strtok_r(<[source]>, <[delimiters]>, <[lasts]>) + char *<[source]>; + char *<[delimiters]>; + char **<[lasts]>; + + char *strsep(<[source_ptr]>, <[delimiters]>) + char **<[source_ptr]>; + char *<[delimiters]>; + +DESCRIPTION + The <> function is used to isolate sequential tokens in a + null-terminated string, <<*<[source]>>>. These tokens are delimited + in the string by at least one of the characters in <<*<[delimiters]>>>. + The first time that <> is called, <<*<[source]>>> should be + specified; subsequent calls, wishing to obtain further tokens from + the same string, should pass a null pointer instead. The separator + string, <<*<[delimiters]>>>, must be supplied each time and may + change between calls. + + The <> function returns a pointer to the beginning of each + subsequent token in the string, after replacing the separator + character itself with a null character. When no more tokens remain, + a null pointer is returned. + + The <> function has the same behavior as <>, except + a pointer to placeholder <<*<[lasts]>>> must be supplied by the caller. + + The <> function is similar in behavior to <>, except + a pointer to the string pointer must be supplied <<<[source_ptr]>>> and + the function does not skip leading delimiters. When the string starts + with a delimiter, the delimiter is changed to the null character and + the empty string is returned. Like <> and <>, the + <<*<[source_ptr]>>> is updated to the next character following the + last delimiter found or NULL if the end of string is reached with + no more delimiters. + +RETURNS + <>, <>, and <> all return a pointer to the + next token, or <> if no more tokens can be found. For + <>, a token may be the empty string. + +NOTES + <> is unsafe for multi-threaded applications. <> + and <> are thread-safe and should be used instead. + +PORTABILITY +<> is ANSI C. +<> is POSIX. +<> is a BSD extension. + +<>, <>, and <> require no supporting OS subroutines. + +QUICKREF + strtok ansi impure +*/ + +/* undef STRICT_ANSI so that strtok_r prototype will be defined */ +#undef __STRICT_ANSI__ +#include +#include <_ansi.h> +#include + +#ifndef _REENT_ONLY + +extern char *__strtok_r (char *, const char *, char **, int); + +char * +_DEFUN (strtok, (s, delim), + register char *__restrict s _AND + register const char *__restrict delim) +{ + struct _reent *reent = _REENT; + + _REENT_CHECK_MISC(reent); + return __strtok_r (s, delim, &(_REENT_STRTOK_LAST(reent)), 1); +} +#endif diff --git a/contrib/sdk/sources/newlib/libc/string/strtok_r.c b/contrib/sdk/sources/newlib/libc/string/strtok_r.c index 82af55d772..6ace7008b4 100644 --- a/contrib/sdk/sources/newlib/libc/string/strtok_r.c +++ b/contrib/sdk/sources/newlib/libc/string/strtok_r.c @@ -1,99 +1,99 @@ -/* - * Copyright (c) 1988 Regents of the University of California. - * All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * 3. Neither the name of the University nor the names of its contributors - * may be used to endorse or promote products derived from this software - * without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND - * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE - * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE - * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL - * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS - * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) - * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT - * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY - * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF - * SUCH DAMAGE. - */ - -#include - -char * -_DEFUN (__strtok_r, (s, delim, lasts, skip_leading_delim), - register char *s _AND - register const char *delim _AND - char **lasts _AND - int skip_leading_delim) -{ - register char *spanp; - register int c, sc; - char *tok; - - - if (s == NULL && (s = *lasts) == NULL) - return (NULL); - - /* - * Skip (span) leading delimiters (s += strspn(s, delim), sort of). - */ -cont: - c = *s++; - for (spanp = (char *)delim; (sc = *spanp++) != 0;) { - if (c == sc) { - if (skip_leading_delim) { - goto cont; - } - else { - *lasts = s; - s[-1] = 0; - return (s - 1); - } - } - } - - if (c == 0) { /* no non-delimiter characters */ - *lasts = NULL; - return (NULL); - } - tok = s - 1; - - /* - * Scan token (scan for delimiters: s += strcspn(s, delim), sort of). - * Note that delim must have one NUL; we stop if we see that, too. - */ - for (;;) { - c = *s++; - spanp = (char *)delim; - do { - if ((sc = *spanp++) == c) { - if (c == 0) - s = NULL; - else - s[-1] = 0; - *lasts = s; - return (tok); - } - } while (sc != 0); - } - /* NOTREACHED */ -} - -char * -_DEFUN (strtok_r, (s, delim, lasts), - register char *s _AND - register const char *delim _AND - char **lasts) -{ - return __strtok_r (s, delim, lasts, 1); -} +/* + * Copyright (c) 1988 Regents of the University of California. + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * 3. Neither the name of the University nor the names of its contributors + * may be used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + */ + +#include + +char * +_DEFUN (__strtok_r, (s, delim, lasts, skip_leading_delim), + register char *s _AND + register const char *delim _AND + char **lasts _AND + int skip_leading_delim) +{ + register char *spanp; + register int c, sc; + char *tok; + + + if (s == NULL && (s = *lasts) == NULL) + return (NULL); + + /* + * Skip (span) leading delimiters (s += strspn(s, delim), sort of). + */ +cont: + c = *s++; + for (spanp = (char *)delim; (sc = *spanp++) != 0;) { + if (c == sc) { + if (skip_leading_delim) { + goto cont; + } + else { + *lasts = s; + s[-1] = 0; + return (s - 1); + } + } + } + + if (c == 0) { /* no non-delimiter characters */ + *lasts = NULL; + return (NULL); + } + tok = s - 1; + + /* + * Scan token (scan for delimiters: s += strcspn(s, delim), sort of). + * Note that delim must have one NUL; we stop if we see that, too. + */ + for (;;) { + c = *s++; + spanp = (char *)delim; + do { + if ((sc = *spanp++) == c) { + if (c == 0) + s = NULL; + else + s[-1] = 0; + *lasts = s; + return (tok); + } + } while (sc != 0); + } + /* NOTREACHED */ +} + +char * +_DEFUN (strtok_r, (s, delim, lasts), + register char *__restrict s _AND + register const char *__restrict delim _AND + char **__restrict lasts) +{ + return __strtok_r (s, delim, lasts, 1); +} diff --git a/contrib/sdk/sources/newlib/libc/sys/close.c b/contrib/sdk/sources/newlib/libc/sys/close.c new file mode 100644 index 0000000000..ecd70789c6 --- /dev/null +++ b/contrib/sdk/sources/newlib/libc/sys/close.c @@ -0,0 +1,43 @@ +/* close.c -- close a file descriptor. + * + * Copyright (c) 1995 Cygnus Support + * + * The authors hereby grant permission to use, copy, modify, distribute, + * and license this software and its documentation for any purpose, provided + * that existing copyright notices are retained in all copies and that this + * notice is included verbatim in any distributions. No written agreement, + * license, or royalty fee is required for any of the authorized uses. + * Modifications to this software may be copyrighted by their authors + * and need not follow the licensing terms described here, provided that + * the new terms are clearly indicated on the first page of each file where + * they apply. + */ +#include +#include +#include +#include +#include "glue.h" +#include "io.h" + +int +_DEFUN (close ,(fd), + int fd) +{ + __io_handle *ioh; + + if( (fd < 0) || (fd >=64) ) + { + errno = EBADF; + return (-1); + }; + + ioh = &__io_tab[fd]; + + if( fd > STDERR_FILENO ) + { + free(ioh->name); + __io_free(fd); + } + + return (0); +} diff --git a/contrib/sdk/sources/newlib/libc/sys/errno.c b/contrib/sdk/sources/newlib/libc/sys/errno.c new file mode 100644 index 0000000000..858be6c148 --- /dev/null +++ b/contrib/sdk/sources/newlib/libc/sys/errno.c @@ -0,0 +1,2 @@ + +int errno; \ No newline at end of file diff --git a/contrib/sdk/sources/newlib/libc/sys/fload.c b/contrib/sdk/sources/newlib/libc/sys/fload.c deleted file mode 100644 index 583047af36..0000000000 --- a/contrib/sdk/sources/newlib/libc/sys/fload.c +++ /dev/null @@ -1,37 +0,0 @@ - -#include -#include -#include - -void *load_file(const char *path, size_t *len) -{ - fileinfo_t info; - size_t bytes; - void *file = NULL; - - if( len) *len = 0; - - - if( !get_fileinfo(path, &info) ) - { - - file = (void*)user_alloc( info.size ); - read_file(path, file, 0, info.size, &bytes ); - if( bytes == info.size ) - { - if ( *(uint32_t*)file == 0x4B43504B ) - { - void *tmp = NULL; - info.size = ((size_t*)file)[1]; - tmp = (void*)user_alloc(info.size); - unpack(file, tmp); - user_free(file); - file = tmp; - } - if(len) *len = info.size; - }; - }; - return file; -}; - - diff --git a/contrib/sdk/sources/newlib/libc/sys/fstat.c b/contrib/sdk/sources/newlib/libc/sys/fstat.c new file mode 100644 index 0000000000..671376ab72 --- /dev/null +++ b/contrib/sdk/sources/newlib/libc/sys/fstat.c @@ -0,0 +1,59 @@ +/* fstat.c -- get status of a file. + * + * Copyright (c) 1995 Cygnus Support + * + * The authors hereby grant permission to use, copy, modify, distribute, + * and license this software and its documentation for any purpose, provided + * that existing copyright notices are retained in all copies and that this + * notice is included verbatim in any distributions. No written agreement, + * license, or royalty fee is required for any of the authorized uses. + * Modifications to this software may be copyrighted by their authors + * and need not follow the licensing terms described here, provided that + * the new terms are clearly indicated on the first page of each file where + * they apply. + */ +#include +#include +#include +#include +#include +#include "glue.h" +#include "io.h" + +int +_DEFUN (fstat, (fd, buf), + int fd _AND + struct stat *buf) +{ + fileinfo_t info; + __io_handle *ioh; + + if( (fd < 0) || (fd >=64) ) + { + errno = EBADF; + return (-1); + }; + + memset (buf, 0, sizeof (* buf)); + + if (fd <= STDERR_FILENO) + { + buf->st_mode = S_IFCHR; + buf->st_blksize = 0; + } + else + { + + ioh = &__io_tab[fd]; + get_fileinfo(ioh->name, &info); + + buf->st_mode = S_IFREG; + buf->st_blksize = 4096; + buf->st_size = info.size; + }; + + return (0); +} + + + diff --git a/contrib/sdk/sources/newlib/libc/sys/gettod.c b/contrib/sdk/sources/newlib/libc/sys/gettod.c new file mode 100644 index 0000000000..f1aa3c8f1d --- /dev/null +++ b/contrib/sdk/sources/newlib/libc/sys/gettod.c @@ -0,0 +1,45 @@ +#include <_ansi.h> +#include +#include +#include +#include +#include + +#define BCD_TO_BIN(val) ((val)=((val)&15) + ((val)>>4)*10) + +int +_DEFUN (gettimeofday, (ptimeval, ptimezone), + struct timeval *ptimeval _AND + void *ptimezone) +{ + unsigned int xtmp; + struct tm tmblk; + + if( ptimeval ) + { + ptimeval->tv_usec = 0; + + __asm__ __volatile__("int $0x40":"=a"(xtmp):"0"(3)); + tmblk.tm_sec = (xtmp>>16)&0xff; + tmblk.tm_min = (xtmp>>8)&0xff; + tmblk.tm_hour = xtmp&0xff; + BCD_TO_BIN(tmblk.tm_sec); + BCD_TO_BIN(tmblk.tm_min); + BCD_TO_BIN(tmblk.tm_hour); + __asm__ __volatile__("int $0x40":"=a"(xtmp):"0"(29)); + tmblk.tm_mday = (xtmp>>16)&0xff; + tmblk.tm_mon = ((xtmp>>8)&0xff)-1; + tmblk.tm_year = ((xtmp&0xff)+2000)-1900; + tmblk.tm_wday = tmblk.tm_yday = 0; + tmblk.tm_isdst = -1; + ptimeval->tv_sec = mktime(&tmblk); + return 0; + } + else + { + errno = EINVAL; + return -1; + }; + +} + diff --git a/contrib/sdk/sources/newlib/libc/sys/glue.h b/contrib/sdk/sources/newlib/libc/sys/glue.h new file mode 100644 index 0000000000..0a7e36db21 --- /dev/null +++ b/contrib/sdk/sources/newlib/libc/sys/glue.h @@ -0,0 +1,31 @@ +/* glue.h -- common definitions for "glue" fucntions. + * + * Copyright (c) 1995 Cygnus Support + * + * The authors hereby grant permission to use, copy, modify, distribute, + * and license this software and its documentation for any purpose, provided + * that existing copyright notices are retained in all copies and that this + * notice is included verbatim in any distributions. No written agreement, + * license, or royalty fee is required for any of the authorized uses. + * Modifications to this software may be copyrighted by their authors + * and need not follow the licensing terms described here, provided that + * the new terms are clearly indicated on the first page of each file where + * they apply. + */ +#include <_ansi.h> + +#ifndef NULL +# define NULL 0 +#endif + +#ifdef __NO_UNDERSCORE__ +# define _end end +# define _exit exit +#endif + +extern char _end[]; /* _end is set in the linker command file */ + +/* only one prcess support, as this is OS dependant */ +#define __MYPID 1 + + diff --git a/contrib/sdk/sources/newlib/libc/sys/io.c b/contrib/sdk/sources/newlib/libc/sys/io.c new file mode 100644 index 0000000000..e0f24246ab --- /dev/null +++ b/contrib/sdk/sources/newlib/libc/sys/io.c @@ -0,0 +1,60 @@ + +#include +#include "io.h" + +extern __io_handle __io_tab[64]; + +static int fake_io(const char *path, const void *buff, + size_t offset, size_t count, size_t *done) +{ + *done = 0; + return 10; +}; + +static int fake_io_read(const char *path, void *buff, + size_t offset, size_t count, size_t *done) __attribute__ ((alias("fake_io"))); + +static int fake_io_write(const char *path, const void *buff, + size_t offset, size_t count, size_t *done) __attribute__ ((alias("fake_io"))); + +static inline void debug_out(const char val) +{ + __asm__ __volatile__( + "int $0x40 \n\t" + ::"a"(63), "b"(1),"c"(val)); +} + +static int debugwrite(const char *path, const void *buff, + size_t offset, size_t count, size_t *writes) +{ + int ret = count; + const char *p = buff; + + while (count--) + { + debug_out(*p++); + }; + *writes = ret; + return ret; +}; + +void init_stdio() +{ + __io_handle *ioh; + + ioh = &__io_tab[__io_alloc()]; + ioh->mode = _READ|_ISTTY; + ioh->read = &fake_io_read; + ioh->write = &fake_io_write; + + ioh = &__io_tab[__io_alloc()]; + ioh->mode = _WRITE|_ISTTY; + ioh->read = &fake_io_read; + ioh->write = &debugwrite; + + ioh = &__io_tab[__io_alloc()]; + ioh->mode = _WRITE|_ISTTY; + ioh->read = &fake_io_read; + ioh->write = &debugwrite; + +} diff --git a/contrib/sdk/sources/newlib/libc/sys/io.h b/contrib/sdk/sources/newlib/libc/sys/io.h new file mode 100644 index 0000000000..14563c7c6d --- /dev/null +++ b/contrib/sdk/sources/newlib/libc/sys/io.h @@ -0,0 +1,32 @@ + +#define _READ 0x0001 /* file opened for reading */ +#define _WRITE 0x0002 /* file opened for writing */ +#define _UNGET 0x0004 /* ungetc has been done */ +#define _BIGBUF 0x0008 /* big buffer allocated */ +#define _EOF 0x0010 /* EOF has occurred */ +#define _SFERR 0x0020 /* error has occurred on this file */ +#define _APPEND 0x0080 /* file opened for append */ +#define _BINARY 0x0040 /* file is binary, skip CRLF processing */ +#define _TMPFIL 0x0800 /* this is a temporary file */ +#define _DIRTY 0x1000 /* buffer has been modified */ +#define _ISTTY 0x2000 /* is console device */ +#define _DYNAMIC 0x4000 /* FILE is dynamically allocated */ +#define _FILEEXT 0x8000 /* lseek with positive offset has been done */ +#define _COMMIT 0x0001 /* extended flag: commit OS buffers on flush */ + +typedef struct +{ + char *name; + unsigned int offset; + int mode; + int lock; + int (*read)(const char *, void *, size_t, size_t, size_t *); + int (*write)(const char*, const void *, size_t, size_t, size_t*); +}__io_handle; + +extern __io_handle __io_tab[64]; + +int __io_alloc(); +void __io_free(int handle); + + diff --git a/contrib/sdk/sources/newlib/libc/sys/io_alloc.S b/contrib/sdk/sources/newlib/libc/sys/io_alloc.S new file mode 100644 index 0000000000..edecf82487 --- /dev/null +++ b/contrib/sdk/sources/newlib/libc/sys/io_alloc.S @@ -0,0 +1,50 @@ + +.section .text + +.global ___io_alloc +.global ___io_free +.global ___io_tab + +.align 8 +___io_alloc: + pushl $__io_mutex + call ___mutex_lock + popl %eax + + xorl %ecx, %ecx + bsfl __io_map, %eax + jnz .done + + movl $32, %ecx + bsfl __io_map+4, %eax + jnz .done + + xorl %eax, %eax + mov %eax, __io_mutex + notl %eax + ret + +.done: + addl %ecx, %eax + btrl %eax, __io_map + movl $0, __io_mutex + ret + +.align 8 +___io_free: + movl 4(%esp), %eax + bts %eax, __io_map + ret + +.section .data + +__io_map: .long(0xFFFFFFFF) + .long(0xFFFFFFFF) + +.section .bss + +.align 16 + +___io_tab: .space 64*24 +__io_mutex: .space 4 + diff --git a/contrib/sdk/sources/newlib/libc/sys/ioread.c b/contrib/sdk/sources/newlib/libc/sys/ioread.c new file mode 100644 index 0000000000..1840c7154e --- /dev/null +++ b/contrib/sdk/sources/newlib/libc/sys/ioread.c @@ -0,0 +1,31 @@ + +#include +#include + +int read_file(const char *path, void *buff, + size_t offset, size_t count, size_t *reads) +{ + int retval; + int d0; + __asm__ __volatile__( + "pushl $0 \n\t" + "pushl $0 \n\t" + "movl %%eax, 1(%%esp) \n\t" + "pushl %%ebx \n\t" + "pushl %%edx \n\t" + "pushl $0 \n\t" + "pushl %%ecx \n\t" + "pushl $0 \n\t" + "movl %%esp, %%ebx \n\t" + "mov $70, %%eax \n\t" + "int $0x40 \n\t" + "testl %%esi, %%esi \n\t" + "jz 1f \n\t" + "movl %%ebx, (%%esi) \n\t" +"1:" + "addl $28, %%esp \n\t" + :"=a" (retval) + :"a"(path),"b"(buff),"c"(offset),"d"(count),"S"(reads)); + return retval; +}; + diff --git a/contrib/sdk/sources/newlib/libc/sys/iowrite.c b/contrib/sdk/sources/newlib/libc/sys/iowrite.c new file mode 100644 index 0000000000..a92814f452 --- /dev/null +++ b/contrib/sdk/sources/newlib/libc/sys/iowrite.c @@ -0,0 +1,28 @@ +#include +#include + +int write_file(const char *path,const void *buff, + size_t offset, size_t count, size_t *writes) +{ + int retval; + __asm__ __volatile__( + "pushl $0 \n\t" + "pushl $0 \n\t" + "movl %%eax, 1(%%esp) \n\t" + "pushl %%ebx \n\t" + "pushl %%edx \n\t" + "pushl $0 \n\t" + "pushl %%ecx \n\t" + "pushl $3 \n\t" + "movl %%esp, %%ebx \n\t" + "mov $70, %%eax \n\t" + "int $0x40 \n\t" + "testl %%esi, %%esi \n\t" + "jz 1f \n\t" + "movl %%ebx, (%%esi) \n\t" +"1:" + "addl $28, %%esp \n\t" + :"=a" (retval) + :"a"(path),"b"(buff),"c"(offset),"d"(count),"S"(writes)); + return retval; +}; diff --git a/contrib/sdk/sources/newlib/libc/sys/isatty.c b/contrib/sdk/sources/newlib/libc/sys/isatty.c new file mode 100644 index 0000000000..2d66cd6525 --- /dev/null +++ b/contrib/sdk/sources/newlib/libc/sys/isatty.c @@ -0,0 +1,27 @@ +/* isatty.c -- chek the terminal device. + * + * Copyright (c) 1995 Cygnus Support + * + * The authors hereby grant permission to use, copy, modify, distribute, + * and license this software and its documentation for any purpose, provided + * that existing copyright notices are retained in all copies and that this + * notice is included verbatim in any distributions. No written agreement, + * license, or royalty fee is required for any of the authorized uses. + * Modifications to this software may be copyrighted by their authors + * and need not follow the licensing terms described here, provided that + * the new terms are clearly indicated on the first page of each file where + * they apply. + */ +#include "glue.h" + +/* + * isatty -- returns 1 if connected to a terminal device, + * returns 0 if not. Since we're hooked up to a + * serial port, we'll say yes _AND return a 1. + */ +int +_DEFUN (isatty, (fd), + int fd) +{ + return (1); +} diff --git a/contrib/sdk/sources/newlib/libc/sys/lseek.c b/contrib/sdk/sources/newlib/libc/sys/lseek.c new file mode 100644 index 0000000000..fe51ba9c74 --- /dev/null +++ b/contrib/sdk/sources/newlib/libc/sys/lseek.c @@ -0,0 +1,51 @@ + +#include +#include +#include +#include +#include "glue.h" +#include "io.h" + + +_off_t +_DEFUN (lseek, (fd, pos, whence), + int fd _AND + _off_t pos _AND + int whence) + +{ + fileinfo_t info; + __io_handle *ioh; + _off_t ret; + + if( (fd < 0) || (fd >=64) ) + { + errno = EBADF; + return (-1); + }; + + ioh = &__io_tab[fd]; + + switch(whence) + { + case SEEK_SET: + ret = pos; + break; + case SEEK_CUR: + ret = ioh->offset + pos; + break; + case SEEK_END: + { + get_fileinfo(ioh->name, &info); + ret = pos + info.size; + break; + } + default: + errno = EINVAL; + return (-1); + }; + + ioh->offset = ret; + + return( ret ); +}; diff --git a/contrib/sdk/sources/newlib/libc/sys/open.c b/contrib/sdk/sources/newlib/libc/sys/open.c new file mode 100644 index 0000000000..85dc2633c2 --- /dev/null +++ b/contrib/sdk/sources/newlib/libc/sys/open.c @@ -0,0 +1,104 @@ +/* open.c -- open a file. + * + * Copyright (c) 1995 Cygnus Support + * + * The authors hereby grant permission to use, copy, modify, distribute, + * and license this software and its documentation for any purpose, provided + * that existing copyright notices are retained in all copies and that this + * notice is included verbatim in any distributions. No written agreement, + * license, or royalty fee is required for any of the authorized uses. + * Modifications to this software may be copyrighted by their authors + * and need not follow the licensing terms described here, provided that + * the new terms are clearly indicated on the first page of each file where + * they apply. + */ +#include +#include +#include +#include +#include "glue.h" +#include "io.h" + +#undef erro +extern int errno; + +int open (const char * filename, int flags, ...) +{ + __io_handle *ioh; + fileinfo_t info; + int iomode, rwmode, offset; + int hid; + int err; + + hid = __io_alloc(); + if(hid < 0) + { + errno = EMFILE; + return (-1); + }; + +// path = getfullpath(name); + + err = get_fileinfo(filename, &info); + + if( flags & O_EXCL && + flags & O_CREAT ) + { + if( !err ) + { + errno = EEXIST; + return (-1); + }; + } + + if( err ) + { + if(flags & O_CREAT) + err=create_file(filename); + if( err ) + { + errno = EACCES; + return -1; + }; + }; + + if( flags & O_TRUNC ) + set_file_size(filename, 0); + + ioh = &__io_tab[hid]; + + rwmode = flags & ( O_RDONLY | O_WRONLY | O_RDWR ); + + iomode = 0; + offset = 0; + + if( rwmode == O_RDWR ) + iomode |= _READ | _WRITE; + else if( rwmode == O_RDONLY) + iomode |= _READ; + else if( rwmode == O_WRONLY) + iomode |= _WRITE; + + if( flags & O_APPEND ) + { + iomode |= _APPEND; + offset = info.size; + }; + + if( flags & (O_BINARY|O_TEXT) ) + { + if( flags & O_BINARY ) + iomode |= _BINARY; + } else + iomode |= _BINARY; + + ioh->name = strdup(filename); + ioh->offset = offset; + ioh->mode = iomode; + ioh->read = read_file; + ioh->write = write_file; + + return hid; +}; + + diff --git a/contrib/sdk/sources/newlib/libc/sys/read.c b/contrib/sdk/sources/newlib/libc/sys/read.c index 1840c7154e..126280c74d 100644 --- a/contrib/sdk/sources/newlib/libc/sys/read.c +++ b/contrib/sdk/sources/newlib/libc/sys/read.c @@ -1,31 +1,112 @@ - -#include -#include - -int read_file(const char *path, void *buff, - size_t offset, size_t count, size_t *reads) -{ - int retval; - int d0; - __asm__ __volatile__( - "pushl $0 \n\t" - "pushl $0 \n\t" - "movl %%eax, 1(%%esp) \n\t" - "pushl %%ebx \n\t" - "pushl %%edx \n\t" - "pushl $0 \n\t" - "pushl %%ecx \n\t" - "pushl $0 \n\t" - "movl %%esp, %%ebx \n\t" - "mov $70, %%eax \n\t" - "int $0x40 \n\t" - "testl %%esi, %%esi \n\t" - "jz 1f \n\t" - "movl %%ebx, (%%esi) \n\t" -"1:" - "addl $28, %%esp \n\t" - :"=a" (retval) - :"a"(path),"b"(buff),"c"(offset),"d"(count),"S"(reads)); - return retval; -}; - +/* read.c -- read bytes from a input device. + * + * Copyright (c) 1995 Cygnus Support + * + * The authors hereby grant permission to use, copy, modify, distribute, + * and license this software and its documentation for any purpose, provided + * that existing copyright notices are retained in all copies and that this + * notice is included verbatim in any distributions. No written agreement, + * license, or royalty fee is required for any of the authorized uses. + * Modifications to this software may be copyrighted by their authors + * and need not follow the licensing terms described here, provided that + * the new terms are clearly indicated on the first page of each file where + * they apply. + */ +#include +#include +#include +#include +#include +#include +#include "glue.h" +#include "io.h" + +#undef erro +extern int errno; + +ssize_t read(int fd, void *buf, size_t cnt) +{ + _ssize_t ret; + + _ssize_t read_len, total_len; + unsigned reduce_idx, finish_idx; + unsigned iomode_flags; + char *buffer = buf; + int rc; + int h; + unsigned amount_read; + int err; + + __io_handle *ioh; + + if( (fd < 0) || (fd >=64) ) + { + errno = EBADF; + return -1; + }; + + ioh = &__io_tab[fd]; + + iomode_flags = ioh->mode; + + if( iomode_flags == 0 ) + { + errno = EBADF; + return( -1 ); + } + + if( !(iomode_flags & _READ) ) + { + errno = EACCES; + return( -1 ); + } + + if( iomode_flags & _BINARY ) /* if binary mode */ + { + err = read_file(ioh->name, buffer, ioh->offset, cnt, &amount_read); + ioh->offset+= amount_read; + total_len = amount_read; + + if(err) + if ( amount_read == 0) + return (-1); + } + else + { + total_len = 0; + read_len = cnt; + do + { + err=read_file(ioh->name,buffer, ioh->offset, cnt, &amount_read); + ioh->offset+=amount_read; + + if( amount_read == 0 ) + break; /* EOF */ + + reduce_idx = 0; + finish_idx = reduce_idx; + for( ; reduce_idx < amount_read; ++reduce_idx ) + { + if( buffer[ reduce_idx ] == 0x1a ) /* EOF */ + { + lseek(fd, ((long)reduce_idx - (long)amount_read)+1L, SEEK_CUR ); + total_len += finish_idx; + return( total_len ); + } + if( buffer[ reduce_idx ] != '\r' ) + { + buffer[ finish_idx++ ] = buffer[ reduce_idx ]; + }; + } + + total_len += finish_idx; + buffer += finish_idx; + read_len -= finish_idx; + if( iomode_flags & _ISTTY ) + { + break; + } + } while( read_len != 0 ); + } + return( total_len ); +} diff --git a/contrib/sdk/sources/newlib/libc/sys/unlink.c b/contrib/sdk/sources/newlib/libc/sys/unlink.c new file mode 100644 index 0000000000..8e7a654ec7 --- /dev/null +++ b/contrib/sdk/sources/newlib/libc/sys/unlink.c @@ -0,0 +1,48 @@ +/* unlink.c -- remove a file. + * + * Copyright (c) 1995 Cygnus Support + * + * The authors hereby grant permission to use, copy, modify, distribute, + * and license this software and its documentation for any purpose, provided + * that existing copyright notices are retained in all copies and that this + * notice is included verbatim in any distributions. No written agreement, + * license, or royalty fee is required for any of the authorized uses. + * Modifications to this software may be copyrighted by their authors + * and need not follow the licensing terms described here, provided that + * the new terms are clearly indicated on the first page of each file where + * they apply. + */ +#include +#include +#include +#include + +#include "glue.h" + +/* + * unlink -- since we have no file system, + * we just return an error. + */ +int +_DEFUN (unlink, (path), + char * path) +{ + errno = EIO; + return (-1); +} + +int +_DEFUN(link, (old, new), + const char *old _AND + const char *new) +{ + errno = EIO; + return (-1); +} + +clock_t +times (struct tms *tp) +{ + return -1; +} + diff --git a/contrib/sdk/sources/newlib/libc/sys/write.c b/contrib/sdk/sources/newlib/libc/sys/write.c index 80afc7c7bb..f30edfd931 100644 --- a/contrib/sdk/sources/newlib/libc/sys/write.c +++ b/contrib/sdk/sources/newlib/libc/sys/write.c @@ -1,29 +1,217 @@ - -#include +/* write.c -- write bytes to an output device. + * + * Copyright (c) 1995 Cygnus Support + * + * The authors hereby grant permission to use, copy, modify, distribute, + * and license this software and its documentation for any purpose, provided + * that existing copyright notices are retained in all copies and that this + * notice is included verbatim in any distributions. No written agreement, + * license, or royalty fee is required for any of the authorized uses. + * Modifications to this software may be copyrighted by their authors + * and need not follow the licensing terms described here, provided that + * the new terms are clearly indicated on the first page of each file where + * they apply. + */ +#include +#include +#include +#include +#include #include +#include "glue.h" +#include "io.h" -int write_file(const char *path,const void *buff, - size_t offset, size_t count, size_t *writes) +#undef erro +extern int errno; + + +#if 0 +#define PAD_SIZE 512 + +static int zero_pad(int handle ) /* 09-jan-95 */ +/*******************************/ { - int retval; - __asm__ __volatile__( - "pushl $0 \n\t" - "pushl $0 \n\t" - "movl %%eax, 1(%%esp) \n\t" - "pushl %%ebx \n\t" - "pushl %%edx \n\t" - "pushl $0 \n\t" - "pushl %%ecx \n\t" - "pushl $3 \n\t" - "movl %%esp, %%ebx \n\t" - "mov $70, %%eax \n\t" - "int $0x40 \n\t" - "testl %%esi, %%esi \n\t" - "jz 1f \n\t" - "movl %%ebx, (%%esi) \n\t" -"1:" - "addl $28, %%esp \n\t" - :"=a" (retval) - :"a"(path),"b"(buff),"c"(offset),"d"(count),"S"(writes)); - return retval; -}; + int rc; + long curPos, eodPos; + long bytesToWrite; + unsigned writeAmt; + char zeroBuf[PAD_SIZE]; + + // Pad with zeros due to lseek() past EOF (POSIX) + curPos = lseek( handle, 0L, SEEK_CUR ); /* current offset */ + if( curPos == -1 ) + return( -1 ); + eodPos = lseek( handle, 0L, SEEK_END ); /* end of data offset */ + if( eodPos == -1 ) + return( -1 ); + + if( curPos > eodPos ) { + bytesToWrite = curPos - eodPos; /* amount to pad by */ + + if( bytesToWrite > 0 ) { /* only write if needed */ + memset( zeroBuf, 0x00, PAD_SIZE ); /* zero out a buffer */ + do { /* loop until done */ + if( bytesToWrite > PAD_SIZE ) + writeAmt = 512; + else + writeAmt = (unsigned)bytesToWrite; + rc = _write_r(ptr, handle, zeroBuf, writeAmt ); + if( rc < 0 ) + return( rc ); + bytesToWrite -= writeAmt; /* more bytes written */ + } while( bytesToWrite != 0 ); + } + } else { + curPos = _lseek_r( ptr, handle, curPos, SEEK_SET ); + if( curPos == -1 ) { + return( -1 ); + } + } + + return( 0 ); /* return success code */ +} +#endif + +static int os_write(int handle, const void *buffer, unsigned len, unsigned *amt ) +{ + __io_handle *ioh; + int rc; + + rc = 0; + *amt = 0; + + ioh = &__io_tab[handle]; + + rc = ioh->write(ioh->name,(const void*)buffer,ioh->offset,len,amt); + + ioh->offset+= *amt; + + if( *amt != len ) + { + rc = ENOSPC; + } + + return( rc ); +} + +/* + * write -- write bytes to the serial port. Ignore fd, since + * stdout and stderr are the same. Since we have no filesystem, + * open will only return an error. + */ +ssize_t write(int fd, const void *buffer, size_t cnt) +{ + _ssize_t ret; + unsigned int iomode_flags; + unsigned len_written, i, j; + int rc2; + char *buf; + + __io_handle *ioh; + + if( (fd < 0) || (fd >=64) ) + { + errno = EBADF; + return -1; + }; + + ioh = &__io_tab[fd]; + + iomode_flags = ioh->mode; + + if( iomode_flags == 0 ) + { + errno = EBADF; + return( -1 ); + } + + if( !(iomode_flags & _WRITE) ) + { + errno = EACCES ; + return( -1 ); + } + + if( (iomode_flags & _APPEND) && !(iomode_flags & _ISTTY) ) + { + ioh->offset = lseek(fd, 0L, SEEK_END ); /* end of data offset */ + } + + len_written = 0; + rc2 = 0; + + // Pad the file with zeros if necessary + if( iomode_flags & _FILEEXT ) + { + // turn off file extended flag + ioh->mode = iomode_flags & (~_FILEEXT); + + // It is not required to pad a file with zeroes on an NTFS file system; + // unfortunately it is required on FAT (and probably FAT32). (JBS) +// rc2 = zero_pad( ptr, fd ); + } + + if( rc2 == 0 ) + { + if( iomode_flags & _BINARY ) { /* if binary mode */ + rc2 = os_write(fd, buffer, cnt, &len_written ); + /* end of binary mode part */ + } else { /* text mode */ + + int buf_size = 512; + + buf = (char*)alloca( buf_size ); + + j = 0; + for( i = 0; i < cnt; ) + { + if( ((const char*)buffer)[i] == '\n' ) + { + buf[j] = '\r'; + ++j; + if( j == buf_size ) + { + rc2 = os_write(fd, buf, buf_size, &j ); + if( rc2 == -1 ) + break; + len_written += j; + if( rc2 == ENOSPC ) + break; + len_written = i; + j = 0; + } + } + buf[j] = ((const char*)buffer)[i]; + ++i; + ++j; + if( j == buf_size ) { + rc2 = os_write(fd, buf, buf_size, &j ); + if( rc2 == -1 ) + break; + len_written += j; + if( rc2 == ENOSPC ) + break; + len_written = i; + j = 0; + } + } + if( j ) { + rc2 = os_write(fd, buf, j, &i ); + if( rc2 == ENOSPC ) { + len_written += i; + } else { + len_written = cnt; + } + } + /* end of text mode part */ + } + } + + if( rc2 == -1 ) { + return( rc2 ); + } else { + return( len_written ); + } + + return 0; +} + diff --git a/contrib/sdk/sources/newlib/libc/time/asctime.c b/contrib/sdk/sources/newlib/libc/time/asctime.c index 63b9de0d3a..024310bbf3 100644 --- a/contrib/sdk/sources/newlib/libc/time/asctime.c +++ b/contrib/sdk/sources/newlib/libc/time/asctime.c @@ -1,64 +1,66 @@ -/* - * asctime.c - * Original Author: G. Haley - * - * Converts the broken down time in the structure pointed to by tim_p into a - * string of the form - * - * Wed Jun 15 11:38:07 1988\n\0 - * - * Returns a pointer to the string. - */ - -/* -FUNCTION -<>---format time as string - -INDEX - asctime -INDEX - _asctime_r - -ANSI_SYNOPSIS - #include - char *asctime(const struct tm *<[clock]>); - char *_asctime_r(const struct tm *<[clock]>, char *<[buf]>); - -TRAD_SYNOPSIS - #include - char *asctime(<[clock]>) - struct tm *<[clock]>; - char *asctime_r(<[clock]>) - struct tm *<[clock]>; - char *<[buf]>; - -DESCRIPTION -Format the time value at <[clock]> into a string of the form -. Wed Jun 15 11:38:07 1988\n\0 -The string is generated in a static buffer; each call to <> -overwrites the string generated by previous calls. - -RETURNS -A pointer to the string containing a formatted timestamp. - -PORTABILITY -ANSI C requires <>. - -<> requires no supporting OS subroutines. -*/ - -#include -#include <_ansi.h> -#include - -#ifndef _REENT_ONLY - -char * -_DEFUN (asctime, (tim_p), - _CONST struct tm *tim_p) -{ - _REENT_CHECK_ASCTIME_BUF(_REENT); - return asctime_r (tim_p, _REENT_ASCTIME_BUF(_REENT)); -} - -#endif +/* + * asctime.c + * Original Author: G. Haley + * + * Converts the broken down time in the structure pointed to by tim_p into a + * string of the form + * + * Wed Jun 15 11:38:07 1988\n\0 + * + * Returns a pointer to the string. + */ + +/* +FUNCTION +<>---format time as string + +INDEX + asctime +INDEX + _asctime_r + +ANSI_SYNOPSIS + #include + char *asctime(const struct tm *<[clock]>); + char *_asctime_r(const struct tm *<[clock]>, char *<[buf]>); + +TRAD_SYNOPSIS + #include + char *asctime(<[clock]>) + struct tm *<[clock]>; + char *asctime_r(<[clock]>) + struct tm *<[clock]>; + char *<[buf]>; + +DESCRIPTION +Format the time value at <[clock]> into a string of the form +. Wed Jun 15 11:38:07 1988\n\0 +The string is generated in a static buffer; each call to <> +overwrites the string generated by previous calls. + +RETURNS +A pointer to the string containing a formatted timestamp. + +PORTABILITY +ANSI C requires <>. + +<> requires no supporting OS subroutines. +*/ + +#include +#include <_ansi.h> +#include + +#ifndef _REENT_ONLY + +char * +_DEFUN (asctime, (tim_p), + _CONST struct tm *tim_p) +{ + struct _reent *reent = _REENT; + + _REENT_CHECK_ASCTIME_BUF(reent); + return asctime_r (tim_p, _REENT_ASCTIME_BUF(reent)); +} + +#endif diff --git a/contrib/sdk/sources/newlib/libc/time/asctime_r.c b/contrib/sdk/sources/newlib/libc/time/asctime_r.c index 71f4d6f81d..2ec53698ea 100644 --- a/contrib/sdk/sources/newlib/libc/time/asctime_r.c +++ b/contrib/sdk/sources/newlib/libc/time/asctime_r.c @@ -1,27 +1,27 @@ -/* - * asctime_r.c - */ - -#include -#include - -char * -_DEFUN (asctime_r, (tim_p, result), - _CONST struct tm *tim_p _AND - char *result) -{ - static _CONST char day_name[7][3] = { - "Sun", "Mon", "Tue", "Wed", "Thu", "Fri", "Sat" - }; - static _CONST char mon_name[12][3] = { - "Jan", "Feb", "Mar", "Apr", "May", "Jun", - "Jul", "Aug", "Sep", "Oct", "Nov", "Dec" - }; - - siprintf (result, "%.3s %.3s%3d %.2d:%.2d:%.2d %d\n", - day_name[tim_p->tm_wday], - mon_name[tim_p->tm_mon], - tim_p->tm_mday, tim_p->tm_hour, tim_p->tm_min, - tim_p->tm_sec, 1900 + tim_p->tm_year); - return result; -} +/* + * asctime_r.c + */ + +#include +#include + +char * +_DEFUN (asctime_r, (tim_p, result), + _CONST struct tm *__restrict tim_p _AND + char *__restrict result) +{ + static _CONST char day_name[7][3] = { + "Sun", "Mon", "Tue", "Wed", "Thu", "Fri", "Sat" + }; + static _CONST char mon_name[12][3] = { + "Jan", "Feb", "Mar", "Apr", "May", "Jun", + "Jul", "Aug", "Sep", "Oct", "Nov", "Dec" + }; + + siprintf (result, "%.3s %.3s%3d %.2d:%.2d:%.2d %d\n", + day_name[tim_p->tm_wday], + mon_name[tim_p->tm_mon], + tim_p->tm_mday, tim_p->tm_hour, tim_p->tm_min, + tim_p->tm_sec, 1900 + tim_p->tm_year); + return result; +} diff --git a/contrib/sdk/sources/newlib/libc/time/clock.c b/contrib/sdk/sources/newlib/libc/time/clock.c index 5c29ce2668..64cf438fbc 100644 --- a/contrib/sdk/sources/newlib/libc/time/clock.c +++ b/contrib/sdk/sources/newlib/libc/time/clock.c @@ -1,78 +1,69 @@ -/* NetWare can not use this implementation of clock, since it does not - have times or any similar function. It provides its own version of - clock in clib.nlm. If we can not use clib.nlm, then we must write - clock in sys/netware. */ - -#ifdef CLOCK_PROVIDED - -int _dummy_clock = 1; - -#else - -/* - * clock.c - * Original Author: G. Haley - * - * Determines the processor time used by the program since invocation. The time - * in seconds is the value returned divided by the value of the macro CLK_TCK. - * If the processor time used is not available, (clock_t) -1 is returned. - */ - -/* -FUNCTION -<>---cumulative processor time - -INDEX - clock - -ANSI_SYNOPSIS - #include - clock_t clock(void); - -TRAD_SYNOPSIS - #include - clock_t clock(); - -DESCRIPTION -Calculates the best available approximation of the cumulative amount -of time used by your program since it started. To convert the result -into seconds, divide by the macro <>. - -RETURNS -The amount of processor time used so far by your program, in units -defined by the machine-dependent macro <>. If no -measurement is available, the result is (clock_t)<<-1>>. - -PORTABILITY -ANSI C requires <> and <>. - -Supporting OS subroutine required: <>. -*/ - -#include -#include -#include - - -clock_t -_DEFUN (_times_r, (ptr, ptms), - struct _reent *ptr _AND - struct tms *ptms) -{ - return -1; -} - -clock_t -clock () -{ - struct tms tim_s; - clock_t res; - - if ((res = (clock_t) _times_r (_REENT, &tim_s)) != -1) - res = (clock_t) (tim_s.tms_utime + tim_s.tms_stime + - tim_s.tms_cutime + tim_s.tms_cstime); - - return res; -} - -#endif /* CLOCK_PROVIDED */ +/* NetWare can not use this implementation of clock, since it does not + have times or any similar function. It provides its own version of + clock in clib.nlm. If we can not use clib.nlm, then we must write + clock in sys/netware. */ + +#ifdef CLOCK_PROVIDED + +int _dummy_clock = 1; + +#else + +/* + * clock.c + * Original Author: G. Haley + * + * Determines the processor time used by the program since invocation. The time + * in seconds is the value returned divided by the value of the macro CLK_TCK. + * If the processor time used is not available, (clock_t) -1 is returned. + */ + +/* +FUNCTION +<>---cumulative processor time + +INDEX + clock + +ANSI_SYNOPSIS + #include + clock_t clock(void); + +TRAD_SYNOPSIS + #include + clock_t clock(); + +DESCRIPTION +Calculates the best available approximation of the cumulative amount +of time used by your program since it started. To convert the result +into seconds, divide by the macro <>. + +RETURNS +The amount of processor time used so far by your program, in units +defined by the machine-dependent macro <>. If no +measurement is available, the result is (clock_t)<<-1>>. + +PORTABILITY +ANSI C requires <> and <>. + +Supporting OS subroutine required: <>. +*/ + +#include +#include +#include + +clock_t +clock () +{ + struct tms tim_s; + clock_t res; + + if ((res = (clock_t) _times_r (_REENT, &tim_s)) != -1) + res = (clock_t) (tim_s.tms_utime + tim_s.tms_stime + + tim_s.tms_cutime + tim_s.tms_cstime); + + return res; +} + +#endif /* CLOCK_PROVIDED */ diff --git a/contrib/sdk/sources/newlib/libc/time/gmtime.c b/contrib/sdk/sources/newlib/libc/time/gmtime.c index 7d389298d7..bd831779f6 100644 --- a/contrib/sdk/sources/newlib/libc/time/gmtime.c +++ b/contrib/sdk/sources/newlib/libc/time/gmtime.c @@ -61,8 +61,10 @@ struct tm * _DEFUN (gmtime, (tim_p), _CONST time_t * tim_p) { - _REENT_CHECK_TM(_REENT); - return gmtime_r (tim_p, (struct tm *)_REENT_TM(_REENT)); + struct _reent *reent = _REENT; + + _REENT_CHECK_TM(reent); + return gmtime_r (tim_p, (struct tm *)_REENT_TM(reent)); } #endif diff --git a/contrib/sdk/sources/newlib/libc/time/gmtime_r.c b/contrib/sdk/sources/newlib/libc/time/gmtime_r.c index 8910827aad..232e133a89 100644 --- a/contrib/sdk/sources/newlib/libc/time/gmtime_r.c +++ b/contrib/sdk/sources/newlib/libc/time/gmtime_r.c @@ -7,8 +7,8 @@ struct tm * _DEFUN (gmtime_r, (tim_p, res), - _CONST time_t * tim_p _AND - struct tm *res) + _CONST time_t *__restrict tim_p _AND + struct tm *__restrict res) { return (_mktm_r (tim_p, res, 1)); } diff --git a/contrib/sdk/sources/newlib/libc/time/lcltime.c b/contrib/sdk/sources/newlib/libc/time/lcltime.c index 8a155e2bd0..48a722826b 100644 --- a/contrib/sdk/sources/newlib/libc/time/lcltime.c +++ b/contrib/sdk/sources/newlib/libc/time/lcltime.c @@ -53,8 +53,10 @@ struct tm * _DEFUN (localtime, (tim_p), _CONST time_t * tim_p) { - _REENT_CHECK_TM(_REENT); - return localtime_r (tim_p, (struct tm *)_REENT_TM(_REENT)); + struct _reent *reent = _REENT; + + _REENT_CHECK_TM(reent); + return localtime_r (tim_p, (struct tm *)_REENT_TM(reent)); } #endif diff --git a/contrib/sdk/sources/newlib/libc/time/lcltime_r.c b/contrib/sdk/sources/newlib/libc/time/lcltime_r.c index 7dd42f0779..aac4f8b812 100644 --- a/contrib/sdk/sources/newlib/libc/time/lcltime_r.c +++ b/contrib/sdk/sources/newlib/libc/time/lcltime_r.c @@ -11,8 +11,8 @@ struct tm * _DEFUN (localtime_r, (tim_p, res), - _CONST time_t * tim_p _AND - struct tm *res) + _CONST time_t *__restrict tim_p _AND + struct tm *__restrict res) { return _mktm_r (tim_p, res, 0); } diff --git a/contrib/sdk/sources/newlib/libc/time/ldpart.h b/contrib/sdk/sources/newlib/libc/time/ldpart.h new file mode 100644 index 0000000000..86031fd336 --- /dev/null +++ b/contrib/sdk/sources/newlib/libc/time/ldpart.h @@ -0,0 +1,35 @@ +/*- + * Copyright (c) 2000, 2001 Alexey Zelkin + * 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: src/lib/libc/locale/ldpart.h,v 1.4 2001/12/20 18:28:52 phantom Exp $ + */ + +#ifndef _LDPART_H_ +#define _LDPART_H_ + +int __part_load_locale(const char *, int*, char *, const char *, + int, int, const char **); + +#endif /* !_LDPART_H_ */ diff --git a/contrib/sdk/sources/newlib/libc/time/strftime.c b/contrib/sdk/sources/newlib/libc/time/strftime.c index e4954a63a1..ec6c6e5bca 100644 --- a/contrib/sdk/sources/newlib/libc/time/strftime.c +++ b/contrib/sdk/sources/newlib/libc/time/strftime.c @@ -24,8 +24,9 @@ INDEX ANSI_SYNOPSIS #include - size_t strftime(char *<[s]>, size_t <[maxsize]>, - const char *<[format]>, const struct tm *<[timp]>); + size_t strftime(char *restrict <[s]>, size_t <[maxsize]>, + const char *restrict <[format]>, + const struct tm *restrict <[timp]>); TRAD_SYNOPSIS #include @@ -270,6 +271,8 @@ the "C" locale settings. #include #include #include +#include "local.h" +#include "../locale/timelocal.h" /* Defines to make the file dual use for either strftime() or wcsftime(). * To get wcsftime, define MAKE_WCSFTIME. @@ -283,6 +286,7 @@ the "C" locale settings. # 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 STRTOUL(c,p,b) strtoul((c),(p),(b)) # define STRCPY(a,b) strcpy((a),(b)) @@ -319,15 +323,1467 @@ the "C" locale settings. # endif #endif /* MAKE_WCSFTIME */ +#define CHECK_LENGTH() if (len < 0 || (count += len) >= maxsize) \ + return 0 -size_t _DEFUN (strftime, (s, maxsize, format, tim_p), - CHAR *s _AND - size_t maxsize _AND - _CONST CHAR *format _AND +/* Enforce the coding assumptions that YEAR_BASE is positive. (%C, %Y, etc.) */ +#if YEAR_BASE < 0 +# error "YEAR_BASE < 0" +#endif + +static _CONST int dname_len[7] = +{6, 6, 7, 9, 8, 6, 8}; + +/* Using the tm_year, tm_wday, and tm_yday components of TIM_P, return + -1, 0, or 1 as the adjustment to add to the year for the ISO week + numbering used in "%g%G%V", avoiding overflow. */ +static int +_DEFUN (iso_year_adjust, (tim_p), _CONST struct tm *tim_p) { + /* Account for fact that tm_year==0 is year 1900. */ + int leap = isleap (tim_p->tm_year + (YEAR_BASE + - (tim_p->tm_year < 0 ? 0 : 2000))); + /* Pack the yday, wday, and leap year into a single int since there are so + many disparate cases. */ +#define PACK(yd, wd, lp) (((yd) << 4) + (wd << 1) + (lp)) + switch (PACK (tim_p->tm_yday, tim_p->tm_wday, leap)) + { + case PACK (0, 5, 0): /* Jan 1 is Fri, not leap. */ + case PACK (0, 6, 0): /* Jan 1 is Sat, not leap. */ + case PACK (0, 0, 0): /* Jan 1 is Sun, not leap. */ + case PACK (0, 5, 1): /* Jan 1 is Fri, leap year. */ + case PACK (0, 6, 1): /* Jan 1 is Sat, leap year. */ + case PACK (0, 0, 1): /* Jan 1 is Sun, leap year. */ + case PACK (1, 6, 0): /* Jan 2 is Sat, not leap. */ + case PACK (1, 0, 0): /* Jan 2 is Sun, not leap. */ + case PACK (1, 6, 1): /* Jan 2 is Sat, leap year. */ + case PACK (1, 0, 1): /* Jan 2 is Sun, leap year. */ + case PACK (2, 0, 0): /* Jan 3 is Sun, not leap. */ + case PACK (2, 0, 1): /* Jan 3 is Sun, leap year. */ + return -1; /* Belongs to last week of previous year. */ + case PACK (362, 1, 0): /* Dec 29 is Mon, not leap. */ + case PACK (363, 1, 1): /* Dec 29 is Mon, leap year. */ + case PACK (363, 1, 0): /* Dec 30 is Mon, not leap. */ + case PACK (363, 2, 0): /* Dec 30 is Tue, not leap. */ + case PACK (364, 1, 1): /* Dec 30 is Mon, leap year. */ + case PACK (364, 2, 1): /* Dec 30 is Tue, leap year. */ + case PACK (364, 1, 0): /* Dec 31 is Mon, not leap. */ + case PACK (364, 2, 0): /* Dec 31 is Tue, not leap. */ + case PACK (364, 3, 0): /* Dec 31 is Wed, not leap. */ + case PACK (365, 1, 1): /* Dec 31 is Mon, leap year. */ + case PACK (365, 2, 1): /* Dec 31 is Tue, leap year. */ + case PACK (365, 3, 1): /* Dec 31 is Wed, leap year. */ + return 1; /* Belongs to first week of next year. */ + } + return 0; /* Belongs to specified year. */ +#undef PACK +} + +#ifdef _WANT_C99_TIME_FORMATS +typedef struct { + int year; + CHAR *era_C; + CHAR *era_Y; +} era_info_t; + +static era_info_t * +#if defined (MAKE_WCSFTIME) && defined (__HAVE_LOCALE_INFO_EXTENDED__) +get_era_info (const struct tm *tim_p, const wchar_t *era) +#else +get_era_info (const struct tm *tim_p, const char *era) +#endif +{ +#if defined (MAKE_WCSFTIME) && defined (__HAVE_LOCALE_INFO_EXTENDED__) + wchar_t *c; + const wchar_t *dir; +# define ERA_STRCHR(a,b) wcschr((a),(b)) +# define ERA_STRNCPY(a,b,c) wcsncpy((a),(b),(c)) +# define ERA_STRTOL(a,b,c) wcstol((a),(b),(c)) +#else + char *c; + const char *dir; +# define ERA_STRCHR(a,b) strchr((a),(b)) +# define ERA_STRNCPY(a,b,c) strncpy((a),(b),(c)) +# define ERA_STRTOL(a,b,c) strtol((a),(b),(c)) +#endif + long offset; + struct tm stm, etm; + era_info_t *ei; + + ei = (era_info_t *) calloc (1, sizeof (era_info_t)); + if (!ei) + return NULL; + + stm.tm_isdst = etm.tm_isdst = 0; + while (era) + { + dir = era; + era += 2; + offset = ERA_STRTOL (era, &c, 10); + era = c + 1; + stm.tm_year = ERA_STRTOL (era, &c, 10) - YEAR_BASE; + /* Adjust offset for negative gregorian dates. */ + if (stm.tm_year <= -YEAR_BASE) + ++stm.tm_year; + stm.tm_mon = ERA_STRTOL (c + 1, &c, 10) - 1; + stm.tm_mday = ERA_STRTOL (c + 1, &c, 10); + stm.tm_hour = stm.tm_min = stm.tm_sec = 0; + era = c + 1; + if (era[0] == '-' && era[1] == '*') + { + etm = stm; + stm.tm_year = INT_MIN; + stm.tm_mon = stm.tm_mday = stm.tm_hour = stm.tm_min = stm.tm_sec = 0; + era += 3; + } + else if (era[0] == '+' && era[1] == '*') + { + etm.tm_year = INT_MAX; + etm.tm_mon = 11; + etm.tm_mday = 31; + etm.tm_hour = 23; + etm.tm_min = etm.tm_sec = 59; + era += 3; + } + else + { + etm.tm_year = ERA_STRTOL (era, &c, 10) - YEAR_BASE; + /* Adjust offset for negative gregorian dates. */ + if (etm.tm_year <= -YEAR_BASE) + ++etm.tm_year; + etm.tm_mon = ERA_STRTOL (c + 1, &c, 10) - 1; + etm.tm_mday = ERA_STRTOL (c + 1, &c, 10); + etm.tm_mday = 31; + etm.tm_hour = 23; + etm.tm_min = etm.tm_sec = 59; + era = c + 1; + } + if ((tim_p->tm_year > stm.tm_year + || (tim_p->tm_year == stm.tm_year + && (tim_p->tm_mon > stm.tm_mon + || (tim_p->tm_mon == stm.tm_mon + && tim_p->tm_mday >= stm.tm_mday)))) + && (tim_p->tm_year < etm.tm_year + || (tim_p->tm_year == etm.tm_year + && (tim_p->tm_mon < etm.tm_mon + || (tim_p->tm_mon == etm.tm_mon + && tim_p->tm_mday <= etm.tm_mday))))) + { + /* Gotcha */ + size_t len; + + /* year */ + if (*dir == '+' && stm.tm_year != INT_MIN) + ei->year = tim_p->tm_year - stm.tm_year + offset; + else + ei->year = etm.tm_year - tim_p->tm_year + offset; + /* era_C */ + c = ERA_STRCHR (era, ':'); +#if defined (MAKE_WCSFTIME) && !defined (__HAVE_LOCALE_INFO_EXTENDED__) + len = mbsnrtowcs (NULL, &era, c - era, 0, NULL); + if (len == (size_t) -1) + { + free (ei); + return NULL; + } +#else + len = c - era; +#endif + ei->era_C = (CHAR *) malloc ((len + 1) * sizeof (CHAR)); + if (!ei->era_C) + { + free (ei); + return NULL; + } +#if defined (MAKE_WCSFTIME) && !defined (__HAVE_LOCALE_INFO_EXTENDED__) + len = mbsnrtowcs (ei->era_C, &era, c - era, len + 1, NULL); +#else + ERA_STRNCPY (ei->era_C, era, len); + era += len; +#endif + ei->era_C[len] = CQ('\0'); + /* era_Y */ + ++era; + c = ERA_STRCHR (era, ';'); + if (!c) + c = ERA_STRCHR (era, '\0'); +#if defined (MAKE_WCSFTIME) && !defined (__HAVE_LOCALE_INFO_EXTENDED__) + len = mbsnrtowcs (NULL, &era, c - era, 0, NULL); + if (len == (size_t) -1) + { + free (ei->era_C); + free (ei); + return NULL; + } +#else + len = c - era; +#endif + ei->era_Y = (CHAR *) malloc ((len + 1) * sizeof (CHAR)); + if (!ei->era_Y) + { + free (ei->era_C); + free (ei); + return NULL; + } +#if defined (MAKE_WCSFTIME) && !defined (__HAVE_LOCALE_INFO_EXTENDED__) + len = mbsnrtowcs (ei->era_Y, &era, c - era, len + 1, NULL); +#else + ERA_STRNCPY (ei->era_Y, era, len); + era += len; +#endif + ei->era_Y[len] = CQ('\0'); + return ei; + } + else + era = ERA_STRCHR (era, ';'); + if (era) + ++era; + } + return NULL; +} + +static void +free_era_info (era_info_t *ei) +{ + free (ei->era_C); + free (ei->era_Y); + free (ei); +} + +typedef struct { + size_t num; + CHAR **digit; + CHAR *buffer; +} alt_digits_t; + +static alt_digits_t * +#if defined (MAKE_WCSFTIME) && defined (__HAVE_LOCALE_INFO_EXTENDED__) +get_alt_digits (const wchar_t *alt_digits) +#else +get_alt_digits (const char *alt_digits) +#endif +{ + alt_digits_t *adi; +#if defined (MAKE_WCSFTIME) && defined (__HAVE_LOCALE_INFO_EXTENDED__) + const wchar_t *a, *e; +# define ALT_STRCHR(a,b) wcschr((a),(b)) +# define ALT_STRCPY(a,b) wcscpy((a),(b)) +# define ALT_STRLEN(a) wcslen(a) +#else + const char *a, *e; +# define ALT_STRCHR(a,b) strchr((a),(b)) +# define ALT_STRCPY(a,b) strcpy((a),(b)) +# define ALT_STRLEN(a) strlen(a) +#endif + CHAR *aa, *ae; + size_t len; + + adi = (alt_digits_t *) calloc (1, sizeof (alt_digits_t)); + if (!adi) + return NULL; + + /* Compute number of alt_digits. */ + adi->num = 1; + for (a = alt_digits; (e = ALT_STRCHR (a, ';')) != NULL; a = e + 1) + ++adi->num; + /* Allocate the `digit' array, which is an array of `num' pointers into + `buffer'. */ + adi->digit = (CHAR **) calloc (adi->num, sizeof (CHAR **)); + if (!adi->digit) + { + free (adi); + return NULL; + } + /* Compute memory required for `buffer'. */ +#if defined (MAKE_WCSFTIME) && !defined (__HAVE_LOCALE_INFO_EXTENDED__) + len = mbstowcs (NULL, alt_digits, 0); + if (len == (size_t) -1) + { + free (adi->digit); + free (adi); + return NULL; + } +#else + len = ALT_STRLEN (alt_digits); +#endif + /* Allocate it. */ + adi->buffer = (CHAR *) malloc ((len + 1) * sizeof (CHAR)); + if (!adi->buffer) + { + free (adi->digit); + free (adi); + return NULL; + } + /* Store digits in it. */ +#if defined (MAKE_WCSFTIME) && !defined (__HAVE_LOCALE_INFO_EXTENDED__) + mbstowcs (adi->buffer, alt_digits, len + 1); +#else + ALT_STRCPY (adi->buffer, alt_digits); +#endif + /* Store the pointers into `buffer' into the appropriate `digit' slot. */ + for (len = 0, aa = adi->buffer; (ae = STRCHR (aa, CQ(';'))) != NULL; + ++len, aa = ae + 1) + { + *ae = '\0'; + adi->digit[len] = aa; + } + adi->digit[len] = aa; + return adi; +} + +static void +free_alt_digits (alt_digits_t *adi) +{ + free (adi->digit); + free (adi->buffer); + free (adi); +} + +/* Return 0 if no alt_digit is available for a number. + Return -1 if buffer size isn't sufficient to hold alternative digit. + Return length of new digit otherwise. */ +static int +conv_to_alt_digits (CHAR *buf, size_t bufsiz, unsigned num, alt_digits_t *adi) +{ + if (num < adi->num) + { + size_t len = STRLEN (adi->digit[num]); + if (bufsiz < len) + return -1; + STRCPY (buf, adi->digit[num]); + return (int) len; + } return 0; } +static size_t __strftime (CHAR *, size_t, const CHAR *, const struct tm *, + era_info_t **, alt_digits_t **); +size_t +_DEFUN (strftime, (s, maxsize, format, tim_p), + CHAR *__restrict s _AND + size_t maxsize _AND + _CONST CHAR *__restrict format _AND + _CONST struct tm *__restrict tim_p) +{ + era_info_t *era_info = NULL; + alt_digits_t *alt_digits = NULL; + size_t ret = __strftime (s, maxsize, format, tim_p, &era_info, &alt_digits); + if (era_info) + free_era_info (era_info); + if (alt_digits) + free_alt_digits (alt_digits); + return ret; +} + +static size_t +__strftime (CHAR *s, size_t maxsize, const CHAR *format, + const struct tm *tim_p, era_info_t **era_info, + alt_digits_t **alt_digits) +#else /* !_WANT_C99_TIME_FORMATS */ +# define __strftime(s,m,f,t,e,a) strftime((s),(m),(f),(t)) + +size_t +_DEFUN (strftime, (s, maxsize, format, tim_p), + CHAR *__restrict s _AND + size_t maxsize _AND + _CONST CHAR *__restrict format _AND + _CONST struct tm *__restrict tim_p) +#endif /* !_WANT_C99_TIME_FORMATS */ +{ + size_t count = 0; + int i, len = 0; + const CHAR *ctloc; +#if defined (MAKE_WCSFTIME) && !defined (__HAVE_LOCALE_INFO_EXTENDED__) + CHAR ctlocbuf[CTLOCBUFLEN]; +#endif + size_t ctloclen; + CHAR alt; + CHAR pad; + unsigned long width; + + struct lc_time_T *_CurrentTimeLocale = __get_current_time_locale (); + for (;;) + { + while (*format && *format != CQ('%')) + { + if (count < maxsize - 1) + s[count++] = *format++; + else + return 0; + } + if (*format == CQ('\0')) + break; + format++; + pad = '\0'; + width = 0; + + /* POSIX-1.2008 feature: '0' and '+' modifiers require 0-padding with + slightly different semantics. */ + if (*format == CQ('0') || *format == CQ('+')) + pad = *format++; + + /* POSIX-1.2008 feature: A minimum field width can be specified. */ + if (*format >= CQ('1') && *format <= CQ('9')) + { + CHAR *fp; + width = STRTOUL (format, &fp, 10); + format = fp; + } + + alt = CQ('\0'); + if (*format == CQ('E')) + { + alt = *format++; +#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); +#else + if (!*era_info && *_CurrentTimeLocale->era) + *era_info = get_era_info (tim_p, _CurrentTimeLocale->era); +#endif +#endif /* _WANT_C99_TIME_FORMATS */ + } + else if (*format == CQ('O')) + { + alt = *format++; +#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); +#else + if (!*alt_digits && *_CurrentTimeLocale->alt_digits) + *alt_digits = get_alt_digits (_CurrentTimeLocale->alt_digits); +#endif +#endif /* _WANT_C99_TIME_FORMATS */ + } + + switch (*format) + { + case CQ('a'): + _ctloc (wday[tim_p->tm_wday]); + for (i = 0; i < ctloclen; i++) + { + if (count < maxsize - 1) + s[count++] = ctloc[i]; + else + return 0; + } + break; + case CQ('A'): + _ctloc (weekday[tim_p->tm_wday]); + for (i = 0; i < ctloclen; i++) + { + if (count < maxsize - 1) + s[count++] = ctloc[i]; + else + return 0; + } + break; + case CQ('b'): + case CQ('h'): + _ctloc (mon[tim_p->tm_mon]); + for (i = 0; i < ctloclen; i++) + { + if (count < maxsize - 1) + s[count++] = ctloc[i]; + else + return 0; + } + break; + case CQ('B'): + _ctloc (month[tim_p->tm_mon]); + for (i = 0; i < ctloclen; i++) + { + if (count < maxsize - 1) + s[count++] = ctloc[i]; + else + return 0; + } + break; + case CQ('c'): +#ifdef _WANT_C99_TIME_FORMATS + if (alt == 'E' && *era_info && *_CurrentTimeLocale->era_d_t_fmt) + _ctloc (era_d_t_fmt); + else +#endif /* _WANT_C99_TIME_FORMATS */ + _ctloc (c_fmt); + goto recurse; + case CQ('r'): + _ctloc (ampm_fmt); + goto recurse; + case CQ('x'): +#ifdef _WANT_C99_TIME_FORMATS + if (alt == 'E' && *era_info && *_CurrentTimeLocale->era_d_fmt) + _ctloc (era_d_fmt); + else +#endif /* _WANT_C99_TIME_FORMATS */ + _ctloc (x_fmt); + goto recurse; + case CQ('X'): +#ifdef _WANT_C99_TIME_FORMATS + if (alt == 'E' && *era_info && *_CurrentTimeLocale->era_t_fmt) + _ctloc (era_t_fmt); + else +#endif /* _WANT_C99_TIME_FORMATS */ + _ctloc (X_fmt); +recurse: + if (*ctloc) + { + /* Recurse to avoid need to replicate %Y formation. */ + len = __strftime (&s[count], maxsize - count, ctloc, tim_p, + era_info, alt_digits); + if (len > 0) + count += len; + else + return 0; + } + break; + case CQ('C'): + { + /* Examples of (tm_year + YEAR_BASE) that show how %Y == %C%y + with 32-bit int. + %Y %C %y + 2147485547 21474855 47 + 10000 100 00 + 9999 99 99 + 0999 09 99 + 0099 00 99 + 0001 00 01 + 0000 00 00 + -001 -0 01 + -099 -0 99 + -999 -9 99 + -1000 -10 00 + -10000 -100 00 + -2147481748 -21474817 48 + + Be careful of both overflow and sign adjustment due to the + asymmetric range of years. + */ +#ifdef _WANT_C99_TIME_FORMATS + if (alt == 'E' && *era_info) + len = snprintf (&s[count], maxsize - count, CQ("%" SFLG "s"), + (*era_info)->era_C); + else +#endif /* _WANT_C99_TIME_FORMATS */ + { + CHAR *fmt = CQ("%s%.*d"); + char *pos = ""; + int neg = tim_p->tm_year < -YEAR_BASE; + int century = tim_p->tm_year >= 0 + ? tim_p->tm_year / 100 + YEAR_BASE / 100 + : abs (tim_p->tm_year + YEAR_BASE) / 100; + if (pad) /* '0' or '+' */ + { + fmt = CQ("%s%0.*d"); + if (century >= 100 && pad == CQ('+')) + pos = "+"; + } + if (width < 2) + width = 2; + len = snprintf (&s[count], maxsize - count, fmt, + neg ? "-" : pos, width - neg, century); + } + CHECK_LENGTH (); + } + break; + case CQ('d'): + case CQ('e'): +#ifdef _WANT_C99_TIME_FORMATS + if (alt == CQ('O') && *alt_digits) + { + if (tim_p->tm_mday < 10) + { + if (*format == CQ('d')) + { + if (maxsize - count < 2) return 0; + len = conv_to_alt_digits (&s[count], maxsize - count, + 0, *alt_digits); + CHECK_LENGTH (); + } + if (*format == CQ('e') || len == 0) + s[count++] = CQ(' '); + } + len = conv_to_alt_digits (&s[count], maxsize - count, + tim_p->tm_mday, *alt_digits); + CHECK_LENGTH (); + if (len > 0) + break; + } +#endif /* _WANT_C99_TIME_FORMATS */ + len = snprintf (&s[count], maxsize - count, + *format == CQ('d') ? CQ("%.2d") : CQ("%2d"), + tim_p->tm_mday); + CHECK_LENGTH (); + break; + case CQ('D'): + /* %m/%d/%y */ + len = snprintf (&s[count], maxsize - count, + CQ("%.2d/%.2d/%.2d"), + tim_p->tm_mon + 1, tim_p->tm_mday, + tim_p->tm_year >= 0 ? tim_p->tm_year % 100 + : abs (tim_p->tm_year + YEAR_BASE) % 100); + CHECK_LENGTH (); + break; + case CQ('F'): + { /* %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; + else + *fmt++ = '+'; + if (!pad) + width = 10; + if (width < 6) + width = 6; + width -= 6; + if (width) + { + len = snprintf (fmt, fmtbuf + 32 - fmt, CQ("%lu"), width); + if (len > 0) + fmt += len; + } + STRCPY (fmt, CQ("Y-%m-%d")); + len = __strftime (&s[count], maxsize - count, fmtbuf, tim_p, + era_info, alt_digits); + if (len > 0) + count += len; + else + return 0; + } + break; + case CQ('g'): + /* Be careful of both overflow and negative years, thanks to + the asymmetric range of years. */ + { + int adjust = iso_year_adjust (tim_p); + int year = tim_p->tm_year >= 0 ? tim_p->tm_year % 100 + : abs (tim_p->tm_year + YEAR_BASE) % 100; + if (adjust < 0 && tim_p->tm_year <= -YEAR_BASE) + adjust = 1; + else if (adjust > 0 && tim_p->tm_year < -YEAR_BASE) + adjust = -1; + len = snprintf (&s[count], maxsize - count, CQ("%.2d"), + ((year + adjust) % 100 + 100) % 100); + CHECK_LENGTH (); + } + break; + case CQ('G'): + { + /* See the comments for 'C' and 'Y'; this is a variable length + field. Although there is no requirement for a minimum number + of digits, we use 4 for consistency with 'Y'. */ + int sign = tim_p->tm_year < -YEAR_BASE; + int adjust = iso_year_adjust (tim_p); + int century = tim_p->tm_year >= 0 + ? tim_p->tm_year / 100 + YEAR_BASE / 100 + : abs (tim_p->tm_year + YEAR_BASE) / 100; + int year = tim_p->tm_year >= 0 ? tim_p->tm_year % 100 + : abs (tim_p->tm_year + YEAR_BASE) % 100; + if (adjust < 0 && tim_p->tm_year <= -YEAR_BASE) + sign = adjust = 1; + else if (adjust > 0 && sign) + adjust = -1; + year += adjust; + if (year == -1) + { + year = 99; + --century; + } + else if (year == 100) + { + year = 0; + ++century; + } + CHAR fmtbuf[10], *fmt = fmtbuf; + /* int potentially overflows, so use unsigned instead. */ + unsigned p_year = century * 100 + year; + if (sign) + *fmt++ = CQ('-'); + else if (pad == CQ('+') && p_year >= 10000) + { + *fmt++ = CQ('+'); + sign = 1; + } + if (width && sign) + --width; + *fmt++ = CQ('%'); + if (pad) + *fmt++ = CQ('0'); + STRCPY (fmt, CQ(".*u")); + len = snprintf (&s[count], maxsize - count, fmtbuf, width, p_year); + if (len < 0 || (count+=len) >= maxsize) + return 0; + } + break; + case CQ('H'): +#ifdef _WANT_C99_TIME_FORMATS + if (alt == CQ('O') && *alt_digits) + { + len = conv_to_alt_digits (&s[count], maxsize - count, + tim_p->tm_hour, *alt_digits); + CHECK_LENGTH (); + if (len > 0) + break; + } +#endif /* _WANT_C99_TIME_FORMATS */ + /*FALLTHRU*/ + case CQ('k'): /* newlib extension */ + len = snprintf (&s[count], maxsize - count, + *format == CQ('k') ? CQ("%2d") : CQ("%.2d"), + tim_p->tm_hour); + CHECK_LENGTH (); + break; + case CQ('l'): /* newlib extension */ + if (alt == CQ('O')) + alt = CQ('\0'); + /*FALLTHRU*/ + case CQ('I'): + { + register int h12; + h12 = (tim_p->tm_hour == 0 || tim_p->tm_hour == 12) ? + 12 : tim_p->tm_hour % 12; +#ifdef _WANT_C99_TIME_FORMATS + if (alt != CQ('O') || !*alt_digits + || !(len = conv_to_alt_digits (&s[count], maxsize - count, + h12, *alt_digits))) +#endif /* _WANT_C99_TIME_FORMATS */ + len = snprintf (&s[count], maxsize - count, + *format == CQ('I') ? CQ("%.2d") : CQ("%2d"), h12); + CHECK_LENGTH (); + } + break; + case CQ('j'): + len = snprintf (&s[count], maxsize - count, CQ("%.3d"), + tim_p->tm_yday + 1); + CHECK_LENGTH (); + break; + case CQ('m'): +#ifdef _WANT_C99_TIME_FORMATS + if (alt != CQ('O') || !*alt_digits + || !(len = conv_to_alt_digits (&s[count], maxsize - count, + tim_p->tm_mon + 1, *alt_digits))) +#endif /* _WANT_C99_TIME_FORMATS */ + len = snprintf (&s[count], maxsize - count, CQ("%.2d"), + tim_p->tm_mon + 1); + CHECK_LENGTH (); + break; + case CQ('M'): +#ifdef _WANT_C99_TIME_FORMATS + if (alt != CQ('O') || !*alt_digits + || !(len = conv_to_alt_digits (&s[count], maxsize - count, + tim_p->tm_min, *alt_digits))) +#endif /* _WANT_C99_TIME_FORMATS */ + len = snprintf (&s[count], maxsize - count, CQ("%.2d"), + tim_p->tm_min); + CHECK_LENGTH (); + break; + case CQ('n'): + if (count < maxsize - 1) + s[count++] = CQ('\n'); + else + return 0; + break; + case CQ('p'): + case CQ('P'): + _ctloc (am_pm[tim_p->tm_hour < 12 ? 0 : 1]); + for (i = 0; i < ctloclen; i++) + { + if (count < maxsize - 1) + s[count++] = (*format == CQ('P') ? TOLOWER (ctloc[i]) + : ctloc[i]); + else + return 0; + } + break; + case CQ('R'): + len = snprintf (&s[count], maxsize - count, CQ("%.2d:%.2d"), + tim_p->tm_hour, tim_p->tm_min); + CHECK_LENGTH (); + break; + case CQ('S'): +#ifdef _WANT_C99_TIME_FORMATS + if (alt != CQ('O') || !*alt_digits + || !(len = conv_to_alt_digits (&s[count], maxsize - count, + tim_p->tm_sec, *alt_digits))) +#endif /* _WANT_C99_TIME_FORMATS */ + len = snprintf (&s[count], maxsize - count, CQ("%.2d"), + tim_p->tm_sec); + CHECK_LENGTH (); + break; + case CQ('t'): + if (count < maxsize - 1) + s[count++] = CQ('\t'); + else + return 0; + break; + case CQ('T'): + len = snprintf (&s[count], maxsize - count, CQ("%.2d:%.2d:%.2d"), + tim_p->tm_hour, tim_p->tm_min, tim_p->tm_sec); + CHECK_LENGTH (); + break; + case CQ('u'): +#ifdef _WANT_C99_TIME_FORMATS + if (alt == CQ('O') && *alt_digits) + { + len = conv_to_alt_digits (&s[count], maxsize - count, + tim_p->tm_wday == 0 ? 7 + : tim_p->tm_wday, + *alt_digits); + CHECK_LENGTH (); + if (len > 0) + break; + } +#endif /* _WANT_C99_TIME_FORMATS */ + if (count < maxsize - 1) + { + if (tim_p->tm_wday == 0) + s[count++] = CQ('7'); + else + s[count++] = CQ('0') + tim_p->tm_wday; + } + else + return 0; + break; + case CQ('U'): +#ifdef _WANT_C99_TIME_FORMATS + if (alt != CQ('O') || !*alt_digits + || !(len = conv_to_alt_digits (&s[count], maxsize - count, + (tim_p->tm_yday + 7 - + tim_p->tm_wday) / 7, + *alt_digits))) +#endif /* _WANT_C99_TIME_FORMATS */ + len = snprintf (&s[count], maxsize - count, CQ("%.2d"), + (tim_p->tm_yday + 7 - + tim_p->tm_wday) / 7); + CHECK_LENGTH (); + break; + case CQ('V'): + { + int adjust = iso_year_adjust (tim_p); + int wday = (tim_p->tm_wday) ? tim_p->tm_wday - 1 : 6; + int week = (tim_p->tm_yday + 10 - wday) / 7; + if (adjust > 0) + week = 1; + else if (adjust < 0) + /* Previous year has 53 weeks if current year starts on + Fri, and also if current year starts on Sat and + previous year was leap year. */ + week = 52 + (4 >= (wday - tim_p->tm_yday + - isleap (tim_p->tm_year + + (YEAR_BASE - 1 + - (tim_p->tm_year < 0 + ? 0 : 2000))))); +#ifdef _WANT_C99_TIME_FORMATS + if (alt != CQ('O') || !*alt_digits + || !(len = conv_to_alt_digits (&s[count], maxsize - count, + week, *alt_digits))) +#endif /* _WANT_C99_TIME_FORMATS */ + len = snprintf (&s[count], maxsize - count, CQ("%.2d"), week); + CHECK_LENGTH (); + } + break; + case CQ('w'): +#ifdef _WANT_C99_TIME_FORMATS + if (alt == CQ('O') && *alt_digits) + { + len = conv_to_alt_digits (&s[count], maxsize - count, + tim_p->tm_wday, *alt_digits); + CHECK_LENGTH (); + if (len > 0) + break; + } +#endif /* _WANT_C99_TIME_FORMATS */ + if (count < maxsize - 1) + s[count++] = CQ('0') + tim_p->tm_wday; + else + return 0; + break; + case CQ('W'): + { + int wday = (tim_p->tm_wday) ? tim_p->tm_wday - 1 : 6; + wday = (tim_p->tm_yday + 7 - wday) / 7; +#ifdef _WANT_C99_TIME_FORMATS + if (alt != CQ('O') || !*alt_digits + || !(len = conv_to_alt_digits (&s[count], maxsize - count, + wday, *alt_digits))) +#endif /* _WANT_C99_TIME_FORMATS */ + len = snprintf (&s[count], maxsize - count, CQ("%.2d"), wday); + CHECK_LENGTH (); + } + break; + case CQ('y'): + { +#ifdef _WANT_C99_TIME_FORMATS + if (alt == 'E' && *era_info) + len = snprintf (&s[count], maxsize - count, CQ("%d"), + (*era_info)->year); + else +#endif /* _WANT_C99_TIME_FORMATS */ + { + /* Be careful of both overflow and negative years, thanks to + the asymmetric range of years. */ + int year = tim_p->tm_year >= 0 ? tim_p->tm_year % 100 + : abs (tim_p->tm_year + YEAR_BASE) % 100; +#ifdef _WANT_C99_TIME_FORMATS + if (alt != CQ('O') || !*alt_digits + || !(len = conv_to_alt_digits (&s[count], maxsize - count, + year, *alt_digits))) +#endif /* _WANT_C99_TIME_FORMATS */ + len = snprintf (&s[count], maxsize - count, CQ("%.2d"), + year); + } + CHECK_LENGTH (); + } + break; + case CQ('Y'): +#ifdef _WANT_C99_TIME_FORMATS + if (alt == 'E' && *era_info) + { + ctloc = (*era_info)->era_Y; + goto recurse; + } + else +#endif /* _WANT_C99_TIME_FORMATS */ + { + CHAR fmtbuf[10], *fmt = fmtbuf; + int sign = tim_p->tm_year < -YEAR_BASE; + /* int potentially overflows, so use unsigned instead. */ + register unsigned year = (unsigned) tim_p->tm_year + + (unsigned) YEAR_BASE; + if (sign) + { + *fmt++ = CQ('-'); + year = UINT_MAX - year + 1; + } + else if (pad == CQ('+') && year >= 10000) + { + *fmt++ = CQ('+'); + sign = 1; + } + if (width && sign) + --width; + *fmt++ = CQ('%'); + if (pad) + *fmt++ = CQ('0'); + STRCPY (fmt, CQ(".*u")); + len = snprintf (&s[count], maxsize - count, fmtbuf, width, + year); + CHECK_LENGTH (); + } + break; + case CQ('z'): + if (tim_p->tm_isdst >= 0) + { + long offset; + __tzinfo_type *tz = __gettzinfo (); + TZ_LOCK; + /* 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; + TZ_UNLOCK; + len = snprintf (&s[count], maxsize - count, CQ("%+03ld%.2ld"), + offset / SECSPERHOUR, + labs (offset / SECSPERMIN) % 60L); + CHECK_LENGTH (); + } + break; + case CQ('Z'): + if (tim_p->tm_isdst >= 0) + { + int size; + TZ_LOCK; + size = strlen(_tzname[tim_p->tm_isdst > 0]); + for (i = 0; i < size; i++) + { + if (count < maxsize - 1) + s[count++] = _tzname[tim_p->tm_isdst > 0][i]; + else + { + TZ_UNLOCK; + return 0; + } + } + TZ_UNLOCK; + } + break; + case CQ('%'): + if (count < maxsize - 1) + s[count++] = CQ('%'); + else + return 0; + break; + default: + return 0; + } + if (*format) + format++; + else + break; + } + if (maxsize) + s[count] = CQ('\0'); + + return count; +} + +/* 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 */ + size_t ret; /* Expected return value */ + CHAR *out; /* Expected output string */ + }; +struct list { + const struct tm *tms; /* Time used for these vectors */ + 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 = { + /* Tue Dec 30 10:53:47 EST 2008 (time_t=1230648827) */ + .tm_sec = 47, + .tm_min = 53, + .tm_hour = 9, + .tm_mday = 30, + .tm_mon = 11, + .tm_year = 108, + .tm_wday = 2, + .tm_yday = 364, + .tm_isdst = 0 + }; +const struct test Vec0[] = { + /* Testing fields one at a time, expecting to pass, using exact + * allowed length as what is needed. */ + /* Using tm0 for time: */ + #define EXP(s) sizeof(s)/sizeof(CHAR)-1, s + { CQ("%a"), 3+1, EXP(CQ("Tue")) }, + { CQ("%A"), 7+1, EXP(CQ("Tuesday")) }, + { CQ("%b"), 3+1, EXP(CQ("Dec")) }, + { CQ("%B"), 8+1, EXP(CQ("December")) }, + { CQ("%c"), 24+1, EXP(CQ("Tue Dec 30 09:53:47 2008")) }, + { CQ("%C"), 2+1, EXP(CQ("20")) }, + { CQ("%d"), 2+1, EXP(CQ("30")) }, + { CQ("%D"), 8+1, EXP(CQ("12/30/08")) }, + { CQ("%e"), 2+1, EXP(CQ("30")) }, + { CQ("%F"), 10+1, EXP(CQ("2008-12-30")) }, + { CQ("%g"), 2+1, EXP(CQ("09")) }, + { CQ("%G"), 4+1, EXP(CQ("2009")) }, + { CQ("%h"), 3+1, EXP(CQ("Dec")) }, + { CQ("%H"), 2+1, EXP(CQ("09")) }, + { CQ("%I"), 2+1, EXP(CQ("09")) }, + { CQ("%j"), 3+1, EXP(CQ("365")) }, + { CQ("%k"), 2+1, EXP(CQ(" 9")) }, + { CQ("%l"), 2+1, EXP(CQ(" 9")) }, + { CQ("%m"), 2+1, EXP(CQ("12")) }, + { CQ("%M"), 2+1, EXP(CQ("53")) }, + { CQ("%n"), 1+1, EXP(CQ("\n")) }, + { 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("47")) }, + { CQ("%t"), 1+1, EXP(CQ("\t")) }, + { CQ("%T"), 8+1, EXP(CQ("09:53:47")) }, + { CQ("%u"), 1+1, EXP(CQ("2")) }, + { CQ("%U"), 2+1, EXP(CQ("52")) }, + { CQ("%V"), 2+1, EXP(CQ("01")) }, + { CQ("%w"), 1+1, EXP(CQ("2")) }, + { CQ("%W"), 2+1, EXP(CQ("52")) }, + { CQ("%x"), 8+1, EXP(CQ("12/30/08")) }, + { CQ("%X"), 8+1, EXP(CQ("09:53:47")) }, + { CQ("%y"), 2+1, EXP(CQ("08")) }, + { CQ("%Y"), 4+1, EXP(CQ("2008")) }, + { CQ("%z"), 5+1, EXP(CQ("-0500")) }, + { CQ("%Z"), 3+1, EXP(CQ("EST")) }, + { CQ("%%"), 1+1, EXP(CQ("%")) }, + #undef EXP + }; +/* Define list of test inputs and expected outputs, for the given time zone + * and time. */ +const struct tm tm1 = { + /* Wed Jul 2 23:01:13 EDT 2008 (time_t=1215054073) */ + .tm_sec = 13, + .tm_min = 1, + .tm_hour = 23, + .tm_mday = 2, + .tm_mon = 6, + .tm_year = 108, + .tm_wday = 3, + .tm_yday = 183, + .tm_isdst = 1 + }; +const struct test Vec1[] = { + /* Testing fields one at a time, expecting to pass, using exact + * allowed length as what is needed. */ + /* Using tm1 for time: */ + #define EXP(s) sizeof(s)/sizeof(CHAR)-1, s + { CQ("%a"), 3+1, EXP(CQ("Wed")) }, + { CQ("%A"), 9+1, EXP(CQ("Wednesday")) }, + { CQ("%b"), 3+1, EXP(CQ("Jul")) }, + { CQ("%B"), 4+1, EXP(CQ("July")) }, + { CQ("%c"), 24+1, EXP(CQ("Wed Jul 2 23:01:13 2008")) }, + { CQ("%C"), 2+1, EXP(CQ("20")) }, + { CQ("%d"), 2+1, EXP(CQ("02")) }, + { CQ("%D"), 8+1, EXP(CQ("07/02/08")) }, + { CQ("%e"), 2+1, EXP(CQ(" 2")) }, + { CQ("%F"), 10+1, EXP(CQ("2008-07-02")) }, + { CQ("%g"), 2+1, EXP(CQ("08")) }, + { CQ("%G"), 4+1, EXP(CQ("2008")) }, + { CQ("%h"), 3+1, EXP(CQ("Jul")) }, + { CQ("%H"), 2+1, EXP(CQ("23")) }, + { CQ("%I"), 2+1, EXP(CQ("11")) }, + { CQ("%j"), 3+1, EXP(CQ("184")) }, + { CQ("%k"), 2+1, EXP(CQ("23")) }, + { CQ("%l"), 2+1, EXP(CQ("11")) }, + { CQ("%m"), 2+1, EXP(CQ("07")) }, + { CQ("%M"), 2+1, EXP(CQ("01")) }, + { CQ("%n"), 1+1, EXP(CQ("\n")) }, + { 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("13")) }, + { CQ("%t"), 1+1, EXP(CQ("\t")) }, + { CQ("%T"), 8+1, EXP(CQ("23:01:13")) }, + { CQ("%u"), 1+1, EXP(CQ("3")) }, + { CQ("%U"), 2+1, EXP(CQ("26")) }, + { CQ("%V"), 2+1, EXP(CQ("27")) }, + { CQ("%w"), 1+1, EXP(CQ("3")) }, + { CQ("%W"), 2+1, EXP(CQ("26")) }, + { CQ("%x"), 8+1, EXP(CQ("07/02/08")) }, + { CQ("%X"), 8+1, EXP(CQ("23:01:13")) }, + { CQ("%y"), 2+1, EXP(CQ("08")) }, + { CQ("%Y"), 4+1, EXP(CQ("2008")) }, + { CQ("%z"), 5+1, EXP(CQ("-0400")) }, + { CQ("%Z"), 3+1, EXP(CQ("EDT")) }, + { CQ("%%"), 1+1, EXP(CQ("%")) }, + #undef EXP + #define VEC(s) s, sizeof(s)/sizeof(CHAR), sizeof(s)/sizeof(CHAR)-1, s + #define EXP(s) sizeof(s)/sizeof(CHAR), sizeof(s)/sizeof(CHAR)-1, s + { VEC(CQ("ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz")) }, + { CQ("0123456789%%%h:`~"), EXP(CQ("0123456789%Jul:`~")) }, + { CQ("%R%h:`~ %x %w"), EXP(CQ("23:01Jul:`~ 07/02/08 3")) }, + #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. + * Years more than 4 digits are not mentioned in the standard for %C, so the + * test for those cases are based on the design intent (which is to print the + * whole number, being the century). */ +const struct tm tmyr0 = { + /* Wed Jul 2 23:01:13 EDT [HUGE#] */ + .tm_sec = 13, + .tm_min = 1, + .tm_hour = 23, + .tm_mday = 2, + .tm_mon = 6, + .tm_year = INT_MAX - YEAR_BASE/2, + .tm_wday = 3, + .tm_yday = 183, + .tm_isdst = 1 + }; +#if INT_MAX == 32767 +# define YEAR CQ("33717") /* INT_MAX + YEAR_BASE/2 */ +# define CENT CQ("337") +# define Year CQ("17") +# elif INT_MAX == 2147483647 +# define YEAR CQ("2147484597") +# define CENT CQ("21474845") +# define Year CQ("97") +# elif INT_MAX == 9223372036854775807 +# define YEAR CQ("9223372036854776757") +# define CENT CQ("92233720368547777") +# define Year CQ("57") +# else +# error "Unrecognized INT_MAX value: enhance me to recognize what you have" +#endif +const struct test Vecyr0[] = { + /* Testing fields one at a time, expecting to pass, using a larger + * allowed length than what is needed. */ + /* Using tmyr0 for time: */ + #define EXP(s) sizeof(s)/sizeof(CHAR)-1, s + { CQ("%C"), OUTSIZE, EXP(CENT) }, + { CQ("%c"), OUTSIZE, EXP(CQ("Wed Jul 2 23:01:13 ")YEAR) }, + { CQ("%D"), OUTSIZE, EXP(CQ("07/02/")Year) }, + { CQ("%F"), OUTSIZE, EXP(YEAR CQ("-07-02")) }, + { CQ("%x"), OUTSIZE, EXP(CQ("07/02/")Year) }, + { CQ("%y"), OUTSIZE, EXP(Year) }, + { CQ("%Y"), OUTSIZE, EXP(YEAR) }, + #undef EXP + }; +#undef YEAR +#undef CENT +#undef Year +/* Checks for very large negative years. YEAR_BASE value relied upon so that + * the answer strings can be predetermined. */ +const struct tm tmyr1 = { + /* Wed Jul 2 23:01:13 EDT [HUGE#] */ + .tm_sec = 13, + .tm_min = 1, + .tm_hour = 23, + .tm_mday = 2, + .tm_mon = 6, + .tm_year = INT_MIN, + .tm_wday = 3, + .tm_yday = 183, + .tm_isdst = 1 + }; +#if INT_MAX == 32767 +# define YEAR CQ("-30868") /* INT_MIN + YEAR_BASE */ +# define CENT CQ("-308") +# define Year CQ("68") +# elif INT_MAX == 2147483647 +# define YEAR CQ("-2147481748") +# define CENT CQ("-21474817") +# define Year CQ("48") +# elif INT_MAX == 9223372036854775807 +# define YEAR CQ("-9223372036854773908") +# define CENT CQ("-92233720368547739") +# define Year CQ("08") +# else +# error "Unrecognized INT_MAX value: enhance me to recognize what you have" +#endif +const struct test Vecyr1[] = { + /* Testing fields one at a time, expecting to pass, using a larger + * allowed length than what is needed. */ + /* Using tmyr1 for time: */ + #define EXP(s) sizeof(s)/sizeof(CHAR)-1, s + { CQ("%C"), OUTSIZE, EXP(CENT) }, + { CQ("%c"), OUTSIZE, EXP(CQ("Wed Jul 2 23:01:13 ")YEAR) }, + { CQ("%D"), OUTSIZE, EXP(CQ("07/02/")Year) }, + { CQ("%F"), OUTSIZE, EXP(YEAR CQ("-07-02")) }, + { CQ("%x"), OUTSIZE, EXP(CQ("07/02/")Year) }, + { CQ("%y"), OUTSIZE, EXP(Year) }, + { CQ("%Y"), OUTSIZE, EXP(YEAR) }, + #undef EXP + }; +#undef YEAR +#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. */ +const struct tm tmyrzp = { + /* Wed Jul 2 23:01:60 EDT 0007 */ + .tm_sec = 60, + .tm_min = 1, + .tm_hour = 23, + .tm_mday = 2, + .tm_mon = 6, + .tm_year = 7-YEAR_BASE, + .tm_wday = 3, + .tm_yday = 183, + .tm_isdst = 1 + }; +#define YEAR CQ("0007") /* Design intent: %Y=%C%y */ +#define CENT CQ("00") +#define Year CQ("07") +const struct test Vecyrzp[] = { + /* Testing fields one at a time, expecting to pass, using a larger + * allowed length than what is needed. */ + /* Using tmyrzp for time: */ + #define EXP(s) sizeof(s)/sizeof(CHAR)-1, s + { CQ("%C"), OUTSIZE, EXP(CENT) }, + { CQ("%c"), OUTSIZE, EXP(CQ("Wed Jul 2 23:01:60 ")YEAR) }, + { CQ("%D"), OUTSIZE, EXP(CQ("07/02/")Year) }, + { CQ("%F"), OUTSIZE, EXP(YEAR CQ("-07-02")) }, + { CQ("%x"), OUTSIZE, EXP(CQ("07/02/")Year) }, + { CQ("%y"), OUTSIZE, EXP(Year) }, + { CQ("%Y"), OUTSIZE, EXP(YEAR) }, + #undef EXP + }; +#undef YEAR +#undef CENT +#undef Year +/* Checks for years just under zero. + * Negative years are not handled by the standard, so the vectors here are + * verifying the chosen implemtation. */ +const struct tm tmyrzn = { + /* Wed Jul 2 23:01:00 EDT -004 */ + .tm_sec = 00, + .tm_min = 1, + .tm_hour = 23, + .tm_mday = 2, + .tm_mon = 6, + .tm_year = -4-YEAR_BASE, + .tm_wday = 3, + .tm_yday = 183, + .tm_isdst = 1 + }; +#define YEAR CQ("-004") +#define CENT CQ("-0") +#define Year CQ("04") +const struct test Vecyrzn[] = { + /* Testing fields one at a time, expecting to pass, using a larger + * allowed length than what is needed. */ + /* Using tmyrzn for time: */ + #define EXP(s) sizeof(s)/sizeof(CHAR)-1, s + { CQ("%C"), OUTSIZE, EXP(CENT) }, + { CQ("%c"), OUTSIZE, EXP(CQ("Wed Jul 2 23:01:00 ")YEAR) }, + { CQ("%D"), OUTSIZE, EXP(CQ("07/02/")Year) }, + { CQ("%F"), OUTSIZE, EXP(YEAR CQ("-07-02")) }, + { CQ("%x"), OUTSIZE, EXP(CQ("07/02/")Year) }, + { CQ("%y"), OUTSIZE, EXP(Year) }, + { CQ("%Y"), OUTSIZE, EXP(YEAR) }, + #undef EXP + }; +#undef YEAR +#undef CENT +#undef Year + +const struct list ListYr[] = { + { &tmyrzp, Vecyrzp, sizeof(Vecyrzp)/sizeof(Vecyrzp[0]) }, + { &tmyrzn, Vecyrzn, sizeof(Vecyrzn)/sizeof(Vecyrzn[0]) }, + #if YEAR_BASE == 1900 + { &tmyr0, Vecyr0, sizeof(Vecyr0)/sizeof(Vecyr0[0]) }, + { &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) +{ +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))) { + printf( "putenv(%s) FAILED, ret %d\n", cp, i); + return(-1); + } +if(strcmp(getenv("TZ"),strchr(TZ,'=')+1)) { + printf( "TZ not set properly in environment\n"); + return(-2); + } +tzset(); + +#if defined(VERBOSE) +printf("_timezone=%d, _daylight=%d, _tzname[0]=%s, _tzname[1]=%s\n", _timezone, _daylight, _tzname[0], _tzname[1]); +{ +long offset; +__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. */ +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; lcnt; i++) { + tot++; /* Keep track of number of tests */ + ret = strftime(out, test->vec[i].max, test->vec[i].fmt, test->tms); + if(ret != test->vec[i].ret) { + errr++; + fprintf(stderr, + "ERROR: return %d != %d expected for List[%d].vec[%d]\n", + ret, test->vec[i].ret, l, i); + } + if(strncmp(out, test->vec[i].out, test->vec[i].max-1)) { + erro++; + fprintf(stderr, + "ERROR: \"%"SFLG"s\" != \"%"SFLG"s\" expected for List[%d].vec[%d]\n", + out, test->vec[i].out, l, i); + } + } + } + +/* Run all of the exact-length tests with the length made too short--expect to + * fail. */ +for(l=0; lcnt; i++) { + tot++; /* Keep track of number of tests */ + ret = strftime(out, test->vec[i].max-1, test->vec[i].fmt, test->tms); + if(ret != 0) { + errr++; + fprintf(stderr, + "ERROR: return %d != %d expected for List[%d].vec[%d]\n", + ret, 0, l, i); + } + /* Almost every conversion puts out as many characters as possible, so + * go ahead and test the output even though have failed. (The test + * times chosen happen to not hit any of the cases that fail this, so it + * works.) */ + if(strncmp(out, test->vec[i].out, test->vec[i].max-1-1)) { + erro++; + fprintf(stderr, + "ERROR: \"%"SFLG"s\" != \"%"SFLG"s\" expected for List[%d].vec[%d]\n", + out, test->vec[i].out, l, i); + } + } + } + +/* Run all of the special year test cases */ +for(l=0; lcnt; i++) { + tot++; /* Keep track of number of tests */ + ret = strftime(out, test->vec[i].max, test->vec[i].fmt, test->tms); + if(ret != test->vec[i].ret) { + errr++; + fprintf(stderr, + "ERROR: return %d != %d expected for ListYr[%d].vec[%d]\n", + ret, test->vec[i].ret, l, i); + } + if(strncmp(out, test->vec[i].out, test->vec[i].max-1)) { + erro++; + fprintf(stderr, + "ERROR: \"%"SFLG"s\" != \"%"SFLG"s\" expected for ListYr[%d].vec[%d]\n", + out, test->vec[i].out, l, i); + } + } + } + +#define STRIZE(f) #f +#define NAME(f) STRIZE(f) +printf(NAME(strftime) "() test "); +if(errr || erro) printf("FAILED %d/%d of", errr, erro); + else printf("passed"); +printf(" %d test cases.\n", tot); + +return(errr || erro); +} +#endif /* defined(_REGRESSION_TEST) ] */ diff --git a/contrib/sdk/sources/newlib/libc/time/time.c b/contrib/sdk/sources/newlib/libc/time/time.c index dde5a65731..58f06324f6 100644 --- a/contrib/sdk/sources/newlib/libc/time/time.c +++ b/contrib/sdk/sources/newlib/libc/time/time.c @@ -51,11 +51,3 @@ _DEFUN (time, (t), } return -1; } - -int -_DEFUN (gettimeofday, (ptimeval, ptimezone), - struct timeval *ptimeval _AND - void *ptimezone) -{ - return _gettimeofday_r (_REENT, ptimeval, ptimezone); -} diff --git a/contrib/sdk/sources/newlib/libc/time/timelocal.c b/contrib/sdk/sources/newlib/libc/time/timelocal.c new file mode 100644 index 0000000000..ca2f79b502 --- /dev/null +++ b/contrib/sdk/sources/newlib/libc/time/timelocal.c @@ -0,0 +1,188 @@ +/*- + * Copyright (c) 2001 Alexey Zelkin + * Copyright (c) 1997 FreeBSD Inc. + * 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. + */ + +#include + +#include + +#include "ldpart.h" +#include "timelocal.h" + +static struct lc_time_T _time_locale; +static int _time_using_locale; +static char *time_locale_buf; + +#define LCTIME_SIZE (sizeof(struct lc_time_T) / sizeof(char *)) + +static const struct lc_time_T _C_time_locale = { + { + "Jan", "Feb", "Mar", "Apr", "May", "Jun", + "Jul", "Aug", "Sep", "Oct", "Nov", "Dec" + }, { + "January", "February", "March", "April", "May", "June", + "July", "August", "September", "October", "November", "December" + }, { + "Sun", "Mon", "Tue", "Wed", + "Thu", "Fri", "Sat" + }, { + "Sunday", "Monday", "Tuesday", "Wednesday", + "Thursday", "Friday", "Saturday" + }, + + /* X_fmt */ + "%H:%M:%S", + + /* + * x_fmt + * Since the C language standard calls for + * "date, using locale's date format," anything goes. + * Using just numbers (as here) makes Quakers happier; + * it's also compatible with SVR4. + */ + "%m/%d/%y", + + /* + * c_fmt + */ + "%a %b %e %H:%M:%S %Y", + + /* am pm */ + { "AM", "PM" }, + + /* date_fmt */ + "%a %b %e %H:%M:%S %Z %Y", + + /* alt_month + * Standalone months forms for %OB + */ + { + "January", "February", "March", "April", "May", "June", + "July", "August", "September", "October", "November", "December" + }, + + /* md_order + * Month / day order in dates + */ + "md", + + /* ampm_fmt + * To determine 12-hour clock format time (empty, if N/A) + */ + "%I:%M:%S %p", + + /* era + * Era. This and the following entries are used if the alternative + * date format is specified in strftime + */ + "", + + /* era_d_fmt + * Era date format used with the %Ex + */ + "", + + /* era_d_t_fmt + * Era date/time format (%Ec) + */ + "", + + /* era_t_fmt + * Era time format (%EX) + */ + "", + + /* alt_digits + * Alternate digits used if %O format prefix is specified + */ + "" +#ifdef __HAVE_LOCALE_INFO_EXTENDED__ + , "ASCII", /* codeset */ + { + L"Jan", L"Feb", L"Mar", L"Apr", L"May", L"Jun", + L"Jul", L"Aug", L"Sep", L"Oct", L"Nov", L"Dec" + }, { + L"January", L"February", L"March", L"April", L"May", L"June", + L"July", L"August", L"September", L"October", L"November", + L"December" + }, { + L"Sun", L"Mon", L"Tue", L"Wed", + L"Thu", L"Fri", L"Sat" + }, { + L"Sunday", L"Monday", L"Tuesday", L"Wednesday", + L"Thursday", L"Friday", L"Saturday" + }, + L"%H:%M:%S", + L"%m/%d/%y", + L"%a %b %e %H:%M:%S %Y", + { L"AM", L"PM" }, + L"%a %b %e %H:%M:%S %Z %Y", + L"%I:%M:%S %p", + L"", + L"", + L"", + L"", + L"" +#endif +}; + +struct lc_time_T * +__get_current_time_locale(void) { + return (_time_using_locale + ? &_time_locale + : (struct lc_time_T *)&_C_time_locale); +} + +int +__time_load_locale(const char *name, void *f_wctomb, const char *charset) { + + int ret; + +#ifdef __CYGWIN__ + extern int __set_lc_time_from_win (const char *, + const struct lc_time_T *, + struct lc_time_T *, + char **, void *, const char *); + int old_time_using_locale = _time_using_locale; + _time_using_locale = 0; + ret = __set_lc_time_from_win (name, &_C_time_locale, &_time_locale, + &time_locale_buf, f_wctomb, charset); + /* ret == -1: error, ret == 0: C/POSIX, ret > 0: valid */ + if (ret < 0) + _time_using_locale = old_time_using_locale; + else + { + _time_using_locale = ret; + ret = 0; + } +#else + ret = __part_load_locale(name, &_time_using_locale, + time_locale_buf, "LC_TIME", + LCTIME_SIZE, LCTIME_SIZE, + (const char **)&_time_locale); +#endif + return (ret); +} diff --git a/contrib/sdk/sources/newlib/libc/time/timelocal.h b/contrib/sdk/sources/newlib/libc/time/timelocal.h new file mode 100644 index 0000000000..a0c1ef7ef3 --- /dev/null +++ b/contrib/sdk/sources/newlib/libc/time/timelocal.h @@ -0,0 +1,85 @@ +/*- + * Copyright (c) 1997-2002 FreeBSD Project. + * 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: src/lib/libc/stdtime/timelocal.h,v 1.11 2002/01/24 15:07:44 phantom Exp $ + */ + +#ifndef _TIMELOCAL_H_ +#define _TIMELOCAL_H_ + +#include <_ansi.h> +#include +#include + +__BEGIN_DECLS + +/* + * Private header file for the strftime and strptime localization + * stuff. + */ +struct lc_time_T { + const char *mon[12]; + const char *month[12]; + const char *wday[7]; + const char *weekday[7]; + const char *X_fmt; + const char *x_fmt; + const char *c_fmt; + const char *am_pm[2]; + const char *date_fmt; + const char *alt_month[12]; /* unused */ + const char *md_order; + const char *ampm_fmt; + const char *era; + const char *era_d_fmt; + const char *era_d_t_fmt; + const char *era_t_fmt; + const char *alt_digits; +#ifdef __HAVE_LOCALE_INFO_EXTENDED__ + const char *codeset; /* codeset for mbtowc conversion */ + const wchar_t *wmon[12]; + const wchar_t *wmonth[12]; + const wchar_t *wwday[7]; + const wchar_t *wweekday[7]; + const wchar_t *wX_fmt; + const wchar_t *wx_fmt; + const wchar_t *wc_fmt; + const wchar_t *wam_pm[2]; + const wchar_t *wdate_fmt; + const wchar_t *wampm_fmt; + const wchar_t *wera; + const wchar_t *wera_d_fmt; + const wchar_t *wera_d_t_fmt; + const wchar_t *wera_t_fmt; + const wchar_t *walt_digits; +#endif +}; + +struct lc_time_T *__get_current_time_locale(void); +int __time_load_locale(const char *, void *, const char *); + +__END_DECLS + +#endif /* !_TIMELOCAL_H_ */