Resync with gnulib.

* Makefile.in (GNULIB_CFLAGS): New variable.
	* conf/common.rmk (grub_mkisofs_CFLAGS): Add GNULIB_CFLAGS.
	(grub_script_check_CFLAGS): New variable.
	* gnulib/alloca.h: Resync with gnulib.
	* gnulib/error.c: Likewise.
	* gnulib/error.h: Likewise.
	* gnulib/fnmatch.c: Likewise.
	* gnulib/fnmatch_loop.c: Likewise.
	* gnulib/getdelim.c: Likewise.
	* gnulib/getline.c: Likewise.
	* gnulib/getopt.c: Likewise.
	* gnulib/getopt1.c: Likewise.
	* gnulib/getopt_int.h: Likewise.
	* gnulib/gettext.h: Likewise.
	* gnulib/progname.c: Likewise.
	* gnulib/progname.h: Likewise.
This commit is contained in:
Vladimir 'phcoder' Serbinenko 2010-03-27 12:53:40 +01:00
parent 394a3120a7
commit 3506b90b0d
16 changed files with 1891 additions and 1821 deletions

View File

@ -1,3 +1,24 @@
2010-03-27 Vladimir Serbinenko <phcoder@gmail.com>
Resync with gnulib.
* Makefile.in (GNULIB_CFLAGS): New variable.
* conf/common.rmk (grub_mkisofs_CFLAGS): Add GNULIB_CFLAGS.
(grub_script_check_CFLAGS): New variable.
* gnulib/alloca.h: Resync with gnulib.
* gnulib/error.c: Likewise.
* gnulib/error.h: Likewise.
* gnulib/fnmatch.c: Likewise.
* gnulib/fnmatch_loop.c: Likewise.
* gnulib/getdelim.c: Likewise.
* gnulib/getline.c: Likewise.
* gnulib/getopt.c: Likewise.
* gnulib/getopt1.c: Likewise.
* gnulib/getopt_int.h: Likewise.
* gnulib/gettext.h: Likewise.
* gnulib/progname.c: Likewise.
* gnulib/progname.h: Likewise.
2010-03-27 Grégoire Sutre <gregoire.sutre@gmail.com>
Fix a build failure (-Wundef -Werror) when ENABLE_NLS is not defined,

View File

@ -79,6 +79,7 @@ LIBS = @LIBS@ $(LIBINTL)
CC = @CC@
CFLAGS = @CFLAGS@
GNULIB_CFLAGS = -Wno-undef -D_GL_UNUSED="__attribute__ ((unused))"
ASFLAGS = @ASFLAGS@
LDFLAGS = @LDFLAGS@ $(LIBS)
CPPFLAGS = @CPPFLAGS@ -I$(builddir) -I$(builddir)/include -I$(srcdir)/gnulib -I$(srcdir)/include -Wall -W \

View File

@ -56,7 +56,7 @@ grub_mkisofs_SOURCES = util/mkisofs/eltorito.c \
gnulib/error.c gnulib/progname.c
grub_mkisofs_CFLAGS = -D_FILE_OFFSET_BITS=64 \
-I$(srcdir)/util/mkisofs/include \
-Wno-all -Werror
-Wno-all -Werror $(GNULIB_CFLAGS)
# For grub-fstest.
util/grub-fstest.c_DEPENDENCIES = grub_fstest_init.h
@ -111,7 +111,7 @@ grub_script_check_SOURCES = gnulib/progname.c gnulib/getdelim.c gnulib/getline.c
kern/handler.c kern/err.c kern/parser.c kern/list.c \
kern/misc.c kern/env.c grub_script_check_init.c grub_script.tab.c \
grub_script.yy.c
grub_script_check_CFLAGS = $(GNULIB_CFLAGS)
MOSTLYCLEANFILES += symlist.c kernel_syms.lst
DEFSYMFILES += kernel_syms.lst

View File

