~ubuntu-branches/ubuntu/saucy/augeas/saucy

« back to all changes in this revision

Viewing changes to gnulib/lib/printf-parse.c

  • Committer: Bazaar Package Importer
  • Author(s): Micah Anderson
  • Date: 2011-06-09 10:25:27 UTC
  • mfrom: (1.4.1 upstream) (19.1.7 natty)
  • Revision ID: james.westby@ubuntu.com-20110609102527-8l29k1tv6bwnqujq
Tags: 0.8.1-1
* new upstream release
* pull packaging from Ubuntu - new binary package augeas-docs
* change build dependency on naturaldocs to version in Debian
* remove debian/patches/*, no longer needed
* update standards version - no changes
* update libaugeas0 short description to not start with an article
* update debian/libaugeas0.symbols to match upstream changes

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
1
/* Formatted output to strings.
2
 
   Copyright (C) 1999-2000, 2002-2003, 2006-2010 Free Software Foundation, Inc.
 
2
   Copyright (C) 1999-2000, 2002-2003, 2006-2011 Free Software Foundation, Inc.
3
3
 
4
4
   This program is free software; you can redistribute it and/or modify
5
5
   it under the terms of the GNU Lesser General Public License as published by
63
63
/* malloc(), realloc(), free().  */
64
64
#include <stdlib.h>
65
65
 
 
66
/* memcpy().  */
 
67
#include <string.h>
 
68
 
66
69
/* errno.  */
67
70
#include <errno.h>
68
71
 
80
83
int
81
84
PRINTF_PARSE (const CHAR_T *format, DIRECTIVES *d, arguments *a)
82
85
{
83
 
  const CHAR_T *cp = format;            /* pointer into format */
 
86
  const CHAR_T *cp = format;    /* pointer into format */
84
87
  size_t arg_posn = 0;          /* number of regular arguments consumed */
85
 
  size_t d_allocated;                   /* allocated elements of d->dir */
86
 
  size_t a_allocated;                   /* allocated elements of a->arg */
 
88
  size_t d_allocated;           /* allocated elements of d->dir */
 
89
  size_t a_allocated;           /* allocated elements of a->arg */
87
90
  size_t max_width_length = 0;
88
91
  size_t max_precision_length = 0;
89
92
 
90
93
  d->count = 0;
91
 
  d_allocated = 1;
92
 
  d->dir = (DIRECTIVE *) malloc (d_allocated * sizeof (DIRECTIVE));
93
 
  if (d->dir == NULL)
94
 
    /* Out of memory.  */
95
 
    goto out_of_memory_1;
 
94
  d_allocated = N_DIRECT_ALLOC_DIRECTIVES;
 
95
  d->dir = d->direct_alloc_dir;
96
96
 
97
97
  a->count = 0;
98
 
  a_allocated = 0;
99
 
  a->arg = NULL;
 
98
  a_allocated = N_DIRECT_ALLOC_ARGUMENTS;
 
99
  a->arg = a->direct_alloc_arg;
100
100
 
101
101
#define REGISTER_ARG(_index_,_type_) \
102
102
  {                                                                     \
113
113
        if (size_overflow_p (memory_size))                              \
114
114
          /* Overflow, would lead to out of memory.  */                 \
115
115
          goto out_of_memory;                                           \
116
 
        memory = (argument *) (a->arg                                   \
 
116
        memory = (argument *) (a->arg != a->direct_alloc_arg            \
117
117
                               ? realloc (a->arg, memory_size)          \
118
118
                               : malloc (memory_size));                 \
119
119
        if (memory == NULL)                                             \
120
120
          /* Out of memory.  */                                         \
121
121
          goto out_of_memory;                                           \
 
122
        if (a->arg == a->direct_alloc_arg)                              \
 
123
          memcpy (memory, a->arg, a->count * sizeof (argument));        \
122
124
        a->arg = memory;                                                \
123
125
      }                                                                 \
124
126
    while (a->count <= n)                                               \
206
208
                  dp->flags |= FLAG_ZERO;
207
209
                  cp++;
208
210
                }
 
211
#if __GLIBC__ >= 2 && !defined __UCLIBC__
 
212
              else if (*cp == 'I')
 
213
                {
 
214
                  dp->flags |= FLAG_LOCALIZED;
 
215
                  cp++;
 
216
                }
 
217
#endif
209
218
              else
210
219
                break;
211
220
            }
581
590
              if (size_overflow_p (memory_size))
582
591
                /* Overflow, would lead to out of memory.  */
583
592
                goto out_of_memory;
584
 
              memory = (DIRECTIVE *) realloc (d->dir, memory_size);
 
593
              memory = (DIRECTIVE *) (d->dir != d->direct_alloc_dir
 
594
                                      ? realloc (d->dir, memory_size)
 
595
                                      : malloc (memory_size));
585
596
              if (memory == NULL)
586
597
                /* Out of memory.  */
587
598
                goto out_of_memory;
 
599
              if (d->dir == d->direct_alloc_dir)
 
600
                memcpy (memory, d->dir, d->count * sizeof (DIRECTIVE));
588
601
              d->dir = memory;
589
602
            }
590
603
        }
603
616
  return 0;
604
617
 
605
618
error:
606
 
  if (a->arg)
 
619
  if (a->arg != a->direct_alloc_arg)
607
620
    free (a->arg);
608
 
  if (d->dir)
 
621
  if (d->dir != d->direct_alloc_dir)
609
622
    free (d->dir);
610
623
  errno = EINVAL;
611
624
  return -1;
612
625
 
613
626
out_of_memory:
614
 
  if (a->arg)
 
627
  if (a->arg != a->direct_alloc_arg)
615
628
    free (a->arg);
616
 
  if (d->dir)
 
629
  if (d->dir != d->direct_alloc_dir)
617
630
    free (d->dir);
618
 
out_of_memory_1:
619
631
  errno = ENOMEM;
620
632
  return -1;
621
633
}