* grub-core/gnulib/error.c: Resynced.

* grub-core/gnulib/getopt.c: Likewise.
	* grub-core/gnulib/getopt_int.h: Likewise.
	* grub-core/gnulib/regex.h: Likewise.
	* grub-core/gnulib/regex_internal.c: Likewise.
	* grub-core/gnulib/regex_internal.h: Likewise.
This commit is contained in:
Vladimir 'phcoder' Serbinenko 2010-09-15 11:31:02 +02:00
parent 014f47b74f
commit 5dcdf93ad6
7 changed files with 113 additions and 62 deletions

View file

@ -1,3 +1,12 @@
2010-09-15 Vladimir Serbinenko <phcoder@gmail.com>
* grub-core/gnulib/error.c: Resynced.
* grub-core/gnulib/getopt.c: Likewise.
* grub-core/gnulib/getopt_int.h: Likewise.
* grub-core/gnulib/regex.h: Likewise.
* grub-core/gnulib/regex_internal.c: Likewise.
* grub-core/gnulib/regex_internal.h: Likewise.
2010-09-15 Szymon Janc <szymon@janc.net.pl>
* grub-core/lib/xzembed/xz_dec_stream.c (dec_main): Fix index and block

View file

@ -88,6 +88,15 @@ extern void __error_at_line (int status, int errnum, const char *file_name,
# include <fcntl.h>
# include <unistd.h>
# if (defined _WIN32 || defined __WIN32__) && ! defined __CYGWIN__
/* Get declarations of the Win32 API functions. */
# define WIN32_LEAN_AND_MEAN
# include <windows.h>
# endif
/* The gnulib override of fcntl is not needed in this file. */
# undef fcntl
# if !HAVE_DECL_STRERROR_R && STRERROR_R_CHAR_P
# ifndef HAVE_DECL_STRERROR_R
"this configure-time declaration test was not run"
@ -104,10 +113,29 @@ extern char *program_name;
# endif /* HAVE_STRERROR_R || defined strerror_r */
#endif /* not _LIBC */
#if !_LIBC
/* Return non-zero if FD is open. */
static inline int
is_open (int fd)
{
# if (defined _WIN32 || defined __WIN32__) && ! defined __CYGWIN__
/* On Win32: The initial state of unassigned standard file descriptors is
that they are open but point to an INVALID_HANDLE_VALUE. There is no
fcntl, and the gnulib replacement fcntl does not support F_GETFL. */
return (HANDLE) _get_osfhandle (fd) != INVALID_HANDLE_VALUE;
# else
# ifndef F_GETFL
# error Please port fcntl to your platform
# endif
return 0 <= fcntl (fd, F_GETFL);
# endif
}
#endif
static inline void
flush_stdout (void)
{
#if !_LIBC && defined F_GETFL
#if !_LIBC
int stdout_fd;
# if GNULIB_FREOPEN_SAFER
@ -124,7 +152,7 @@ flush_stdout (void)
/* 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))
if (0 <= stdout_fd && is_open (stdout_fd))
#endif
fflush (stdout);
}

View file

@ -348,8 +348,6 @@ _getopt_internal_r (int argc, char **argv, const char *optstring,
int long_only, struct _getopt_data *d, int posixly_correct)
{
int print_errors = d->opterr;
if (optstring[0] == ':')
print_errors = 0;
if (argc < 1)
return -1;
@ -364,6 +362,10 @@ _getopt_internal_r (int argc, char **argv, const char *optstring,
posixly_correct);
d->__initialized = 1;
}
else if (optstring[0] == '-' || optstring[0] == '+')
optstring++;
if (optstring[0] == ':')
print_errors = 0;
/* Test whether ARGV[optind] points to a non-option argument.
Either it does not have option syntax, or there is an environment flag
@ -633,8 +635,8 @@ _getopt_internal_r (int argc, char **argv, const char *optstring,
char *buf;
if (__asprintf (&buf, _("\
%s: option '%s' requires an argument\n"),
argv[0], argv[d->optind - 1]) >= 0)
%s: option '--%s' requires an argument\n"),
argv[0], pfound->name) >= 0)
{
_IO_flockfile (stderr);
@ -651,8 +653,8 @@ _getopt_internal_r (int argc, char **argv, const char *optstring,
}
#else
fprintf (stderr,
_("%s: option '%s' requires an argument\n"),
argv[0], argv[d->optind - 1]);
_("%s: option '--%s' requires an argument\n"),
argv[0], pfound->name);
#endif
}
d->__nextchar += strlen (d->__nextchar);
@ -736,13 +738,13 @@ _getopt_internal_r (int argc, char **argv, const char *optstring,
{
char c = *d->__nextchar++;
char *temp = strchr (optstring, c);
const char *temp = strchr (optstring, c);
/* Increment `optind' when we start to process its last character. */
if (*d->__nextchar == '\0')
++d->optind;
if (temp == NULL || c == ':')
if (temp == NULL || c == ':' || c == ';')
{
if (print_errors)
{
@ -864,7 +866,10 @@ _getopt_internal_r (int argc, char **argv, const char *optstring,
pfound = p;
indfound = option_index;
}
else
else if (long_only
|| pfound->has_arg != p->has_arg
|| pfound->flag != p->flag
|| pfound->val != p->val)
/* Second or later nonexact match found. */
ambig = 1;
}
@ -876,7 +881,7 @@ _getopt_internal_r (int argc, char **argv, const char *optstring,
char *buf;
if (__asprintf (&buf, _("%s: option '-W %s' is ambiguous\n"),
argv[0], argv[d->optind]) >= 0)
argv[0], d->optarg) >= 0)
{
_IO_flockfile (stderr);
@ -892,7 +897,7 @@ _getopt_internal_r (int argc, char **argv, const char *optstring,
}
#else
fprintf (stderr, _("%s: option '-W %s' is ambiguous\n"),
argv[0], argv[d->optind]);
argv[0], d->optarg);
#endif
}
d->__nextchar += strlen (d->__nextchar);
@ -955,8 +960,8 @@ _getopt_internal_r (int argc, char **argv, const char *optstring,
char *buf;
if (__asprintf (&buf, _("\
%s: option '%s' requires an argument\n"),
argv[0], argv[d->optind - 1]) >= 0)
%s: option '-W %s' requires an argument\n"),
argv[0], pfound->name) >= 0)
{
_IO_flockfile (stderr);
@ -972,15 +977,17 @@ _getopt_internal_r (int argc, char **argv, const char *optstring,
free (buf);
}
#else
fprintf (stderr,
_("%s: option '%s' requires an argument\n"),
argv[0], argv[d->optind - 1]);
fprintf (stderr, _("\
%s: option '-W %s' requires an argument\n"),
argv[0], pfound->name);
#endif
}
d->__nextchar += strlen (d->__nextchar);
return optstring[0] == ':' ? ':' : '?';
}
}
else
d->optarg = NULL;
d->__nextchar += strlen (d->__nextchar);
if (longind != NULL)
*longind = option_index;