@ -1,7 +1,7 @@
/* Memory allocation on the stack.
Copyright (C) 1995, 1999, 2001-2004, 2006-2008 Free Software
Foundation, Inc.
Copyright (C) 1995, 1999, 2001-2004, 2006-2010 Free Software Foundation,
Inc.
This program is free software; you can redistribute it and/or modify it
under the terms of the GNU General Public License as published

View File

@ -1,5 +1,5 @@
/* Error handler for noninteractive utilities
Copyright (C) 1990-1998, 2000-2007, 2009 Free Software Foundation, Inc.
Copyright (C) 1990-1998, 2000-2007, 2009-2010 Free Software Foundation, Inc.
This file is part of the GNU C Library.
This program is free software: you can redistribute it and/or modify
@ -70,8 +70,8 @@ unsigned int error_message_count;
extern void __error (int status, int errnum, const char *message, ...)
__attribute__ ((__format__ (__printf__, 3, 4)));
extern void __error_at_line (int status, int errnum, const char *file_name,
unsigned int line_number, const char *message,
...)
unsigned int line_number, const char *message,
...)
__attribute__ ((__format__ (__printf__, 5, 6)));;
# define error __error
# define error_at_line __error_at_line
@ -86,6 +86,7 @@ extern void __error_at_line (int status, int errnum, const char *file_name,
#else /* not _LIBC */
# include <fcntl.h>
# include <unistd.h>
# if !HAVE_DECL_STRERROR_R && STRERROR_R_CHAR_P
# ifndef HAVE_DECL_STRERROR_R
@ -100,8 +101,33 @@ extern char *program_name;
# if HAVE_STRERROR_R || defined strerror_r
# define __strerror_r strerror_r
# endif /* HAVE_STRERROR_R || defined strerror_r */
#endif /* not _LIBC */
# endif /* HAVE_STRERROR_R || defined strerror_r */
#endif /* not _LIBC */
static inline void
flush_stdout (void)
{
#if !_LIBC && defined F_GETFL
int stdout_fd;
# if GNULIB_FREOPEN_SAFER
/* Use of gnulib's freopen-safer module normally ensures that
fileno (stdout) == 1
whenever stdout is open. */
stdout_fd = STDOUT_FILENO;
# else
/* POSIX states that fileno (stdout) after fclose is unspecified. But in
practice it is not a problem, because stdout is statically allocated and
the fd of a FILE stream is stored as a field in its allocated memory. */
stdout_fd = fileno (stdout);
# endif
/* POSIX states that fflush (stdout) after fclose is unspecified; it
is safe in glibc, but not on all other platforms. fflush (NULL)
is always defined, but too draconian. */
if (0 <= stdout_fd && 0 <= fcntl (stdout_fd, F_GETFL))
#endif
fflush (stdout);
}
static void
print_errno_message (int errnum)
@ -149,58 +175,58 @@ error_tail (int status, int errnum, const char *message, va_list args)
bool use_malloc = false;
while (1)
{
if (__libc_use_alloca (len * sizeof (wchar_t)))
wmessage = (wchar_t *) alloca (len * sizeof (wchar_t));
else
{
if (!use_malloc)
wmessage = NULL;
{
if (__libc_use_alloca (len * sizeof (wchar_t)))
wmessage = (wchar_t *) alloca (len * sizeof (wchar_t));
else
{
if (!use_malloc)
wmessage = NULL;
wchar_t *p = (wchar_t *) realloc (wmessage,
len * sizeof (wchar_t));
if (p == NULL)
{
free (wmessage);
fputws_unlocked (L"out of memory\n", stderr);
return;
}
wmessage = p;
use_malloc = true;
}
wchar_t *p = (wchar_t *) realloc (wmessage,
len * sizeof (wchar_t));
if (p == NULL)
{
free (wmessage);
fputws_unlocked (L"out of memory\n", stderr);
return;
}
wmessage = p;
use_malloc = true;
}
memset (&st, '\0', sizeof (st));
tmp = message;
memset (&st, '\0', sizeof (st));
tmp = message;
res = mbsrtowcs (wmessage, &tmp, len, &st);
if (res != len)
break;
res = mbsrtowcs (wmessage, &tmp, len, &st);
if (res != len)
break;
if (__builtin_expect (len >= SIZE_MAX / 2, 0))
{
/* This really should not happen if everything is fine. */
res = (size_t) -1;
break;
}
if (__builtin_expect (len >= SIZE_MAX / 2, 0))
{
/* This really should not happen if everything is fine. */
res = (size_t) -1;
break;
}
len *= 2;
}
len *= 2;
}
if (res == (size_t) -1)
{
/* The string cannot be converted. */
if (use_malloc)
{
free (wmessage);
use_malloc = false;
}
wmessage = (wchar_t *) L"???";
}
{
/* The string cannot be converted. */
if (use_malloc)
{
free (wmessage);
use_malloc = false;
}
wmessage = (wchar_t *) L"???";
}
__vfwprintf (stderr, wmessage, args);
if (use_malloc)
free (wmessage);
free (wmessage);
}
else
#endif
@ -235,16 +261,10 @@ error (int status, int errnum, const char *message, ...)
cancellation. Therefore disable cancellation for now. */
int state = PTHREAD_CANCEL_ENABLE;
__libc_ptf_call (pthread_setcancelstate, (PTHREAD_CANCEL_DISABLE, &state),
0);
0);
#endif
#if !_LIBC && defined F_GETFL
/* POSIX states that fflush (stdout) after fclose is unspecified; it
is safe in glibc, but not on all other platforms. fflush (NULL)
is always defined, but too draconian. */
if (0 <= fcntl (1, F_GETFL))
#endif
fflush (stdout);
flush_stdout ();
#ifdef _LIBC
_IO_flockfile (stderr);
#endif
@ -276,7 +296,7 @@ int error_one_per_line;
void
error_at_line (int status, int errnum, const char *file_name,
unsigned int line_number, const char *message, ...)
unsigned int line_number, const char *message, ...)
{
va_list args;
@ -286,10 +306,10 @@ error_at_line (int status, int errnum, const char *file_name,
static unsigned int old_line_number;
if (old_line_number == line_number
&& (file_name == old_file_name
|| strcmp (old_file_name, file_name) == 0))
/* Simply return and print nothing. */
return;
&& (file_name == old_file_name
|| strcmp (old_file_name, file_name) == 0))
/* Simply return and print nothing. */
return;
old_file_name = file_name;
old_line_number = line_number;
@ -300,16 +320,10 @@ error_at_line (int status, int errnum, const char *file_name,
cancellation. Therefore disable cancellation for now. */
int state = PTHREAD_CANCEL_ENABLE;
__libc_ptf_call (pthread_setcancelstate, (PTHREAD_CANCEL_DISABLE, &state),
0);
0);
#endif
#if !_LIBC && defined F_GETFL
/* POSIX states that fflush (stdout) after fclose is unspecified; it
is safe in glibc, but not on all other platforms. fflush (NULL)
is always defined, but too draconian. */
if (0 <= fcntl (1, F_GETFL))
#endif
fflush (stdout);
flush_stdout ();
#ifdef _LIBC
_IO_flockfile (stderr);
#endif
@ -326,10 +340,10 @@ error_at_line (int status, int errnum, const char *file_name,
#if _LIBC
__fxprintf (NULL, file_name != NULL ? "%s:%d: " : " ",
file_name, line_number);
file_name, line_number);
#else
fprintf (stderr, file_name != NULL ? "%s:%d: " : " ",
file_name, line_number);
file_name, line_number);
#endif
va_start (args, message);

