summaryrefslogtreecommitdiff
path: root/posix
diff options
context:
space:
mode:
authorAndreas Schwab <schwab@redhat.com>2010-04-06 11:15:58 +0200
committerAndreas Schwab <schwab@redhat.com>2010-04-06 11:15:58 +0200
commit32e5e786daa69be1f153f01cd428ac18634bb7bc (patch)
treeea6947f2380e156ea6ba91f5fa17a67a46304947 /posix
parentb44389edf1a88c6607a6c365bd8d884aee2edead (diff)
parent2e7c805d5ec1f0d2f46354bca65b1feffa7af63b (diff)
Merge remote branch 'origin/master' into fedora/master
Diffstat (limited to 'posix')
-rw-r--r--posix/Makefile4
-rw-r--r--posix/bug-glob3.c45
-rw-r--r--posix/gai.conf9
-rw-r--r--posix/getconf.c4
-rw-r--r--posix/getopt.c25
-rw-r--r--posix/glob.c56
-rw-r--r--posix/tst-gnuglob.c75
7 files changed, 156 insertions, 62 deletions
diff --git a/posix/Makefile b/posix/Makefile
index 535ed1474d..0249977fd6 100644
--- a/posix/Makefile
+++ b/posix/Makefile
@@ -1,4 +1,4 @@
-# Copyright (C) 1991-1999, 2000-2006, 2007, 2009 Free Software Foundation, Inc.
+# Copyright (C) 1991-1999, 2000-2007, 2009, 2010 Free Software Foundation, Inc.
# This file is part of the GNU C Library.
# The GNU C Library is free software; you can redistribute it and/or
@@ -86,7 +86,7 @@ tests := tstgetopt testfnm runtests runptests \
tst-nice tst-nanosleep tst-regex2 \
transbug tst-rxspencer tst-pcre tst-boost \
bug-ga1 tst-vfork1 tst-vfork2 tst-vfork3 tst-waitid \
- tst-getaddrinfo2 bug-glob1 bug-glob2 tst-sysconf \
+ tst-getaddrinfo2 bug-glob1 bug-glob2 bug-glob3 tst-sysconf \
tst-execvp1 tst-execvp2 tst-execlp1 tst-execlp2 \
tst-execv1 tst-execv2 tst-execl1 tst-execl2 \
tst-execve1 tst-execve2 tst-execle1 tst-execle2 \
diff --git a/posix/bug-glob3.c b/posix/bug-glob3.c
new file mode 100644
index 0000000000..f2fbd703dd
--- /dev/null
+++ b/posix/bug-glob3.c
@@ -0,0 +1,45 @@
+#include <glob.h>
+#include <stdio.h>
+#include <string.h>
+
+static int
+do_test (void)
+{
+ int result = 0;
+ glob_t g;
+ g.gl_pathc = 0;
+
+ int r = glob ("", 0, NULL, &g);
+ if (r != GLOB_NOMATCH)
+ {
+ puts ("glob (\"\", 0, NULL, &g) did not fail");
+ result = 1;
+ }
+ else if (g.gl_pathc != 0)
+ {
+ puts ("gl_pathc after glob (\"\", 0, NULL, &g) not zero");
+ result = 1;
+ }
+
+ r = glob ("", GLOB_NOCHECK, NULL, &g);
+ if (r != 0)
+ {
+ puts ("glob (\"\", GLOB_NOCHECK, NULL, &g) did fail");
+ result = 1;
+ }
+ else if (g.gl_pathc != 1)
+ {
+ puts ("gl_pathc after glob (\"\", GLOB_NOCHECK, NULL, &g) not 1");
+ result = 1;
+ }
+ else if (strcmp (g.gl_pathv[0], "") != 0)
+ {
+ puts ("gl_pathv[0] after glob (\"\", GLOB_NOCHECK, NULL, &g) not \"\"");
+ result = 1;
+ }
+
+ return result;
+}
+
+#define TEST_FUNCTION do_test ()
+#include "../test-skeleton.c"
diff --git a/posix/gai.conf b/posix/gai.conf
index 3dba1a905d..195287e1c8 100644
--- a/posix/gai.conf
+++ b/posix/gai.conf
@@ -66,3 +66,12 @@
#scopev4 ::ffff:172.16.0.0/108 5
#scopev4 ::ffff:192.168.0.0/112 5
#scopev4 ::ffff:0.0.0.0/96 14
+#
+# For sites which use site-local IPv4 addresses behind NAT there is
+# the problem that even if IPv4 addresses are preferred they do not
+# have the same scope and are therefore not sorted first. To change
+# this use only these rules:
+#
+#scopev4 ::ffff:169.254.0.0/112 2
+#scopev4 ::ffff:127.0.0.0/104 2
+#scopev4 ::ffff:0.0.0.0/96 14
diff --git a/posix/getconf.c b/posix/getconf.c
index d9d90e44f7..25f4307bea 100644
--- a/posix/getconf.c
+++ b/posix/getconf.c
@@ -1,4 +1,4 @@
-/* Copyright (C) 1991, 92, 1995-2008, 2009 Free Software Foundation, Inc.
+/* Copyright (C) 1991, 92, 1995-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
@@ -1105,7 +1105,7 @@ main (int argc, char *argv[])
Copyright (C) %s Free Software Foundation, Inc.\n\
This is free software; see the source for copying conditions. There is NO\n\
warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.\n\
-"), "2009");
+"), "2010");
printf (gettext ("Written by %s.\n"), "Roland McGrath");
return 0;
}
diff --git a/posix/getopt.c b/posix/getopt.c
index a7f0b54857..88acff0e2f 100644
--- a/posix/getopt.c
+++ b/posix/getopt.c
@@ -2,7 +2,8 @@
NOTE: getopt is part of the C library, so if you don't know what
"Keep this file name-space clean" means, talk to drepper@gnu.org
before changing it!
- Copyright (C) 1987-1996,1998-2004,2008,2009 Free Software Foundation, Inc.
+ Copyright (C) 1987-1996,1998-2004,2008,2009,2010
+ Free Software Foundation, Inc.
This file is part of the GNU C Library.
The GNU C Library is free software; you can redistribute it and/or
@@ -679,8 +680,8 @@ _getopt_internal_r (int argc, char *const *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);
@@ -697,8 +698,8 @@ _getopt_internal_r (int argc, char *const *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);
@@ -922,7 +923,7 @@ _getopt_internal_r (int argc, char *const *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);
@@ -938,7 +939,7 @@ _getopt_internal_r (int argc, char *const *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);
@@ -1001,8 +1002,8 @@ _getopt_internal_r (int argc, char *const *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);
@@ -1018,9 +1019,9 @@ _getopt_internal_r (int argc, char *const *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);
diff --git a/posix/glob.c b/posix/glob.c
index 73081ece66..6df083a67a 100644
--- a/posix/glob.c
+++ b/posix/glob.c
@@ -1,4 +1,4 @@
-/* Copyright (C) 1991-2002, 2003, 2004, 2005, 2006, 2007, 2008
+/* Copyright (C) 1991-2002, 2003, 2004, 2005, 2006, 2007, 2008, 2010
Free Software Foundation, Inc.
This file is part of the GNU C Library.
@@ -418,6 +418,26 @@ glob (pattern, flags, errfunc, pglob)
}
}
+ if (!(flags & GLOB_APPEND))
+ {
+ pglob->gl_pathc = 0;
+ if (!(flags & GLOB_DOOFFS))
+ pglob->gl_pathv = NULL;
+ else
+ {
+ size_t i;
+ pglob->gl_pathv = (char **) malloc ((pglob->gl_offs + 1)
+ * sizeof (char *));
+ if (pglob->gl_pathv == NULL)
+ return GLOB_NOSPACE;
+
+ for (i = 0; i <= pglob->gl_offs; ++i)
+ pglob->gl_pathv[i] = NULL;
+ }
+ }
+
+ oldcount = pglob->gl_pathc + pglob->gl_offs;
+
/* Find the filename. */
filename = strrchr (pattern, '/');
#if defined __MSDOS__ || defined WINDOWS32
@@ -445,6 +465,12 @@ glob (pattern, flags, errfunc, pglob)
}
else
{
+ if (__builtin_expect (pattern[0] == '\0', 0))
+ {
+ dirs.gl_pathv = NULL;
+ goto no_matches;
+ }
+
filename = pattern;
#ifdef _AMIGA
dirname = "";
@@ -492,7 +518,7 @@ glob (pattern, flags, errfunc, pglob)
if (filename[0] == '\0'
#if defined __MSDOS__ || defined WINDOWS32
- && dirname[dirlen - 1] != ':'
+ && dirname[dirlen - 1] != ':'
&& (dirlen < 3 || dirname[dirlen - 2] != ':'
|| dirname[dirlen - 1] != '/')
#endif
@@ -529,26 +555,6 @@ glob (pattern, flags, errfunc, pglob)
}
}
- if (!(flags & GLOB_APPEND))
- {
- pglob->gl_pathc = 0;
- if (!(flags & GLOB_DOOFFS))
- pglob->gl_pathv = NULL;
- else
- {
- size_t i;
- pglob->gl_pathv = (char **) malloc ((pglob->gl_offs + 1)
- * sizeof (char *));
- if (pglob->gl_pathv == NULL)
- return GLOB_NOSPACE;
-
- for (i = 0; i <= pglob->gl_offs; ++i)
- pglob->gl_pathv[i] = NULL;
- }
- }
-
- oldcount = pglob->gl_pathc + pglob->gl_offs;
-
#ifndef VMS
if ((flags & (GLOB_TILDE|GLOB_TILDE_CHECK)) && dirname[0] == '~')
{
@@ -564,7 +570,7 @@ glob (pattern, flags, errfunc, pglob)
# else
# ifdef WINDOWS32
if (home_dir == NULL || home_dir[0] == '\0')
- home_dir = "c:/users/default"; /* poor default */
+ home_dir = "c:/users/default"; /* poor default */
# else
if (home_dir == NULL || home_dir[0] == '\0')
{
@@ -1036,9 +1042,9 @@ glob (pattern, flags, errfunc, pglob)
: (__stat64 (pglob->gl_pathv[i], &st64) == 0
&& S_ISDIR (st64.st_mode))))
{
- size_t len = strlen (pglob->gl_pathv[i]) + 2;
+ size_t len = strlen (pglob->gl_pathv[i]) + 2;
char *new = realloc (pglob->gl_pathv[i], len);
- if (new == NULL)
+ if (new == NULL)
{
globfree (pglob);
pglob->gl_pathc = 0;
diff --git a/posix/tst-gnuglob.c b/posix/tst-gnuglob.c
index 95bfbae641..d4539bddbc 100644
--- a/posix/tst-gnuglob.c
+++ b/posix/tst-gnuglob.c
@@ -1,6 +1,6 @@
/* Test the GNU extensions in glob which allow the user to provide callbacks
for the filesystem access functions.
- Copyright (C) 2001-2002, 2007 Free Software Foundation, Inc.
+ Copyright (C) 2001-2002, 2007, 2010 Free Software Foundation, Inc.
This file is part of the GNU C Library.
Contributed by Ulrich Drepper <drepper@redhat.com>, 2001.
@@ -61,9 +61,9 @@ static struct
{ "..", 3, DT_DIR },
{ ".foo", 3, DT_REG },
{ "dir1lev3", 3, DT_DIR },
- { ".", 4, DT_DIR },
- { "..", 4, DT_DIR },
- { "file1lev4", 4, DT_REG },
+ { ".", 4, DT_DIR },
+ { "..", 4, DT_DIR },
+ { "file1lev4", 4, DT_REG },
{ "file1lev3", 3, DT_REG },
{ "file2lev3", 3, DT_REG },
{ "file2lev2", 2, DT_REG },
@@ -81,9 +81,9 @@ static struct
{ "..", 3, DT_DIR },
{ ".foo", 3, DT_REG },
{ ".dir", 3, DT_DIR },
- { ".", 4, DT_DIR },
- { "..", 4, DT_DIR },
- { "hidden", 4, DT_REG }
+ { ".", 4, DT_DIR },
+ { "..", 4, DT_DIR },
+ { "hidden", 4, DT_REG }
};
#define nfiles (sizeof (filesystem) / sizeof (filesystem[0]))
@@ -283,7 +283,7 @@ static const char *glob_errstring[] =
static const char *
flagstr (int flags)
{
- const char *strs[] =
+ static const char *const strs[] =
{
"GLOB_ERR", "GLOB_MARK", "GLOB_NOSORT", "GLOB_DOOFSS", "GLOB_NOCHECK",
"GLOB_APPEND", "GLOB_NOESCAPE", "GLOB_PERIOD", "GLOB_MAGCHAR",
@@ -312,6 +312,29 @@ flagstr (int flags)
}
return buf;
+#undef nstrs
+}
+
+
+static const char *
+errstr (int val)
+{
+ static const char *const strs[] =
+ {
+ [GLOB_NOSPACE] = "GLOB_NOSPACE",
+ [GLOB_ABORTED] = "GLOB_ABORTED",
+ [GLOB_NOMATCH] = "GLOB_NOMATCH",
+ [GLOB_NOSYS] = "GLOB_NOSYS"
+ };
+#define nstrs (sizeof (strs) / sizeof (strs[0]))
+ static char buf[100];
+ if (val < 0 || val >= nstrs || strs[val] == NULL)
+ {
+ snprintf (buf, sizeof (buf), "GLOB_??? (%d)", val);
+ return buf;
+ }
+ return strs[val];
+#undef nstrs
}
@@ -376,28 +399,34 @@ main (void)
gl.gl_lstat = my_stat;
gl.gl_stat = my_stat;
-#define test(a, b, c...) \
+#define test(a, b, r, c...) \
fmt = a; \
- flags = b; \
+ flags = GLOB_ALTDIRFUNC | b; \
errval = glob (fmt, flags, NULL, &gl); \
- if (errval != 0) \
+ if (errval != r) \
{ \
- printf ("glob (\"%s\", %s) failed: %s\n", fmt, flagstr (flags), \
- errval >= 0 && errval < nglob_errstring \
- ? glob_errstring[errval] : "???"); \
+ if (r == 0) \
+ printf ("glob (\"%s\", %s) failed: %s\n", fmt, flagstr (flags), \
+ errval >= 0 && errval < nglob_errstring \
+ ? glob_errstring[errval] : "???"); \
+ else \
+ printf ("glob (\"%s\", %s) did not fail\n", fmt, flagstr (flags)); \
result = 1; \
} \
+ else if (r == 0) \
+ result |= test_result (fmt, flags, &gl, (const char *[]) { c, NULL }); \
else \
- result |= test_result (fmt, flags, &gl, (const char *[]) { c, NULL })
+ printf ("result for glob (\"%s\", %s) = %s\n\n", fmt, flagstr (flags), \
+ errstr (errval))
- test ("*/*/*", GLOB_ALTDIRFUNC,
+ test ("*/*/*", 0, 0,
"dir1lev1/dir2lev2/dir1lev3",
"dir1lev1/dir2lev2/file1lev3",
"dir1lev1/dir2lev2/file2lev3",
"dir1lev1/dir3lev2/file3lev3",
"dir1lev1/dir3lev2/file4lev3");
- test ("*/*/*", GLOB_ALTDIRFUNC | GLOB_PERIOD,
+ test ("*/*/*", GLOB_PERIOD, 0,
"dir1lev1/dir1lev2/.",
"dir1lev1/dir1lev2/..",
"dir1lev1/dir2lev2/.",
@@ -415,7 +444,7 @@ main (void)
"dir2lev1/dir1lev2/.dir",
"dir2lev1/dir1lev2/.foo");
- test ("*/*/.*", GLOB_ALTDIRFUNC,
+ test ("*/*/.*", 0, 0,
"dir1lev1/dir1lev2/.",
"dir1lev1/dir1lev2/..",
"dir1lev1/dir2lev2/.",
@@ -428,7 +457,7 @@ main (void)
"dir2lev1/dir1lev2/.dir",
"dir2lev1/dir1lev2/.foo");
- test ("*1*/*2*/.*", GLOB_ALTDIRFUNC,
+ test ("*1*/*2*/.*", 0, 0,
"dir1lev1/dir1lev2/.",
"dir1lev1/dir1lev2/..",
"dir1lev1/dir2lev2/.",
@@ -441,7 +470,7 @@ main (void)
"dir2lev1/dir1lev2/.dir",
"dir2lev1/dir1lev2/.foo");
- test ("*1*/*1*/.*", GLOB_ALTDIRFUNC,
+ test ("*1*/*1*/.*", 0, 0,
"dir1lev1/dir1lev2/.",
"dir1lev1/dir1lev2/..",
"dir2lev1/dir1lev2/.",
@@ -449,12 +478,16 @@ main (void)
"dir2lev1/dir1lev2/.dir",
"dir2lev1/dir1lev2/.foo");
- test ("\\/*", GLOB_ALTDIRFUNC,
+ test ("\\/*", 0, 0,
"/dir1lev1",
"/dir2lev1",
"/file1lev1",
"/file2lev1");
+ test ("", 0, GLOB_NOMATCH, NULL);
+
+ test ("", GLOB_NOCHECK, 0, "");
+
globfree (&gl);
return result;