summaryrefslogtreecommitdiff
path: root/posix
diff options
context:
space:
mode:
Diffstat (limited to 'posix')
-rw-r--r--posix/Makefile4
-rw-r--r--posix/Versions3
-rw-r--r--posix/fnmatch.c10
-rw-r--r--posix/fnmatch_loop.c82
-rw-r--r--posix/sched.h13
-rw-r--r--posix/sched_cpucount.c52
-rw-r--r--posix/sys/wait.h6
-rw-r--r--posix/tst-cpucount.c27
-rw-r--r--posix/tst-fnmatch2.c35
-rw-r--r--posix/unistd.h6
10 files changed, 194 insertions, 44 deletions
diff --git a/posix/Makefile b/posix/Makefile
index 74571cd036..467d0dc213 100644
--- a/posix/Makefile
+++ b/posix/Makefile
@@ -66,7 +66,7 @@ routines := \
spawnattr_getsigmask spawnattr_getschedpolicy spawnattr_getschedparam \
spawnattr_setsigmask spawnattr_setschedpolicy spawnattr_setschedparam \
posix_madvise \
- get_child_max
+ get_child_max sched_cpucount
include ../Makeconfig
@@ -90,7 +90,7 @@ tests := tstgetopt testfnm runtests runptests \
tst-execv1 tst-execv2 tst-execl1 tst-execl2 \
tst-execve1 tst-execve2 tst-execle1 tst-execle2 \
tst-execvp3 tst-execvp4 tst-rfc3484 tst-rfc3484-2 \
- tst-getaddrinfo3
+ tst-getaddrinfo3 tst-fnmatch2 tst-cpucount
xtests := bug-ga2
ifeq (yes,$(build-shared))
test-srcs := globtest
diff --git a/posix/Versions b/posix/Versions
index f529ee9d8e..1e1bda8b7b 100644
--- a/posix/Versions
+++ b/posix/Versions
@@ -122,6 +122,9 @@ libc {
GLIBC_2.3.4 {
regexec;
}
+ GLIBC_2.6 {
+ __sched_cpucount;
+ }
GLIBC_PRIVATE {
__libc_fork; __libc_pwrite;
}
diff --git a/posix/fnmatch.c b/posix/fnmatch.c
index 3fa7c322d1..c6cdb88772 100644
--- a/posix/fnmatch.c
+++ b/posix/fnmatch.c
@@ -1,4 +1,4 @@
-/* Copyright (C) 1991,1992,1993,1996,1997,1998,1999,2000,2001,2002,2003
+/* Copyright (C) 1991,1992,1993,1996,1997,1998,1999,2000,2001,2002,2003,2007
Free Software Foundation, Inc.
This file is part of the GNU C Library.
@@ -209,6 +209,7 @@ __wcschrnul (s, c)
# define FCT internal_fnmatch
# define EXT ext_match
# define END end_pattern
+# define STRUCT fnmatch_struct
# define L(CS) CS
# ifdef _LIBC
# define BTOWC(C) __btowc (C)
@@ -235,7 +236,8 @@ __wcschrnul (s, c)
# define INT wint_t
# define FCT internal_fnwmatch
# define EXT ext_wmatch
-# define END end_wpattern
+# define END end_wpattern
+# define STRUCT fnwmatch_struct
# define L(CS) L##CS
# define BTOWC(C) (C)
# define STRLEN(S) __wcslen (S)
@@ -397,12 +399,12 @@ fnmatch (pattern, string, flags)
}
return internal_fnwmatch (wpattern, wstring, wstring + n,
- flags & FNM_PERIOD, flags);
+ flags & FNM_PERIOD, flags, NULL);
}
# endif /* mbstate_t and mbsrtowcs or _LIBC. */
return internal_fnmatch (pattern, string, string + strlen (string),
- flags & FNM_PERIOD, flags);
+ flags & FNM_PERIOD, flags, NULL);
}
# ifdef _LIBC
diff --git a/posix/fnmatch_loop.c b/posix/fnmatch_loop.c
index 02a4e9030c..2bdd837184 100644
--- a/posix/fnmatch_loop.c
+++ b/posix/fnmatch_loop.c
@@ -1,5 +1,5 @@
-/* Copyright (C) 1991,1992,1993,1996,1997,1998,1999,2000,2001,2003,2004,2005
- Free Software Foundation, Inc.
+/* Copyright (C) 1991,1992,1993,1996,1997,1998,1999,2000,2001,2003,2004,2005,
+ 2007 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
@@ -17,10 +17,18 @@
Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
02111-1307 USA. */
+struct STRUCT
+{
+ const CHAR *pattern;
+ const CHAR *string;
+ int no_leading_period;
+};
+
/* Match STRING against the filename pattern PATTERN, returning zero if
it matches, nonzero if not. */
static int FCT (const CHAR *pattern, const CHAR *string,
- const CHAR *string_end, int no_leading_period, int flags)
+ const CHAR *string_end, int no_leading_period, int flags,
+ struct STRUCT *ends)
internal_function;
static int EXT (INT opt, const CHAR *pattern, const CHAR *string,
const CHAR *string_end, int no_leading_period, int flags)
@@ -29,12 +37,13 @@ static const CHAR *END (const CHAR *patternp) internal_function;
static int
internal_function
-FCT (pattern, string, string_end, no_leading_period, flags)
+FCT (pattern, string, string_end, no_leading_period, flags, ends)
const CHAR *pattern;
const CHAR *string;
const CHAR *string_end;
int no_leading_period;
int flags;
+ struct STRUCT *ends;
{
register const CHAR *p = pattern, *n = string;
register UCHAR c;
@@ -97,6 +106,13 @@ FCT (pattern, string, string_end, no_leading_period, flags)
if (res != -1)
return res;
}
+ else if (ends != NULL)
+ {
+ ends->pattern = p - 1;
+ ends->string = n;
+ ends->no_leading_period = no_leading_period;
+ return 0;
+ }
if (n != string_end && *n == L('.') && no_leading_period)
return FNM_NOMATCH;
@@ -157,7 +173,9 @@ FCT (pattern, string, string_end, no_leading_period, flags)
else
{
const CHAR *endp;
+ struct STRUCT end;
+ end.pattern = NULL;
endp = MEMCHR (n, (flags & FNM_FILE_NAME) ? L('/') : L('\0'),
string_end - n);
if (endp == NULL)
@@ -170,36 +188,46 @@ FCT (pattern, string, string_end, no_leading_period, flags)
{
int flags2 = ((flags & FNM_FILE_NAME)
? flags : (flags & ~FNM_PERIOD));
- int no_leading_period2 = no_leading_period;
- for (--p; n < endp; ++n, no_leading_period2 = 0)
- if (FCT (p, n, string_end, no_leading_period2, flags2)
- == 0)
- return 0;
+ for (--p; n < endp; ++n, no_leading_period = 0)
+ if (FCT (p, n, string_end, no_leading_period, flags2,
+ &end) == 0)
+ goto found;
}
else if (c == L('/') && (flags & FNM_FILE_NAME))
{
while (n < string_end && *n != L('/'))
++n;
if (n < string_end && *n == L('/')
- && (FCT (p, n + 1, string_end, flags & FNM_PERIOD, flags)
- == 0))
+ && (FCT (p, n + 1, string_end, flags & FNM_PERIOD, flags,
+ NULL) == 0))
return 0;
}
else
{
int flags2 = ((flags & FNM_FILE_NAME)
? flags : (flags & ~FNM_PERIOD));
- int no_leading_period2 = no_leading_period;
if (c == L('\\') && !(flags & FNM_NOESCAPE))
c = *p;
c = FOLD (c);
- for (--p; n < endp; ++n, no_leading_period2 = 0)
+ for (--p; n < endp; ++n, no_leading_period = 0)
if (FOLD ((UCHAR) *n) == c
- && (FCT (p, n, string_end, no_leading_period2, flags2)
- == 0))
- return 0;
+ && (FCT (p, n, string_end, no_leading_period, flags2,
+ &end) == 0))
+ {
+ found:
+ if (end.pattern == NULL)
+ return 0;
+ break;
+ }
+ if (end.pattern != NULL)
+ {
+ p = end.pattern;
+ n = end.string;
+ no_leading_period = end.no_leading_period;
+ continue;
+ }
}
}
@@ -1098,7 +1126,7 @@ EXT (INT opt, const CHAR *pattern, const CHAR *string, const CHAR *string_end,
switch (opt)
{
case L('*'):
- if (FCT (p, string, string_end, no_leading_period, flags) == 0)
+ if (FCT (p, string, string_end, no_leading_period, flags, NULL) == 0)
return 0;
/* FALLTHROUGH */
@@ -1109,7 +1137,8 @@ EXT (INT opt, const CHAR *pattern, const CHAR *string, const CHAR *string_end,
/* First match the prefix with the current pattern with the
current pattern. */
if (FCT (list->str, string, rs, no_leading_period,
- flags & FNM_FILE_NAME ? flags : flags & ~FNM_PERIOD) == 0
+ flags & FNM_FILE_NAME ? flags : flags & ~FNM_PERIOD,
+ NULL) == 0
/* This was successful. Now match the rest with the rest
of the pattern. */
&& (FCT (p, rs, string_end,
@@ -1117,7 +1146,7 @@ EXT (INT opt, const CHAR *pattern, const CHAR *string, const CHAR *string_end,
? no_leading_period
: rs[-1] == '/' && NO_LEADING_PERIOD (flags) ? 1 : 0,
flags & FNM_FILE_NAME
- ? flags : flags & ~FNM_PERIOD) == 0
+ ? flags : flags & ~FNM_PERIOD, NULL) == 0
/* This didn't work. Try the whole pattern. */
|| (rs != string
&& FCT (pattern - 1, rs, string_end,
@@ -1126,7 +1155,7 @@ EXT (INT opt, const CHAR *pattern, const CHAR *string, const CHAR *string_end,
: (rs[-1] == '/' && NO_LEADING_PERIOD (flags)
? 1 : 0),
flags & FNM_FILE_NAME
- ? flags : flags & ~FNM_PERIOD) == 0)))
+ ? flags : flags & ~FNM_PERIOD, NULL) == 0)))
/* It worked. Signal success. */
return 0;
}
@@ -1136,7 +1165,7 @@ EXT (INT opt, const CHAR *pattern, const CHAR *string, const CHAR *string_end,
return FNM_NOMATCH;
case L('?'):
- if (FCT (p, string, string_end, no_leading_period, flags) == 0)
+ if (FCT (p, string, string_end, no_leading_period, flags, NULL) == 0)
return 0;
/* FALLTHROUGH */
@@ -1148,7 +1177,8 @@ EXT (INT opt, const CHAR *pattern, const CHAR *string, const CHAR *string_end,
pattern list. */
if (FCT (STRCAT (list->str, p), string, string_end,
no_leading_period,
- flags & FNM_FILE_NAME ? flags : flags & ~FNM_PERIOD) == 0)
+ flags & FNM_FILE_NAME ? flags : flags & ~FNM_PERIOD,
+ NULL) == 0)
/* It worked. Signal success. */
return 0;
while ((list = list->next) != NULL);
@@ -1163,7 +1193,8 @@ EXT (INT opt, const CHAR *pattern, const CHAR *string, const CHAR *string_end,
for (runp = list; runp != NULL; runp = runp->next)
if (FCT (runp->str, string, rs, no_leading_period,
- flags & FNM_FILE_NAME ? flags : flags & ~FNM_PERIOD) == 0)
+ flags & FNM_FILE_NAME ? flags : flags & ~FNM_PERIOD,
+ NULL) == 0)
break;
/* If none of the patterns matched see whether the rest does. */
@@ -1172,8 +1203,8 @@ EXT (INT opt, const CHAR *pattern, const CHAR *string, const CHAR *string_end,
rs == string
? no_leading_period
: rs[-1] == '/' && NO_LEADING_PERIOD (flags) ? 1 : 0,
- flags & FNM_FILE_NAME ? flags : flags & ~FNM_PERIOD)
- == 0))
+ flags & FNM_FILE_NAME ? flags : flags & ~FNM_PERIOD,
+ NULL) == 0))
/* This is successful. */
return 0;
}
@@ -1198,6 +1229,7 @@ EXT (INT opt, const CHAR *pattern, const CHAR *string, const CHAR *string_end,
#undef FCT
#undef EXT
#undef END
+#undef STRUCT
#undef MEMPCPY
#undef MEMCHR
#undef STRCOLL
diff --git a/posix/sched.h b/posix/sched.h
index 7cfdbf1f96..becad0f365 100644
--- a/posix/sched.h
+++ b/posix/sched.h
@@ -1,5 +1,5 @@
/* Definitions for POSIX 1003.1b-1993 (aka POSIX.4) scheduling interface.
- Copyright (C) 1996,1997,1999,2001-2003,2004 Free Software Foundation, Inc.
+ Copyright (C) 1996,1997,1999,2001-2004,2007 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
@@ -65,11 +65,12 @@ extern int sched_rr_get_interval (__pid_t __pid, struct timespec *__t) __THROW;
#ifdef __USE_GNU
/* Access macros for `cpu_set'. */
-#define CPU_SETSIZE __CPU_SETSIZE
-#define CPU_SET(cpu, cpusetp) __CPU_SET (cpu, cpusetp)
-#define CPU_CLR(cpu, cpusetp) __CPU_CLR (cpu, cpusetp)
-#define CPU_ISSET(cpu, cpusetp) __CPU_ISSET (cpu, cpusetp)
-#define CPU_ZERO(cpusetp) __CPU_ZERO (cpusetp)
+# define CPU_SETSIZE __CPU_SETSIZE
+# define CPU_SET(cpu, cpusetp) __CPU_SET (cpu, cpusetp)
+# define CPU_CLR(cpu, cpusetp) __CPU_CLR (cpu, cpusetp)
+# define CPU_ISSET(cpu, cpusetp) __CPU_ISSET (cpu, cpusetp)
+# define CPU_ZERO(cpusetp) __CPU_ZERO (cpusetp)
+# define CPU_COUNT(cpusetp) __CPU_COUNT (cpusetp)
/* Set the CPU affinity for a task */
diff --git a/posix/sched_cpucount.c b/posix/sched_cpucount.c
new file mode 100644
index 0000000000..d7f6b7b49f
--- /dev/null
+++ b/posix/sched_cpucount.c
@@ -0,0 +1,52 @@
+/* Copyright (C) 2007 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
+ modify it under the terms of the GNU Lesser General Public
+ License as published by the Free Software Foundation; either
+ version 2.1 of the License, or (at your option) any later version.
+
+ The GNU C Library is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ Lesser General Public License for more details.
+
+ You should have received a copy of the GNU Lesser General Public
+ License along with the GNU C Library; if not, write to the Free
+ Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
+ 02111-1307 USA. */
+
+#include <limits.h>
+#include <sched.h>
+
+
+int
+__sched_cpucount (size_t setsize, cpu_set_t *setp)
+{
+ int s = 0;
+ for (unsigned int j = 0; j < setsize / sizeof (__cpu_mask); ++j)
+ {
+ __cpu_mask l = setp->__bits[j];
+ if (l == 0)
+ continue;
+
+#if LONG_BIT > 32
+ l = (l & 0x5555555555555555ul) + ((l >> 1) & 0x5555555555555555ul);
+ l = (l & 0x3333333333333333ul) + ((l >> 2) & 0x3333333333333333ul);
+ l = (l & 0x0f0f0f0f0f0f0f0ful) + ((l >> 4) & 0x0f0f0f0f0f0f0f0ful);
+ l = (l & 0x00ff00ff00ff00fful) + ((l >> 8) & 0x00ff00ff00ff00fful);
+ l = (l & 0x0000ffff0000fffful) + ((l >> 16) & 0x0000ffff0000fffful);
+ l = (l & 0x00000000fffffffful) + ((l >> 32) & 0x00000000fffffffful);
+#else
+ l = (l & 0x55555555ul) + ((l >> 1) & 0x55555555ul);
+ l = (l & 0x33333333ul) + ((l >> 2) & 0x33333333ul);
+ l = (l & 0x0f0f0f0ful) + ((l >> 4) & 0x0f0f0f0ful);
+ l = (l & 0x00ff00fful) + ((l >> 8) & 0x00ff00fful);
+ l = (l & 0x0000fffful) + ((l >> 16) & 0x0000fffful);
+#endif
+
+ s += l;
+ }
+
+ return s;
+}
diff --git a/posix/sys/wait.h b/posix/sys/wait.h
index d7a58eab13..fe103570db 100644
--- a/posix/sys/wait.h
+++ b/posix/sys/wait.h
@@ -1,4 +1,4 @@
-/* Copyright (C) 1991-1994,1996-2001,2003,2004,2005
+/* Copyright (C) 1991-1994,1996-2001,2003,2004,2005,2007
Free Software Foundation, Inc.
This file is part of the GNU C Library.
@@ -171,10 +171,6 @@ extern __pid_t wait3 (__WAIT_STATUS __stat_loc, int __options,
#endif
#ifdef __USE_BSD
-/* This being here makes the prototypes valid whether or not
- we have already included <sys/resource.h> to define `struct rusage'. */
-struct rusage;
-
/* PID is like waitpid. Other args are like wait3. */
extern __pid_t wait4 (__pid_t __pid, __WAIT_STATUS __stat_loc, int __options,
struct rusage *__usage) __THROW;
diff --git a/posix/tst-cpucount.c b/posix/tst-cpucount.c
new file mode 100644
index 0000000000..fe3cded732
--- /dev/null
+++ b/posix/tst-cpucount.c
@@ -0,0 +1,27 @@
+#include <sched.h>
+#include <stdio.h>
+
+static int
+do_test (void)
+{
+ cpu_set_t c;
+
+ CPU_ZERO (&c);
+
+ for (int cnt = 0; cnt < 130; ++cnt)
+ {
+ int n = CPU_COUNT (&c);
+ if (n != cnt)
+ {
+ printf ("expected %d, not %d\n", cnt, n);
+ return 1;
+ }
+
+ CPU_SET (cnt, &c);
+ }
+
+ return 0;
+}
+
+#define TEST_FUNCTION do_test ()
+#include "../test-skeleton.c"
diff --git a/posix/tst-fnmatch2.c b/posix/tst-fnmatch2.c
new file mode 100644
index 0000000000..28a0871c1c
--- /dev/null
+++ b/posix/tst-fnmatch2.c
@@ -0,0 +1,35 @@
+#include <fnmatch.h>
+#include <stdio.h>
+
+int
+do_test (void)
+{
+ char pattern[] = "a*b*c*d*e*f*g*h*i*j*k*l*m*n*o*p*q*r*s*t*u*v*w*x*y*z*";
+ const char *string = "aaaabbbbccccddddeeeeffffgggghhhhiiiijjjjkkkkllllmmmm"
+ "nnnnooooppppqqqqrrrrssssttttuuuuvvvvwwwwxxxxyyyy";
+ if (fnmatch (pattern, string, 0) != FNM_NOMATCH)
+ {
+ puts ("First fnmatch didn't return FNM_NOMATCH");
+ return 1;
+ }
+ pattern[(sizeof pattern) - 3] = '*';
+ if (fnmatch (pattern, string, 0) != 0)
+ {
+ puts ("Second fnmatch didn't return 0");
+ return 1;
+ }
+ if (fnmatch ("a*b/*", "abbb/.x", FNM_PATHNAME | FNM_PERIOD) != FNM_NOMATCH)
+ {
+ puts ("Third fnmatch didn't return FNM_NOMATCH");
+ return 1;
+ }
+ if (fnmatch ("a*b/*", "abbb/xy", FNM_PATHNAME | FNM_PERIOD) != 0)
+ {
+ puts ("Fourth fnmatch didn't return 0");
+ return 1;
+ }
+ return 0;
+}
+
+#define TEST_FUNCTION do_test ()
+#include "../test-skeleton.c"
diff --git a/posix/unistd.h b/posix/unistd.h
index c74190dfc3..577925c0fa 100644
--- a/posix/unistd.h
+++ b/posix/unistd.h
@@ -1,4 +1,4 @@
-/* Copyright (C) 1991-2002,2003,2004,2005,2006 Free Software Foundation, Inc.
+/* Copyright (C) 1991-2006, 2007 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
@@ -56,7 +56,9 @@ __BEGIN_DECLS
#define _POSIX2_LOCALEDEF 200112L
/* X/Open version number to which the library conforms. It is selectable. */
-#ifdef __USE_UNIX98
+#ifdef __USE_XOPEN2K
+# define _XOPEN_VERSION 600
+#elif defined __USE_UNIX98
# define _XOPEN_VERSION 500
#else
# define _XOPEN_VERSION 4