View File

@ -1,5 +1,6 @@
/* Declaration for error-reporting function
Copyright (C) 1995, 1996, 1997, 2003, 2006, 2008 Free Software Foundation, Inc.
Copyright (C) 1995, 1996, 1997, 2003, 2006, 2008, 2009, 2010 Free Software
Foundation, Inc.
This file is part of the GNU C Library.
This program is free software: you can redistribute it and/or modify
@ -19,19 +20,18 @@
#define _ERROR_H 1
#ifndef __attribute__
/* This feature is available in gcc versions 2.5 and later. */
# if __GNUC__ < 2 || (__GNUC__ == 2 && __GNUC_MINOR__ < 5)
# define __attribute__(Spec) /* empty */
# endif
/* The __-protected variants of `format' and `printf' attributes
are accepted by gcc versions 2.6.4 (effectively 2.7) and later. */
/* The __attribute__ feature is available in gcc versions 2.5 and later.
The __-protected variants of the attributes 'format' and 'printf' are
accepted by gcc versions 2.6.4 (effectively 2.7) and later.
We enable __attribute__ only if these are supported too, because
gnulib and libintl do '#define printf __printf__' when they override
the 'printf' function. */
# if __GNUC__ < 2 || (__GNUC__ == 2 && __GNUC_MINOR__ < 7)
# define __format__ format
# define __printf__ printf
# define __attribute__(Spec) /* empty */
# endif
#endif
#ifdef __cplusplus
#ifdef __cplusplus
extern "C" {
#endif
@ -43,7 +43,7 @@ extern void error (int __status, int __errnum, const char *__format, ...)
__attribute__ ((__format__ (__printf__, 3, 4)));
extern void error_at_line (int __status, int __errnum, const char *__fname,
unsigned int __lineno, const char *__format, ...)
unsigned int __lineno, const char *__format, ...)
__attribute__ ((__format__ (__printf__, 5, 6)));
/* If NULL, error will flush stdout, then print on stderr the program
@ -58,7 +58,7 @@ extern unsigned int error_message_count;
variable controls whether this mode is selected or not. */
extern int error_one_per_line;
#ifdef __cplusplus
#ifdef __cplusplus
}
#endif

View File

