about summary refs log tree commit diff
path: root/posix
diff options
context:
space:
mode:
authorJakub Jelinek <jakub@redhat.com>2007-07-12 17:08:40 +0000
committerJakub Jelinek <jakub@redhat.com>2007-07-12 17:08:40 +0000
commita6778488dba0313ea73a4f871f2ae8e5223517e0 (patch)
tree7333b44eb84e11f7271ebe4c34e94feedea0710c /posix
parent8b6256b34923f0ad719179285676e84143eeb2c8 (diff)
downloadglibc-a6778488dba0313ea73a4f871f2ae8e5223517e0.tar.gz
glibc-a6778488dba0313ea73a4f871f2ae8e5223517e0.tar.xz
glibc-a6778488dba0313ea73a4f871f2ae8e5223517e0.zip
Updated to fedora-glibc-2_5-20070712T1701
Diffstat (limited to 'posix')
-rw-r--r--posix/Makefile17
-rw-r--r--posix/bug-regex27.c64
-rw-r--r--posix/bug-regex28.c75
-rw-r--r--posix/execvp.c104
-rw-r--r--posix/regcomp.c8
-rw-r--r--posix/tst-vfork3.c224
-rw-r--r--posix/unistd.h8
7 files changed, 445 insertions, 55 deletions
diff --git a/posix/Makefile b/posix/Makefile
index 311712d24e..74571cd036 100644
--- a/posix/Makefile
+++ b/posix/Makefile
@@ -1,4 +1,4 @@
-# Copyright (C) 1991-1999, 2000-2005, 2006 Free Software Foundation, Inc.
+# Copyright (C) 1991-1999, 2000-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
@@ -81,9 +81,10 @@ tests		:= tstgetopt testfnm runtests runptests	     \
 		   bug-regex13 bug-regex14 bug-regex15 bug-regex16 \
 		   bug-regex17 bug-regex18 bug-regex19 bug-regex20 \
 		   bug-regex21 bug-regex22 bug-regex23 bug-regex24 \
-		   bug-regex25 bug-regex26 tst-nice tst-nanosleep tst-regex2 \
+		   bug-regex25 bug-regex26 bug-regex27 bug-regex28 \
+		   tst-nice tst-nanosleep tst-regex2 \
 		   transbug tst-rxspencer tst-pcre tst-boost \
-		   bug-ga1 tst-vfork1 tst-vfork2 tst-waitid \
+		   bug-ga1 tst-vfork1 tst-vfork2 tst-vfork3 tst-waitid \
 		   tst-getaddrinfo2 bug-glob1 bug-glob2 tst-sysconf \
 		   tst-execvp1 tst-execvp2 tst-execlp1 tst-execlp2 \
 		   tst-execv1 tst-execv2 tst-execl1 tst-execl2 \
@@ -109,7 +110,7 @@ generated := $(addprefix wordexp-test-result, 1 2 3 4 5 6 7 8 9 10) \
 	     tst-rxspencer-mem tst-rxspencer.mtrace tst-getconf.out \
 	     tst-pcre-mem tst-pcre.mtrace tst-boost-mem tst-boost.mtrace \
 	     bug-ga2.mtrace bug-ga2-mem bug-glob2.mtrace bug-glob2-mem \
-	     getconf.speclist
+	     tst-vfork3-mem tst-vfork3.mtrace getconf.speclist
 
 include ../Rules
 
@@ -175,6 +176,7 @@ tst-exec-ARGS = -- $(built-program-cmd)
 tst-spawn-ARGS = -- $(built-program-cmd)
 tst-dir-ARGS = `pwd` `cd $(common-objdir)/$(subdir); pwd` `cd $(common-objdir); pwd` $(objpfx)tst-dir
 tst-chmod-ARGS = `pwd`
+tst-vfork3-ARGS = --test-dir=$(objpfx)
 
 tst-fnmatch-ENV = LOCPATH=$(common-objpfx)localedata
 tst-regexloc-ENV = LOCPATH=$(common-objpfx)localedata
