~hamo/ubuntu/precise/grub2/grub2.hi_res

« back to all changes in this revision

Viewing changes to grub-core/gnulib/getdelim.c

  • Committer: Bazaar Package Importer
  • Author(s): Colin Watson, Colin Watson, Robert Millan, Updated translations
  • Date: 2010-11-22 12:24:56 UTC
  • mfrom: (1.26.4 upstream) (17.3.36 sid)
  • mto: (17.3.43 sid)
  • mto: This revision was merged to the branch mainline in revision 89.
  • Revision ID: james.westby@ubuntu.com-20101122122456-y82z3sfb7k4zfdcc
Tags: 1.99~20101122-1
[ Colin Watson ]
* New Bazaar snapshot.  Too many changes to list in full, but some of the
  more user-visible ones are as follows:
  - GRUB script:
    + Function parameters, "break", "continue", "shift", "setparams",
      "return", and "!".
    + "export" command supports multiple variable names.
    + Multi-line quoted strings support.
    + Wildcard expansion.
  - sendkey support.
  - USB hotunplugging and USB serial support.
  - Rename CD-ROM to cd on BIOS.
  - Add new --boot-directory option to grub-install, grub-reboot, and
    grub-set-default; the old --root-directory option is still accepted
    but was often confusing.
  - Basic btrfs detection/UUID support (but no file reading yet).
  - bash-completion for utilities.
  - If a device is listed in device.map, always assume that it is
    BIOS-visible rather than using extra layers such as LVM or RAID.
  - Add grub-mknetdir script (closes: #550658).
  - Remove deprecated "root" command.
  - Handle RAID devices containing virtio components.
  - GRUB Legacy configuration file support (via grub-menulst2cfg).
  - Keyboard layout support (via grub-mklayout and grub-kbdcomp).
  - Check generated grub.cfg for syntax errors before saving.
  - Pause execution for at most ten seconds if any errors are displayed,
    so that the user has a chance to see them.
  - Support submenus.
  - Write embedding zone using Reed-Solomon, so that it's robust against
    being partially overwritten (closes: #550702, #591416, #593347).
  - GRUB_DISABLE_LINUX_RECOVERY and GRUB_DISABLE_NETBSD_RECOVERY merged
    into a single GRUB_DISABLE_RECOVERY variable.
  - Fix loader memory allocation failure (closes: #551627).
  - Don't call savedefault on recovery entries (closes: #589325).
  - Support triple-indirect blocks on ext2 (closes: #543924).
  - Recognise DDF1 fake RAID (closes: #603354).

[ Robert Millan ]
* Use dpkg architecture wildcards.

[ Updated translations ]
* Slovenian (Vanja Cvelbar).  Closes: #604003
* Dzongkha (dawa pemo via Tenzin Dendup).  Closes: #604102

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/* getdelim.c --- Implementation of replacement getdelim function.
 
2
   Copyright (C) 1994, 1996, 1997, 1998, 2001, 2003, 2005, 2006, 2007, 2008,
 
3
   2009, 2010 Free Software Foundation, Inc.
 
4
 
 
5
   This program is free software; you can redistribute it and/or
 
6
   modify it under the terms of the GNU General Public License as
 
7
   published by the Free Software Foundation; either version 3, or (at
 
8
   your option) any later version.
 
9
 
 
10
   This program is distributed in the hope that it will be useful, but
 
11
   WITHOUT ANY WARRANTY; without even the implied warranty of
 
12
   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 
13
   General Public License for more details.
 
14
 
 
15
   You should have received a copy of the GNU General Public License
 
16
   along with this program; if not, write to the Free Software
 
17
   Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
 
18
   02110-1301, USA.  */
 
19
 
 
20
/* Ported from glibc by Simon Josefsson. */
 
21
 
 
22
#include <config.h>
 
23
 
 
24
/* Don't use __attribute__ __nonnull__ in this compilation unit.  Otherwise gcc
 
25
   optimizes away the lineptr == NULL || n == NULL || fp == NULL tests below.  */
 
26
#define _GL_ARG_NONNULL(params)
 
27
 
 
28
#include <stdio.h>
 
29
 
 
30
#include <limits.h>
 
31
#include <stdint.h>
 
32
#include <stdlib.h>
 
33
#include <errno.h>
 
34
 
 
35
#ifndef SSIZE_MAX
 
36
# define SSIZE_MAX ((ssize_t) (SIZE_MAX / 2))
 
37
#endif
 
38
 
 
39
#if USE_UNLOCKED_IO
 
40
# include "unlocked-io.h"
 
41
# define getc_maybe_unlocked(fp)        getc(fp)
 
42
#elif !HAVE_FLOCKFILE || !HAVE_FUNLOCKFILE || !HAVE_DECL_GETC_UNLOCKED
 
43
# undef flockfile
 
44
# undef funlockfile
 
45
# define flockfile(x) ((void) 0)
 
46
# define funlockfile(x) ((void) 0)
 
47
# define getc_maybe_unlocked(fp)        getc(fp)
 
48
#else
 
49
# define getc_maybe_unlocked(fp)        getc_unlocked(fp)
 
50
#endif
 
51
 
 
52
/* Read up to (and including) a DELIMITER from FP into *LINEPTR (and
 
53
   NUL-terminate it).  *LINEPTR is a pointer returned from malloc (or
 
54
   NULL), pointing to *N characters of space.  It is realloc'ed as
 
55
   necessary.  Returns the number of characters read (not including
 
56
   the null terminator), or -1 on error or EOF.  */
 
57
 
 
58
ssize_t
 
59
getdelim (char **lineptr, size_t *n, int delimiter, FILE *fp)
 
60
{
 
61
  ssize_t result;
 
62
  size_t cur_len = 0;
 
63
 
 
64
  if (lineptr == NULL || n == NULL || fp == NULL)
 
65
    {
 
66
      errno = EINVAL;
 
67
      return -1;
 
68
    }
 
69
 
 
70
  flockfile (fp);
 
71
 
 
72
  if (*lineptr == NULL || *n == 0)
 
73
    {
 
74
      char *new_lineptr;
 
75
      *n = 120;
 
76
      new_lineptr = (char *) realloc (*lineptr, *n);
 
77
      if (new_lineptr == NULL)
 
78
        {
 
79
          result = -1;
 
80
          goto unlock_return;
 
81
        }
 
82
      *lineptr = new_lineptr;
 
83
    }
 
84
 
 
85
  for (;;)
 
86
    {
 
87
      int i;
 
88
 
 
89
      i = getc_maybe_unlocked (fp);
 
90
      if (i == EOF)
 
91
        {
 
92
          result = -1;
 
93
          break;
 
94
        }
 
95
 
 
96
      /* Make enough space for len+1 (for final NUL) bytes.  */
 
97
      if (cur_len + 1 >= *n)
 
98
        {
 
99
          size_t needed_max =
 
100
            SSIZE_MAX < SIZE_MAX ? (size_t) SSIZE_MAX + 1 : SIZE_MAX;
 
101
          size_t needed = 2 * *n + 1;   /* Be generous. */
 
102
          char *new_lineptr;
 
103
 
 
104
          if (needed_max < needed)
 
105
            needed = needed_max;
 
106
          if (cur_len + 1 >= needed)
 
107
            {
 
108
              result = -1;
 
109
              errno = EOVERFLOW;
 
110
              goto unlock_return;
 
111
            }
 
112
 
 
113
          new_lineptr = (char *) realloc (*lineptr, needed);
 
114
          if (new_lineptr == NULL)
 
115
            {
 
116
              result = -1;
 
117
              goto unlock_return;
 
118
            }
 
119
 
 
120
          *lineptr = new_lineptr;
 
121
          *n = needed;
 
122
        }
 
123
 
 
124
      (*lineptr)[cur_len] = i;
 
125
      cur_len++;
 
126
 
 
127
      if (i == delimiter)
 
128
        break;
 
129
    }
 
130
  (*lineptr)[cur_len] = '\0';
 
131
  result = cur_len ? cur_len : result;
 
132
 
 
133
 unlock_return:
 
134
  funlockfile (fp); /* doesn't set errno */
 
135
 
 
136
  return result;
 
137
}