diff options
Diffstat (limited to 'newlib/libc/stdlib')
-rw-r--r-- | newlib/libc/stdlib/envlock.h | 15 | ||||
-rw-r--r-- | newlib/libc/stdlib/gdtoa-hexnan.c | 2 | ||||
-rw-r--r-- | newlib/libc/stdlib/getopt.c | 433 | ||||
-rw-r--r-- | newlib/libc/stdlib/mprec.h | 49 | ||||
-rw-r--r-- | newlib/libc/stdlib/strtod.c | 65 | ||||
-rw-r--r-- | newlib/libc/stdlib/wcsrtombs.c | 2 |
6 files changed, 262 insertions, 304 deletions
diff --git a/newlib/libc/stdlib/envlock.h b/newlib/libc/stdlib/envlock.h new file mode 100644 index 000000000..9bb6a813e --- /dev/null +++ b/newlib/libc/stdlib/envlock.h @@ -0,0 +1,15 @@ +/* envlock.h -- header file for env routines. */ + +#ifndef _INCLUDE_ENVLOCK_H_ +#define _INCLUDE_ENVLOCK_H_ + +#include <_ansi.h> +#include <sys/reent.h> + +#define ENV_LOCK __env_lock(reent_ptr) +#define ENV_UNLOCK __env_unlock(reent_ptr) + +void _EXFUN(__env_lock,(struct _reent *reent)); +void _EXFUN(__env_unlock,(struct _reent *reent)); + +#endif /* _INCLUDE_ENVLOCK_H_ */ diff --git a/newlib/libc/stdlib/gdtoa-hexnan.c b/newlib/libc/stdlib/gdtoa-hexnan.c index 189fb238d..058bbd17d 100644 --- a/newlib/libc/stdlib/gdtoa-hexnan.c +++ b/newlib/libc/stdlib/gdtoa-hexnan.c @@ -98,7 +98,7 @@ _DEFUN (hexnan, (sp, fpi, x0), } continue; } - if (/*(*/ c == ')') { + if (/*(*/ c == ')' && havedig) { *sp = s + 1; break; } diff --git a/newlib/libc/stdlib/getopt.c b/newlib/libc/stdlib/getopt.c index 944214d5f..06e378170 100644 --- a/newlib/libc/stdlib/getopt.c +++ b/newlib/libc/stdlib/getopt.c @@ -83,13 +83,10 @@ Gregory Pietsch's current e-mail address: gpietsch@comcast.net ****************************************************************************/ -#ifndef HAVE_GETOPT - /* include files */ #include <stdio.h> #include <stdlib.h> #include <string.h> -#define __need_getopt_newlib #include <getopt.h> /* macros */ @@ -103,19 +100,16 @@ typedef enum GETOPT_ORDERING_T } GETOPT_ORDERING_T; /* globally-defined variables */ -char *optarg = 0; +char *optarg = NULL; int optind = 0; int opterr = 1; int optopt = '?'; -/* static variables */ -static int optwhere = 0; - /* functions */ /* reverse_argv_elements: reverses num elements starting at argv */ static void -reverse_argv_elements (char **argv, int num) +reverse_argv_elements (char ** argv, int num) { int i; char *tmp; @@ -132,348 +126,281 @@ reverse_argv_elements (char **argv, int num) static void permute (char *const argv[], int len1, int len2) { - reverse_argv_elements ((char **) argv, len1); - reverse_argv_elements ((char **) argv, len1 + len2); - reverse_argv_elements ((char **) argv, len2); + reverse_argv_elements ((char **)argv, len1); + reverse_argv_elements ((char **)argv, len1 + len2); + reverse_argv_elements ((char **)argv, len2); } /* is_option: is this argv-element an option or the end of the option list? */ static int is_option (char *argv_element, int only) { - return ((argv_element == 0) - || (argv_element[0] == '-') || (only && argv_element[0] == '+')); -} - -/* read_globals: read the values from the globals into a getopt_data - structure */ -static void -read_globals (struct getopt_data *data) -{ - data->optarg = optarg; - data->optind = optind; - data->opterr = opterr; - data->optopt = optopt; - data->optwhere = optwhere; -} - -/* write_globals: write the values into the globals from a getopt_data - structure */ -static void -write_globals (struct getopt_data *data) -{ - optarg = data->optarg; - optind = data->optind; - opterr = data->opterr; - optopt = data->optopt; - optwhere = data->optwhere; + return ((argv_element == NULL) + || (argv_element[0] == '-') || (only && argv_element[0] == '+')); } /* getopt_internal: the function that does all the dirty work */ static int getopt_internal (int argc, char *const argv[], const char *shortopts, - const struct option *longopts, int *longind, int only, - struct getopt_data *data) + const struct option *longopts, int *longind, int only) { GETOPT_ORDERING_T ordering = PERMUTE; + static size_t optwhere = 0; size_t permute_from = 0; int num_nonopts = 0; int optindex = 0; size_t match_chars = 0; - char *possible_arg = 0; + char *possible_arg = NULL; int longopt_match = -1; int has_arg = -1; - char *cp = 0; + char *cp = NULL; int arg_next = 0; /* first, deal with silly parameters and easy stuff */ - if (argc == 0 || argv == 0 || (shortopts == 0 && longopts == 0) - || data->optind >= argc || argv[data->optind] == 0) + if (argc == 0 || argv == NULL || (shortopts == NULL && longopts == NULL)) return EOF; - if (strcmp (argv[data->optind], "--") == 0) + if (optind >= argc || argv[optind] == NULL) + return EOF; + if (strcmp (argv[optind], "--") == 0) { - data->optind++; + optind++; return EOF; } - /* if this is our first time through */ - if (data->optind == 0) - data->optind = data->optwhere = 1; + if (optind == 0) + optind = optwhere = 1; /* define ordering */ - if (shortopts != 0 && (*shortopts == '-' || *shortopts == '+')) + if (shortopts != NULL && (*shortopts == '-' || *shortopts == '+')) { ordering = (*shortopts == '-') ? RETURN_IN_ORDER : REQUIRE_ORDER; shortopts++; } else - ordering = (getenv ("POSIXLY_CORRECT") != 0) ? REQUIRE_ORDER : PERMUTE; + ordering = (getenv ("POSIXLY_CORRECT") != NULL) ? REQUIRE_ORDER : PERMUTE; /* * based on ordering, find our next option, if we're at the beginning of * one */ - if (data->optwhere == 1) + if (optwhere == 1) { switch (ordering) - { - default: /* shouldn't happen */ - case PERMUTE: - permute_from = data->optind; - num_nonopts = 0; - while (!is_option (argv[data->optind], only)) - { - data->optind++; - num_nonopts++; - } - if (argv[data->optind] == 0) - { - /* no more options */ - data->optind = permute_from; - return EOF; - } - else if (strcmp (argv[data->optind], "--") == 0) - { - /* no more options, but have to get `--' out of the way */ - permute (argv + permute_from, num_nonopts, 1); - data->optind = permute_from + 1; - return EOF; - } - break; - case RETURN_IN_ORDER: - if (!is_option (argv[data->optind], only)) - { - data->optarg = argv[data->optind++]; - return (data->optopt = 1); - } - break; - case REQUIRE_ORDER: - if (!is_option (argv[data->optind], only)) - return EOF; - break; - } + { + case PERMUTE: + permute_from = optind; + num_nonopts = 0; + while (!is_option (argv[optind], only)) + { + optind++; + num_nonopts++; + } + if (argv[optind] == NULL) + { + /* no more options */ + optind = permute_from; + return EOF; + } + else if (strcmp (argv[optind], "--") == 0) + { + /* no more options, but have to get `--' out of the way */ + permute (argv + permute_from, num_nonopts, 1); + optind = permute_from + 1; + return EOF; + } + break; + case RETURN_IN_ORDER: + if (!is_option (argv[optind], only)) + { + optarg = argv[optind++]; + return (optopt = 1); + } + break; + case REQUIRE_ORDER: + if (!is_option (argv[optind], only)) + return EOF; + break; + } } /* we've got an option, so parse it */ /* first, is it a long option? */ - if (longopts != 0 - && (memcmp (argv[data->optind], "--", 2) == 0 - || (only && argv[data->optind][0] == '+')) && data->optwhere == 1) + if (longopts != NULL + && (memcmp (argv[optind], "--", 2) == 0 + || (only && argv[optind][0] == '+')) && optwhere == 1) { /* handle long options */ - if (memcmp (argv[data->optind], "--", 2) == 0) - data->optwhere = 2; + if (memcmp (argv[optind], "--", 2) == 0) + optwhere = 2; longopt_match = -1; - possible_arg = strchr (argv[data->optind] + data->optwhere, '='); - if (possible_arg == 0) - { - /* no =, so next argv might be arg */ - match_chars = strlen (argv[data->optind]); - possible_arg = argv[data->optind] + match_chars; - match_chars = match_chars - data->optwhere; - } + possible_arg = strchr (argv[optind] + optwhere, '='); + if (possible_arg == NULL) + { + /* no =, so next argv might be arg */ + match_chars = strlen (argv[optind]); + possible_arg = argv[optind] + match_chars; + match_chars = match_chars - optwhere; + } else - match_chars = (possible_arg - argv[data->optind]) - data->optwhere; - for (optindex = 0; longopts[optindex].name != 0; ++optindex) - { - if (memcmp - (argv[data->optind] + data->optwhere, longopts[optindex].name, - match_chars) == 0) - { - /* do we have an exact match? */ - if (match_chars == (int) (strlen (longopts[optindex].name))) - { - longopt_match = optindex; - break; - } - /* do any characters match? */ - else - { - if (longopt_match < 0) - longopt_match = optindex; - else - { - /* we have ambiguous options */ - if (data->opterr) - fprintf (stderr, "%s: option `%s' is ambiguous " - "(could be `--%s' or `--%s')\n", - argv[0], - argv[data->optind], - longopts[longopt_match].name, - longopts[optindex].name); - return (data->optopt = '?'); - } - } - } - } + match_chars = (possible_arg - argv[optind]) - optwhere; + for (optindex = 0; longopts[optindex].name != NULL; optindex++) + { + if (memcmp (argv[optind] + optwhere, + longopts[optindex].name, match_chars) == 0) + { + /* do we have an exact match? */ + if (match_chars == (int) (strlen (longopts[optindex].name))) + { + longopt_match = optindex; + break; + } + /* do any characters match? */ + else + { + if (longopt_match < 0) + longopt_match = optindex; + else + { + /* we have ambiguous options */ + if (opterr) + fprintf (stderr, "%s: option `%s' is ambiguous " + "(could be `--%s' or `--%s')\n", + argv[0], + argv[optind], + longopts[longopt_match].name, + longopts[optindex].name); + return (optopt = '?'); + } + } + } + } if (longopt_match >= 0) - has_arg = longopts[longopt_match].has_arg; + has_arg = longopts[longopt_match].has_arg; } - /* if we didn't find a long option, is it a short option? */ - if (longopt_match < 0 && shortopts != 0) + if (longopt_match < 0 && shortopts != NULL) { - cp = strchr (shortopts, argv[data->optind][data->optwhere]); - if (cp == 0) - { - /* couldn't find option in shortopts */ - if (data->opterr) - fprintf (stderr, - "%s: invalid option -- `-%c'\n", - argv[0], argv[data->optind][data->optwhere]); - data->optwhere++; - if (argv[data->optind][data->optwhere] == '\0') - { - data->optind++; - data->optwhere = 1; - } - return (data->optopt = '?'); - } + cp = strchr (shortopts, argv[optind][optwhere]); + if (cp == NULL) + { + /* couldn't find option in shortopts */ + if (opterr) + fprintf (stderr, + "%s: invalid option -- `-%c'\n", + argv[0], argv[optind][optwhere]); + optwhere++; + if (argv[optind][optwhere] == '\0') + { + optind++; + optwhere = 1; + } + return (optopt = '?'); + } has_arg = ((cp[1] == ':') - ? ((cp[2] == ':') ? OPTIONAL_ARG : REQUIRED_ARG) : NO_ARG); - possible_arg = argv[data->optind] + data->optwhere + 1; - data->optopt = *cp; + ? ((cp[2] == ':') ? OPTIONAL_ARG : REQUIRED_ARG) : NO_ARG); + possible_arg = argv[optind] + optwhere + 1; + optopt = *cp; } - - /* get argument and reset data->optwhere */ + /* get argument and reset optwhere */ arg_next = 0; switch (has_arg) { case OPTIONAL_ARG: if (*possible_arg == '=') - possible_arg++; - data->optarg = (*possible_arg != '\0') ? possible_arg : 0; - data->optwhere = 1; + possible_arg++; + if (*possible_arg != '\0') + { + optarg = possible_arg; + optwhere = 1; + } + else + optarg = NULL; break; case REQUIRED_ARG: if (*possible_arg == '=') - possible_arg++; + possible_arg++; if (*possible_arg != '\0') - { - data->optarg = possible_arg; - data->optwhere = 1; - } - else if (data->optind + 1 >= argc) - { - if (data->opterr) - { - fprintf (stderr, "%s: argument required for option `", argv[0]); - if (longopt_match >= 0) - fprintf (stderr, "--%s'\n", longopts[longopt_match].name); - else - fprintf (stderr, "-%c'\n", *cp); - } - data->optind++; - return (data->optopt = ':'); - } + { + optarg = possible_arg; + optwhere = 1; + } + else if (optind + 1 >= argc) + { + if (opterr) + { + fprintf (stderr, "%s: argument required for option `", argv[0]); + if (longopt_match >= 0) + fprintf (stderr, "--%s'\n", longopts[longopt_match].name); + else + fprintf (stderr, "-%c'\n", *cp); + } + optind++; + return (optopt = ':'); + } else - { - data->optarg = argv[data->optind + 1]; - arg_next = 1; - data->optwhere = 1; - } + { + optarg = argv[optind + 1]; + arg_next = 1; + optwhere = 1; + } break; - default: /* shouldn't happen */ case NO_ARG: if (longopt_match < 0) - { - data->optwhere++; - if (argv[data->optind][data->optwhere] == '\0') - data->optwhere = 1; - } + { + optwhere++; + if (argv[optind][optwhere] == '\0') + optwhere = 1; + } else - data->optwhere = 1; - data->optarg = 0; + optwhere = 1; + optarg = NULL; break; } - /* do we have to permute or otherwise modify data->optind? */ - if (ordering == PERMUTE && data->optwhere == 1 && num_nonopts != 0) + /* do we have to permute or otherwise modify optind? */ + if (ordering == PERMUTE && optwhere == 1 && num_nonopts != 0) { permute (argv + permute_from, num_nonopts, 1 + arg_next); - data->optind = permute_from + 1 + arg_next; + optind = permute_from + 1 + arg_next; } - else if (data->optwhere == 1) - data->optind = data->optind + 1 + arg_next; + else if (optwhere == 1) + optind = optind + 1 + arg_next; /* finally return */ if (longopt_match >= 0) { - if (longind != 0) - *longind = longopt_match; - if (longopts[longopt_match].flag != 0) - { - *(longopts[longopt_match].flag) = longopts[longopt_match].val; - return 0; - } + if (longind != NULL) + *longind = longopt_match; + if (longopts[longopt_match].flag != NULL) + { + *(longopts[longopt_match].flag) = longopts[longopt_match].val; + return 0; + } else - return longopts[longopt_match].val; + return longopts[longopt_match].val; } else - return data->optopt; + return optopt; } int getopt (int argc, char *const argv[], const char *optstring) { - struct getopt_data data; - int r; - - read_globals (&data); - r = getopt_internal (argc, argv, optstring, 0, 0, 0, &data); - write_globals (&data); - return r; + return getopt_internal (argc, argv, optstring, NULL, NULL, 0); } int getopt_long (int argc, char *const argv[], const char *shortopts, - const struct option *longopts, int *longind) + const struct option *longopts, int *longind) { - struct getopt_data data; - int r; - - read_globals (&data); - r = getopt_internal (argc, argv, shortopts, longopts, longind, 0, &data); - write_globals (&data); - return r; + return getopt_internal (argc, argv, shortopts, longopts, longind, 0); } int getopt_long_only (int argc, char *const argv[], const char *shortopts, - const struct option *longopts, int *longind) -{ - struct getopt_data data; - int r; - - read_globals (&data); - r = getopt_internal (argc, argv, shortopts, longopts, longind, 1, &data); - write_globals (&data); - return r; -} - -int -__getopt_r (int argc, char *const argv[], const char *optstring, - struct getopt_data *data) -{ - return getopt_internal (argc, argv, optstring, 0, 0, 0, data); -} - -int -__getopt_long_r (int argc, char *const argv[], const char *shortopts, - const struct option *longopts, int *longind, - struct getopt_data *data) -{ - return getopt_internal (argc, argv, shortopts, longopts, longind, 0, data); -} - -int -__getopt_long_only_r (int argc, char *const argv[], const char *shortopts, - const struct option *longopts, int *longind, - struct getopt_data *data) + const struct option *longopts, int *longind) { - return getopt_internal (argc, argv, shortopts, longopts, longind, 1, data); + return getopt_internal (argc, argv, shortopts, longopts, longind, 1); } -#endif /* !HAVE_GETOPT */ - /* end of file GETOPT.C */ diff --git a/newlib/libc/stdlib/mprec.h b/newlib/libc/stdlib/mprec.h index dea89bf11..498de5b74 100644 --- a/newlib/libc/stdlib/mprec.h +++ b/newlib/libc/stdlib/mprec.h @@ -78,18 +78,31 @@ union double_union #define word1(x) (x.i[1]) #endif -/* The following is taken from gdtoaimp.h for use with new strtod, but - adjusted to avoid invalid type-punning. */ + +/* The following is taken from gdtoaimp.h for use with new strtod. */ typedef __int32_t Long; +typedef union { double d; __ULong L[2]; } U; -/* Unfortunately, because __ULong might be a different type than - __uint32_t, we can't re-use union double_union as-is without - further edits in strtod.c. */ -typedef union { double d; __ULong i[2]; } U; +#ifdef YES_ALIAS +#define dval(x) x +#ifdef IEEE_8087 +#define dword0(x) ((__ULong *)&x)[1] +#define dword1(x) ((__ULong *)&x)[0] +#else +#define dword0(x) ((__ULong *)&x)[0] +#define dword1(x) ((__ULong *)&x)[1] +#endif +#else /* !YES_ALIAS */ +#ifdef IEEE_8087 +#define dword0(x) ((U*)&x)->L[1] +#define dword1(x) ((U*)&x)->L[0] +#else +#define dword0(x) ((U*)&x)->L[0] +#define dword1(x) ((U*)&x)->L[1] +#endif +#define dval(x) ((U*)&x)->d +#endif /* YES_ALIAS */ -#define dword0(x) word0(x) -#define dword1(x) word1(x) -#define dval(x) (x.d) #undef SI #ifdef Sudden_Underflow @@ -98,7 +111,17 @@ typedef union { double d; __ULong i[2]; } U; #define SI 0 #endif -#define Storeinc(a,b,c) (*(a)++ = (b) << 16 | (c) & 0xffff) +/* The following definition of Storeinc is appropriate for MIPS processors. + * An alternative that might be better on some machines is + * #define Storeinc(a,b,c) (*a++ = b << 16 | c & 0xffff) + */ +#if defined (__IEEE_BYTES_LITTLE_ENDIAN) + defined (IEEE_8087) + defined (VAX) +#define Storeinc(a,b,c) (((unsigned short *)a)[1] = (unsigned short)b, \ +((unsigned short *)a)[0] = (unsigned short)c, a++) +#else +#define Storeinc(a,b,c) (((unsigned short *)a)[0] = (unsigned short)b, \ +((unsigned short *)a)[1] = (unsigned short)c, a++) +#endif /* #define P DBL_MANT_DIG */ /* Ten_pmax = floor(P*log(2)/log(5)) */ @@ -144,7 +167,11 @@ typedef union { double d; __ULong i[2]; } U; #define word0(x) (x.i[0]) #define word1(x) 0 -#define dword0(x) word0(x) +#ifdef YES_ALIAS +#define dword0(x) ((__ULong *)&x)[0] +#else +#define dword0(x) ((U*)&x)->L[0] +#endif #define dword1(x) 0 #else diff --git a/newlib/libc/stdlib/strtod.c b/newlib/libc/stdlib/strtod.c index 703fbce1d..e206d0587 100644 --- a/newlib/libc/stdlib/strtod.c +++ b/newlib/libc/stdlib/strtod.c @@ -14,7 +14,7 @@ ANSI_SYNOPSIS double strtod(const char *<[str]>, char **<[tail]>); float strtof(const char *<[str]>, char **<[tail]>); - double _strtod_r(void *<[reent]>, + double _strtod_r(void *<[reent]>, const char *<[str]>, char **<[tail]>); TRAD_SYNOPSIS @@ -37,19 +37,12 @@ DESCRIPTION producing a substring which can be converted to a double value. The substring converted is the longest initial subsequence of <[str]>, beginning with the first - non-whitespace character, that has one of these formats: - .[+|-]<[digits]>[.[<[digits]>]][(e|E)[+|-]<[digits]>] - .[+|-].<[digits]>[(e|E)[+|-]<[digits]>] - .[+|-](i|I)(n|N)(f|F)[(i|I)(n|N)(i|I)(t|T)(y|Y)] - .[+|-](n|N)(a|A)(n|N)[<(>[<[hexdigits]>]<)>] - .[+|-]0(x|X)<[hexdigits]>[.[<[hexdigits]>]][(p|P)[+|-]<[digits]>] - .[+|-]0(x|X).<[hexdigits]>[(p|P)[+|-]<[digits]>] + non-whitespace character, that has the format: + .[+|-]<[digits]>[.][<[digits]>][(e|E)[+|-]<[digits]>] The substring contains no characters if <[str]> is empty, consists entirely of whitespace, or if the first non-whitespace character is something other than <<+>>, <<->>, <<.>>, or a - digit, and cannot be parsed as infinity or NaN. If the platform - does not support NaN, then NaN is treated as an empty substring. - If the substring is empty, no conversion is done, and + digit. If the substring is empty, no conversion is done, and the value of <[str]> is stored in <<*<[tail]>>>. Otherwise, the substring is converted, and a pointer to the final string (which will contain at least the terminating null character of @@ -59,8 +52,7 @@ DESCRIPTION This implementation returns the nearest machine number to the input decimal string. Ties are broken by using the IEEE - round-even rule. However, <<strtof>> is currently subject to - double rounding errors. + round-even rule. The alternate function <<_strtod_r>> is a reentrant version. The extra argument <[reent]> is a pointer to a reentrancy structure. @@ -184,7 +176,7 @@ _DEFUN (ULtod, (L, bits, exp, k), L[_0] |= 0x80000000L; } #endif /* !NO_HEX_FP */ - + #ifdef INFNAN_CHECK static int _DEFUN (match, (sp, t), @@ -218,8 +210,7 @@ _DEFUN (_strtod_r, (ptr, s00, se), int bb2, bb5, bbe, bd2, bd5, bbbits, bs2, c, decpt, dsign, e, e1, esign, i, j, k, nd, nd0, nf, nz, nz0, sign; _CONST char *s, *s0, *s1; - double aadj, adj; - U aadj1, rv, rv0; + double aadj, aadj1, adj, rv, rv0; Long L; __ULong y, z; _Bigint *bb, *bb1, *bd, *bd0, *bs, *delta; @@ -263,9 +254,6 @@ _DEFUN (_strtod_r, (ptr, s00, se), switch(s[1]) { case 'x': case 'X': - /* If the number is not hex, then the parse of - 0 is still valid. */ - s00 = s + 1; { #if defined(FE_DOWNWARD) && defined(FE_TONEAREST) && defined(FE_TOWARDZERO) && defined(FE_UPWARD) FPI fpi1 = fpi; @@ -280,6 +268,7 @@ _DEFUN (_strtod_r, (ptr, s00, se), switch((i = gethex(ptr, &s, &fpi1, &exp, &bb, sign)) & STRTOG_Retmask) { case STRTOG_NoNumber: s = s00; + sign = 0; case STRTOG_Zero: break; default: @@ -287,7 +276,7 @@ _DEFUN (_strtod_r, (ptr, s00, se), copybits(bits, fpi.nbits, bb); Bfree(ptr,bb); } - ULtod(rv.i, bits, exp, i); + ULtod(((U*)&rv)->L, bits, exp, i); }} goto ret; } @@ -470,7 +459,7 @@ _DEFUN (_strtod_r, (ptr, s00, se), #ifdef Honor_FLT_ROUNDS /* round correctly FLT_ROUNDS = 2 or 3 */ if (sign) { - dval(rv) = -dval(rv); + rv = -rv; sign = 0; } #endif @@ -486,7 +475,7 @@ _DEFUN (_strtod_r, (ptr, s00, se), #ifdef Honor_FLT_ROUNDS /* round correctly FLT_ROUNDS = 2 or 3 */ if (sign) { - dval(rv) = -dval(rv); + rv = -rv; sign = 0; } #endif @@ -514,7 +503,7 @@ _DEFUN (_strtod_r, (ptr, s00, se), #ifdef Honor_FLT_ROUNDS /* round correctly FLT_ROUNDS = 2 or 3 */ if (sign) { - dval(rv) = -dval(rv); + rv = -rv; sign = 0; } #endif @@ -977,14 +966,14 @@ _DEFUN (_strtod_r, (ptr, s00, se), } if ((aadj = ratio(delta, bs)) <= 2.) { if (dsign) - aadj = dval(aadj1) = 1.; + aadj = aadj1 = 1.; else if (dword1(rv) || dword0(rv) & Bndry_mask) { #ifndef Sudden_Underflow if (dword1(rv) == Tiny1 && !dword0(rv)) goto undfl; #endif aadj = 1.; - dval(aadj1) = -1.; + aadj1 = -1.; } else { /* special case -- power of FLT_RADIX to be */ @@ -994,24 +983,24 @@ _DEFUN (_strtod_r, (ptr, s00, se), aadj = 1./FLT_RADIX; else aadj *= 0.5; - dval(aadj1) = -aadj; + aadj1 = -aadj; } } else { aadj *= 0.5; - dval(aadj1) = dsign ? aadj : -aadj; + aadj1 = dsign ? aadj : -aadj; #ifdef Check_FLT_ROUNDS switch(Rounding) { case 2: /* towards +infinity */ - dval(aadj1) -= 0.5; + aadj1 -= 0.5; break; case 0: /* towards 0 */ case 3: /* towards -infinity */ - dval(aadj1) += 0.5; + aadj1 += 0.5; } #else if (Flt_Rounds == 0) - dval(aadj1) += 0.5; + aadj1 += 0.5; #endif /*Check_FLT_ROUNDS*/ } y = dword0(rv) & Exp_mask; @@ -1021,7 +1010,7 @@ _DEFUN (_strtod_r, (ptr, s00, se), if (y == Exp_msk1*(DBL_MAX_EXP+Bias-1)) { dval(rv0) = dval(rv); dword0(rv) -= P*Exp_msk1; - adj = dval(aadj1) * ulp(dval(rv)); + adj = aadj1 * ulp(dval(rv)); dval(rv) += adj; if ((dword0(rv) & Exp_mask) >= Exp_msk1*(DBL_MAX_EXP+Bias-P)) { @@ -1043,18 +1032,18 @@ _DEFUN (_strtod_r, (ptr, s00, se), if ((z = aadj) <= 0) z = 1; aadj = z; - dval(aadj1) = dsign ? aadj : -aadj; + aadj1 = dsign ? aadj : -aadj; } dword0(aadj1) += (2*P+1)*Exp_msk1 - y; } - adj = dval(aadj1) * ulp(dval(rv)); + adj = aadj1 * ulp(dval(rv)); dval(rv) += adj; #else #ifdef Sudden_Underflow if ((dword0(rv) & Exp_mask) <= P*Exp_msk1) { dval(rv0) = dval(rv); dword0(rv) += P*Exp_msk1; - adj = dval(aadj1) * ulp(dval(rv)); + adj = aadj1 * ulp(dval(rv)); dval(rv) += adj; #ifdef IBM if ((dword0(rv) & Exp_mask) < P*Exp_msk1) @@ -1077,7 +1066,7 @@ _DEFUN (_strtod_r, (ptr, s00, se), dword0(rv) -= P*Exp_msk1; } else { - adj = dval(aadj1) * ulp(dval(rv)); + adj = aadj1 * ulp(dval(rv)); dval(rv) += adj; } #else /*Sudden_Underflow*/ @@ -1089,11 +1078,11 @@ _DEFUN (_strtod_r, (ptr, s00, se), * example: 1.2e-307 . */ if (y <= (P-1)*Exp_msk1 && aadj > 1.) { - dval(aadj1) = (double)(int)(aadj + 0.5); + aadj1 = (double)(int)(aadj + 0.5); if (!dsign) - dval(aadj1) = -dval(aadj1); + aadj1 = -aadj1; } - adj = dval(aadj1) * ulp(dval(rv)); + adj = aadj1 * ulp(dval(rv)); dval(rv) += adj; #endif /*Sudden_Underflow*/ #endif /*Avoid_Underflow*/ diff --git a/newlib/libc/stdlib/wcsrtombs.c b/newlib/libc/stdlib/wcsrtombs.c index a16d36cf6..6871d0c00 100644 --- a/newlib/libc/stdlib/wcsrtombs.c +++ b/newlib/libc/stdlib/wcsrtombs.c @@ -45,7 +45,7 @@ _DEFUN (_wcsrtombs_r, (r, dst, src, len, ps), ps->__count = 0; return (size_t)-1; } - if (n + bytes <= len) + if (n <= len - bytes && bytes < len) { n += bytes; if (dst) |