@@ -219,7 +221,7 @@ ifeq (no,$(cross-compiling))
 tests: $(objpfx)bug-regex2-mem $(objpfx)bug-regex14-mem \
   $(objpfx)bug-regex21-mem $(objpfx)tst-rxspencer-mem \
   $(objpfx)tst-pcre-mem $(objpfx)tst-boost-mem $(objpfx)tst-getconf.out \
-  $(objpfx)bug-glob2-mem
+  $(objpfx)bug-glob2-mem $(objpfx)tst-vfork3-mem
 xtests: $(objpfx)bug-ga2-mem
 endif
 
@@ -246,6 +248,11 @@ bug-regex21-ENV = MALLOC_TRACE=$(objpfx)bug-regex21.mtrace
 $(objpfx)bug-regex21-mem: $(objpfx)bug-regex21.out
 	$(common-objpfx)malloc/mtrace $(objpfx)bug-regex21.mtrace > $@
 
+tst-vfork3-ENV = MALLOC_TRACE=$(objpfx)tst-vfork3.mtrace
+
+$(objpfx)tst-vfork3-mem: $(objpfx)tst-vfork3.out
+	$(common-objpfx)malloc/mtrace $(objpfx)tst-vfork3.mtrace > $@
+
 # tst-rxspencer.mtrace is generated only when run without --utf8
 # option, since otherwise the file has almost 100M and takes very long
 # time to process.
diff --git a/posix/bug-regex27.c b/posix/bug-regex27.c
new file mode 100644
index 0000000000..327acd8684
--- /dev/null
+++ b/posix/bug-regex27.c
@@ -0,0 +1,64 @@
+/* Test REG_NEWLINE.
+   Copyright (C) 2007 Free Software Foundation, Inc.
+   This file is part of the GNU C Library.
+   Contributed by Jakub Jelinek <jakub@redhat.com>, 2007.
+
+   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 <regex.h>
+#include <stdio.h>
+#include <string.h>
+
+struct tests
+{
+  const char *regex;
+  const char *string;
+  int cflags;
+  int retval;
+} tests[] = {
+  { "a.b", "a\nb", REG_EXTENDED | REG_NEWLINE, REG_NOMATCH },
+  { "a.b", "a\nb", REG_EXTENDED, 0 },
+  { "a[^x]b", "a\nb", REG_EXTENDED | REG_NEWLINE, REG_NOMATCH },
+  { "a[^x]b", "a\nb", REG_EXTENDED, 0 }
+};
+
+int
+main (void)
+{
+  regex_t r;
+  size_t i;
+  int ret = 0;
+
+  for (i = 0; i < sizeof (tests) / sizeof (tests[i]); ++i)
+    {
+      memset (&r, 0, sizeof (r));
+      if (regcomp (&r, tests[i].regex, tests[i].cflags))
+	{
+	  printf ("regcomp %zd failed\n", i);
+	  ret = 1;
+	  continue;
+	}
+      int rv = regexec (&r, tests[i].string, 0, NULL, 0);
+      if (rv != tests[i].retval)
+	{
+	  printf ("regexec %zd unexpected value %d != %d\n",
+		  i, rv, tests[i].retval);
+	  ret = 1;
+	}
+      regfree (&r);
+    }
+  return ret;
+}
diff --git a/posix/bug-regex28.c b/posix/bug-regex28.c
new file mode 100644
index 0000000000..e58a08fabe
--- /dev/null
+++ b/posix/bug-regex28.c
@@ -0,0 +1,75 @@
+/* Test RE_HAT_LISTS_NOT_NEWLINE and RE_DOT_NEWLINE.
+   Copyright (C) 2007 Free Software Foundation, Inc.
+   This file is part of the GNU C Library.
+   Contributed by Jakub Jelinek <jakub@redhat.com>, 2007.
+
+   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 <regex.h>
+#include <stdio.h>
+#include <string.h>
+
+struct tests
+{
+  const char *regex;
+  const char *string;
+  reg_syntax_t syntax;
+  int retval;
+} tests[] = {
+#define EGREP RE_SYNTAX_EGREP
+#define EGREP_NL (RE_SYNTAX_EGREP | RE_DOT_NEWLINE) & ~RE_HAT_LISTS_NOT_NEWLINE
+  { "a.b", "a\nb", EGREP, -1 },
+  { "a.b", "a\nb", EGREP_NL, 0 },
+  { "a[^x]b", "a\nb", EGREP, -1 },
+  { "a[^x]b", "a\nb", EGREP_NL, 0 },
+  /* While \S and \W are internally handled as [^[:space:]] and [^[:alnum:]_],
+     RE_HAT_LISTS_NOT_NEWLINE did not make any difference, so ensure
+     it doesn't change.  */
+  { "a\\Sb", "a\nb", EGREP, -1 },
+  { "a\\Sb", "a\nb", EGREP_NL, -1 },
+  { "a\\Wb", "a\nb", EGREP, 0 },
+  { "a\\Wb", "a\nb", EGREP_NL, 0 }
+};
+
+int
+main (void)
+{
+  struct re_pattern_buffer r;
+  size_t i;
+  int ret = 0;
+
+  for (i = 0; i < sizeof (tests) / sizeof (tests[i]); ++i)
+    {
+      re_set_syntax (tests[i].syntax);
+      memset (&r, 0, sizeof (r));
+      if (re_compile_pattern (tests[i].regex, strlen (tests[i].regex), &r))
+	{
+	  printf ("re_compile_pattern %zd failed\n", i);
+	  ret = 1;
+	  continue;
+	}
+      size_t len = strlen (tests[i].string);
+      int rv = re_search (&r, tests[i].string, len, 0, len, NULL);
+      if (rv != tests[i].retval)
+	{
+	  printf ("re_search %zd unexpected value %d != %d\n",
+		  i, rv, tests[i].retval);
+	  ret = 1;
+	}
+      regfree (&r);
+    }
+  return ret;
+}
diff --git a/posix/execvp.c b/posix/execvp.c
index 8421bd048f..887379e3a2 100644
--- a/posix/execvp.c
+++ b/posix/execvp.c
@@ -1,4 +1,5 @@
-/* Copyright (C) 1991,92,1995-99,2002,2004,2005 Free Software Foundation, Inc.
+/* Copyright (C) 1991,92, 1995-99, 2002, 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
@@ -16,6 +17,7 @@
    Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
    02111-1307 USA.  */
 
