Changeset 1964 for cpio/vendor/current/gnu/printf-parse.c
- Timestamp:
- Feb 3, 2017, 2:02:34 PM (8 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
TabularUnified cpio/vendor/current/gnu/printf-parse.c ¶
r118 r1964 1 /* -*- buffer-read-only: t -*- vi: set ro: */2 /* DO NOT EDIT! GENERATED AUTOMATICALLY! */3 1 /* Formatted output to strings. 4 Copyright (C) 1999-2000, 2002-2003, 2006-201 0Free Software Foundation, Inc.2 Copyright (C) 1999-2000, 2002-2003, 2006-2015 Free Software Foundation, Inc. 5 3 6 4 This program is free software; you can redistribute it and/or modify … … 15 13 16 14 You should have received a copy of the GNU General Public License along 17 with this program; if not, write to the Free Software Foundation, 18 Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */ 15 with this program; if not, see <http://www.gnu.org/licenses/>. */ 19 16 20 17 /* This file can be parametrized with the following macros: … … 66 63 #include <stdlib.h> 67 64 65 /* memcpy(). */ 66 #include <string.h> 67 68 68 /* errno. */ 69 69 #include <errno.h> … … 83 83 PRINTF_PARSE (const CHAR_T *format, DIRECTIVES *d, arguments *a) 84 84 { 85 const CHAR_T *cp = format; 85 const CHAR_T *cp = format; /* pointer into format */ 86 86 size_t arg_posn = 0; /* number of regular arguments consumed */ 87 size_t d_allocated; 88 size_t a_allocated; 87 size_t d_allocated; /* allocated elements of d->dir */ 88 size_t a_allocated; /* allocated elements of a->arg */ 89 89 size_t max_width_length = 0; 90 90 size_t max_precision_length = 0; 91 91 92 92 d->count = 0; 93 d_allocated = 1; 94 d->dir = (DIRECTIVE *) malloc (d_allocated * sizeof (DIRECTIVE)); 95 if (d->dir == NULL) 96 /* Out of memory. */ 97 goto out_of_memory_1; 93 d_allocated = N_DIRECT_ALLOC_DIRECTIVES; 94 d->dir = d->direct_alloc_dir; 98 95 99 96 a->count = 0; 100 a_allocated = 0;101 a->arg = NULL;97 a_allocated = N_DIRECT_ALLOC_ARGUMENTS; 98 a->arg = a->direct_alloc_arg; 102 99 103 100 #define REGISTER_ARG(_index_,_type_) \ … … 116 113 /* Overflow, would lead to out of memory. */ \ 117 114 goto out_of_memory; \ 118 memory = (argument *) (a->arg 115 memory = (argument *) (a->arg != a->direct_alloc_arg \ 119 116 ? realloc (a->arg, memory_size) \ 120 117 : malloc (memory_size)); \ … … 122 119 /* Out of memory. */ \ 123 120 goto out_of_memory; \ 121 if (a->arg == a->direct_alloc_arg) \ 122 memcpy (memory, a->arg, a->count * sizeof (argument)); \ 124 123 a->arg = memory; \ 125 124 } \ … … 209 208 cp++; 210 209 } 210 #if __GLIBC__ >= 2 && !defined __UCLIBC__ 211 else if (*cp == 'I') 212 { 213 dp->flags |= FLAG_LOCALIZED; 214 cp++; 215 } 216 #endif 211 217 else 212 218 break; … … 396 402 } 397 403 #if defined __APPLE__ && defined __MACH__ 398 /* On Mac OS X 10.3, PRIdMAX is defined as "qd".404 /* On Mac OS X 10.3, PRIdMAX is defined as "qd". 399 405 We cannot change it to "lld" because PRIdMAX must also 400 406 be understood by the system's printf routines. */ … … 415 421 #endif 416 422 #if (defined _WIN32 || defined __WIN32__) && ! defined __CYGWIN__ 417 /* On native Win 32, PRIdMAX is defined as "I64d".423 /* On native Windows, PRIdMAX is defined as "I64d". 418 424 We cannot change it to "lld" because PRIdMAX must also 419 425 be understood by the system's printf routines. */ … … 584 590 /* Overflow, would lead to out of memory. */ 585 591 goto out_of_memory; 586 memory = (DIRECTIVE *) realloc (d->dir, memory_size); 592 memory = (DIRECTIVE *) (d->dir != d->direct_alloc_dir 593 ? realloc (d->dir, memory_size) 594 : malloc (memory_size)); 587 595 if (memory == NULL) 588 596 /* Out of memory. */ 589 597 goto out_of_memory; 598 if (d->dir == d->direct_alloc_dir) 599 memcpy (memory, d->dir, d->count * sizeof (DIRECTIVE)); 590 600 d->dir = memory; 591 601 } … … 606 616 607 617 error: 608 if (a->arg )618 if (a->arg != a->direct_alloc_arg) 609 619 free (a->arg); 610 if (d->dir )620 if (d->dir != d->direct_alloc_dir) 611 621 free (d->dir); 612 622 errno = EINVAL; … … 614 624 615 625 out_of_memory: 616 if (a->arg )626 if (a->arg != a->direct_alloc_arg) 617 627 free (a->arg); 618 if (d->dir )628 if (d->dir != d->direct_alloc_dir) 619 629 free (d->dir); 620 out_of_memory_1:621 630 errno = ENOMEM; 622 631 return -1;
Note:
See TracChangeset
for help on using the changeset viewer.