@ -1,5 +1,5 @@
/* Copyright (C) 1991,1992,1993,1996,1997,1998,1999,2000,2001,2002,2003,2004,2005,2006,2007
Free Software Foundation, Inc.
/* Copyright (C) 1991, 1992, 1993, 1996, 1997, 1998, 1999, 2000, 2001, 2002,
2003, 2004, 2005, 2006, 2007, 2009, 2010 Free Software Foundation, Inc.
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
@ -21,7 +21,7 @@
/* Enable GNU extensions in fnmatch.h. */
#ifndef _GNU_SOURCE
# define _GNU_SOURCE 1
# define _GNU_SOURCE 1
#endif
#if ! defined __builtin_expect && __GNUC__ < 3
@ -89,7 +89,7 @@ extern int fnmatch (const char *pattern, const char *string, int flags);
# define isblank(c) ((c) == ' ' || (c) == '\t')
# endif
# define STREQ(s1, s2) ((strcmp (s1, s2) == 0))
# define STREQ(s1, s2) (strcmp (s1, s2) == 0)
# if defined _LIBC || WIDE_CHAR_SUPPORT
/* The GNU C library provides support for user-defined character classes
@ -109,25 +109,25 @@ extern int fnmatch (const char *pattern, const char *string, int flags);
# endif
# ifdef _LIBC
# define ISWCTYPE(WC, WT) __iswctype (WC, WT)
# define ISWCTYPE(WC, WT) __iswctype (WC, WT)
# else
# define ISWCTYPE(WC, WT) iswctype (WC, WT)
# define ISWCTYPE(WC, WT) iswctype (WC, WT)
# endif
# if (HAVE_MBSTATE_T && HAVE_MBSRTOWCS) || _LIBC
/* In this case we are implementing the multibyte character handling. */
# define HANDLE_MULTIBYTE 1
# define HANDLE_MULTIBYTE 1
# endif
# else
# define CHAR_CLASS_MAX_LENGTH 6 /* Namely, `xdigit'. */
# define IS_CHAR_CLASS(string) \
(STREQ (string, "alpha") || STREQ (string, "upper") \
|| STREQ (string, "lower") || STREQ (string, "digit") \
|| STREQ (string, "alnum") || STREQ (string, "xdigit") \
|| STREQ (string, "space") || STREQ (string, "print") \
|| STREQ (string, "punct") || STREQ (string, "graph") \
# define IS_CHAR_CLASS(string) \
(STREQ (string, "alpha") || STREQ (string, "upper") \
|| STREQ (string, "lower") || STREQ (string, "digit") \
|| STREQ (string, "alnum") || STREQ (string, "xdigit") \
|| STREQ (string, "space") || STREQ (string, "print") \
|| STREQ (string, "punct") || STREQ (string, "graph") \
|| STREQ (string, "cntrl") || STREQ (string, "blank"))
# endif
@ -145,17 +145,17 @@ static int posixly_correct;
/* Note that this evaluates C many times. */
# define FOLD(c) ((flags & FNM_CASEFOLD) ? tolower (c) : (c))
# define CHAR char
# define UCHAR unsigned char
# define INT int
# define FCT internal_fnmatch
# define EXT ext_match
# define END end_pattern
# define L_(CS) CS
# define CHAR char
# define UCHAR unsigned char
# define INT int
# define FCT internal_fnmatch
# define EXT ext_match
# define END end_pattern
# define L_(CS) CS
# ifdef _LIBC
# define BTOWC(C) __btowc (C)
# define BTOWC(C) __btowc (C)
# else
# define BTOWC(C) btowc (C)
# define BTOWC(C) btowc (C)
# endif
# define STRLEN(S) strlen (S)
# define STRCAT(D, S) strcat (D, S)
@ -175,14 +175,14 @@ static int posixly_correct;
# if HANDLE_MULTIBYTE
# define FOLD(c) ((flags & FNM_CASEFOLD) ? towlower (c) : (c))
# define CHAR wchar_t
# define UCHAR wint_t
# define INT wint_t
# define FCT internal_fnwmatch
# define EXT ext_wmatch
# define END end_wpattern
# define L_(CS) L##CS
# define BTOWC(C) (C)
# define CHAR wchar_t
# define UCHAR wint_t
# define INT wint_t
# define FCT internal_fnwmatch
# define EXT ext_wmatch
# define END end_wpattern
# define L_(CS) L##CS
# define BTOWC(C) (C)
# ifdef _LIBC
# define STRLEN(S) __wcslen (S)
# define STRCAT(D, S) __wcscat (D, S)
@ -218,40 +218,40 @@ is_char_class (const wchar_t *wcs)
/* Test for a printable character from the portable character set. */
# ifdef _LIBC
if (*wcs < 0x20 || *wcs > 0x7e
|| *wcs == 0x24 || *wcs == 0x40 || *wcs == 0x60)
return (wctype_t) 0;
|| *wcs == 0x24 || *wcs == 0x40 || *wcs == 0x60)
return (wctype_t) 0;
# else
switch (*wcs)
{
case L' ': case L'!': case L'"': case L'#': case L'%':
case L'&': case L'\'': case L'(': case L')': case L'*':
case L'+': case L',': case L'-': case L'.': case L'/':
case L'0': case L'1': case L'2': case L'3': case L'4':
case L'5': case L'6': case L'7': case L'8': case L'9':
case L':': case L';': case L'<': case L'=': case L'>':
case L'?':
case L'A': case L'B': case L'C': case L'D': case L'E':
case L'F': case L'G': case L'H': case L'I': case L'J':
case L'K': case L'L': case L'M': case L'N': case L'O':
case L'P': case L'Q': case L'R': case L'S': case L'T':
case L'U': case L'V': case L'W': case L'X': case L'Y':
case L'Z':
case L'[': case L'\\': case L']': case L'^': case L'_':
case L'a': case L'b': case L'c': case L'd': case L'e':
case L'f': case L'g': case L'h': case L'i': case L'j':
case L'k': case L'l': case L'm': case L'n': case L'o':
case L'p': case L'q': case L'r': case L's': case L't':
case L'u': case L'v': case L'w': case L'x': case L'y':
case L'z': case L'{': case L'|': case L'}': case L'~':
break;
default:
return (wctype_t) 0;
}
{
case L' ': case L'!': case L'"': case L'#': case L'%':
case L'&': case L'\'': case L'(': case L')': case L'*':
case L'+': case L',': case L'-': case L'.': case L'/':
case L'0': case L'1': case L'2': case L'3': case L'4':
case L'5': case L'6': case L'7': case L'8': case L'9':
case L':': case L';': case L'<': case L'=': case L'>':
case L'?':
case L'A': case L'B': case L'C': case L'D': case L'E':
case L'F': case L'G': case L'H': case L'I': case L'J':
case L'K': case L'L': case L'M': case L'N': case L'O':
case L'P': case L'Q': case L'R': case L'S': case L'T':
case L'U': case L'V': case L'W': case L'X': case L'Y':
case L'Z':
case L'[': case L'\\': case L']': case L'^': case L'_':
case L'a': case L'b': case L'c': case L'd': case L'e':
case L'f': case L'g': case L'h': case L'i': case L'j':
case L'k': case L'l': case L'm': case L'n': case L'o':
case L'p': case L'q': case L'r': case L's': case L't':
case L'u': case L'v': case L'w': case L'x': case L'y':
case L'z': case L'{': case L'|': case L'}': case L'~':
break;
default:
return (wctype_t) 0;
}
# endif
/* Avoid overrunning the buffer. */
if (cp == s + CHAR_CLASS_MAX_LENGTH)
return (wctype_t) 0;
return (wctype_t) 0;
*cp++ = (char) *wcs++;
}
@ -287,58 +287,58 @@ fnmatch (const char *pattern, const char *string, int flags)
int res;
/* Calculate the size needed to convert the strings to
wide characters. */
wide characters. */
memset (&ps, '\0', sizeof (ps));
patsize = mbsrtowcs (NULL, &pattern, 0, &ps) + 1;
if (__builtin_expect (patsize != 0, 1))
{
assert (mbsinit (&ps));
strsize = mbsrtowcs (NULL, &string, 0, &ps) + 1;
if (__builtin_expect (strsize != 0, 1))
{
assert (mbsinit (&ps));
totsize = patsize + strsize;
if (__builtin_expect (! (patsize <= totsize
&& totsize <= SIZE_MAX / sizeof (wchar_t)),
0))
{
errno = ENOMEM;
return -1;
}
{
assert (mbsinit (&ps));
strsize = mbsrtowcs (NULL, &string, 0, &ps) + 1;
if (__builtin_expect (strsize != 0, 1))
{
assert (mbsinit (&ps));
totsize = patsize + strsize;
if (__builtin_expect (! (patsize <= totsize
&& totsize <= SIZE_MAX / sizeof (wchar_t)),
0))
{
errno = ENOMEM;
return -1;
}
/* Allocate room for the wide characters. */
if (__builtin_expect (totsize < ALLOCA_LIMIT, 1))
wpattern = (wchar_t *) alloca (totsize * sizeof (wchar_t));
else
{
wpattern = malloc (totsize * sizeof (wchar_t));
if (__builtin_expect (! wpattern, 0))
{
errno = ENOMEM;
return -1;
}
}
wstring = wpattern + patsize;
/* Allocate room for the wide characters. */
if (__builtin_expect (totsize < ALLOCA_LIMIT, 1))
wpattern = (wchar_t *) alloca (totsize * sizeof (wchar_t));
else
{
wpattern = malloc (totsize * sizeof (wchar_t));
if (__builtin_expect (! wpattern, 0))
{
errno = ENOMEM;
return -1;
}
}
wstring = wpattern + patsize;
/* Convert the strings into wide characters. */
mbsrtowcs (wpattern, &pattern, patsize, &ps);
assert (mbsinit (&ps));
mbsrtowcs (wstring, &string, strsize, &ps);
/* Convert the strings into wide characters. */
mbsrtowcs (wpattern, &pattern, patsize, &ps);
assert (mbsinit (&ps));
mbsrtowcs (wstring, &string, strsize, &ps);
res = internal_fnwmatch (wpattern, wstring, wstring + strsize - 1,
flags & FNM_PERIOD, flags);
res = internal_fnwmatch (wpattern, wstring, wstring + strsize - 1,
flags & FNM_PERIOD, flags);
if (__builtin_expect (! (totsize < ALLOCA_LIMIT), 0))
free (wpattern);
return res;
}
}
if (__builtin_expect (! (totsize < ALLOCA_LIMIT), 0))
free (wpattern);
return res;
}
}
}
# endif /* HANDLE_MULTIBYTE */
return internal_fnmatch (pattern, string, string + strlen (string),
flags & FNM_PERIOD, flags);
flags & FNM_PERIOD, flags);
}
# ifdef _LIBC
@ -351,4 +351,4 @@ compat_symbol (libc, __fnmatch_old, fnmatch, GLIBC_2_0);
libc_hidden_ver (__fnmatch, fnmatch)
# endif
#endif /* _LIBC or not __GNU_LIBRARY__. */
#endif /* _LIBC or not __GNU_LIBRARY__. */

