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> 2010-03-27 Grégoire Sutre <gregoire.sutre@gmail.com>
Fix a build failure (-Wundef -Werror) when ENABLE_NLS is not defined, Fix a build failure (-Wundef -Werror) when ENABLE_NLS is not defined,

View file

@ -79,6 +79,7 @@ LIBS = @LIBS@ $(LIBINTL)
CC = @CC@ CC = @CC@
CFLAGS = @CFLAGS@ CFLAGS = @CFLAGS@
GNULIB_CFLAGS = -Wno-undef -D_GL_UNUSED="__attribute__ ((unused))"
ASFLAGS = @ASFLAGS@ ASFLAGS = @ASFLAGS@
LDFLAGS = @LDFLAGS@ $(LIBS) LDFLAGS = @LDFLAGS@ $(LIBS)
CPPFLAGS = @CPPFLAGS@ -I$(builddir) -I$(builddir)/include -I$(srcdir)/gnulib -I$(srcdir)/include -Wall -W \ 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 gnulib/error.c gnulib/progname.c
grub_mkisofs_CFLAGS = -D_FILE_OFFSET_BITS=64 \ grub_mkisofs_CFLAGS = -D_FILE_OFFSET_BITS=64 \
-I$(srcdir)/util/mkisofs/include \ -I$(srcdir)/util/mkisofs/include \
-Wno-all -Werror -Wno-all -Werror $(GNULIB_CFLAGS)
# For grub-fstest. # For grub-fstest.
util/grub-fstest.c_DEPENDENCIES = grub_fstest_init.h 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/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 \ kern/misc.c kern/env.c grub_script_check_init.c grub_script.tab.c \
grub_script.yy.c grub_script.yy.c
grub_script_check_CFLAGS = $(GNULIB_CFLAGS)
MOSTLYCLEANFILES += symlist.c kernel_syms.lst MOSTLYCLEANFILES += symlist.c kernel_syms.lst
DEFSYMFILES += kernel_syms.lst DEFSYMFILES += kernel_syms.lst

View file

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

View file