+#include <alloca.h>
 #include <unistd.h>
 #include <stdarg.h>
 #include <stdbool.h>
@@ -27,29 +29,18 @@
 
 /* The file is accessible but it is not an executable file.  Invoke
    the shell to interpret it as a script.  */
-static char **
+static void
 internal_function
-allocate_scripts_argv (const char *file, char *const argv[])
+scripts_argv (const char *file, char *const argv[], int argc, char **new_argv)
 {
-  /* Count the arguments.  */
-  int argc = 0;
-  while (argv[argc++])
-    ;
-
   /* Construct an argument list for the shell.  */
-  char **new_argv = (char **) malloc ((argc + 1) * sizeof (char *));
-  if (new_argv != NULL)
+  new_argv[0] = (char *) _PATH_BSHELL;
+  new_argv[1] = (char *) file;
+  while (argc > 1)
     {
-      new_argv[0] = (char *) _PATH_BSHELL;
-      new_argv[1] = (char *) file;
-      while (argc > 1)
-	{
-	  new_argv[argc] = argv[argc - 1];
-	  --argc;
-	}
+      new_argv[argc] = argv[argc - 1];
+      --argc;
     }
-
-  return new_argv;
 }
 
 
@@ -67,8 +58,6 @@ execvp (file, argv)
       return -1;
     }
 