File diff suppressed because it is too large Load Diff

View File

@ -1,6 +1,6 @@
/* getdelim.c --- Implementation of replacement getdelim function.
Copyright (C) 1994, 1996, 1997, 1998, 2001, 2003, 2005, 2006, 2007,
2008, 2009 Free Software Foundation, Inc.
Copyright (C) 1994, 1996, 1997, 1998, 2001, 2003, 2005, 2006, 2007, 2008,
2009, 2010 Free Software Foundation, Inc.
This program is free software; you can redistribute it and/or
modify it under the terms of the GNU General Public License as
@ -21,13 +21,16 @@
#include <config.h>
/* Don't use __attribute__ __nonnull__ in this compilation unit. Otherwise gcc
optimizes away the lineptr == NULL || n == NULL || fp == NULL tests below. */
#define _GL_ARG_NONNULL(params)
#include <stdio.h>
#include <limits.h>
#include <stdint.h>
#include <stdlib.h>
#include <errno.h>
#include <unistd.h>
#ifndef SSIZE_MAX
# define SSIZE_MAX ((ssize_t) (SIZE_MAX / 2))
@ -35,15 +38,15 @@
#if USE_UNLOCKED_IO
# include "unlocked-io.h"
# define getc_maybe_unlocked(fp) getc(fp)
# define getc_maybe_unlocked(fp) getc(fp)
#elif !HAVE_FLOCKFILE || !HAVE_FUNLOCKFILE || !HAVE_DECL_GETC_UNLOCKED
# undef flockfile
# undef funlockfile
# define flockfile(x) ((void) 0)
# define funlockfile(x) ((void) 0)
# define getc_maybe_unlocked(fp) getc(fp)
# define getc_maybe_unlocked(fp) getc(fp)
#else
# define getc_maybe_unlocked(fp) getc_unlocked(fp)
# define getc_maybe_unlocked(fp) getc_unlocked(fp)
#endif
/* Read up to (and including) a DELIMITER from FP into *LINEPTR (and
@ -72,10 +75,10 @@ getdelim (char **lineptr, size_t *n, int delimiter, FILE *fp)
*n = 120;
new_lineptr = (char *) realloc (*lineptr, *n);
if (new_lineptr == NULL)
{
result = -1;
goto unlock_return;
}
{
result = -1;
goto unlock_return;
}
*lineptr = new_lineptr;
}
@ -85,44 +88,44 @@ getdelim (char **lineptr, size_t *n, int delimiter, FILE *fp)
i = getc_maybe_unlocked (fp);
if (i == EOF)
{
result = -1;
break;
}
{
result = -1;
break;
}
/* Make enough space for len+1 (for final NUL) bytes. */
if (cur_len + 1 >= *n)
{
size_t needed_max =
SSIZE_MAX < SIZE_MAX ? (size_t) SSIZE_MAX + 1 : SIZE_MAX;
size_t needed = 2 * *n + 1; /* Be generous. */
char *new_lineptr;
{
size_t needed_max =
SSIZE_MAX < SIZE_MAX ? (size_t) SSIZE_MAX + 1 : SIZE_MAX;
size_t needed = 2 * *n + 1; /* Be generous. */
char *new_lineptr;
if (needed_max < needed)
needed = needed_max;
if (cur_len + 1 >= needed)
{
result = -1;
errno = EOVERFLOW;
goto unlock_return;
}
if (needed_max < needed)
needed = needed_max;
if (cur_len + 1 >= needed)
{
result = -1;
errno = EOVERFLOW;
goto unlock_return;
}
new_lineptr = (char *) realloc (*lineptr, needed);
if (new_lineptr == NULL)
{
result = -1;
goto unlock_return;
}
new_lineptr = (char *) realloc (*lineptr, needed);
if (new_lineptr == NULL)
{
result = -1;
goto unlock_return;
}
*lineptr = new_lineptr;
*n = needed;
}
*lineptr = new_lineptr;
*n = needed;
}
(*lineptr)[cur_len] = i;
cur_len++;
if (i == delimiter)
break;
break;
}
(*lineptr)[cur_len] = '\0';
result = cur_len ? cur_len : result;