@ -1,5 +1,5 @@
/* Error handler for noninteractive utilities /* 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 file is part of the GNU C Library.
This program is free software: you can redistribute it and/or modify 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, ...) extern void __error (int status, int errnum, const char *message, ...)
__attribute__ ((__format__ (__printf__, 3, 4))); __attribute__ ((__format__ (__printf__, 3, 4)));
extern void __error_at_line (int status, int errnum, const char *file_name, 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)));; __attribute__ ((__format__ (__printf__, 5, 6)));;
# define error __error # define error __error
# define error_at_line __error_at_line # 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 */ #else /* not _LIBC */
# include <fcntl.h> # include <fcntl.h>
# include <unistd.h>
# if !HAVE_DECL_STRERROR_R && STRERROR_R_CHAR_P # if !HAVE_DECL_STRERROR_R && STRERROR_R_CHAR_P
# ifndef HAVE_DECL_STRERROR_R # ifndef HAVE_DECL_STRERROR_R
@ -100,8 +101,33 @@ extern char *program_name;
# if HAVE_STRERROR_R || defined strerror_r # if HAVE_STRERROR_R || defined strerror_r
# define __strerror_r strerror_r # define __strerror_r strerror_r
# endif /* HAVE_STRERROR_R || defined strerror_r */ # endif /* HAVE_STRERROR_R || defined strerror_r */
#endif /* not _LIBC */ #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 static void
print_errno_message (int errnum) 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; bool use_malloc = false;
while (1) while (1)
{ {
if (__libc_use_alloca (len * sizeof (wchar_t))) if (__libc_use_alloca (len * sizeof (wchar_t)))
wmessage = (wchar_t *) alloca (len * sizeof (wchar_t)); wmessage = (wchar_t *) alloca (len * sizeof (wchar_t));
else else
{ {
if (!use_malloc) if (!use_malloc)
wmessage = NULL; wmessage = NULL;
wchar_t *p = (wchar_t *) realloc (wmessage, wchar_t *p = (wchar_t *) realloc (wmessage,
len * sizeof (wchar_t)); len * sizeof (wchar_t));
if (p == NULL) if (p == NULL)
{ {
free (wmessage); free (wmessage);
fputws_unlocked (L"out of memory\n", stderr); fputws_unlocked (L"out of memory\n", stderr);
return; return;
} }
wmessage = p; wmessage = p;
use_malloc = true; use_malloc = true;
} }
memset (&st, '\0', sizeof (st)); memset (&st, '\0', sizeof (st));
tmp = message; tmp = message;
res = mbsrtowcs (wmessage, &tmp, len, &st); res = mbsrtowcs (wmessage, &tmp, len, &st);
if (res != len) if (res != len)
break; break;
if (__builtin_expect (len >= SIZE_MAX / 2, 0)) if (__builtin_expect (len >= SIZE_MAX / 2, 0))
{ {
/* This really should not happen if everything is fine. */ /* This really should not happen if everything is fine. */
res = (size_t) -1; res = (size_t) -1;
break; break;
} }
len *= 2; len *= 2;
} }
if (res == (size_t) -1) if (res == (size_t) -1)
{ {
/* The string cannot be converted. */ /* The string cannot be converted. */
if (use_malloc) if (use_malloc)
{ {
free (wmessage); free (wmessage);
use_malloc = false; use_malloc = false;
} }
wmessage = (wchar_t *) L"???"; wmessage = (wchar_t *) L"???";
} }
__vfwprintf (stderr, wmessage, args); __vfwprintf (stderr, wmessage, args);
if (use_malloc) if (use_malloc)
free (wmessage); free (wmessage);
} }
else else
#endif #endif
@ -235,16 +261,10 @@ error (int status, int errnum, const char *message, ...)
cancellation. Therefore disable cancellation for now. */ cancellation. Therefore disable cancellation for now. */
int state = PTHREAD_CANCEL_ENABLE; int state = PTHREAD_CANCEL_ENABLE;
__libc_ptf_call (pthread_setcancelstate, (PTHREAD_CANCEL_DISABLE, &state), __libc_ptf_call (pthread_setcancelstate, (PTHREAD_CANCEL_DISABLE, &state),
0); 0);
#endif #endif
#if !_LIBC && defined F_GETFL flush_stdout ();
/* 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);
#ifdef _LIBC #ifdef _LIBC
_IO_flockfile (stderr); _IO_flockfile (stderr);
#endif #endif
@ -276,7 +296,7 @@ int error_one_per_line;
void void
error_at_line (int status, int errnum, const char *file_name, 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; va_list args;
@ -286,10 +306,10 @@ error_at_line (int status, int errnum, const char *file_name,
static unsigned int old_line_number; static unsigned int old_line_number;
if (old_line_number == line_number if (old_line_number == line_number
&& (file_name == old_file_name && (file_name == old_file_name
|| strcmp (old_file_name, file_name) == 0)) || strcmp (old_file_name, file_name) == 0))
/* Simply return and print nothing. */ /* Simply return and print nothing. */
return; return;
old_file_name = file_name; old_file_name = file_name;
old_line_number = line_number; 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. */ cancellation. Therefore disable cancellation for now. */
int state = PTHREAD_CANCEL_ENABLE; int state = PTHREAD_CANCEL_ENABLE;
__libc_ptf_call (pthread_setcancelstate, (PTHREAD_CANCEL_DISABLE, &state), __libc_ptf_call (pthread_setcancelstate, (PTHREAD_CANCEL_DISABLE, &state),
0); 0);
#endif #endif
#if !_LIBC && defined F_GETFL flush_stdout ();
/* 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);
#ifdef _LIBC #ifdef _LIBC
_IO_flockfile (stderr); _IO_flockfile (stderr);
#endif #endif
@ -326,10 +340,10 @@ error_at_line (int status, int errnum, const char *file_name,
#if _LIBC #if _LIBC
__fxprintf (NULL, file_name != NULL ? "%s:%d: " : " ", __fxprintf (NULL, file_name != NULL ? "%s:%d: " : " ",
file_name, line_number); file_name, line_number);
#else #else
fprintf (stderr, file_name != NULL ? "%s:%d: " : " ", fprintf (stderr, file_name != NULL ? "%s:%d: " : " ",
file_name, line_number); file_name, line_number);
#endif #endif
va_start (args, message); va_start (args, message);

View file

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

View file

@ -1,5 +1,5 @@
/* Copyright (C) 1991,1992,1993,1996,1997,1998,1999,2000,2001,2002,2003,2004,2005,2006,2007 /* Copyright (C) 1991, 1992, 1993, 1996, 1997, 1998, 1999, 2000, 2001, 2002,
Free Software Foundation, Inc. 2003, 2004, 2005, 2006, 2007, 2009, 2010 Free Software Foundation, Inc.
This program is free software; you can redistribute it and/or modify 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 it under the terms of the GNU General Public License as published by
@ -21,7 +21,7 @@
/* Enable GNU extensions in fnmatch.h. */ /* Enable GNU extensions in fnmatch.h. */
#ifndef _GNU_SOURCE #ifndef _GNU_SOURCE
# define _GNU_SOURCE 1 # define _GNU_SOURCE 1
#endif #endif
#if ! defined __builtin_expect && __GNUC__ < 3 #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') # define isblank(c) ((c) == ' ' || (c) == '\t')
# endif # endif
# define STREQ(s1, s2) ((strcmp (s1, s2) == 0)) # define STREQ(s1, s2) (strcmp (s1, s2) == 0)
# if defined _LIBC || WIDE_CHAR_SUPPORT # if defined _LIBC || WIDE_CHAR_SUPPORT
/* The GNU C library provides support for user-defined character classes /* 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 # endif
# ifdef _LIBC # ifdef _LIBC
# define ISWCTYPE(WC, WT) __iswctype (WC, WT) # define ISWCTYPE(WC, WT) __iswctype (WC, WT)
# else # else
# define ISWCTYPE(WC, WT) iswctype (WC, WT) # define ISWCTYPE(WC, WT) iswctype (WC, WT)
# endif # endif
# if (HAVE_MBSTATE_T && HAVE_MBSRTOWCS) || _LIBC # if (HAVE_MBSTATE_T && HAVE_MBSRTOWCS) || _LIBC
/* In this case we are implementing the multibyte character handling. */ /* In this case we are implementing the multibyte character handling. */
# define HANDLE_MULTIBYTE 1 # define HANDLE_MULTIBYTE 1
# endif # endif
# else # else
# define CHAR_CLASS_MAX_LENGTH 6 /* Namely, `xdigit'. */ # define CHAR_CLASS_MAX_LENGTH 6 /* Namely, `xdigit'. */
# define IS_CHAR_CLASS(string) \ # define IS_CHAR_CLASS(string) \
(STREQ (string, "alpha") || STREQ (string, "upper") \ (STREQ (string, "alpha") || STREQ (string, "upper") \
|| STREQ (string, "lower") || STREQ (string, "digit") \ || STREQ (string, "lower") || STREQ (string, "digit") \
|| STREQ (string, "alnum") || STREQ (string, "xdigit") \ || STREQ (string, "alnum") || STREQ (string, "xdigit") \
|| STREQ (string, "space") || STREQ (string, "print") \ || STREQ (string, "space") || STREQ (string, "print") \
|| STREQ (string, "punct") || STREQ (string, "graph") \ || STREQ (string, "punct") || STREQ (string, "graph") \
|| STREQ (string, "cntrl") || STREQ (string, "blank")) || STREQ (string, "cntrl") || STREQ (string, "blank"))
# endif # endif
@ -145,17 +145,17 @@ static int posixly_correct;
/* Note that this evaluates C many times. */ /* Note that this evaluates C many times. */
# define FOLD(c) ((flags & FNM_CASEFOLD) ? tolower (c) : (c)) # define FOLD(c) ((flags & FNM_CASEFOLD) ? tolower (c) : (c))
# define CHAR char # define CHAR char
# define UCHAR unsigned char # define UCHAR unsigned char
# define INT int # define INT int
# define FCT internal_fnmatch # define FCT internal_fnmatch
# define EXT ext_match # define EXT ext_match
# define END end_pattern # define END end_pattern
# define L_(CS) CS # define L_(CS) CS
# ifdef _LIBC # ifdef _LIBC
# define BTOWC(C) __btowc (C) # define BTOWC(C) __btowc (C)
# else # else
# define BTOWC(C) btowc (C) # define BTOWC(C) btowc (C)
# endif # endif
# define STRLEN(S) strlen (S) # define STRLEN(S) strlen (S)
# define STRCAT(D, S) strcat (D, S) # define STRCAT(D, S) strcat (D, S)
@ -175,14 +175,14 @@ static int posixly_correct;
# if HANDLE_MULTIBYTE # if HANDLE_MULTIBYTE
# define FOLD(c) ((flags & FNM_CASEFOLD) ? towlower (c) : (c)) # define FOLD(c) ((flags & FNM_CASEFOLD) ? towlower (c) : (c))
# define CHAR wchar_t # define CHAR wchar_t
# define UCHAR wint_t # define UCHAR wint_t
# define INT wint_t # define INT wint_t
# define FCT internal_fnwmatch # define FCT internal_fnwmatch
# define EXT ext_wmatch # define EXT ext_wmatch
# define END end_wpattern # define END end_wpattern
# define L_(CS) L##CS # define L_(CS) L##CS
# define BTOWC(C) (C) # define BTOWC(C) (C)
# ifdef _LIBC # ifdef _LIBC
# define STRLEN(S) __wcslen (S) # define STRLEN(S) __wcslen (S)
# define STRCAT(D, S) __wcscat (D, 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. */ /* Test for a printable character from the portable character set. */
# ifdef _LIBC # ifdef _LIBC
if (*wcs < 0x20 || *wcs > 0x7e if (*wcs < 0x20 || *wcs > 0x7e
|| *wcs == 0x24 || *wcs == 0x40 || *wcs == 0x60) || *wcs == 0x24 || *wcs == 0x40 || *wcs == 0x60)
return (wctype_t) 0; return (wctype_t) 0;
# else # else
switch (*wcs) 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'&': 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'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'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';': 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'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'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'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'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'U': case L'V': case L'W': case L'X': case L'Y':
case L'Z': case L'Z':
case L'[': case L'\\': case L']': case L'^': 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'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'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'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'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'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'z': case L'{': case L'|': case L'}': case L'~':
break; break;
default: default:
return (wctype_t) 0; return (wctype_t) 0;
} }
# endif # endif
/* Avoid overrunning the buffer. */ /* Avoid overrunning the buffer. */
if (cp == s + CHAR_CLASS_MAX_LENGTH) if (cp == s + CHAR_CLASS_MAX_LENGTH)
return (wctype_t) 0; return (wctype_t) 0;
*cp++ = (char) *wcs++; *cp++ = (char) *wcs++;
} }
@ -287,58 +287,58 @@ fnmatch (const char *pattern, const char *string, int flags)
int res; int res;
/* Calculate the size needed to convert the strings to /* Calculate the size needed to convert the strings to
wide characters. */ wide characters. */
memset (&ps, '\0', sizeof (ps)); memset (&ps, '\0', sizeof (ps));
patsize = mbsrtowcs (NULL, &pattern, 0, &ps) + 1; patsize = mbsrtowcs (NULL, &pattern, 0, &ps) + 1;
if (__builtin_expect (patsize != 0, 1)) if (__builtin_expect (patsize != 0, 1))
{ {
assert (mbsinit (&ps)); assert (mbsinit (&ps));
strsize = mbsrtowcs (NULL, &string, 0, &ps) + 1; strsize = mbsrtowcs (NULL, &string, 0, &ps) + 1;
if (__builtin_expect (strsize != 0, 1)) if (__builtin_expect (strsize != 0, 1))
{ {
assert (mbsinit (&ps)); assert (mbsinit (&ps));
totsize = patsize + strsize; totsize = patsize + strsize;
if (__builtin_expect (! (patsize <= totsize if (__builtin_expect (! (patsize <= totsize
&& totsize <= SIZE_MAX / sizeof (wchar_t)), && totsize <= SIZE_MAX / sizeof (wchar_t)),
0)) 0))
{ {
errno = ENOMEM; errno = ENOMEM;
return -1; return -1;
} }
/* Allocate room for the wide characters. */ /* Allocate room for the wide characters. */
if (__builtin_expect (totsize < ALLOCA_LIMIT, 1)) if (__builtin_expect (totsize < ALLOCA_LIMIT, 1))
wpattern = (wchar_t *) alloca (totsize * sizeof (wchar_t)); wpattern = (wchar_t *) alloca (totsize * sizeof (wchar_t));
else else
{ {
wpattern = malloc (totsize * sizeof (wchar_t)); wpattern = malloc (totsize * sizeof (wchar_t));
if (__builtin_expect (! wpattern, 0)) if (__builtin_expect (! wpattern, 0))
{ {
errno = ENOMEM; errno = ENOMEM;
return -1; return -1;
} }
} }
wstring = wpattern + patsize; wstring = wpattern + patsize;
/* Convert the strings into wide characters. */ /* Convert the strings into wide characters. */
mbsrtowcs (wpattern, &pattern, patsize, &ps); mbsrtowcs (wpattern, &pattern, patsize, &ps);
assert (mbsinit (&ps)); assert (mbsinit (&ps));
mbsrtowcs (wstring, &string, strsize, &ps); mbsrtowcs (wstring, &string, strsize, &ps);
res = internal_fnwmatch (wpattern, wstring, wstring + strsize - 1, res = internal_fnwmatch (wpattern, wstring, wstring + strsize - 1,
flags & FNM_PERIOD, flags); flags & FNM_PERIOD, flags);
if (__builtin_expect (! (totsize < ALLOCA_LIMIT), 0)) if (__builtin_expect (! (totsize < ALLOCA_LIMIT), 0))
free (wpattern); free (wpattern);
return res; return res;
} }
} }
} }
# endif /* HANDLE_MULTIBYTE */ # endif /* HANDLE_MULTIBYTE */
return internal_fnmatch (pattern, string, string + strlen (string), return internal_fnmatch (pattern, string, string + strlen (string),
flags & FNM_PERIOD, flags); flags & FNM_PERIOD, flags);
} }
# ifdef _LIBC # ifdef _LIBC
@ -351,4 +351,4 @@ compat_symbol (libc, __fnmatch_old, fnmatch, GLIBC_2_0);
libc_hidden_ver (__fnmatch, fnmatch) libc_hidden_ver (__fnmatch, fnmatch)
# endif # 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. /* getdelim.c --- Implementation of replacement getdelim function.
Copyright (C) 1994, 1996, 1997, 1998, 2001, 2003, 2005, 2006, 2007, Copyright (C) 1994, 1996, 1997, 1998, 2001, 2003, 2005, 2006, 2007, 2008,
2008, 2009 Free Software Foundation, Inc. 2009, 2010 Free Software Foundation, Inc.
This program is free software; you can redistribute it and/or This program is free software; you can redistribute it and/or
modify it under the terms of the GNU General Public License as modify it under the terms of the GNU General Public License as
@ -21,13 +21,16 @@
#include <config.h> #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 <stdio.h>
#include <limits.h> #include <limits.h>
#include <stdint.h> #include <stdint.h>
#include <stdlib.h> #include <stdlib.h>
#include <errno.h> #include <errno.h>
#include <unistd.h>
#ifndef SSIZE_MAX #ifndef SSIZE_MAX
# define SSIZE_MAX ((ssize_t) (SIZE_MAX / 2)) # define SSIZE_MAX ((ssize_t) (SIZE_MAX / 2))
@ -35,15 +38,15 @@
#if USE_UNLOCKED_IO #if USE_UNLOCKED_IO
# include "unlocked-io.h" # 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 #elif !HAVE_FLOCKFILE || !HAVE_FUNLOCKFILE || !HAVE_DECL_GETC_UNLOCKED
# undef flockfile # undef flockfile
# undef funlockfile # undef funlockfile
# define flockfile(x) ((void) 0) # define flockfile(x) ((void) 0)
# define funlockfile(x) ((void) 0) # define funlockfile(x) ((void) 0)
# define getc_maybe_unlocked(fp) getc(fp) # define getc_maybe_unlocked(fp) getc(fp)
#else #else
# define getc_maybe_unlocked(fp) getc_unlocked(fp) # define getc_maybe_unlocked(fp) getc_unlocked(fp)
#endif #endif
/* Read up to (and including) a DELIMITER from FP into *LINEPTR (and /* 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; *n = 120;
new_lineptr = (char *) realloc (*lineptr, *n); new_lineptr = (char *) realloc (*lineptr, *n);
if (new_lineptr == NULL) if (new_lineptr == NULL)
{ {
result = -1; result = -1;
goto unlock_return; goto unlock_return;
} }
*lineptr = new_lineptr; *lineptr = new_lineptr;
} }
@ -85,44 +88,44 @@ getdelim (char **lineptr, size_t *n, int delimiter, FILE *fp)
i = getc_maybe_unlocked (fp); i = getc_maybe_unlocked (fp);
if (i == EOF) if (i == EOF)
{ {
result = -1; result = -1;
break; break;
} }
/* Make enough space for len+1 (for final NUL) bytes. */ /* Make enough space for len+1 (for final NUL) bytes. */
if (cur_len + 1 >= *n) if (cur_len + 1 >= *n)
{ {
size_t needed_max = size_t needed_max =
SSIZE_MAX < SIZE_MAX ? (size_t) SSIZE_MAX + 1 : SIZE_MAX; SSIZE_MAX < SIZE_MAX ? (size_t) SSIZE_MAX + 1 : SIZE_MAX;
size_t needed = 2 * *n + 1; /* Be generous. */ size_t needed = 2 * *n + 1; /* Be generous. */
char *new_lineptr; char *new_lineptr;
if (needed_max < needed) if (needed_max < needed)
needed = needed_max; needed = needed_max;
if (cur_len + 1 >= needed) if (cur_len + 1 >= needed)
{ {
result = -1; result = -1;
errno = EOVERFLOW; errno = EOVERFLOW;
goto unlock_return; goto unlock_return;
} }
new_lineptr = (char *) realloc (*lineptr, needed); new_lineptr = (char *) realloc (*lineptr, needed);
if (new_lineptr == NULL) if (new_lineptr == NULL)
{ {
result = -1; result = -1;
goto unlock_return; goto unlock_return;
} }
*lineptr = new_lineptr; *lineptr = new_lineptr;
*n = needed; *n = needed;
} }
(*lineptr)[cur_len] = i; (*lineptr)[cur_len] = i;
cur_len++; cur_len++;
if (i == delimiter) if (i == delimiter)
break; break;
} }
(*lineptr)[cur_len] = '\0'; (*lineptr)[cur_len] = '\0';
result = cur_len ? cur_len : result; result = cur_len ? cur_len : result;