-  char **script_argv = NULL;
-
   if (strchr (file, '/') != NULL)
     {
       /* Don't search when it contains a slash.  */
@@ -76,46 +65,71 @@ execvp (file, argv)
 
       if (errno == ENOEXEC)
 	{
-	  script_argv = allocate_scripts_argv (file, argv);
+	  /* Count the arguments.  */
+	  int argc = 0;
+	  while (argv[argc++])
+	    ;
+	  size_t len = (argc + 1) * sizeof (char *);
+	  char **script_argv;
+	  void *ptr = NULL;
+	  if (__libc_use_alloca (len))
+	    script_argv = alloca (len);
+	  else
+	    script_argv = ptr = malloc (len);
+
 	  if (script_argv != NULL)
 	    {
+	      scripts_argv (file, argv, argc, script_argv);
 	      __execve (script_argv[0], script_argv, __environ);
 
-	      free (script_argv);
+	      free (ptr);
 	    }
 	}
     }
   else
     {
+      size_t pathlen;
+      size_t alloclen = 0;
       char *path = getenv ("PATH");
+      if (path == NULL)
+	{
+	  pathlen = confstr (_CS_PATH, (char *) NULL, 0);
+	  alloclen = pathlen + 1;
+	}
+      else
+	pathlen = strlen (path);
+
+      size_t len = strlen (file) + 1;
+      alloclen += pathlen + len + 1;
+
+      char *name;
       char *path_malloc = NULL;
+      if (__libc_use_alloca (alloclen))
+	name = alloca (alloclen);
+      else
+	{
+	  path_malloc = name = malloc (alloclen);
+	  if (name == NULL)
+	    return -1;
+	}
+
       if (path == NULL)
 	{
 	  /* There is no `PATH' in the environment.
 	     The default search path is the current directory
 	     followed by the path `confstr' returns for `_CS_PATH'.  */
-	  size_t len = confstr (_CS_PATH, (char *) NULL, 0);
-	  path = (char *) malloc (1 + len);
-	  if (path == NULL)
-	    return -1;
+	  path = name + pathlen + len + 1;
 	  path[0] = ':';
-	  (void) confstr (_CS_PATH, path + 1, len);
-	  path_malloc = path;
+	  (void) confstr (_CS_PATH, path + 1, pathlen);
 	}
 
-      size_t len = strlen (file) + 1;
-      size_t pathlen = strlen (path);
-      char *name = malloc (pathlen + len + 1);
-      if (name == NULL)
-	{
-	  free (path_malloc);
-	  return -1;
-	}
       /* Copy the file name at the top.  */
       name = (char *) memcpy (name + pathlen + 1, file, len);
       /* And add the slash.  */
       *--name = '/';
 
+      char **script_argv = NULL;
+      void *script_argv_malloc = NULL;
       bool got_eacces = false;
       char *p = path;
       do
@@ -139,7 +153,15 @@ execvp (file, argv)
 	    {
 	      if (script_argv == NULL)
 		{
-		  script_argv = allocate_scripts_argv (startp, argv);
+		  /* Count the arguments.  */
+		  int argc = 0;
+		  while (argv[argc++])
+		    ;
+		  size_t arglen = (argc + 1) * sizeof (char *);
+		  if (__libc_use_alloca (alloclen + arglen))
+		    script_argv = alloca (arglen);
+		  else
+		    script_argv = script_argv_malloc = malloc (arglen);
 		  if (script_argv == NULL)
 		    {
 		      /* A possible EACCES error is not as important as
@@ -147,6 +169,7 @@ execvp (file, argv)
 		      got_eacces = false;
 		      break;
 		    }
+		  scripts_argv (startp, argv, argc, script_argv);
 		}
 
 	      __execve (script_argv[0], script_argv, __environ);
@@ -184,11 +207,10 @@ execvp (file, argv)
       /* We tried every element and none of them worked.  */
       if (got_eacces)
 	/* At least one failure was due to permissions, so report that
-           error.  */
+	   error.  */
 	__set_errno (EACCES);
 
-      free (script_argv);
-      free (name - pathlen);
+      free (script_argv_malloc);
       free (path_malloc);
     }
 
diff --git a/posix/regcomp.c b/posix/regcomp.c
index 78a1218cf8..e99fd74924 100644
--- a/posix/regcomp.c
+++ b/posix/regcomp.c
@@ -1,5 +1,5 @@
 /* Extended regular expression matching and search library.
-   Copyright (C) 2002,2003,2004,2005,2006 Free Software Foundation, Inc.
+   Copyright (C) 2002,2003,2004,2005,2006,2007 Free Software Foundation, Inc.
    This file is part of the GNU C Library.
    Contributed by Isamu Hasegawa <isamu@yamato.ibm.com>.
 
@@ -3019,7 +3019,7 @@ parse_bracket_exp (re_string_t *regexp, re_dfa_t *dfa, re_token_t *token,
 #endif /* not RE_ENABLE_I18N */
       non_match = 1;
       if (syntax & RE_HAT_LISTS_NOT_NEWLINE)
-	bitset_set (sbcset, '\0');
+	bitset_set (sbcset, '\n');
       re_string_skip_bytes (regexp, token_len); /* Skip a token.  */
       token_len = peek_token_bracket (token, regexp, syntax);
       if (BE (token->type == END_OF_RE, 0))
@@ -3549,10 +3549,6 @@ build_charclass_op (re_dfa_t *dfa, RE_TRANSLATE_TYPE trans,
   if (non_match)
     {
 #ifdef RE_ENABLE_I18N
-      /*
-      if (syntax & RE_HAT_LISTS_NOT_NEWLINE)
-	bitset_set(cset->sbcset, '\0');
-      */
       mbcset->non_match = 1;
 #endif /* not RE_ENABLE_I18N */
     }
diff --git a/posix/tst-vfork3.c b/posix/tst-vfork3.c
new file mode 100644
index 0000000000..954d395fd2
--- /dev/null
+++ b/posix/tst-vfork3.c
@@ -0,0 +1,224 @@
+/* Test for vfork functions.
+   Copyright (C) 2007 Free Software Foundation, Inc.
+   This file is part of the GNU C Library.
+   Contributed by Jakub Jelinek <jakub@redhat.com>, 2007.
+
+   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 <errno.h>
+#include <fcntl.h>
+#include <mcheck.h>
+#include <stdlib.h>
+#include <string.h>
+#include <unistd.h>
+#include <sys/wait.h>
+
+static int do_test (void);
+static void do_prepare (void);
+char *tmpdirname;
+
+#define TEST_FUNCTION do_test ()
+#define PREPARE(argc, argv) do_prepare ()
+#include "../test-skeleton.c"
+
+static int
+do_test (void)
+{
+  mtrace ();
+
+  const char *path = getenv ("PATH");
+  if (path == NULL)
+    path = "/bin";
+  char pathbuf[strlen (tmpdirname) + 1 + strlen (path) + 1];
+  strcpy (stpcpy (stpcpy (pathbuf, tmpdirname), ":"), path);
+  if (setenv ("PATH", pathbuf, 1) < 0)
+    {
+      puts ("setenv failed");
+      return 1;
+    }
+
+  size_t i;
+  char *argv[3] = { (char *) "script1.sh", (char *) "1", NULL };
+  for (i = 0; i < 5; i++)
+    {
+      pid_t pid = vfork ();
+      if (pid < 0)
+	{
+	  printf ("vfork failed: %m\n");
+	  return 1;
+	}
+      else if (pid == 0)
+	{
+	  execvp ("script1.sh", argv);
+	  _exit (errno);
+	}
+      int status;
+      if (TEMP_FAILURE_RETRY (waitpid (pid, &status, 0)) != pid)
+	{
+	  puts ("waitpid failed");
+	  return 1;
+	}
+      else if (status != 0)
+	{
+	  if (WIFEXITED (status))
+	    printf ("script1.sh failed with status %d\n",
+		    WEXITSTATUS (status));
+	  else
+	    printf ("script1.sh kill by signal %d\n",
+		    WTERMSIG (status));
+	  return 1;
+	}
+    }
+
+  argv[0] = (char *) "script2.sh";
+  argv[1] = (char *) "2";
+  for (i = 0; i < 5; i++)
+    {
+      pid_t pid = vfork ();
+      if (pid < 0)
+	{
+	  printf ("vfork failed: %m\n");
+	  return 1;
+	}
+      else if (pid == 0)
+	{
+	  execvp ("script2.sh", argv);
+	  _exit (errno);
+	}
+      int status;
+      if (TEMP_FAILURE_RETRY (waitpid (pid, &status, 0)) != pid)
+	{
+	  puts ("waitpid failed");
+	  return 1;
+	}
+      else if (status != 0)
+	{
+	  printf ("script2.sh failed with status %d\n", status);
+	  return 1;
+	}
+    }
+
+  for (i = 0; i < 5; i++)
+    {
+      pid_t pid = vfork ();
+      if (pid < 0)
+	{
+	  printf ("vfork failed: %m\n");
+	  return 1;
+	}
+      else if (pid == 0)
+	{
+	  execlp ("script2.sh", "script2.sh", "3", NULL);
+	  _exit (errno);
+	}
+      int status;
+      if (TEMP_FAILURE_RETRY (waitpid (pid, &status, 0)) != pid)
+	{
+	  puts ("waitpid failed");
+	  return 1;
+	}
+      else if (status != 0)
+	{
+	  printf ("script2.sh failed with status %d\n", status);
+	  return 1;
+	}
+    }
+
+  unsetenv ("PATH");
+  argv[0] = (char *) "echo";
+  argv[1] = (char *) "script 4";
+  for (i = 0; i < 5; i++)
+    {
+      pid_t pid = vfork ();
+      if (pid < 0)
+	{
+	  printf ("vfork failed: %m\n");
+	  return 1;
+	}
+      else if (pid == 0)
+	{
+	  execvp ("echo", argv);
+	  _exit (errno);
+	}
+      int status;
+      if (TEMP_FAILURE_RETRY (waitpid (pid, &status, 0)) != pid)
+	{
+	  puts ("waitpid failed");
+	  return 1;
+	}
+      else if (status != 0)
+	{
+	  printf ("echo failed with status %d\n", status);
+	  return 1;
+	}
+    }
+
+  return 0;
+}
+
+static void
+do_prepare (void)
+{
+  size_t len = strlen (test_dir) + sizeof ("/tst-vfork3.XXXXXX");
+  tmpdirname = malloc (len);
+  char *script1 = malloc (len + sizeof "/script1.sh");
+  char *script2 = malloc (len + sizeof "/script2.sh");
+  if (tmpdirname == NULL || script1 == NULL || script2 == NULL)
+    {
+      puts ("out of memory");
+      exit (1);
+    }
+  strcpy (stpcpy (tmpdirname, test_dir), "/tst-vfork3.XXXXXX");
+
+  tmpdirname = mkdtemp (tmpdirname);
+  if (tmpdirname == NULL)
+    {
+      puts ("could not create temporary directory");
+      exit (1);
+    }
+
+  strcpy (stpcpy (script1, tmpdirname), "/script1.sh");
+  strcpy (stpcpy (script2, tmpdirname), "/script2.sh");
+
+  /* Need to make sure tmpdirname is at the end of the linked list.  */
+  add_temp_file (script1);
+  add_temp_file (tmpdirname);
+  add_temp_file (script2);
+
+  const char content1[] = "#!/bin/sh\necho script $1\n";
+  int fd = open (script1, O_WRONLY | O_CREAT, 0700);
+  if (fd < 0
+      || TEMP_FAILURE_RETRY (write (fd, content1, sizeof content1))
+	 != sizeof content1
+      || fchmod (fd, S_IRUSR | S_IXUSR) < 0)
+    {
+      printf ("Could not write %s\n", script1);
+      exit (1);
+    }
+  close (fd);
+
+  const char content2[] = "echo script $1\n";
+  fd = open (script2, O_WRONLY | O_CREAT, 0700);
+  if (fd < 0
+      || TEMP_FAILURE_RETRY (write (fd, content2, sizeof content2))
+	 != sizeof content2
+      || fchmod (fd, S_IRUSR | S_IXUSR) < 0)
+    {
+      printf ("Could not write %s\n", script2);
+      exit (1);
+    }
+  close (fd);
+}
diff --git a/posix/unistd.h b/posix/unistd.h
index b751928b1e..4e1e9dfaa2 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
@@ -1060,7 +1062,7 @@ extern int lockf64 (int __fd, int __cmd, __off64_t __len) __wur;
 #if defined __USE_POSIX199309 || defined __USE_UNIX98
 /* Synchronize at least the data part of a file with the underlying
    media.  */
-extern int fdatasync (int __fildes) __THROW;
+extern int fdatasync (int __fildes);
 #endif /* Use POSIX199309 */