View File

@ -1,5 +1,5 @@
/* getline.c --- Implementation of replacement getline function.
Copyright (C) 2005, 2006, 2007 Free Software Foundation, Inc.
Copyright (C) 2005, 2006, 2007, 2009, 2010 Free Software Foundation, Inc.
This program is free software; you can redistribute it and/or
modify it under the terms of the GNU General Public License as

File diff suppressed because it is too large Load Diff

View File

@ -1,6 +1,6 @@
/* getopt_long and getopt_long_only entry points for GNU getopt.
Copyright (C) 1987,88,89,90,91,92,93,94,96,97,98,2004,2006
Free Software Foundation, Inc.
Copyright (C) 1987, 1988, 1989, 1990, 1991, 1992, 1993, 1994, 1996, 1997,
1998, 2004, 2006, 2009, 2010 Free Software Foundation, Inc.
This file is part of the GNU C Library.
This program is free software: you can redistribute it and/or modify
@ -32,25 +32,25 @@
#include <stdlib.h>
#endif
#ifndef NULL
#ifndef NULL
#define NULL 0
#endif
int
getopt_long (int argc, char *__getopt_argv_const *argv, const char *options,
const struct option *long_options, int *opt_index)
const struct option *long_options, int *opt_index)
{
return _getopt_internal (argc, (char **) argv, options, long_options,
opt_index, 0, 0);
opt_index, 0, 0);
}
int
_getopt_long_r (int argc, char **argv, const char *options,
const struct option *long_options, int *opt_index,
struct _getopt_data *d)
const struct option *long_options, int *opt_index,
struct _getopt_data *d)
{
return _getopt_internal_r (argc, argv, options, long_options, opt_index,
0, 0, d);
0, d, 0);
}
/* Like getopt_long, but '-' as well as '--' can indicate a long option.
@ -60,20 +60,20 @@ _getopt_long_r (int argc, char **argv, const char *options,
int
getopt_long_only (int argc, char *__getopt_argv_const *argv,
const char *options,
const struct option *long_options, int *opt_index)
const char *options,
const struct option *long_options, int *opt_index)
{
return _getopt_internal (argc, (char **) argv, options, long_options,
opt_index, 1, 0);
opt_index, 1, 0);
}
int
_getopt_long_only_r (int argc, char **argv, const char *options,
const struct option *long_options, int *opt_index,
struct _getopt_data *d)
const struct option *long_options, int *opt_index,
struct _getopt_data *d)
{
return _getopt_internal_r (argc, argv, options, long_options, opt_index,
1, 0, d);
1, d, 0);
}
@ -91,76 +91,76 @@ main (int argc, char **argv)
{
int this_option_optind = optind ? optind : 1;
int option_index = 0;
static struct option long_options[] =
static const struct option long_options[] =
{
{"add", 1, 0, 0},
{"append", 0, 0, 0},
{"delete", 1, 0, 0},
{"verbose", 0, 0, 0},
{"create", 0, 0, 0},
{"file", 1, 0, 0},
{0, 0, 0, 0}
{"add", 1, 0, 0},
{"append", 0, 0, 0},
{"delete", 1, 0, 0},
{"verbose", 0, 0, 0},
{"create", 0, 0, 0},
{"file", 1, 0, 0},
{0, 0, 0, 0}
};
c = getopt_long (argc, argv, "abc:d:0123456789",
long_options, &option_index);
long_options, &option_index);
if (c == -1)
break;
break;
switch (c)
{
case 0:
printf ("option %s", long_options[option_index].name);
if (optarg)
printf (" with arg %s", optarg);
printf ("\n");
break;
{
case 0:
printf ("option %s", long_options[option_index].name);
if (optarg)
printf (" with arg %s", optarg);
printf ("\n");
break;
case '0':
case '1':
case '2':
case '3':
case '4':
case '5':
case '6':
case '7':
case '8':
case '9':
if (digit_optind != 0 && digit_optind != this_option_optind)
printf ("digits occur in two different argv-elements.\n");
digit_optind = this_option_optind;
printf ("option %c\n", c);
break;
case '0':
case '1':
case '2':
case '3':
case '4':
case '5':
case '6':
case '7':
case '8':
case '9':
if (digit_optind != 0 && digit_optind != this_option_optind)
printf ("digits occur in two different argv-elements.\n");
digit_optind = this_option_optind;
printf ("option %c\n", c);
break;
case 'a':
printf ("option a\n");
break;
case 'a':
printf ("option a\n");
break;
case 'b':
printf ("option b\n");
break;
case 'b':
printf ("option b\n");
break;
case 'c':
printf ("option c with value `%s'\n", optarg);
break;
case 'c':
printf ("option c with value `%s'\n", optarg);
break;
case 'd':
printf ("option d with value `%s'\n", optarg);
break;
case 'd':
printf ("option d with value `%s'\n", optarg);
break;
case '?':
break;
case '?':
break;
default:
printf ("?? getopt returned character code 0%o ??\n", c);
}
default:
printf ("?? getopt returned character code 0%o ??\n", c);
}
}
if (optind < argc)
{
printf ("non-option ARGV-elements: ");
while (optind < argc)
printf ("%s ", argv[optind++]);
printf ("%s ", argv[optind++]);
printf ("\n");
}

View File

@ -1,6 +1,6 @@
/* Internal declarations for getopt.
Copyright (C) 1989-1994,1996-1999,2001,2003,2004
Free Software Foundation, Inc.
Copyright (C) 1989-1994, 1996-1999, 2001, 2003-2004, 2009-2010 Free Software
Foundation, Inc.
This file is part of the GNU C Library.
This program is free software: you can redistribute it and/or modify
@ -17,12 +17,14 @@
along with this program. If not, see <http://www.gnu.org/licenses/>. */
#ifndef _GETOPT_INT_H
#define _GETOPT_INT_H 1
#define _GETOPT_INT_H 1
#include <getopt.h>
extern int _getopt_internal (int ___argc, char **___argv,
const char *__shortopts,
const struct option *__longopts, int *__longind,
int __long_only, int __posixly_correct);
const char *__shortopts,
const struct option *__longopts, int *__longind,
int __long_only, int __posixly_correct);
/* Reentrant versions which can handle parsing multiple argument
@ -108,23 +110,23 @@ struct _getopt_data
/* The initializer is necessary to set OPTIND and OPTERR to their
default values and to clear the initialization flag. */
#define _GETOPT_DATA_INITIALIZER { 1, 1 }
#define _GETOPT_DATA_INITIALIZER { 1, 1 }
extern int _getopt_internal_r (int ___argc, char **___argv,
const char *__shortopts,
const struct option *__longopts, int *__longind,
int __long_only, int __posixly_correct,
struct _getopt_data *__data);
const char *__shortopts,
const struct option *__longopts, int *__longind,
int __long_only, struct _getopt_data *__data,
int __posixly_correct);
extern int _getopt_long_r (int ___argc, char **___argv,
const char *__shortopts,
const struct option *__longopts, int *__longind,
struct _getopt_data *__data);
const char *__shortopts,
const struct option *__longopts, int *__longind,
struct _getopt_data *__data);
extern int _getopt_long_only_r (int ___argc, char **___argv,
const char *__shortopts,
const struct option *__longopts,
int *__longind,
struct _getopt_data *__data);
const char *__shortopts,
const struct option *__longopts,
int *__longind,
struct _getopt_data *__data);
#endif /* getopt_int.h */