View file

@ -30,6 +30,40 @@ extern int _getopt_internal (int ___argc, char **___argv,
/* Reentrant versions which can handle parsing multiple argument
vectors at the same time. */
/* Describe how to deal with options that follow non-option ARGV-elements.
If the caller did not specify anything,
the default is REQUIRE_ORDER if the environment variable
POSIXLY_CORRECT is defined, PERMUTE otherwise.
REQUIRE_ORDER means don't recognize them as options;
stop option processing when the first non-option is seen.
This is what Unix does.
This mode of operation is selected by either setting the environment
variable POSIXLY_CORRECT, or using `+' as the first character
of the list of option characters, or by calling getopt.
PERMUTE is the default. We permute the contents of ARGV as we
scan, so that eventually all the non-options are at the end.
This allows options to be given in any order, even with programs
that were not written to expect this.
RETURN_IN_ORDER is an option available to programs that were
written to expect options and other ARGV-elements in any order
and that care about the ordering of the two. We describe each
non-option ARGV-element as if it were the argument of an option
with character code 1. Using `-' as the first character of the
list of option characters selects this mode of operation.
The special argument `--' forces an end of option-scanning regardless
of the value of `ordering'. In the case of RETURN_IN_ORDER, only
`--' can cause `getopt' to return -1 with `optind' != ARGC. */
enum __ord
{
REQUIRE_ORDER, PERMUTE, RETURN_IN_ORDER
};
/* Data type for reentrant functions. */
struct _getopt_data
{
@ -54,39 +88,8 @@ struct _getopt_data
by advancing to the next ARGV-element. */
char *__nextchar;
/* Describe how to deal with options that follow non-option ARGV-elements.
If the caller did not specify anything,
the default is REQUIRE_ORDER if the environment variable
POSIXLY_CORRECT is defined, PERMUTE otherwise.
REQUIRE_ORDER means don't recognize them as options;
stop option processing when the first non-option is seen.
This is what Unix does.
This mode of operation is selected by either setting the environment
variable POSIXLY_CORRECT, or using `+' as the first character
of the list of option characters, or by calling getopt.
PERMUTE is the default. We permute the contents of ARGV as we
scan, so that eventually all the non-options are at the end.
This allows options to be given in any order, even with programs
that were not written to expect this.
RETURN_IN_ORDER is an option available to programs that were
written to expect options and other ARGV-elements in any order
and that care about the ordering of the two. We describe each
non-option ARGV-element as if it were the argument of an option
with character code 1. Using `-' as the first character of the
list of option characters selects this mode of operation.
The special argument `--' forces an end of option-scanning regardless
of the value of `ordering'. In the case of RETURN_IN_ORDER, only
`--' can cause `getopt' to return -1 with `optind' != ARGC. */
enum
{
REQUIRE_ORDER, PERMUTE, RETURN_IN_ORDER
} __ordering;
/* See __ord above. */
enum __ord __ordering;
/* If the POSIXLY_CORRECT environment variable is set
or getopt was called. */

View file

@ -114,10 +114,10 @@ typedef unsigned long int reg_syntax_t;
/* If this bit is set, then ^ and $ are always anchors (outside bracket
expressions, of course).
If this bit is not set, then it depends:
^ is an anchor if it is at the beginning of a regular
expression or after an open-group or an alternation operator;
$ is an anchor if it is at the end of a regular expression, or
before a close-group or an alternation operator.
^ is an anchor if it is at the beginning of a regular
expression or after an open-group or an alternation operator;
$ is an anchor if it is at the end of a regular expression, or
before a close-group or an alternation operator.
This bit could be (re)combined with RE_CONTEXT_INDEP_OPS, because
POSIX draft 11.2 says that * etc. in leading positions is undefined.
@ -219,8 +219,8 @@ typedef unsigned long int reg_syntax_t;
whether ^ should be special. */
# define RE_CARET_ANCHORS_HERE (RE_ICASE << 1)
/* If this bit is set, then \{ cannot be first in an bre or
immediately after an alternation or begin-group operator. */
/* If this bit is set, then \{ cannot be first in a regex or
immediately after an alternation, open-group or \} operator. */
# define RE_CONTEXT_INVALID_DUP (RE_CARET_ANCHORS_HERE << 1)
/* If this bit is set, then no_sub will be set to 1 during
@ -495,8 +495,8 @@ struct re_pattern_buffer
#endif
unsigned int _REG_RE_NAME (regs_allocated) : 2;
/* Set to zero when `regex_compile' compiles a pattern; set to one
by `re_compile_fastmap' if it updates the fastmap. */
/* Set to zero when `re_compile_pattern' compiles a pattern; set to
one by `re_compile_fastmap' if it updates the fastmap. */
unsigned int _REG_RE_NAME (fastmap_accurate) : 1;
/* If set, `re_match_2' does not return information about
@ -610,8 +610,8 @@ extern regoff_t re_match_2 (struct re_pattern_buffer *__buffer,
register data.
Unless this function is called, the first search or match using
PATTERN_BUFFER will allocate its own register data, without
freeing the old data. */
BUFFER will allocate its own register data, without freeing the old
data. */
extern void re_set_registers (struct re_pattern_buffer *__buffer,
struct re_registers *__regs,
__re_size_t __num_regs,

View file

@ -733,15 +733,17 @@ re_string_reconstruct (re_string_t *pstr, Idx idx, int eflags)
mbstate_t cur_state;
wchar_t wc2;
Idx mlen = raw + pstr->len - p;
unsigned char buf[6];
size_t mbclen;
#if 0 /* dead code: buf is set but never used */
unsigned char buf[6];
if (BE (pstr->trans != NULL, 0))
{
int i = mlen < 6 ? mlen : 6;
while (--i >= 0)
buf[i] = pstr->trans[p[i]];
}
#endif
/* XXX Don't use mbrtowc, we know which conversion
to use (UTF-8 -> UCS4). */
memset (&cur_state, 0, sizeof (cur_state));

View file

@ -467,6 +467,8 @@ static unsigned int re_string_context_at (const re_string_t *input, Idx idx,
# else
/* alloca is implemented with malloc, so just use malloc. */
# define __libc_use_alloca(n) 0
# undef alloca
# define alloca(n) malloc (n)
# endif
#endif