View file

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

View file

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

View file

@ -1,5 +1,6 @@
/* Convenience header for conditional use of GNU <libintl.h>. /* 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 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 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. for invalid uses of the value returned from these functions.
On pre-ANSI systems without 'const', the config.h file is supposed to On pre-ANSI systems without 'const', the config.h file is supposed to
contain "#define const". */ contain "#define const". */
# undef gettext
# define gettext(Msgid) ((const char *) (Msgid)) # define gettext(Msgid) ((const char *) (Msgid))
# undef dgettext
# define dgettext(Domainname, Msgid) ((void) (Domainname), gettext (Msgid)) # define dgettext(Domainname, Msgid) ((void) (Domainname), gettext (Msgid))
# undef dcgettext
# define dcgettext(Domainname, Msgid, Category) \ # define dcgettext(Domainname, Msgid, Category) \
((void) (Category), dgettext (Domainname, Msgid)) ((void) (Category), dgettext (Domainname, Msgid))
# undef ngettext
# define ngettext(Msgid1, Msgid2, N) \ # define ngettext(Msgid1, Msgid2, N) \
((N) == 1 \ ((N) == 1 \
? ((void) (Msgid2), (const char *) (Msgid1)) \ ? ((void) (Msgid2), (const char *) (Msgid1)) \
: ((void) (Msgid1), (const char *) (Msgid2))) : ((void) (Msgid1), (const char *) (Msgid2)))
# undef dngettext
# define dngettext(Domainname, Msgid1, Msgid2, N) \ # define dngettext(Domainname, Msgid1, Msgid2, N) \
((void) (Domainname), ngettext (Msgid1, Msgid2, N)) ((void) (Domainname), ngettext (Msgid1, Msgid2, N))
# undef dcngettext
# define dcngettext(Domainname, Msgid1, Msgid2, N, Category) \ # 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)) # define textdomain(Domainname) ((const char *) (Domainname))
# undef bindtextdomain
# define bindtextdomain(Domainname, Dirname) \ # define bindtextdomain(Domainname, Dirname) \
((void) (Domainname), (const char *) (Dirname)) ((void) (Domainname), (const char *) (Dirname))
# undef bind_textdomain_codeset
# define bind_textdomain_codeset(Domainname, Codeset) \ # define bind_textdomain_codeset(Domainname, Codeset) \
((void) (Domainname), (const char *) (Codeset)) ((void) (Domainname), (const char *) (Codeset))
@ -131,8 +141,8 @@ inline
#endif #endif
static const char * static const char *
pgettext_aux (const char *domain, pgettext_aux (const char *domain,
const char *msg_ctxt_id, const char *msgid, const char *msg_ctxt_id, const char *msgid,
int category) int category)
{ {
const char *translation = dcgettext (domain, msg_ctxt_id, category); const char *translation = dcgettext (domain, msg_ctxt_id, category);
if (translation == msg_ctxt_id) if (translation == msg_ctxt_id)
@ -150,9 +160,9 @@ inline
#endif #endif
static const char * static const char *
npgettext_aux (const char *domain, npgettext_aux (const char *domain,
const char *msg_ctxt_id, const char *msgid, const char *msg_ctxt_id, const char *msgid,
const char *msgid_plural, unsigned long int n, const char *msgid_plural, unsigned long int n,
int category) int category)
{ {
const char *translation = const char *translation =
dcngettext (domain, msg_ctxt_id, msgid_plural, n, category); dcngettext (domain, msg_ctxt_id, msgid_plural, n, category);
@ -190,8 +200,8 @@ inline
#endif #endif
static const char * static const char *
dcpgettext_expr (const char *domain, dcpgettext_expr (const char *domain,
const char *msgctxt, const char *msgid, const char *msgctxt, const char *msgid,
int category) int category)
{ {
size_t msgctxt_len = strlen (msgctxt) + 1; size_t msgctxt_len = strlen (msgctxt) + 1;
size_t msgid_len = strlen (msgid) + 1; size_t msgid_len = strlen (msgid) + 1;
@ -213,10 +223,10 @@ dcpgettext_expr (const char *domain,
translation = dcgettext (domain, msg_ctxt_id, category); translation = dcgettext (domain, msg_ctxt_id, category);
#if !_LIBGETTEXT_HAVE_VARIABLE_SIZE_ARRAYS #if !_LIBGETTEXT_HAVE_VARIABLE_SIZE_ARRAYS
if (msg_ctxt_id != buf) if (msg_ctxt_id != buf)
free (msg_ctxt_id); free (msg_ctxt_id);
#endif #endif
if (translation != msg_ctxt_id) if (translation != msg_ctxt_id)
return translation; return translation;
} }
return msgid; return msgid;
} }
@ -235,9 +245,9 @@ inline
#endif #endif
static const char * static const char *
dcnpgettext_expr (const char *domain, dcnpgettext_expr (const char *domain,
const char *msgctxt, const char *msgid, const char *msgctxt, const char *msgid,
const char *msgid_plural, unsigned long int n, const char *msgid_plural, unsigned long int n,
int category) int category)
{ {
size_t msgctxt_len = strlen (msgctxt) + 1; size_t msgctxt_len = strlen (msgctxt) + 1;
size_t msgid_len = strlen (msgid) + 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); translation = dcngettext (domain, msg_ctxt_id, msgid_plural, n, category);
#if !_LIBGETTEXT_HAVE_VARIABLE_SIZE_ARRAYS #if !_LIBGETTEXT_HAVE_VARIABLE_SIZE_ARRAYS
if (msg_ctxt_id != buf) if (msg_ctxt_id != buf)
free (msg_ctxt_id); free (msg_ctxt_id);
#endif #endif
if (!(translation == msg_ctxt_id || translation == msgid_plural)) if (!(translation == msg_ctxt_id || translation == msgid_plural))
return translation; return translation;
} }
return (n == 1 ? msgid : msgid_plural); return (n == 1 ? msgid : msgid_plural);
} }