View File

@ -1,5 +1,6 @@
/* Convenience header for conditional use of GNU <libintl.h>.
Copyright (C) 1995-1998, 2000-2002, 2004-2006 Free Software Foundation, Inc.
Copyright (C) 1995-1998, 2000-2002, 2004-2006, 2009-2010 Free Software
Foundation, Inc.
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
@ -63,21 +64,30 @@
for invalid uses of the value returned from these functions.
On pre-ANSI systems without 'const', the config.h file is supposed to
contain "#define const". */
# undef gettext
# define gettext(Msgid) ((const char *) (Msgid))
# undef dgettext
# define dgettext(Domainname, Msgid) ((void) (Domainname), gettext (Msgid))
# undef dcgettext
# define dcgettext(Domainname, Msgid, Category) \
((void) (Category), dgettext (Domainname, Msgid))
# undef ngettext
# define ngettext(Msgid1, Msgid2, N) \
((N) == 1 \
? ((void) (Msgid2), (const char *) (Msgid1)) \
: ((void) (Msgid1), (const char *) (Msgid2)))
# undef dngettext
# define dngettext(Domainname, Msgid1, Msgid2, N) \
((void) (Domainname), ngettext (Msgid1, Msgid2, N))
# undef dcngettext
# define dcngettext(Domainname, Msgid1, Msgid2, N, Category) \
((void) (Category), dngettext(Domainname, Msgid1, Msgid2, N))
((void) (Category), dngettext (Domainname, Msgid1, Msgid2, N))
# undef textdomain
# define textdomain(Domainname) ((const char *) (Domainname))
# undef bindtextdomain
# define bindtextdomain(Domainname, Dirname) \
((void) (Domainname), (const char *) (Dirname))
# undef bind_textdomain_codeset
# define bind_textdomain_codeset(Domainname, Codeset) \
((void) (Domainname), (const char *) (Codeset))
@ -131,8 +141,8 @@ inline
#endif
static const char *
pgettext_aux (const char *domain,
const char *msg_ctxt_id, const char *msgid,
int category)
const char *msg_ctxt_id, const char *msgid,
int category)
{
const char *translation = dcgettext (domain, msg_ctxt_id, category);
if (translation == msg_ctxt_id)
@ -150,9 +160,9 @@ inline
#endif
static const char *
npgettext_aux (const char *domain,
const char *msg_ctxt_id, const char *msgid,
const char *msgid_plural, unsigned long int n,
int category)
const char *msg_ctxt_id, const char *msgid,
const char *msgid_plural, unsigned long int n,
int category)
{
const char *translation =
dcngettext (domain, msg_ctxt_id, msgid_plural, n, category);
@ -190,8 +200,8 @@ inline
#endif
static const char *
dcpgettext_expr (const char *domain,
const char *msgctxt, const char *msgid,
int category)
const char *msgctxt, const char *msgid,
int category)
{
size_t msgctxt_len = strlen (msgctxt) + 1;
size_t msgid_len = strlen (msgid) + 1;
@ -213,10 +223,10 @@ dcpgettext_expr (const char *domain,
translation = dcgettext (domain, msg_ctxt_id, category);
#if !_LIBGETTEXT_HAVE_VARIABLE_SIZE_ARRAYS
if (msg_ctxt_id != buf)
free (msg_ctxt_id);
free (msg_ctxt_id);
#endif
if (translation != msg_ctxt_id)
return translation;
return translation;
}
return msgid;
}
@ -235,9 +245,9 @@ inline
#endif
static const char *
dcnpgettext_expr (const char *domain,
const char *msgctxt, const char *msgid,
const char *msgid_plural, unsigned long int n,
int category)
const char *msgctxt, const char *msgid,
const char *msgid_plural, unsigned long int n,
int category)
{
size_t msgctxt_len = strlen (msgctxt) + 1;
size_t msgid_len = strlen (msgid) + 1;
@ -259,10 +269,10 @@ dcnpgettext_expr (const char *domain,
translation = dcngettext (domain, msg_ctxt_id, msgid_plural, n, category);
#if !_LIBGETTEXT_HAVE_VARIABLE_SIZE_ARRAYS
if (msg_ctxt_id != buf)
free (msg_ctxt_id);
free (msg_ctxt_id);
#endif
if (!(translation == msg_ctxt_id || translation == msgid_plural))
return translation;
return translation;
}
return (n == 1 ? msgid : msgid_plural);
}