View file

@ -1,6 +1,6 @@
/* Program name management. /* Program name management.
Copyright (C) 2001-2003, 2005-2009 Free Software Foundation, Inc. Copyright (C) 2001-2003, 2005-2010 Free Software Foundation, Inc.
Written by Bruno Haible <haible@clisp.cons.org>, 2001. Written by Bruno Haible <bruno@clisp.org>, 2001.
This program is free software: you can redistribute it and/or modify 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 it under the terms of the GNU General Public License as published by
@ -23,6 +23,8 @@
#include "progname.h" #include "progname.h"
#include <errno.h> /* get program_invocation_name declaration */ #include <errno.h> /* get program_invocation_name declaration */
#include <stdio.h>
#include <stdlib.h>
#include <string.h> #include <string.h>
@ -30,7 +32,9 @@
To be initialized by main(). */ To be initialized by main(). */
const char *program_name = NULL; 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 void
set_program_name (const char *argv0) set_program_name (const char *argv0)
{ {
@ -42,20 +46,30 @@ set_program_name (const char *argv0)
const char *slash; const char *slash;
const char *base; 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, '/'); slash = strrchr (argv0, '/');
base = (slash != NULL ? slash + 1 : argv0); base = (slash != NULL ? slash + 1 : argv0);
if (base - argv0 >= 7 && strncmp (base - 7, "/.libs/", 7) == 0) if (base - argv0 >= 7 && strncmp (base - 7, "/.libs/", 7) == 0)
{ {
argv0 = base; argv0 = base;
if (strncmp (base, "lt-", 3) == 0) if (strncmp (base, "lt-", 3) == 0)
{ {
argv0 = base + 3; argv0 = base + 3;
/* On glibc systems, remove the "lt-" prefix from the variable /* On glibc systems, remove the "lt-" prefix from the variable
program_invocation_short_name. */ program_invocation_short_name. */
#if HAVE_DECL_PROGRAM_INVOCATION_SHORT_NAME #if HAVE_DECL_PROGRAM_INVOCATION_SHORT_NAME
program_invocation_short_name = (char *) argv0; program_invocation_short_name = (char *) argv0;
#endif #endif
} }
} }
/* But don't strip off a leading <dirname>/ in general, because when the user /* But don't strip off a leading <dirname>/ in general, because when the user

View file

@ -1,6 +1,6 @@
/* Program name management. /* Program name management.
Copyright (C) 2001-2004, 2006 Free Software Foundation, Inc. Copyright (C) 2001-2004, 2006, 2009-2010 Free Software Foundation, Inc.
Written by Bruno Haible <haible@clisp.cons.org>, 2001. Written by Bruno Haible <bruno@clisp.org>, 2001.
This program is free software: you can redistribute it and/or modify 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 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. */ /* String containing name the program is called with. */
extern const char *program_name; 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); extern void set_program_name (const char *argv0);
#if ENABLE_RELOCATABLE #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 /* Set program_name, based on argv[0], and original installation prefix and
directory, for relocatability. */ directory, for relocatability. */
extern void set_program_name_and_installdir (const char *argv0, extern void set_program_name_and_installdir (const char *argv0,
const char *orig_installprefix, const char *orig_installprefix,
const char *orig_installdir); const char *orig_installdir);
#undef set_program_name #undef set_program_name
#define set_program_name(ARG0) \ #define set_program_name(ARG0) \
set_program_name_and_installdir (ARG0, INSTALLPREFIX, INSTALLDIR) set_program_name_and_installdir (ARG0, INSTALLPREFIX, INSTALLDIR)