View File

@ -1,6 +1,6 @@
/* Program name management.
Copyright (C) 2001-2003, 2005-2009 Free Software Foundation, Inc.
Written by Bruno Haible <haible@clisp.cons.org>, 2001.
Copyright (C) 2001-2003, 2005-2010 Free Software Foundation, Inc.
Written by Bruno Haible <bruno@clisp.org>, 2001.
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
@ -23,6 +23,8 @@
#include "progname.h"
#include <errno.h> /* get program_invocation_name declaration */
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
@ -30,7 +32,9 @@
To be initialized by main(). */
const char *program_name = NULL;
/* Set program_name, based on argv[0]. */
/* Set program_name, based on argv[0].
argv0 must be a string allocated with indefinite extent, and must not be
modified after this call. */
void
set_program_name (const char *argv0)
{
@ -42,20 +46,30 @@ set_program_name (const char *argv0)
const char *slash;
const char *base;
/* Sanity check. POSIX requires the invoking process to pass a non-NULL
argv[0]. */
if (argv0 == NULL)
{
/* It's a bug in the invoking program. Help diagnosing it. */
fputs ("A NULL argv[0] was passed through an exec system call.\n",
stderr);
abort ();
}
slash = strrchr (argv0, '/');
base = (slash != NULL ? slash + 1 : argv0);
if (base - argv0 >= 7 && strncmp (base - 7, "/.libs/", 7) == 0)
{
argv0 = base;
if (strncmp (base, "lt-", 3) == 0)
{
argv0 = base + 3;
/* On glibc systems, remove the "lt-" prefix from the variable
program_invocation_short_name. */
{
argv0 = base + 3;
/* On glibc systems, remove the "lt-" prefix from the variable
program_invocation_short_name. */
#if HAVE_DECL_PROGRAM_INVOCATION_SHORT_NAME
program_invocation_short_name = (char *) argv0;
program_invocation_short_name = (char *) argv0;
#endif
}
}
}
/* But don't strip off a leading <dirname>/ in general, because when the user

View File

@ -1,6 +1,6 @@
/* Program name management.
Copyright (C) 2001-2004, 2006 Free Software Foundation, Inc.
Written by Bruno Haible <haible@clisp.cons.org>, 2001.
Copyright (C) 2001-2004, 2006, 2009-2010 Free Software Foundation, Inc.
Written by Bruno Haible <bruno@clisp.org>, 2001.
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
@ -31,7 +31,9 @@ extern "C" {
/* String containing name the program is called with. */
extern const char *program_name;
/* Set program_name, based on argv[0]. */
/* Set program_name, based on argv[0].
argv0 must be a string allocated with indefinite extent, and must not be
modified after this call. */
extern void set_program_name (const char *argv0);
#if ENABLE_RELOCATABLE
@ -39,8 +41,8 @@ extern void set_program_name (const char *argv0);
/* Set program_name, based on argv[0], and original installation prefix and
directory, for relocatability. */
extern void set_program_name_and_installdir (const char *argv0,
const char *orig_installprefix,
const char *orig_installdir);
const char *orig_installprefix,
const char *orig_installdir);
#undef set_program_name
#define set_program_name(ARG0) \
set_program_name_and_installdir (ARG0, INSTALLPREFIX, INSTALLDIR)