about summary refs log tree commit diff
path: root/posix
diff options
context:
space:
mode:
Diffstat (limited to 'posix')
-rw-r--r--posix/environ.c12
-rw-r--r--posix/execve.c44
-rw-r--r--posix/fexecve.c43
-rw-r--r--posix/fork.c36
-rw-r--r--posix/fpathconf.c62
-rw-r--r--posix/gai_strerror.c29
-rw-r--r--posix/getaddrinfo.c41
-rw-r--r--posix/getegid.c32
-rw-r--r--posix/geteuid.c33
-rw-r--r--posix/getgid.c33
-rw-r--r--posix/getgroups.c48
-rw-r--r--posix/getlogin.c33
-rw-r--r--posix/getlogin_r.c37
-rw-r--r--posix/getpgid.c33
-rw-r--r--posix/getpgrp.c27
-rw-r--r--posix/getpid.c34
-rw-r--r--posix/getppid.c33
-rw-r--r--posix/getresgid.c34
-rw-r--r--posix/getresuid.c34
-rw-r--r--posix/getsid.c32
-rw-r--r--posix/getuid.c33
-rw-r--r--posix/glob.c1558
-rw-r--r--posix/glob64.c54
-rw-r--r--posix/group_member.c50
-rw-r--r--posix/init-posix.c1
-rw-r--r--posix/nanosleep.c36
-rw-r--r--posix/pathconf.c41
-rw-r--r--posix/pause.c34
-rw-r--r--posix/posix_madvise.c32
-rw-r--r--posix/pread.c46
-rw-r--r--posix/pread64.c46
-rw-r--r--posix/pwrite.c46
-rw-r--r--posix/pwrite64.c47
-rw-r--r--posix/sched_getaffinity.c35
-rw-r--r--posix/sched_getp.c34
-rw-r--r--posix/sched_gets.c34
-rw-r--r--posix/sched_primax.c33
-rw-r--r--posix/sched_primin.c33
-rw-r--r--posix/sched_rr_gi.c34
-rw-r--r--posix/sched_setaffinity.c35
-rw-r--r--posix/sched_setp.c34
-rw-r--r--posix/sched_sets.c35
-rw-r--r--posix/sched_yield.c33
-rw-r--r--posix/setgid.c37
-rw-r--r--posix/setlogin.c32
-rw-r--r--posix/setpgid.c37
-rw-r--r--posix/setpgrp.c25
-rw-r--r--posix/setresgid.c35
-rw-r--r--posix/setresuid.c35
-rw-r--r--posix/setsid.c35
-rw-r--r--posix/setuid.c37
-rw-r--r--posix/sleep.c41
-rw-r--r--posix/spawni.c46
-rw-r--r--posix/sysconf.c273
-rw-r--r--posix/times.c43
-rw-r--r--posix/uname.c66
-rw-r--r--posix/vfork.c31
-rw-r--r--posix/wait.c33
-rw-r--r--posix/wait3.c43
-rw-r--r--posix/wait4.c33
-rw-r--r--posix/waitid.c35
-rw-r--r--posix/waitpid.c53
-rw-r--r--posix/wordexp.c2457
63 files changed, 6501 insertions, 0 deletions
diff --git a/posix/environ.c b/posix/environ.c
new file mode 100644
index 0000000000..a0ed0d80ea
--- /dev/null
+++ b/posix/environ.c
@@ -0,0 +1,12 @@
+/* This file just defines the `__environ' variable (and alias `environ').  */
+
+#include <unistd.h>
+#include <stddef.h>
+
+/* This must be initialized; we cannot have a weak alias into bss.  */
+char **__environ = NULL;
+weak_alias (__environ, environ)
+
+/* The SVR4 ABI says `_environ' will be the name to use
+   in case the user overrides the weak alias `environ'.  */
+weak_alias (__environ, _environ)
diff --git a/posix/execve.c b/posix/execve.c
new file mode 100644
index 0000000000..2d756293ed
--- /dev/null
+++ b/posix/execve.c
@@ -0,0 +1,44 @@
+/* Copyright (C) 1991, 1995, 1996, 1997 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 <errno.h>
+#include <stddef.h>
+#include <unistd.h>
+
+
+/* Replace the current process, executing PATH with arguments ARGV and
+   environment ENVP.  ARGV and ENVP are terminated by NULL pointers.  */
+int
+__execve (path, argv, envp)
+     const char *path;
+     char *const argv[];
+     char *const envp[];
+{
+  if (path == NULL || argv == NULL || envp == NULL)
+    {
+      __set_errno (EINVAL);
+      return -1;
+    }
+
+  __set_errno (ENOSYS);
+  return -1;
+}
+stub_warning (execve)
+
+weak_alias (__execve, execve)
+#include <stub-tag.h>
diff --git a/posix/fexecve.c b/posix/fexecve.c
new file mode 100644
index 0000000000..fceae9251a
--- /dev/null
+++ b/posix/fexecve.c
@@ -0,0 +1,43 @@
+/* Copyright (C) 1994, 1995, 1996, 1997 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 <errno.h>
+#include <stddef.h>
+#include <unistd.h>
+
+
+/* Execute the file FD refers to, overlaying the running program image.
+   ARGV and ENVP are passed to the new program, as for `execve'.  */
+int
+fexecve (fd, argv, envp)
+     int fd;
+     char *const argv[];
+     char *const envp[];
+{
+  if (fd < 0 || argv == NULL || envp == NULL)
+    {
+      __set_errno (EINVAL);
+      return -1;
+    }
+
+  __set_errno (ENOSYS);
+  return -1;
+}
+
+stub_warning (fexecve)
+#include <stub-tag.h>
diff --git a/posix/fork.c b/posix/fork.c
new file mode 100644
index 0000000000..c19fa656b3
--- /dev/null
+++ b/posix/fork.c
@@ -0,0 +1,36 @@
+/* Copyright (C) 1991, 1995, 1996, 1997, 2002 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 <errno.h>
+#include <unistd.h>
+
+
+/* Clone the calling process, creating an exact copy.
+   Return -1 for errors, 0 to the new process,
+   and the process ID of the new process to the old process.  */
+int
+__fork ()
+{
+  __set_errno (ENOSYS);
+  return -1;
+}
+libc_hidden_def (__fork)
+stub_warning (fork)
+
+weak_alias (__fork, fork)
+#include <stub-tag.h>
diff --git a/posix/fpathconf.c b/posix/fpathconf.c
new file mode 100644
index 0000000000..840460b04b
--- /dev/null
+++ b/posix/fpathconf.c
@@ -0,0 +1,62 @@
+/* Copyright (C) 1991, 1995, 1996, 1997 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 <errno.h>
+#include <stddef.h>
+#include <unistd.h>
+
+
+/* Get file-specific information about descriptor FD.  */
+long int
+__fpathconf (fd, name)
+     int fd;
+     int name;
+{
+  if (fd < 0)
+    {
+      __set_errno (EBADF);
+      return -1;
+    }
+
+  switch (name)
+    {
+    default:
+      __set_errno (EINVAL);
+      return -1;
+
+    case _PC_LINK_MAX:
+    case _PC_MAX_CANON:
+    case _PC_MAX_INPUT:
+    case _PC_NAME_MAX:
+    case _PC_PATH_MAX:
+    case _PC_PIPE_BUF:
+    case _PC_SOCK_MAXBUF:
+    case _PC_CHOWN_RESTRICTED:
+    case _PC_NO_TRUNC:
+    case _PC_VDISABLE:
+      break;
+    }
+
+  __set_errno (ENOSYS);
+  return -1;
+}
+
+weak_alias (__fpathconf, fpathconf)
+
+stub_warning (fpathconf)
+#include <stub-tag.h>
diff --git a/posix/gai_strerror.c b/posix/gai_strerror.c
new file mode 100644
index 0000000000..932c5910df
--- /dev/null
+++ b/posix/gai_strerror.c
@@ -0,0 +1,29 @@
+/* Copyright (C) 1996,97,2001,02 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 <errno.h>
+#include <netdb.h>
+
+const char *
+gai_strerror (int code)
+{
+  static char buffer[128];
+  snprintf (buffer, sizeof buffer, "Unknown error (%d)", code);
+  return buffer;
+}
+libc_hidden_def (gai_strerror)
diff --git a/posix/getaddrinfo.c b/posix/getaddrinfo.c
new file mode 100644
index 0000000000..548c0b863e
--- /dev/null
+++ b/posix/getaddrinfo.c
@@ -0,0 +1,41 @@
+/* Stub version of getaddrinfo function.
+   Copyright (C) 1996, 2002 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 <errno.h>
+#include <netdb.h>
+
+int
+getaddrinfo (const char *name, const char *service, const struct addrinfo *req,
+	     struct addrinfo **pai)
+{
+  __set_errno (ENOSYS);
+  return EAI_SYSTEM;
+}
+stub_warning (getaddrinfo)
+libc_hidden_def (getaddrinfo)
+
+void
+freeaddrinfo (struct addrinfo *ai)
+{
+  /* Nothing.  */
+}
+stub_warning (freeaddrinfo)
+libc_hidden_def (freeaddrinfo)
+
+#include <stub-tag.h>
diff --git a/posix/getegid.c b/posix/getegid.c
new file mode 100644
index 0000000000..d939d6ad64
--- /dev/null
+++ b/posix/getegid.c
@@ -0,0 +1,32 @@
+/* Copyright (C) 1991, 1992, 1995, 1996, 1997 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 <errno.h>
+#include <unistd.h>
+
+/* Get the effective group ID of the calling process.  */
+__gid_t
+__getegid ()
+{
+  __set_errno (ENOSYS);
+  return -1;
+}
+stub_warning (getegid)
+
+weak_alias (__getegid, getegid)
+#include <stub-tag.h>
diff --git a/posix/geteuid.c b/posix/geteuid.c
new file mode 100644
index 0000000000..c67dbfd708
--- /dev/null
+++ b/posix/geteuid.c
@@ -0,0 +1,33 @@
+/* Copyright (C) 1991, 1992, 1995, 1996, 1997 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 <errno.h>
+#include <unistd.h>
+
+
+/* Get the effective user ID of the calling process.  */
+__uid_t
+__geteuid ()
+{
+  __set_errno (ENOSYS);
+  return -1;
+}
+stub_warning (geteuid)
+
+weak_alias (__geteuid, geteuid)
+#include <stub-tag.h>
diff --git a/posix/getgid.c b/posix/getgid.c
new file mode 100644
index 0000000000..742c099fa2
--- /dev/null
+++ b/posix/getgid.c
@@ -0,0 +1,33 @@
+/* Copyright (C) 1991, 1993, 1995, 1996, 1997 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 <errno.h>
+#include <unistd.h>
+#include <sys/types.h>
+
+/* Get the real group ID of the calling process.  */
+gid_t
+__getgid ()
+{
+  __set_errno (ENOSYS);
+  return -1;
+}
+stub_warning (getgid)
+
+weak_alias (__getgid, getgid)
+#include <stub-tag.h>
diff --git a/posix/getgroups.c b/posix/getgroups.c
new file mode 100644
index 0000000000..d5868cc1b8
--- /dev/null
+++ b/posix/getgroups.c
@@ -0,0 +1,48 @@
+/* Copyright (C) 1991,1992,1995,1996,1997,2005 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 <errno.h>
+#include <stddef.h>
+#include <unistd.h>
+#include <sys/types.h>
+#include <limits.h>
+
+
+/* If SIZE is zero, return the number of supplementary groups
+   the calling process is in.  Otherwise, fill in the group IDs
+   of its supplementary groups in LIST and return the number written.  */
+int
+__getgroups (size, list)
+     int size;
+     gid_t *list;
+{
+#if defined (NGROUPS_MAX) && NGROUPS_MAX == 0
+  /* The system has no supplementary groups.  */
+  return 0;
+#endif
+
+  __set_errno (ENOSYS);
+  return -1;
+}
+
+#if !(defined (NGROUPS_MAX) && NGROUPS_MAX == 0)
+stub_warning (getgroups);
+#endif
+
+weak_alias (__getgroups, getgroups)
+#include <stub-tag.h>
diff --git a/posix/getlogin.c b/posix/getlogin.c
new file mode 100644
index 0000000000..12b4283396
--- /dev/null
+++ b/posix/getlogin.c
@@ -0,0 +1,33 @@
+/* Copyright (C) 1991, 1995, 1996 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 <stddef.h>
+#include <errno.h>
+#include <unistd.h>
+
+/* Return the login name of the user, or NULL if it can't be determined.
+   The returned pointer, if not NULL, is good only until the next call.  */
+char *
+getlogin (void)
+{
+  __set_errno (ENOSYS);
+  return NULL;
+}
+
+stub_warning (getlogin)
+#include <stub-tag.h>
diff --git a/posix/getlogin_r.c b/posix/getlogin_r.c
new file mode 100644
index 0000000000..f2470ee032
--- /dev/null
+++ b/posix/getlogin_r.c
@@ -0,0 +1,37 @@
+/* Reentrant function to return the current login name.  Stub version.
+   Copyright (C) 1996, 2002 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 <errno.h>
+#include <unistd.h>
+
+/* Return at most NAME_LEN characters of the login name of the user in NAME.
+   If it cannot be determined or some other error occurred, return the error
+   code.  Otherwise return 0.  */
+int
+getlogin_r (name, name_len)
+     char *name;
+     size_t name_len;
+{
+  __set_errno (ENOSYS);
+  return errno;
+}
+libc_hidden_def (getlogin_r)
+
+stub_warning (getlogin_r)
+#include <stub-tag.h>
diff --git a/posix/getpgid.c b/posix/getpgid.c
new file mode 100644
index 0000000000..ad46771d2f
--- /dev/null
+++ b/posix/getpgid.c
@@ -0,0 +1,33 @@
+/* Copyright (C) 1991,1995,1996,1997,1998,2002 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 <unistd.h>
+#include <sys/types.h>
+
+/* Get the process group ID of process PID.  */
+pid_t
+__getpgid (pid)
+     pid_t pid;
+{
+  return pid;
+}
+libc_hidden_def (__getpgid)
+weak_alias (__getpgid, getpgid)
+
+stub_warning (getpgid)
+#include <stub-tag.h>
diff --git a/posix/getpgrp.c b/posix/getpgrp.c
new file mode 100644
index 0000000000..85efc2f215
--- /dev/null
+++ b/posix/getpgrp.c
@@ -0,0 +1,27 @@
+/* Copyright (C) 1991, 1995, 1997, 1999 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 <errno.h>
+#include <unistd.h>
+
+/* Get the process group ID of the calling process.  */
+pid_t
+getpgrp (void)
+{
+  return __getpgid (0);
+}
diff --git a/posix/getpid.c b/posix/getpid.c
new file mode 100644
index 0000000000..c1c91fede7
--- /dev/null
+++ b/posix/getpid.c
@@ -0,0 +1,34 @@
+/* Copyright (C) 1991, 1995, 1996, 1997, 2002 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 <errno.h>
+#include <unistd.h>
+
+/* Get the process ID of the calling process.  */
+int
+__getpid ()
+{
+  __set_errno (ENOSYS);
+  return -1;
+}
+libc_hidden_def (__getpid)
+stub_warning (getpid)
+
+weak_alias (__getpid, getpid)
+libc_hidden_weak (getpid)
+#include <stub-tag.h>
diff --git a/posix/getppid.c b/posix/getppid.c
new file mode 100644
index 0000000000..e00c237496
--- /dev/null
+++ b/posix/getppid.c
@@ -0,0 +1,33 @@
+/* Copyright (C) 1991, 1995, 1996, 1997 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 <errno.h>
+#include <unistd.h>
+
+
+/* Get the parent process ID of the calling process.  */
+int
+__getppid ()
+{
+  __set_errno (ENOSYS);
+  return -1;
+}
+stub_warning (getppid)
+
+weak_alias (__getppid, getppid)
+#include <stub-tag.h>
diff --git a/posix/getresgid.c b/posix/getresgid.c
new file mode 100644
index 0000000000..d6a9b52957
--- /dev/null
+++ b/posix/getresgid.c
@@ -0,0 +1,34 @@
+/* Copyright (C) 1991,1995,1996,1997,1998,2002 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 <errno.h>
+#include <unistd.h>
+
+/* Fetch the effective group ID, real group ID, and saved-set group ID,
+   of the calling process.  */
+int
+__getresgid (gid_t *egid, gid_t *rgid, gid_t *sgid)
+{
+  __set_errno (ENOSYS);
+  return -1;
+}
+libc_hidden_def (__getresgid)
+stub_warning (getresgid)
+
+weak_alias (__getresgid, getresgid)
+#include <stub-tag.h>
diff --git a/posix/getresuid.c b/posix/getresuid.c
new file mode 100644
index 0000000000..227d6b7ded
--- /dev/null
+++ b/posix/getresuid.c
@@ -0,0 +1,34 @@
+/* Copyright (C) 1991,1995,1996,1997,1998,2002 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 <errno.h>
+#include <unistd.h>
+
+/* Fetch the effective user ID, real user ID, and saved-set user ID,
+   of the calling process.  */
+int
+__getresuid (uid_t *euid, uid_t *ruid, uid_t *suid)
+{
+  __set_errno (ENOSYS);
+  return -1;
+}
+libc_hidden_def (__getresuid)
+stub_warning (getresuid)
+
+weak_alias (__getresuid, getresuid)
+#include <stub-tag.h>
diff --git a/posix/getsid.c b/posix/getsid.c
new file mode 100644
index 0000000000..eb7e60fa42
--- /dev/null
+++ b/posix/getsid.c
@@ -0,0 +1,32 @@
+/* getsid -- Return session ID of a process.  Stub version.
+   Copyright (C) 1995,96,97,2002 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 <sys/types.h>
+#include <unistd.h>
+#include <errno.h>
+
+pid_t
+getsid (pid_t pid)
+{
+  __set_errno (ENOSYS);
+  return (pid_t) -1;
+}
+libc_hidden_def (getsid)
+stub_warning (getsid)
+#include <stub-tag.h>
diff --git a/posix/getuid.c b/posix/getuid.c
new file mode 100644
index 0000000000..c4ea7e8c98
--- /dev/null
+++ b/posix/getuid.c
@@ -0,0 +1,33 @@
+/* Copyright (C) 1991, 1993, 1995, 1996, 1997 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 <errno.h>
+#include <unistd.h>
+#include <sys/types.h>
+
+/* Get the real user ID of the calling process.  */
+uid_t
+__getuid ()
+{
+  __set_errno (ENOSYS);
+  return -1;
+}
+stub_warning (getuid)
+
+weak_alias (__getuid, getuid)
+#include <stub-tag.h>
diff --git a/posix/glob.c b/posix/glob.c
new file mode 100644
index 0000000000..2e767304a7
--- /dev/null
+++ b/posix/glob.c
@@ -0,0 +1,1558 @@
+/* Copyright (C) 1991-2002,2003,2004,2005 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.  */
+
+/* AIX requires this to be the first thing in the file.  */
+#if defined _AIX && !defined __GNUC__
+ #pragma alloca
+#endif
+
+#ifdef	HAVE_CONFIG_H
+# include <config.h>
+#endif
+
+/* Enable GNU extensions in glob.h.  */
+#ifndef _GNU_SOURCE
+# define _GNU_SOURCE	1
+#endif
+
+#include <errno.h>
+#include <sys/types.h>
+#include <sys/stat.h>
+
+/* Outcomment the following line for production quality code.  */
+/* #define NDEBUG 1 */
+#include <assert.h>
+
+#include <stdio.h>		/* Needed on stupid SunOS for assert.  */
+
+
+/* Comment out all this code if we are using the GNU C Library, and are not
+   actually compiling the library itself.  This code is part of the GNU C
+   Library, but also included in many other GNU distributions.  Compiling
+   and linking in this code is a waste when using the GNU C library
+   (especially if it is a shared library).  Rather than having every GNU
+   program understand `configure --with-gnu-libc' and omit the object files,
+   it is simpler to just do this in the source for each such file.  */
+
+#define GLOB_INTERFACE_VERSION 1
+#if !defined _LIBC && defined __GNU_LIBRARY__ && __GNU_LIBRARY__ > 1
+# include <gnu-versions.h>
+# if _GNU_GLOB_INTERFACE_VERSION == GLOB_INTERFACE_VERSION
+#  define ELIDE_CODE
+# endif
+#endif
+
+#ifndef ELIDE_CODE
+#if !defined _LIBC || !defined GLOB_ONLY_P
+
+#if defined STDC_HEADERS || defined __GNU_LIBRARY__
+# include <stddef.h>
+#endif
+
+#if defined HAVE_UNISTD_H || defined _LIBC
+# include <unistd.h>
+# ifndef POSIX
+#  ifdef _POSIX_VERSION
+#   define POSIX
+#  endif
+# endif
+#endif
+
+#if !defined _AMIGA && !defined VMS && !defined WINDOWS32
+# include <pwd.h>
+#endif
+
+#if !defined __GNU_LIBRARY__ && !defined STDC_HEADERS
+extern int errno;
+#endif
+#ifndef __set_errno
+# define __set_errno(val) errno = (val)
+#endif
+
+#ifndef	NULL
+# define NULL	0
+#endif
+
+
+#if defined HAVE_DIRENT_H || defined __GNU_LIBRARY__
+# include <dirent.h>
+# define NAMLEN(dirent) strlen((dirent)->d_name)
+#else
+# define dirent direct
+# define NAMLEN(dirent) (dirent)->d_namlen
+# ifdef HAVE_SYS_NDIR_H
+#  include <sys/ndir.h>
+# endif
+# ifdef HAVE_SYS_DIR_H
+#  include <sys/dir.h>
+# endif
+# ifdef HAVE_NDIR_H
+#  include <ndir.h>
+# endif
+# ifdef HAVE_VMSDIR_H
+#  include "vmsdir.h"
+# endif /* HAVE_VMSDIR_H */
+#endif
+
+
+/* In GNU systems, <dirent.h> defines this macro for us.  */
+#ifdef _D_NAMLEN
+# undef NAMLEN
+# define NAMLEN(d) _D_NAMLEN(d)
+#endif
+
+/* When used in the GNU libc the symbol _DIRENT_HAVE_D_TYPE is available
+   if the `d_type' member for `struct dirent' is available.  */
+#ifdef _DIRENT_HAVE_D_TYPE
+# define HAVE_D_TYPE	1
+#endif
+
+#if _LIBC
+# define HAVE_DIRENT64	1
+#endif
+
+/* If the system has the `struct dirent64' type we use it internally.  */
+#if defined HAVE_DIRENT64 && !defined COMPILE_GLOB64
+# if defined HAVE_DIRENT_H || defined __GNU_LIBRARY__
+#  define CONVERT_D_NAMLEN(d64, d32)
+# else
+#  define CONVERT_D_NAMLEN(d64, d32) \
+  (d64)->d_namlen = (d32)->d_namlen;
+# endif
+
+# if (defined POSIX || defined WINDOWS32) && !defined __GNU_LIBRARY__
+#  define CONVERT_D_INO(d64, d32)
+# else
+#  define CONVERT_D_INO(d64, d32) \
+  (d64)->d_ino = (d32)->d_ino;
+# endif
+
+# ifdef HAVE_D_TYPE
+#  define CONVERT_D_TYPE(d64, d32) \
+  (d64)->d_type = (d32)->d_type;
+# else
+#  define CONVERT_D_TYPE(d64, d32)
+# endif
+
+# define CONVERT_DIRENT_DIRENT64(d64, d32) \
+  memcpy ((d64)->d_name, (d32)->d_name, NAMLEN (d32) + 1);		      \
+  CONVERT_D_NAMLEN (d64, d32)						      \
+  CONVERT_D_INO (d64, d32)						      \
+  CONVERT_D_TYPE (d64, d32)
+#endif
+
+
+#if (defined POSIX || defined WINDOWS32) && !defined __GNU_LIBRARY__
+/* Posix does not require that the d_ino field be present, and some
+   systems do not provide it. */
+# define REAL_DIR_ENTRY(dp) 1
+#else
+# define REAL_DIR_ENTRY(dp) (dp->d_ino != 0)
+#endif /* POSIX */
+
+#if defined STDC_HEADERS || defined __GNU_LIBRARY__
+# include <stdlib.h>
+# include <string.h>
+# define	ANSI_STRING
+#else	/* No standard headers.  */
+
+extern char *getenv ();
+
+# ifdef HAVE_STRING_H
+#  include <string.h>
+#  define ANSI_STRING
+# else
+#  include <strings.h>
+# endif
+# ifdef	HAVE_MEMORY_H
+#  include <memory.h>
+# endif
+
+extern char *malloc (), *realloc ();
+extern void free ();
+
+extern void qsort ();
+extern void abort (), exit ();
+
+#endif	/* Standard headers.  */
+
+/* NAME_MAX is usually defined in <dirent.h> or <limits.h>.  */
+#if defined HAVE_LIMITS_H || defined __GNU_LIBRARY__
+# include <limits.h>
+#endif
+#ifndef NAME_MAX
+# define NAME_MAX (sizeof (((struct dirent *) 0)->d_name))
+#endif
+
+#ifndef	ANSI_STRING
+
+# ifndef bzero
+extern void bzero ();
+# endif
+# ifndef bcopy
+extern void bcopy ();
+# endif
+
+# define memcpy(d, s, n)	bcopy ((s), (d), (n))
+# define strrchr	rindex
+/* memset is only used for zero here, but let's be paranoid.  */
+# define memset(s, better_be_zero, n) \
+  ((void) ((better_be_zero) == 0 ? (bzero((s), (n)), 0) : (abort(), 0)))
+#endif	/* Not ANSI_STRING.  */
+
+#if !defined HAVE_STRCOLL && !defined _LIBC
+# define strcoll	strcmp
+#endif
+
+#if !defined HAVE_MEMPCPY && __GLIBC__ - 0 == 2 && __GLIBC_MINOR__ >= 1
+# define HAVE_MEMPCPY	1
+# undef  mempcpy
+# define mempcpy(Dest, Src, Len) __mempcpy (Dest, Src, Len)
+#endif
+
+#ifndef	__GNU_LIBRARY__
+# ifdef	__GNUC__
+__inline
+# endif
+# ifndef __SASC
+#  ifdef WINDOWS32
+static void *
+#  else
+static char *
+# endif
+my_realloc (p, n)
+     char *p;
+     unsigned int n;
+{
+  /* These casts are the for sake of the broken Ultrix compiler,
+     which warns of illegal pointer combinations otherwise.  */
+  if (p == NULL)
+    return (char *) malloc (n);
+  return (char *) realloc (p, n);
+}
+# define	realloc	my_realloc
+# endif /* __SASC */
+#endif /* __GNU_LIBRARY__ */
+
+
+#if !defined __alloca && !defined __GNU_LIBRARY__
+
+# ifdef	__GNUC__
+#  undef alloca
+#  define alloca(n)	__builtin_alloca (n)
+# else	/* Not GCC.  */
+#  ifdef HAVE_ALLOCA_H
+#   include <alloca.h>
+#  else	/* Not HAVE_ALLOCA_H.  */
+#   ifndef _AIX
+#    ifdef WINDOWS32
+#     include <malloc.h>
+#    else
+extern char *alloca ();
+#    endif /* WINDOWS32 */
+#   endif /* Not _AIX.  */
+#  endif /* sparc or HAVE_ALLOCA_H.  */
+# endif	/* GCC.  */
+
+# define __alloca	alloca
+
+#endif
+
+#ifndef __GNU_LIBRARY__
+# define __stat stat
+# ifdef STAT_MACROS_BROKEN
+#  undef S_ISDIR
+# endif
+# ifndef S_ISDIR
+#  define S_ISDIR(mode) (((mode) & S_IFMT) == S_IFDIR)
+# endif
+#endif
+
+#ifdef _LIBC
+# include <alloca.h>
+# undef strdup
+# define strdup(str) __strdup (str)
+# define sysconf(id) __sysconf (id)
+# define closedir(dir) __closedir (dir)
+# define opendir(name) __opendir (name)
+# define readdir(str) __readdir64 (str)
+# define getpwnam_r(name, bufp, buf, len, res) \
+   __getpwnam_r (name, bufp, buf, len, res)
+# ifndef __stat64
+#  define __stat64(fname, buf) __xstat64 (_STAT_VER, fname, buf)
+# endif
+# define HAVE_STAT64	1
+#endif
+
+#ifndef HAVE_STAT64
+# define __stat64(fname, buf) __stat (fname, buf)
+/* This is the variable name we are using.  */
+# define st64 st
+#endif
+
+#if !(defined STDC_HEADERS || defined __GNU_LIBRARY__)
+# undef	size_t
+# define size_t	unsigned int
+#endif
+
+/* Some system header files erroneously define these.
+   We want our own definitions from <fnmatch.h> to take precedence.  */
+#ifndef __GNU_LIBRARY__
+# undef	FNM_PATHNAME
+# undef	FNM_NOESCAPE
+# undef	FNM_PERIOD
+#endif
+#include <fnmatch.h>
+
+/* Some system header files erroneously define these.
+   We want our own definitions from <glob.h> to take precedence.  */
+#ifndef __GNU_LIBRARY__
+# undef	GLOB_ERR
+# undef	GLOB_MARK
+# undef	GLOB_NOSORT
+# undef	GLOB_DOOFFS
+# undef	GLOB_NOCHECK
+# undef	GLOB_APPEND
+# undef	GLOB_NOESCAPE
+# undef	GLOB_PERIOD
+#endif
+#include <glob.h>
+
+#ifdef HAVE_GETLOGIN_R
+extern int getlogin_r (char *, size_t);
+#else
+extern char *getlogin (void);
+#endif
+
+static const char *next_brace_sub (const char *begin, int flags) __THROW;
+
+#endif /* GLOB_ONLY_P */
+
+static int glob_in_dir (const char *pattern, const char *directory,
+			int flags, int (*errfunc) (const char *, int),
+			glob_t *pglob);
+
+#if !defined _LIBC || !defined GLOB_ONLY_P
+static int prefix_array (const char *prefix, char **array, size_t n) __THROW;
+static int collated_compare (const __ptr_t, const __ptr_t) __THROW;
+
+
+/* Find the end of the sub-pattern in a brace expression.  */
+static const char *
+next_brace_sub (cp, flags)
+     const char *cp;
+     int flags;
+{
+  unsigned int depth = 0;
+  while (*cp != '\0')
+    if ((flags & GLOB_NOESCAPE) == 0 && *cp == '\\')
+      {
+	if (*++cp == '\0')
+	  break;
+	++cp;
+      }
+    else
+      {
+	if ((*cp == '}' && depth-- == 0) || (*cp == ',' && depth == 0))
+	  break;
+
+	if (*cp++ == '{')
+	  depth++;
+      }
+
+  return *cp != '\0' ? cp : NULL;
+}
+
+#endif /* !GLOB_ONLY_P */
+
+/* Do glob searching for PATTERN, placing results in PGLOB.
+   The bits defined above may be set in FLAGS.
+   If a directory cannot be opened or read and ERRFUNC is not nil,
+   it is called with the pathname that caused the error, and the
+   `errno' value from the failing call; if it returns non-zero
+   `glob' returns GLOB_ABORTED; if it returns zero, the error is ignored.
+   If memory cannot be allocated for PGLOB, GLOB_NOSPACE is returned.
+   Otherwise, `glob' returns zero.  */
+int
+#ifdef GLOB_ATTRIBUTE
+GLOB_ATTRIBUTE
+#endif
+glob (pattern, flags, errfunc, pglob)
+     const char *pattern;
+     int flags;
+     int (*errfunc) (const char *, int);
+     glob_t *pglob;
+{
+  const char *filename;
+  const char *dirname;
+  size_t dirlen;
+  int status;
+  size_t oldcount;
+
+  if (pattern == NULL || pglob == NULL || (flags & ~__GLOB_FLAGS) != 0)
+    {
+      __set_errno (EINVAL);
+      return -1;
+    }
+
+  if (!(flags & GLOB_DOOFFS))
+    /* Have to do this so `globfree' knows where to start freeing.  It
+       also makes all the code that uses gl_offs simpler. */
+    pglob->gl_offs = 0;
+
+  if (flags & GLOB_BRACE)
+    {
+      const char *begin;
+
+      if (flags & GLOB_NOESCAPE)
+	begin = strchr (pattern, '{');
+      else
+	{
+	  begin = pattern;
+	  while (1)
+	    {
+	      if (*begin == '\0')
+		{
+		  begin = NULL;
+		  break;
+		}
+
+	      if (*begin == '\\' && begin[1] != '\0')
+		++begin;
+	      else if (*begin == '{')
+		break;
+
+	      ++begin;
+	    }
+	}
+
+      if (begin != NULL)
+	{
+	  /* Allocate working buffer large enough for our work.  Note that
+	    we have at least an opening and closing brace.  */
+	  size_t firstc;
+	  char *alt_start;
+	  const char *p;
+	  const char *next;
+	  const char *rest;
+	  size_t rest_len;
+#ifdef __GNUC__
+	  char onealt[strlen (pattern) - 1];
+#else
+	  char *onealt = (char *) malloc (strlen (pattern) - 1);
+	  if (onealt == NULL)
+	    {
+	      if (!(flags & GLOB_APPEND))
+		{
+		  pglob->gl_pathc = 0;
+		  pglob->gl_pathv = NULL;
+		}
+	      return GLOB_NOSPACE;
+	    }
+#endif
+
+	  /* We know the prefix for all sub-patterns.  */
+#ifdef HAVE_MEMPCPY
+	  alt_start = mempcpy (onealt, pattern, begin - pattern);
+#else
+	  memcpy (onealt, pattern, begin - pattern);
+	  alt_start = &onealt[begin - pattern];
+#endif
+
+	  /* Find the first sub-pattern and at the same time find the
+	     rest after the closing brace.  */
+	  next = next_brace_sub (begin + 1, flags);
+	  if (next == NULL)
+	    {
+	      /* It is an illegal expression.  */
+#ifndef __GNUC__
+	      free (onealt);
+#endif
+	      return glob (pattern, flags & ~GLOB_BRACE, errfunc, pglob);
+	    }
+
+	  /* Now find the end of the whole brace expression.  */
+	  rest = next;
+	  while (*rest != '}')
+	    {
+	      rest = next_brace_sub (rest + 1, flags);
+	      if (rest == NULL)
+		{
+		  /* It is an illegal expression.  */
+#ifndef __GNUC__
+		  free (onealt);
+#endif
+		  return glob (pattern, flags & ~GLOB_BRACE, errfunc, pglob);
+		}
+	    }
+	  /* Please note that we now can be sure the brace expression
+	     is well-formed.  */
+	  rest_len = strlen (++rest) + 1;
+
+	  /* We have a brace expression.  BEGIN points to the opening {,
+	     NEXT points past the terminator of the first element, and END
+	     points past the final }.  We will accumulate result names from
+	     recursive runs for each brace alternative in the buffer using
+	     GLOB_APPEND.  */
+
+	  if (!(flags & GLOB_APPEND))
+	    {
+	      /* This call is to set a new vector, so clear out the
+		 vector so we can append to it.  */
+	      pglob->gl_pathc = 0;
+	      pglob->gl_pathv = NULL;
+	    }
+	  firstc = pglob->gl_pathc;
+
+	  p = begin + 1;
+	  while (1)
+	    {
+	      int result;
+
+	      /* Construct the new glob expression.  */
+#ifdef HAVE_MEMPCPY
+	      mempcpy (mempcpy (alt_start, p, next - p), rest, rest_len);
+#else
+	      memcpy (alt_start, p, next - p);
+	      memcpy (&alt_start[next - p], rest, rest_len);
+#endif
+
+	      result = glob (onealt,
+			     ((flags & ~(GLOB_NOCHECK | GLOB_NOMAGIC))
+			      | GLOB_APPEND), errfunc, pglob);
+
+	      /* If we got an error, return it.  */
+	      if (result && result != GLOB_NOMATCH)
+		{
+#ifndef __GNUC__
+		  free (onealt);
+#endif
+		  if (!(flags & GLOB_APPEND))
+		    {
+		      globfree (pglob);
+		      pglob->gl_pathc = 0;
+		    }
+		  return result;
+		}
+
+	      if (*next == '}')
+		/* We saw the last entry.  */
+		break;
+
+	      p = next + 1;
+	      next = next_brace_sub (p, flags);
+	      assert (next != NULL);
+	    }
+
+#ifndef __GNUC__
+	  free (onealt);
+#endif
+
+	  if (pglob->gl_pathc != firstc)
+	    /* We found some entries.  */
+	    return 0;
+	  else if (!(flags & (GLOB_NOCHECK|GLOB_NOMAGIC)))
+	    return GLOB_NOMATCH;
+	}
+    }
+
+  /* Find the filename.  */
+  filename = strrchr (pattern, '/');
+#if defined __MSDOS__ || defined WINDOWS32
+  /* The case of "d:pattern".  Since `:' is not allowed in
+     file names, we can safely assume that wherever it
+     happens in pattern, it signals the filename part.  This
+     is so we could some day support patterns like "[a-z]:foo".  */
+  if (filename == NULL)
+    filename = strchr (pattern, ':');
+#endif /* __MSDOS__ || WINDOWS32 */
+  if (filename == NULL)
+    {
+      /* This can mean two things: a simple name or "~name".  The latter
+	 case is nothing but a notation for a directory.  */
+      if ((flags & (GLOB_TILDE|GLOB_TILDE_CHECK)) && pattern[0] == '~')
+	{
+	  dirname = pattern;
+	  dirlen = strlen (pattern);
+
+	  /* Set FILENAME to NULL as a special flag.  This is ugly but
+	     other solutions would require much more code.  We test for
+	     this special case below.  */
+	  filename = NULL;
+	}
+      else
+	{
+	  filename = pattern;
+#ifdef _AMIGA
+	  dirname = "";
+#else
+	  dirname = ".";
+#endif
+	  dirlen = 0;
+	}
+    }
+  else if (filename == pattern)
+    {
+      /* "/pattern".  */
+      dirname = "/";
+      dirlen = 1;
+      ++filename;
+    }
+  else
+    {
+      char *newp;
+      dirlen = filename - pattern;
+#if defined __MSDOS__ || defined WINDOWS32
+      if (*filename == ':'
+	  || (filename > pattern + 1 && filename[-1] == ':'))
+	{
+	  char *drive_spec;
+
+	  ++dirlen;
+	  drive_spec = (char *) __alloca (dirlen + 1);
+#ifdef HAVE_MEMPCPY
+	  *((char *) mempcpy (drive_spec, pattern, dirlen)) = '\0';
+#else
+	  memcpy (drive_spec, pattern, dirlen);
+	  drive_spec[dirlen] = '\0';
+#endif
+	  /* For now, disallow wildcards in the drive spec, to
+	     prevent infinite recursion in glob.  */
+	  if (__glob_pattern_p (drive_spec, !(flags & GLOB_NOESCAPE)))
+	    return GLOB_NOMATCH;
+	  /* If this is "d:pattern", we need to copy `:' to DIRNAME
+	     as well.  If it's "d:/pattern", don't remove the slash
+	     from "d:/", since "d:" and "d:/" are not the same.*/
+	}
+#endif
+      newp = (char *) __alloca (dirlen + 1);
+#ifdef HAVE_MEMPCPY
+      *((char *) mempcpy (newp, pattern, dirlen)) = '\0';
+#else
+      memcpy (newp, pattern, dirlen);
+      newp[dirlen] = '\0';
+#endif
+      dirname = newp;
+      ++filename;
+
+      if (filename[0] == '\0'
+#if defined __MSDOS__ || defined WINDOWS32
+          && dirname[dirlen - 1] != ':'
+	  && (dirlen < 3 || dirname[dirlen - 2] != ':'
+	      || dirname[dirlen - 1] != '/')
+#endif
+	  && dirlen > 1)
+	/* "pattern/".  Expand "pattern", appending slashes.  */
+	{
+	  int val = glob (dirname, flags | GLOB_MARK, errfunc, pglob);
+	  if (val == 0)
+	    pglob->gl_flags = ((pglob->gl_flags & ~GLOB_MARK)
+			       | (flags & GLOB_MARK));
+	  return val;
+	}
+    }
+
+  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] == '~')
+    {
+      if (dirname[1] == '\0' || dirname[1] == '/')
+	{
+	  /* Look up home directory.  */
+	  const char *home_dir = getenv ("HOME");
+# ifdef _AMIGA
+	  if (home_dir == NULL || home_dir[0] == '\0')
+	    home_dir = "SYS:";
+# else
+#  ifdef WINDOWS32
+	  if (home_dir == NULL || home_dir[0] == '\0')
+            home_dir = "c:/users/default"; /* poor default */
+#  else
+	  if (home_dir == NULL || home_dir[0] == '\0')
+	    {
+	      int success;
+	      char *name;
+#   if defined HAVE_GETLOGIN_R || defined _LIBC
+	      size_t buflen = sysconf (_SC_LOGIN_NAME_MAX) + 1;
+
+	      if (buflen == 0)
+		/* `sysconf' does not support _SC_LOGIN_NAME_MAX.  Try
+		   a moderate value.  */
+		buflen = 20;
+	      name = (char *) __alloca (buflen);
+
+	      success = getlogin_r (name, buflen) == 0;
+#   else
+	      success = (name = getlogin ()) != NULL;
+#   endif
+	      if (success)
+		{
+		  struct passwd *p;
+#   if defined HAVE_GETPWNAM_R || defined _LIBC
+		  long int pwbuflen = sysconf (_SC_GETPW_R_SIZE_MAX);
+		  char *pwtmpbuf;
+		  struct passwd pwbuf;
+		  int save = errno;
+
+#    ifndef _LIBC
+		  if (pwbuflen == -1)
+		    /* `sysconf' does not support _SC_GETPW_R_SIZE_MAX.
+		       Try a moderate value.  */
+		    pwbuflen = 1024;
+#    endif
+		  pwtmpbuf = (char *) __alloca (pwbuflen);
+
+		  while (getpwnam_r (name, &pwbuf, pwtmpbuf, pwbuflen, &p)
+			 != 0)
+		    {
+		      if (errno != ERANGE)
+			{
+			  p = NULL;
+			  break;
+			}
+#    ifdef _LIBC
+		      pwtmpbuf = extend_alloca (pwtmpbuf, pwbuflen,
+						2 * pwbuflen);
+#    else
+		      pwbuflen *= 2;
+		      pwtmpbuf = (char *) __alloca (pwbuflen);
+#    endif
+		      __set_errno (save);
+		    }
+#   else
+		  p = getpwnam (name);
+#   endif
+		  if (p != NULL)
+		    home_dir = p->pw_dir;
+		}
+	    }
+	  if (home_dir == NULL || home_dir[0] == '\0')
+	    {
+	      if (flags & GLOB_TILDE_CHECK)
+		return GLOB_NOMATCH;
+	      else
+		home_dir = "~"; /* No luck.  */
+	    }
+#  endif /* WINDOWS32 */
+# endif
+	  /* Now construct the full directory.  */
+	  if (dirname[1] == '\0')
+	    dirname = home_dir;
+	  else
+	    {
+	      char *newp;
+	      size_t home_len = strlen (home_dir);
+	      newp = (char *) __alloca (home_len + dirlen);
+# ifdef HAVE_MEMPCPY
+	      mempcpy (mempcpy (newp, home_dir, home_len),
+		       &dirname[1], dirlen);
+# else
+	      memcpy (newp, home_dir, home_len);
+	      memcpy (&newp[home_len], &dirname[1], dirlen);
+# endif
+	      dirname = newp;
+	    }
+	}
+# if !defined _AMIGA && !defined WINDOWS32
+      else
+	{
+	  char *end_name = strchr (dirname, '/');
+	  const char *user_name;
+	  const char *home_dir;
+
+	  if (end_name == NULL)
+	    user_name = dirname + 1;
+	  else
+	    {
+	      char *newp;
+	      newp = (char *) __alloca (end_name - dirname);
+# ifdef HAVE_MEMPCPY
+	      *((char *) mempcpy (newp, dirname + 1, end_name - dirname))
+		= '\0';
+# else
+	      memcpy (newp, dirname + 1, end_name - dirname);
+	      newp[end_name - dirname - 1] = '\0';
+# endif
+	      user_name = newp;
+	    }
+
+	  /* Look up specific user's home directory.  */
+	  {
+	    struct passwd *p;
+#  if defined HAVE_GETPWNAM_R || defined _LIBC
+	    long int buflen = sysconf (_SC_GETPW_R_SIZE_MAX);
+	    char *pwtmpbuf;
+	    struct passwd pwbuf;
+	    int save = errno;
+
+#   ifndef _LIBC
+	    if (buflen == -1)
+	      /* `sysconf' does not support _SC_GETPW_R_SIZE_MAX.  Try a
+		 moderate value.  */
+	      buflen = 1024;
+#   endif
+	    pwtmpbuf = (char *) __alloca (buflen);
+
+	    while (getpwnam_r (user_name, &pwbuf, pwtmpbuf, buflen, &p) != 0)
+	      {
+		if (errno != ERANGE)
+		  {
+		    p = NULL;
+		    break;
+		  }
+#   ifdef _LIBC
+		pwtmpbuf = extend_alloca (pwtmpbuf, buflen, 2 * buflen);
+#   else
+		buflen *= 2;
+		pwtmpbuf = __alloca (buflen);
+#   endif
+		__set_errno (save);
+	      }
+#  else
+	    p = getpwnam (user_name);
+#  endif
+	    if (p != NULL)
+	      home_dir = p->pw_dir;
+	    else
+	      home_dir = NULL;
+	  }
+	  /* If we found a home directory use this.  */
+	  if (home_dir != NULL)
+	    {
+	      char *newp;
+	      size_t home_len = strlen (home_dir);
+	      size_t rest_len = end_name == NULL ? 0 : strlen (end_name);
+	      newp = (char *) __alloca (home_len + rest_len + 1);
+#  ifdef HAVE_MEMPCPY
+	      *((char *) mempcpy (mempcpy (newp, home_dir, home_len),
+				  end_name, rest_len)) = '\0';
+#  else
+	      memcpy (newp, home_dir, home_len);
+	      memcpy (&newp[home_len], end_name, rest_len);
+	      newp[home_len + rest_len] = '\0';
+#  endif
+	      dirname = newp;
+	    }
+	  else
+	    if (flags & GLOB_TILDE_CHECK)
+	      /* We have to regard it as an error if we cannot find the
+		 home directory.  */
+	      return GLOB_NOMATCH;
+	}
+# endif	/* Not Amiga && not WINDOWS32.  */
+    }
+#endif	/* Not VMS.  */
+
+  /* Now test whether we looked for "~" or "~NAME".  In this case we
+     can give the answer now.  */
+  if (filename == NULL)
+    {
+      struct stat st;
+#ifdef HAVE_STAT64
+      struct stat64 st64;
+#endif
+
+      /* Return the directory if we don't check for error or if it exists.  */
+      if ((flags & GLOB_NOCHECK)
+	  || (((flags & GLOB_ALTDIRFUNC)
+	       ? ((*pglob->gl_stat) (dirname, &st) == 0
+		  && S_ISDIR (st.st_mode))
+	       : (__stat64 (dirname, &st64) == 0 && S_ISDIR (st64.st_mode)))))
+	{
+	  int newcount = pglob->gl_pathc + pglob->gl_offs;
+	  char **new_gl_pathv;
+
+	  new_gl_pathv
+	    = (char **) realloc (pglob->gl_pathv,
+				 (newcount + 1 + 1) * sizeof (char *));
+	  if (new_gl_pathv == NULL)
+	    {
+	    nospace:
+	      free (pglob->gl_pathv);
+	      pglob->gl_pathv = NULL;
+	      pglob->gl_pathc = 0;
+	      return GLOB_NOSPACE;
+	    }
+	  pglob->gl_pathv = new_gl_pathv;
+
+#if defined HAVE_STRDUP || defined _LIBC
+	   pglob->gl_pathv[newcount] = strdup (dirname);
+#else
+	  {
+	    size_t len = strlen (dirname) + 1;
+	    char *dircopy = (char *) malloc (len);
+	    if (dircopy != NULL)
+	      pglob->gl_pathv[newcount] = memcpy (dircopy, dirname, len);
+	  }
+#endif
+	  if (pglob->gl_pathv[newcount] == NULL)
+	    goto nospace;
+	  pglob->gl_pathv[++newcount] = NULL;
+	  ++pglob->gl_pathc;
+	  pglob->gl_flags = flags;
+
+	  return 0;
+	}
+
+      /* Not found.  */
+      return GLOB_NOMATCH;
+    }
+
+  if (__glob_pattern_p (dirname, !(flags & GLOB_NOESCAPE)))
+    {
+      /* The directory name contains metacharacters, so we
+	 have to glob for the directory, and then glob for
+	 the pattern in each directory found.  */
+      glob_t dirs;
+      size_t i;
+
+      if ((flags & GLOB_ALTDIRFUNC) != 0)
+	{
+	  /* Use the alternative access functions also in the recursive
+	     call.  */
+	  dirs.gl_opendir = pglob->gl_opendir;
+	  dirs.gl_readdir = pglob->gl_readdir;
+	  dirs.gl_closedir = pglob->gl_closedir;
+	  dirs.gl_stat = pglob->gl_stat;
+	  dirs.gl_lstat = pglob->gl_lstat;
+	}
+
+      status = glob (dirname,
+		     ((flags & (GLOB_ERR | GLOB_NOCHECK | GLOB_NOESCAPE
+				| GLOB_ALTDIRFUNC))
+		      | GLOB_NOSORT | GLOB_ONLYDIR),
+		     errfunc, &dirs);
+      if (status != 0)
+	return status;
+
+      /* We have successfully globbed the preceding directory name.
+	 For each name we found, call glob_in_dir on it and FILENAME,
+	 appending the results to PGLOB.  */
+      for (i = 0; i < dirs.gl_pathc; ++i)
+	{
+	  int old_pathc;
+
+#ifdef	SHELL
+	  {
+	    /* Make globbing interruptible in the bash shell. */
+	    extern int interrupt_state;
+
+	    if (interrupt_state)
+	      {
+		globfree (&dirs);
+		return GLOB_ABORTED;
+	      }
+	  }
+#endif /* SHELL.  */
+
+	  old_pathc = pglob->gl_pathc;
+	  status = glob_in_dir (filename, dirs.gl_pathv[i],
+				((flags | GLOB_APPEND)
+				 & ~(GLOB_NOCHECK | GLOB_NOMAGIC)),
+				errfunc, pglob);
+	  if (status == GLOB_NOMATCH)
+	    /* No matches in this directory.  Try the next.  */
+	    continue;
+
+	  if (status != 0)
+	    {
+	      globfree (&dirs);
+	      globfree (pglob);
+	      pglob->gl_pathc = 0;
+	      return status;
+	    }
+
+	  /* Stick the directory on the front of each name.  */
+	  if (prefix_array (dirs.gl_pathv[i],
+			    &pglob->gl_pathv[old_pathc + pglob->gl_offs],
+			    pglob->gl_pathc - old_pathc))
+	    {
+	      globfree (&dirs);
+	      globfree (pglob);
+	      pglob->gl_pathc = 0;
+	      return GLOB_NOSPACE;
+	    }
+	}
+
+      flags |= GLOB_MAGCHAR;
+
+      /* We have ignored the GLOB_NOCHECK flag in the `glob_in_dir' calls.
+	 But if we have not found any matching entry and the GLOB_NOCHECK
+	 flag was set we must return the input pattern itself.  */
+      if (pglob->gl_pathc + pglob->gl_offs == oldcount)
+	{
+	  /* No matches.  */
+	  if (flags & GLOB_NOCHECK)
+	    {
+	      int newcount = pglob->gl_pathc + pglob->gl_offs;
+	      char **new_gl_pathv;
+
+	      new_gl_pathv = (char **) realloc (pglob->gl_pathv,
+						(newcount + 2)
+						* sizeof (char *));
+	      if (new_gl_pathv == NULL)
+		{
+		  globfree (&dirs);
+		  return GLOB_NOSPACE;
+		}
+	      pglob->gl_pathv = new_gl_pathv;
+
+	      pglob->gl_pathv[newcount] = __strdup (pattern);
+	      if (pglob->gl_pathv[newcount] == NULL)
+		{
+		  globfree (&dirs);
+		  globfree (pglob);
+		  pglob->gl_pathc = 0;
+		  return GLOB_NOSPACE;
+		}
+
+	      ++pglob->gl_pathc;
+	      ++newcount;
+
+	      pglob->gl_pathv[newcount] = NULL;
+	      pglob->gl_flags = flags;
+	    }
+	  else
+	    {
+	      globfree (&dirs);
+	      return GLOB_NOMATCH;
+	    }
+	}
+
+      globfree (&dirs);
+    }
+  else
+    {
+      int old_pathc = pglob->gl_pathc;
+
+      status = glob_in_dir (filename, dirname, flags, errfunc, pglob);
+      if (status != 0)
+	return status;
+
+      if (dirlen > 0)
+	{
+	  /* Stick the directory on the front of each name.  */
+	  if (prefix_array (dirname,
+			    &pglob->gl_pathv[old_pathc + pglob->gl_offs],
+			    pglob->gl_pathc - old_pathc))
+	    {
+	      globfree (pglob);
+	      pglob->gl_pathc = 0;
+	      return GLOB_NOSPACE;
+	    }
+	}
+    }
+
+  if (flags & GLOB_MARK)
+    {
+      /* Append slashes to directory names.  */
+      size_t i;
+      struct stat st;
+#ifdef HAVE_STAT64
+      struct stat64 st64;
+#endif
+
+      for (i = oldcount; i < pglob->gl_pathc + pglob->gl_offs; ++i)
+	if (((flags & GLOB_ALTDIRFUNC)
+	     ? ((*pglob->gl_stat) (pglob->gl_pathv[i], &st) == 0
+		&& S_ISDIR (st.st_mode))
+	     : (__stat64 (pglob->gl_pathv[i], &st64) == 0
+		&& S_ISDIR (st64.st_mode))))
+	  {
+ 	    size_t len = strlen (pglob->gl_pathv[i]) + 2;
+	    char *new = realloc (pglob->gl_pathv[i], len);
+ 	    if (new == NULL)
+	      {
+		globfree (pglob);
+		pglob->gl_pathc = 0;
+		return GLOB_NOSPACE;
+	      }
+	    strcpy (&new[len - 2], "/");
+	    pglob->gl_pathv[i] = new;
+	  }
+    }
+
+  if (!(flags & GLOB_NOSORT))
+    {
+      /* Sort the vector.  */
+      qsort ((__ptr_t) &pglob->gl_pathv[oldcount],
+	     pglob->gl_pathc + pglob->gl_offs - oldcount,
+	     sizeof (char *), collated_compare);
+    }
+
+  return 0;
+}
+#if defined _LIBC && !defined glob
+libc_hidden_def (glob)
+#endif
+
+
+#if !defined _LIBC || !defined GLOB_ONLY_P
+
+/* Free storage allocated in PGLOB by a previous `glob' call.  */
+void
+globfree (pglob)
+     register glob_t *pglob;
+{
+  if (pglob->gl_pathv != NULL)
+    {
+      size_t i;
+      for (i = 0; i < pglob->gl_pathc; ++i)
+	if (pglob->gl_pathv[pglob->gl_offs + i] != NULL)
+	  free ((__ptr_t) pglob->gl_pathv[pglob->gl_offs + i]);
+      free ((__ptr_t) pglob->gl_pathv);
+      pglob->gl_pathv = NULL;
+    }
+}
+#if defined _LIBC && !defined globfree
+libc_hidden_def (globfree)
+#endif
+
+
+/* Do a collated comparison of A and B.  */
+static int
+collated_compare (a, b)
+     const __ptr_t a;
+     const __ptr_t b;
+{
+  const char *const s1 = *(const char *const * const) a;
+  const char *const s2 = *(const char *const * const) b;
+
+  if (s1 == s2)
+    return 0;
+  if (s1 == NULL)
+    return 1;
+  if (s2 == NULL)
+    return -1;
+  return strcoll (s1, s2);
+}
+
+
+/* Prepend DIRNAME to each of N members of ARRAY, replacing ARRAY's
+   elements in place.  Return nonzero if out of memory, zero if successful.
+   A slash is inserted between DIRNAME and each elt of ARRAY,
+   unless DIRNAME is just "/".  Each old element of ARRAY is freed.  */
+static int
+prefix_array (dirname, array, n)
+     const char *dirname;
+     char **array;
+     size_t n;
+{
+  register size_t i;
+  size_t dirlen = strlen (dirname);
+#if defined __MSDOS__ || defined WINDOWS32
+  int sep_char = '/';
+# define DIRSEP_CHAR sep_char
+#else
+# define DIRSEP_CHAR '/'
+#endif
+
+  if (dirlen == 1 && dirname[0] == '/')
+    /* DIRNAME is just "/", so normal prepending would get us "//foo".
+       We want "/foo" instead, so don't prepend any chars from DIRNAME.  */
+    dirlen = 0;
+#if defined __MSDOS__ || defined WINDOWS32
+  else if (dirlen > 1)
+    {
+      if (dirname[dirlen - 1] == '/' && dirname[dirlen - 2] == ':')
+	/* DIRNAME is "d:/".  Don't prepend the slash from DIRNAME.  */
+	--dirlen;
+      else if (dirname[dirlen - 1] == ':')
+	{
+	  /* DIRNAME is "d:".  Use `:' instead of `/'.  */
+	  --dirlen;
+	  sep_char = ':';
+	}
+    }
+#endif
+
+  for (i = 0; i < n; ++i)
+    {
+      size_t eltlen = strlen (array[i]) + 1;
+      char *new = (char *) malloc (dirlen + 1 + eltlen);
+      if (new == NULL)
+	{
+	  while (i > 0)
+	    free ((__ptr_t) array[--i]);
+	  return 1;
+	}
+
+#ifdef HAVE_MEMPCPY
+      {
+	char *endp = (char *) mempcpy (new, dirname, dirlen);
+	*endp++ = DIRSEP_CHAR;
+	mempcpy (endp, array[i], eltlen);
+      }
+#else
+      memcpy (new, dirname, dirlen);
+      new[dirlen] = DIRSEP_CHAR;
+      memcpy (&new[dirlen + 1], array[i], eltlen);
+#endif
+      free ((__ptr_t) array[i]);
+      array[i] = new;
+    }
+
+  return 0;
+}
+
+
+/* We must not compile this function twice.  */
+#if !defined _LIBC || !defined NO_GLOB_PATTERN_P
+/* Return nonzero if PATTERN contains any metacharacters.
+   Metacharacters can be quoted with backslashes if QUOTE is nonzero.  */
+int
+__glob_pattern_p (pattern, quote)
+     const char *pattern;
+     int quote;
+{
+  register const char *p;
+  int open = 0;
+
+  for (p = pattern; *p != '\0'; ++p)
+    switch (*p)
+      {
+      case '?':
+      case '*':
+	return 1;
+
+      case '\\':
+	if (quote && p[1] != '\0')
+	  ++p;
+	break;
+
+      case '[':
+	open = 1;
+	break;
+
+      case ']':
+	if (open)
+	  return 1;
+	break;
+      }
+
+  return 0;
+}
+# ifdef _LIBC
+weak_alias (__glob_pattern_p, glob_pattern_p)
+# endif
+#endif
+
+#endif /* !GLOB_ONLY_P */
+
+
+/* We put this in a separate function mainly to allow the memory
+   allocated with alloca to be recycled.  */
+#if !defined _LIBC || !defined GLOB_ONLY_P
+static int
+link_exists_p (const char *dir, size_t dirlen, const char *fname,
+	       glob_t *pglob, int flags)
+{
+  size_t fnamelen = strlen (fname);
+  char *fullname = (char *) __alloca (dirlen + 1 + fnamelen + 1);
+  struct stat st;
+  struct stat64 st64;
+
+# ifdef HAVE_MEMPCPY
+  mempcpy (mempcpy (mempcpy (fullname, dir, dirlen), "/", 1),
+	   fname, fnamelen + 1);
+# else
+  memcpy (fullname, dir, dirlen);
+  fullname[dirlen] = '/';
+  memcpy (&fullname[dirlen + 1], fname, fnamelen + 1);
+# endif
+
+  return (((flags & GLOB_ALTDIRFUNC)
+	   ? (*pglob->gl_stat) (fullname, &st)
+	   : __stat64 (fullname, &st64)) == 0);
+}
+#endif
+
+
+/* Like `glob', but PATTERN is a final pathname component,
+   and matches are searched for in DIRECTORY.
+   The GLOB_NOSORT bit in FLAGS is ignored.  No sorting is ever done.
+   The GLOB_APPEND flag is assumed to be set (always appends).  */
+static int
+glob_in_dir (pattern, directory, flags, errfunc, pglob)
+     const char *pattern;
+     const char *directory;
+     int flags;
+     int (*errfunc) (const char *, int);
+     glob_t *pglob;
+{
+  size_t dirlen = strlen (directory);
+  __ptr_t stream = NULL;
+  struct globlink
+    {
+      struct globlink *next;
+      char *name;
+    };
+  struct globlink *names = NULL;
+  size_t nfound;
+  int meta;
+  int save;
+
+  meta = __glob_pattern_p (pattern, !(flags & GLOB_NOESCAPE));
+  if (meta == 0 && (flags & (GLOB_NOCHECK|GLOB_NOMAGIC)))
+    {
+      /* We need not do any tests.  The PATTERN contains no meta
+	 characters and we must not return an error therefore the
+	 result will always contain exactly one name.  */
+      flags |= GLOB_NOCHECK;
+      nfound = 0;
+    }
+  else if (meta == 0 &&
+	   ((flags & GLOB_NOESCAPE) || strchr (pattern, '\\') == NULL))
+    {
+      /* Since we use the normal file functions we can also use stat()
+	 to verify the file is there.  */
+      struct stat st;
+# ifdef HAVE_STAT64
+      struct stat64 st64;
+# endif
+      size_t patlen = strlen (pattern);
+      char *fullname = (char *) __alloca (dirlen + 1 + patlen + 1);
+
+# ifdef HAVE_MEMPCPY
+      mempcpy (mempcpy (mempcpy (fullname, directory, dirlen),
+			"/", 1),
+	       pattern, patlen + 1);
+# else
+      memcpy (fullname, directory, dirlen);
+      fullname[dirlen] = '/';
+      memcpy (&fullname[dirlen + 1], pattern, patlen + 1);
+# endif
+      if (((flags & GLOB_ALTDIRFUNC)
+	   ? (*pglob->gl_stat) (fullname, &st)
+	   : __stat64 (fullname, &st64)) == 0)
+	/* We found this file to be existing.  Now tell the rest
+	   of the function to copy this name into the result.  */
+	flags |= GLOB_NOCHECK;
+
+      nfound = 0;
+    }
+  else
+    {
+      if (pattern[0] == '\0')
+	{
+	  /* This is a special case for matching directories like in
+	     "*a/".  */
+	  names = (struct globlink *) __alloca (sizeof (struct globlink));
+	  names->name = (char *) malloc (1);
+	  if (names->name == NULL)
+	    goto memory_error;
+	  names->name[0] = '\0';
+	  names->next = NULL;
+	  nfound = 1;
+	  meta = 0;
+	}
+      else
+	{
+	  stream = ((flags & GLOB_ALTDIRFUNC)
+		    ? (*pglob->gl_opendir) (directory)
+		    : (__ptr_t) opendir (directory));
+	  if (stream == NULL)
+	    {
+	      if (errno != ENOTDIR
+		  && ((errfunc != NULL && (*errfunc) (directory, errno))
+		      || (flags & GLOB_ERR)))
+		return GLOB_ABORTED;
+	      nfound = 0;
+	      meta = 0;
+	    }
+	  else
+	    {
+	      int fnm_flags = ((!(flags & GLOB_PERIOD) ? FNM_PERIOD : 0)
+			       | ((flags & GLOB_NOESCAPE) ? FNM_NOESCAPE : 0)
+#if defined _AMIGA || defined VMS
+			       | FNM_CASEFOLD
+#endif
+			       );
+	      nfound = 0;
+	      flags |= GLOB_MAGCHAR;
+
+	      while (1)
+		{
+		  const char *name;
+		  size_t len;
+#if defined HAVE_DIRENT64 && !defined COMPILE_GLOB64
+		  struct dirent64 *d;
+		  union
+		    {
+		      struct dirent64 d64;
+		      char room [offsetof (struct dirent64, d_name[0])
+				 + NAME_MAX + 1];
+		    }
+		  d64buf;
+
+		  if (flags & GLOB_ALTDIRFUNC)
+		    {
+		      struct dirent *d32 = (*pglob->gl_readdir) (stream);
+		      if (d32 != NULL)
+			{
+			  CONVERT_DIRENT_DIRENT64 (&d64buf.d64, d32);
+			  d = &d64buf.d64;
+			}
+		      else
+			d = NULL;
+		    }
+		  else
+		    d = __readdir64 ((DIR *) stream);
+#else
+		  struct dirent *d = ((flags & GLOB_ALTDIRFUNC)
+				      ? ((struct dirent *)
+					 (*pglob->gl_readdir) (stream))
+				      : __readdir ((DIR *) stream));
+#endif
+		  if (d == NULL)
+		    break;
+		  if (! REAL_DIR_ENTRY (d))
+		    continue;
+
+#ifdef HAVE_D_TYPE
+		  /* If we shall match only directories use the information
+		     provided by the dirent call if possible.  */
+		  if ((flags & GLOB_ONLYDIR)
+		      && d->d_type != DT_UNKNOWN
+		      && d->d_type != DT_DIR
+		      && d->d_type != DT_LNK)
+		    continue;
+#endif
+
+		  name = d->d_name;
+
+		  if (fnmatch (pattern, name, fnm_flags) == 0)
+		    {
+		      /* If the file we found is a symlink we have to
+			 make sure the target file exists.  */
+		      if (
+#ifdef HAVE_D_TYPE
+			  (d->d_type != DT_UNKNOWN && d->d_type != DT_LNK) ||
+#endif
+			  link_exists_p (directory, dirlen, name, pglob,
+					 flags))
+			{
+			  struct globlink *new = (struct globlink *)
+			    __alloca (sizeof (struct globlink));
+			  len = NAMLEN (d);
+			  new->name = (char *) malloc (len + 1);
+			  if (new->name == NULL)
+			    goto memory_error;
+#ifdef HAVE_MEMPCPY
+			  *((char *) mempcpy ((__ptr_t) new->name, name, len))
+			    = '\0';
+#else
+			  memcpy ((__ptr_t) new->name, name, len);
+			  new->name[len] = '\0';
+#endif
+			  new->next = names;
+			  names = new;
+			  ++nfound;
+			}
+		    }
+		}
+	    }
+	}
+    }
+
+  if (nfound == 0 && (flags & GLOB_NOCHECK))
+    {
+      size_t len = strlen (pattern);
+      nfound = 1;
+      names = (struct globlink *) __alloca (sizeof (struct globlink));
+      names->next = NULL;
+      names->name = (char *) malloc (len + 1);
+      if (names->name == NULL)
+	goto memory_error;
+#ifdef HAVE_MEMPCPY
+      *((char *) mempcpy (names->name, pattern, len)) = '\0';
+#else
+      memcpy (names->name, pattern, len);
+      names->name[len] = '\0';
+#endif
+    }
+
+  if (nfound != 0)
+    {
+      char **new_gl_pathv;
+
+      new_gl_pathv
+	= (char **) realloc (pglob->gl_pathv,
+			     (pglob->gl_pathc + pglob->gl_offs + nfound + 1)
+			     * sizeof (char *));
+      if (new_gl_pathv == NULL)
+	goto memory_error;
+      pglob->gl_pathv = new_gl_pathv;
+
+      for (; names != NULL; names = names->next)
+	pglob->gl_pathv[pglob->gl_offs + pglob->gl_pathc++] = names->name;
+      pglob->gl_pathv[pglob->gl_offs + pglob->gl_pathc] = NULL;
+
+      pglob->gl_flags = flags;
+    }
+
+  save = errno;
+  if (stream != NULL)
+    {
+      if (flags & GLOB_ALTDIRFUNC)
+	(*pglob->gl_closedir) (stream);
+      else
+	closedir ((DIR *) stream);
+    }
+  __set_errno (save);
+
+  return nfound == 0 ? GLOB_NOMATCH : 0;
+
+ memory_error:
+  {
+    int save = errno;
+    if (flags & GLOB_ALTDIRFUNC)
+      (*pglob->gl_closedir) (stream);
+    else
+      closedir ((DIR *) stream);
+    __set_errno (save);
+  }
+  while (names != NULL)
+    {
+      if (names->name != NULL)
+	free ((__ptr_t) names->name);
+      names = names->next;
+    }
+  return GLOB_NOSPACE;
+}
+
+#endif	/* Not ELIDE_CODE.  */
diff --git a/posix/glob64.c b/posix/glob64.c
new file mode 100644
index 0000000000..2bfab74074
--- /dev/null
+++ b/posix/glob64.c
@@ -0,0 +1,54 @@
+/* Copyright (C) 1998,99,2002,2004 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 <stddef.h>
+#include <sys/types.h>
+#include <glob.h>
+#include <errno.h>
+
+/* Do glob searching for PATTERN, placing results in PGLOB.
+   The bits defined above may be set in FLAGS.
+   If a directory cannot be opened or read and ERRFUNC is not nil,
+   it is called with the pathname that caused the error, and the
+   `errno' value from the failing call; if it returns non-zero
+   `glob' returns GLOB_ABORTED; if it returns zero, the error is ignored.
+   If memory cannot be allocated for PGLOB, GLOB_NOSPACE is returned.
+   Otherwise, `glob' returns zero.  */
+int
+glob64 (const char *pattern, int flags,
+	int (*errfunc) (const char *, int), glob64_t *pglob)
+{
+  if (pattern == NULL || pglob == NULL || (flags & ~__GLOB_FLAGS) != 0)
+    {
+      __set_errno (EINVAL);
+      return -1;
+    }
+
+  __set_errno (ENOSYS);
+  return GLOB_NOSYS;
+}
+libc_hidden_def (glob64)
+
+void
+globfree64 (glob64_t *pglob)
+{
+}
+libc_hidden_def (globfree64)
+
+stub_warning (glob64)
+#include <stub-tag.h>
diff --git a/posix/group_member.c b/posix/group_member.c
new file mode 100644
index 0000000000..7bd9c46ba2
--- /dev/null
+++ b/posix/group_member.c
@@ -0,0 +1,50 @@
+/* `group_member' -- test if process is in a given group.
+   Copyright (C) 1995, 1997, 2002 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 <sys/types.h>
+#include <unistd.h>
+#include <stdlib.h>
+#include <limits.h>
+
+#ifndef NGROUPS_MAX
+#define NGROUPS_MAX	16	/* First guess.  */
+#endif
+
+int
+__group_member (gid)
+     gid_t gid;
+{
+  int n, size;
+  gid_t *groups;
+
+  size = NGROUPS_MAX;
+  do
+    {
+      groups = __alloca (size * sizeof *groups);
+      n = __getgroups (size, groups);
+      size *= 2;
+    } while (n == size / 2);
+
+  while (n >= 0)
+    if (groups[n--] == gid)
+      return 1;
+
+  return 0;
+}
+weak_alias (__group_member, group_member)
diff --git a/posix/init-posix.c b/posix/init-posix.c
new file mode 100644
index 0000000000..0c2b717e6d
--- /dev/null
+++ b/posix/init-posix.c
@@ -0,0 +1 @@
+/* Nothing to do.  */
diff --git a/posix/nanosleep.c b/posix/nanosleep.c
new file mode 100644
index 0000000000..7a2138b6f1
--- /dev/null
+++ b/posix/nanosleep.c
@@ -0,0 +1,36 @@
+/* Copyright (C) 1996, 1997, 2002 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 <errno.h>
+#include <time.h>
+
+
+/* Pause execution for a number of nanoseconds.  */
+int
+__libc_nanosleep (const struct timespec *requested_time,
+		  struct timespec *remaining)
+{
+  __set_errno (ENOSYS);
+  return -1;
+}
+stub_warning (nanosleep)
+
+weak_alias (__libc_nanosleep, __nanosleep)
+libc_hidden_def (__nanosleep)
+weak_alias (__libc_nanosleep, nanosleep)
+#include <stub-tag.h>
diff --git a/posix/pathconf.c b/posix/pathconf.c
new file mode 100644
index 0000000000..6ac5d31902
--- /dev/null
+++ b/posix/pathconf.c
@@ -0,0 +1,41 @@
+/* Copyright (C) 1991, 1995, 1996, 1997 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 <errno.h>
+#include <stddef.h>
+#include <unistd.h>
+
+
+/* Get file-specific information about PATH.  */
+long int
+__pathconf (path, name)
+     const char *path;
+     int name;
+{
+  if (path == NULL)
+    {
+      __set_errno (EINVAL);
+      return -1;
+    }
+  return __fpathconf (0, name);
+}
+
+weak_alias (__pathconf, pathconf)
+
+stub_warning (pathconf)
+#include <stub-tag.h>
diff --git a/posix/pause.c b/posix/pause.c
new file mode 100644
index 0000000000..2e34b436f1
--- /dev/null
+++ b/posix/pause.c
@@ -0,0 +1,34 @@
+/* Copyright (C) 1991, 1996, 1997 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 <errno.h>
+#include <unistd.h>
+
+
+/* Suspend the process until a signal arrives.
+   This is supposed to always return -1 and set errno to EINTR,
+   but rules were meant to be broken.  */
+int
+pause ()
+{
+  __set_errno (ENOSYS);
+  return -1;
+}
+
+stub_warning (pause)
+#include <stub-tag.h>
diff --git a/posix/posix_madvise.c b/posix/posix_madvise.c
new file mode 100644
index 0000000000..6f8d60f55f
--- /dev/null
+++ b/posix/posix_madvise.c
@@ -0,0 +1,32 @@
+/* Copyright (C) 1994, 1995, 1996, 1997, 2000 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 <sys/types.h>
+#include <sys/mman.h>
+#include <errno.h>
+
+/* Advise the system about particular usage patterns the program follows
+   for the region starting at ADDR and extending LEN bytes.  */
+
+int
+posix_madvise (__ptr_t addr, size_t len, int advice)
+{
+  return ENOSYS;
+}
+stub_warning (posix_madvise)
+#include <stub-tag.h>
diff --git a/posix/pread.c b/posix/pread.c
new file mode 100644
index 0000000000..5c79dd526d
--- /dev/null
+++ b/posix/pread.c
@@ -0,0 +1,46 @@
+/* Copyright (C) 1991, 1995, 1996, 1997, 1999 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 <errno.h>
+#include <unistd.h>
+
+/* Read NBYTES into BUF from FD at the given position OFFSET without
+   changing the file pointer.  Return the number read or -1.  */
+ssize_t
+__libc_pread (int fd, void *buf, size_t nbytes, off_t offset)
+{
+  if (nbytes == 0)
+    return 0;
+  if (fd < 0)
+    {
+      __set_errno (EBADF);
+      return -1;
+    }
+  if (buf == NULL || offset < 0)
+    {
+      __set_errno (EINVAL);
+      return -1;
+    }
+
+  __set_errno (ENOSYS);
+  return -1;
+}
+strong_alias (__libc_pread, __pread)
+weak_alias (__libc_pread, pread)
+stub_warning (pread)
+#include <stub-tag.h>
diff --git a/posix/pread64.c b/posix/pread64.c
new file mode 100644
index 0000000000..68316579c6
--- /dev/null
+++ b/posix/pread64.c
@@ -0,0 +1,46 @@
+/* Copyright (C) 1991, 1995, 1996, 1997, 1999 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 <errno.h>
+#include <unistd.h>
+
+/* Read NBYTES into BUF from FD at the given position OFFSET without
+   changing the file pointer.  Return the number read or -1.  */
+ssize_t
+__libc_pread64 (int fd, void *buf, size_t nbytes, off64_t offset)
+{
+  if (nbytes == 0)
+    return 0;
+  if (fd < 0)
+    {
+      __set_errno (EBADF);
+      return -1;
+    }
+  if (buf == NULL || offset < 0)
+    {
+      __set_errno (EINVAL);
+      return -1;
+    }
+
+  __set_errno (ENOSYS);
+  return -1;
+}
+strong_alias (__libc_pread64, __pread64)
+weak_alias (__libc_pread64, pread64)
+stub_warning (pread64)
+#include <stub-tag.h>
diff --git a/posix/pwrite.c b/posix/pwrite.c
new file mode 100644
index 0000000000..ec35ecea9c
--- /dev/null
+++ b/posix/pwrite.c
@@ -0,0 +1,46 @@
+/* Copyright (C) 1991, 1995, 1996, 1997, 1999 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 <errno.h>
+#include <unistd.h>
+
+/* Write NBYTES of BUF to FD at given position OFFSET without changing
+   the file position.  Return the number written, or -1.  */
+ssize_t
+__libc_pwrite (int fd, const void *buf, size_t nbytes, off_t offset)
+{
+  if (nbytes == 0)
+    return 0;
+  if (fd < 0)
+    {
+      __set_errno (EBADF);
+      return -1;
+    }
+  if (buf == NULL || offset < 0)
+    {
+      __set_errno (EINVAL);
+      return -1;
+    }
+
+  __set_errno (ENOSYS);
+  return -1;
+}
+strong_alias (__libc_pwrite, __pwrite)
+weak_alias (__libc_pwrite, pwrite)
+stub_warning (pwrite)
+#include <stub-tag.h>
diff --git a/posix/pwrite64.c b/posix/pwrite64.c
new file mode 100644
index 0000000000..dd14aa0bd7
--- /dev/null
+++ b/posix/pwrite64.c
@@ -0,0 +1,47 @@
+/* Copyright (C) 1991,1995,1996,1997,1999,2002 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 <errno.h>
+#include <unistd.h>
+
+/* Write NBYTES of BUF to FD at given position OFFSET without changing
+   the file position.  Return the number written, or -1.  */
+ssize_t
+__libc_pwrite64 (int fd, const void *buf, size_t nbytes, off64_t offset)
+{
+  if (nbytes == 0)
+    return 0;
+  if (fd < 0)
+    {
+      __set_errno (EBADF);
+      return -1;
+    }
+  if (buf == NULL || offset < 0)
+    {
+      __set_errno (EINVAL);
+      return -1;
+    }
+
+  __set_errno (ENOSYS);
+  return -1;
+}
+strong_alias (__libc_pwrite64, __pwrite64)
+libc_hidden_def (__pwrite64)
+weak_alias (__libc_pwrite64, pwrite64)
+stub_warning (pwrite64)
+#include <stub-tag.h>
diff --git a/posix/sched_getaffinity.c b/posix/sched_getaffinity.c
new file mode 100644
index 0000000000..b2e452f879
--- /dev/null
+++ b/posix/sched_getaffinity.c
@@ -0,0 +1,35 @@
+/* Copyright (C) 2002, 2003, 2004 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 <errno.h>
+#include <sched.h>
+#include <sys/types.h>
+
+
+/* Retrieve the CPU affinity mask for a particular process.  */
+int
+sched_getaffinity (pid, cpusetsize, cpuset)
+     pid_t pid;
+     size_t cpusetsize;
+     cpu_set_t *cpuset;
+{
+  __set_errno (ENOSYS);
+  return -1;
+}
+stub_warning (sched_getaffinity)
+#include <stub-tag.h>
diff --git a/posix/sched_getp.c b/posix/sched_getp.c
new file mode 100644
index 0000000000..1ca77893f4
--- /dev/null
+++ b/posix/sched_getp.c
@@ -0,0 +1,34 @@
+/* Copyright (C) 1996, 1997 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 <errno.h>
+#include <sys/types.h>
+#include <sched.h>
+
+
+/* Retrieve scheduling parameters for a particular process.  */
+int
+__sched_getparam (pid_t pid, struct sched_param *param)
+{
+  __set_errno (ENOSYS);
+  return -1;
+}
+stub_warning (sched_getparam)
+
+weak_alias (__sched_getparam, sched_getparam)
+#include <stub-tag.h>
diff --git a/posix/sched_gets.c b/posix/sched_gets.c
new file mode 100644
index 0000000000..479b913f32
--- /dev/null
+++ b/posix/sched_gets.c
@@ -0,0 +1,34 @@
+/* Copyright (C) 1996, 1997 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 <errno.h>
+#include <sched.h>
+#include <sys/types.h>
+
+
+/* Retrieve scheduling algorithm for a particular purpose.  */
+int
+__sched_getscheduler (pid_t pid)
+{
+  __set_errno (ENOSYS);
+  return -1;
+}
+stub_warning (sched_getscheduler)
+
+weak_alias (__sched_getscheduler, sched_getscheduler)
+#include <stub-tag.h>
diff --git a/posix/sched_primax.c b/posix/sched_primax.c
new file mode 100644
index 0000000000..4b3c1cbe67
--- /dev/null
+++ b/posix/sched_primax.c
@@ -0,0 +1,33 @@
+/* Copyright (C) 1996, 1997 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 <errno.h>
+#include <sched.h>
+
+
+/* Get maximum priority value for a scheduler.  */
+int
+__sched_get_priority_max (int algorithm)
+{
+  __set_errno (ENOSYS);
+  return -1;
+}
+stub_warning (sched_get_priority_max)
+
+weak_alias (__sched_get_priority_max, sched_get_priority_max)
+#include <stub-tag.h>
diff --git a/posix/sched_primin.c b/posix/sched_primin.c
new file mode 100644
index 0000000000..813b8f63ca
--- /dev/null
+++ b/posix/sched_primin.c
@@ -0,0 +1,33 @@
+/* Copyright (C) 1996, 1997 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 <errno.h>
+#include <sched.h>
+
+
+/* Get minimum priority value for a scheduler.  */
+int
+__sched_get_priority_min (int algorithm)
+{
+  __set_errno (ENOSYS);
+  return -1;
+}
+stub_warning (sched_get_priority_min)
+
+weak_alias (__sched_get_priority_min, sched_get_priority_min)
+#include <stub-tag.h>
diff --git a/posix/sched_rr_gi.c b/posix/sched_rr_gi.c
new file mode 100644
index 0000000000..f8fec63617
--- /dev/null
+++ b/posix/sched_rr_gi.c
@@ -0,0 +1,34 @@
+/* Copyright (C) 1996, 1997 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 <errno.h>
+#include <sched.h>
+#include <sys/types.h>
+
+
+/* Get the SCHED_RR interval for the named process.  */
+int
+__sched_rr_get_interval (pid_t pid, struct timespec *t)
+{
+  __set_errno (ENOSYS);
+  return -1;
+}
+stub_warning (sched_rr_get_interval)
+
+weak_alias (__sched_rr_get_interval, sched_rr_get_interval)
+#include <stub-tag.h>
diff --git a/posix/sched_setaffinity.c b/posix/sched_setaffinity.c
new file mode 100644
index 0000000000..652163db85
--- /dev/null
+++ b/posix/sched_setaffinity.c
@@ -0,0 +1,35 @@
+/* Copyright (C) 2002, 2003, 2004 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 <errno.h>
+#include <sys/types.h>
+#include <sched.h>
+
+
+/* Retrieve the CPU affinity mask for a particular process.  */
+int
+sched_setaffinity (pid, cpusetsize, cpuset)
+     pid_t pid;
+     size_t cpusetsize;
+     const cpu_set_t *cpuset;
+{
+  __set_errno (ENOSYS);
+  return -1;
+}
+stub_warning (sched_setaffinity)
+#include <stub-tag.h>
diff --git a/posix/sched_setp.c b/posix/sched_setp.c
new file mode 100644
index 0000000000..cc451fc131
--- /dev/null
+++ b/posix/sched_setp.c
@@ -0,0 +1,34 @@
+/* Copyright (C) 1996, 1997 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 <errno.h>
+#include <sys/types.h>
+#include <sched.h>
+
+
+/* Set scheduling parameters for a process.  */
+int
+__sched_setparam (pid_t pid, const struct sched_param *param)
+{
+  __set_errno (ENOSYS);
+  return -1;
+}
+stub_warning (sched_setparam)
+
+weak_alias (__sched_setparam, sched_setparam)
+#include <stub-tag.h>
diff --git a/posix/sched_sets.c b/posix/sched_sets.c
new file mode 100644
index 0000000000..631cac228b
--- /dev/null
+++ b/posix/sched_sets.c
@@ -0,0 +1,35 @@
+/* Copyright (C) 1996, 1997, 2002 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 <errno.h>
+#include <sched.h>
+#include <sys/types.h>
+
+
+/* Set scheduling algorithm and/or parameters for a process.  */
+int
+__sched_setscheduler (pid_t pid, int policy, const struct sched_param *param)
+{
+  __set_errno (ENOSYS);
+  return -1;
+}
+libc_hidden_def (__sched_setscheduler)
+stub_warning (sched_setscheduler)
+
+weak_alias (__sched_setscheduler, sched_setscheduler)
+#include <stub-tag.h>
diff --git a/posix/sched_yield.c b/posix/sched_yield.c
new file mode 100644
index 0000000000..ce41ce9b6f
--- /dev/null
+++ b/posix/sched_yield.c
@@ -0,0 +1,33 @@
+/* Copyright (C) 1996, 1997 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 <errno.h>
+#include <sched.h>
+
+
+/* Yield the processor.  */
+int
+__sched_yield (void)
+{
+  __set_errno (ENOSYS);
+  return -1;
+}
+stub_warning (sched_yield)
+
+weak_alias (__sched_yield, sched_yield)
+#include <stub-tag.h>
diff --git a/posix/setgid.c b/posix/setgid.c
new file mode 100644
index 0000000000..05c2cc6621
--- /dev/null
+++ b/posix/setgid.c
@@ -0,0 +1,37 @@
+/* Copyright (C) 1991, 1993, 1995, 1996, 1997 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 <errno.h>
+#include <unistd.h>
+#include <sys/types.h>
+
+/* Set the group ID of the calling process to GID.
+   If the calling process is the super-user, the real
+   and effective group IDs, and the saved set-group-ID to GID;
+   if not, the effective group ID is set to GID.  */
+int
+__setgid (gid)
+     gid_t gid;
+{
+  __set_errno (ENOSYS);
+  return -1;
+}
+stub_warning (setgid)
+
+weak_alias (__setgid, setgid)
+#include <stub-tag.h>
diff --git a/posix/setlogin.c b/posix/setlogin.c
new file mode 100644
index 0000000000..c16e29dd9e
--- /dev/null
+++ b/posix/setlogin.c
@@ -0,0 +1,32 @@
+/* Copyright (C) 1991, 1995, 1996, 1997 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 <errno.h>
+#include <unistd.h>
+
+/* Set the login name returned by `getlogin'.  */
+int
+setlogin (name)
+     const char *name;
+{
+  __set_errno (ENOSYS);
+  return -1;
+}
+
+stub_warning (setlogin)
+#include <stub-tag.h>
diff --git a/posix/setpgid.c b/posix/setpgid.c
new file mode 100644
index 0000000000..cb2abf1159
--- /dev/null
+++ b/posix/setpgid.c
@@ -0,0 +1,37 @@
+/* Copyright (C) 1991, 1995, 1996, 1997, 2002 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 <errno.h>
+#include <unistd.h>
+
+/* Set the process group ID of the process matching PID to PGID.
+   If PID is zero, the current process's process group ID is set.
+   If PGID is zero, the process ID of the process is used.  */
+int
+__setpgid (pid, pgid)
+     int pid;
+     int pgid;
+{
+  __set_errno (ENOSYS);
+  return -1;
+}
+libc_hidden_def (__setpgid)
+stub_warning (setpgid)
+
+weak_alias (__setpgid, setpgid)
+#include <stub-tag.h>
diff --git a/posix/setpgrp.c b/posix/setpgrp.c
new file mode 100644
index 0000000000..8ceb159341
--- /dev/null
+++ b/posix/setpgrp.c
@@ -0,0 +1,25 @@
+/* Copyright (C) 1996, 1997, 1998 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 <unistd.h>
+
+int
+setpgrp ()
+{
+  return __setpgid (0, 0);
+}
diff --git a/posix/setresgid.c b/posix/setresgid.c
new file mode 100644
index 0000000000..78e308c5d0
--- /dev/null
+++ b/posix/setresgid.c
@@ -0,0 +1,35 @@
+/* setresgid -- set effective group ID, real group ID, and saved-set group ID
+   Copyright (C) 2002 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 <errno.h>
+#include <unistd.h>
+
+/* Set the effective group ID, real group ID, and saved-set group ID,
+   of the calling process to EGID, RGID, and SGID, respectively.  */
+int
+__setresgid (gid_t egid, gid_t rgid, gid_t sgid)
+{
+  __set_errno (ENOSYS);
+  return -1;
+}
+libc_hidden_def (__setresgid)
+stub_warning (setresgid)
+
+weak_alias (__setresgid, setresgid)
+#include <stub-tag.h>
diff --git a/posix/setresuid.c b/posix/setresuid.c
new file mode 100644
index 0000000000..430b63b2fd
--- /dev/null
+++ b/posix/setresuid.c
@@ -0,0 +1,35 @@
+/* setresuid -- set effective user ID, real user ID, and saved-set user ID
+   Copyright (C) 2002 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 <errno.h>
+#include <unistd.h>
+
+/* Set the effective user ID, real user ID, and saved-set user ID,
+   of the calling process to EUID, RUID, and SUID, respectively.  */
+int
+__setresuid (uid_t euid, uid_t ruid, uid_t suid)
+{
+  __set_errno (ENOSYS);
+  return -1;
+}
+libc_hidden_def (__setresuid)
+stub_warning (setresuid)
+
+weak_alias (__setresuid, setresuid)
+#include <stub-tag.h>
diff --git a/posix/setsid.c b/posix/setsid.c
new file mode 100644
index 0000000000..6a6712b9bd
--- /dev/null
+++ b/posix/setsid.c
@@ -0,0 +1,35 @@
+/* Copyright (C) 1991, 1995, 1996, 1997 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 <errno.h>
+#include <unistd.h>
+
+
+/* Create a new session with the calling process as its leader.
+   The process group IDs of the session and the calling process
+   are set to the process ID of the calling process, which is returned.  */
+int
+__setsid ()
+{
+  __set_errno (ENOSYS);
+  return -1;
+}
+stub_warning (setsid)
+
+weak_alias (__setsid, setsid)
+#include <stub-tag.h>
diff --git a/posix/setuid.c b/posix/setuid.c
new file mode 100644
index 0000000000..96c3e01cb9
--- /dev/null
+++ b/posix/setuid.c
@@ -0,0 +1,37 @@
+/* Copyright (C) 1991, 1993, 1995, 1996, 1997 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 <errno.h>
+#include <unistd.h>
+#include <sys/types.h>
+
+/* Set the user ID of the calling process to UID.
+   If the calling process is the super-user, the real
+   and effective user IDs, and the saved set-user-ID to UID;
+   if not, the effective user ID is set to UID.  */
+int
+__setuid (uid)
+     uid_t uid;
+{
+  __set_errno (ENOSYS);
+  return -1;
+}
+stub_warning (setuid)
+
+weak_alias (__setuid, setuid)
+#include <stub-tag.h>
diff --git a/posix/sleep.c b/posix/sleep.c
new file mode 100644
index 0000000000..f9d2a6593f
--- /dev/null
+++ b/posix/sleep.c
@@ -0,0 +1,41 @@
+/* Copyright (C) 1991, 1992, 1995, 1996, 1997 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 <signal.h>
+#include <time.h>
+#include <unistd.h>
+#include <errno.h>
+
+/* Make the process sleep for SECONDS seconds, or until a signal arrives
+   and is not ignored.  The function returns the number of seconds less
+   than SECONDS which it actually slept (zero if it slept the full time).
+   If a signal handler does a `longjmp' or modifies the handling of the
+   SIGALRM signal while inside `sleep' call, the handling of the SIGALRM
+   signal afterwards is undefined.  There is no return value to indicate
+   error, but if `sleep' returns SECONDS, it probably didn't work.  */
+unsigned int
+__sleep (seconds)
+     unsigned int seconds;
+{
+  __set_errno (ENOSYS);
+  return seconds;
+}
+weak_alias (__sleep, sleep)
+
+stub_warning (sleep)
+#include <stub-tag.h>
diff --git a/posix/spawni.c b/posix/spawni.c
new file mode 100644
index 0000000000..c7d5f59ffc
--- /dev/null
+++ b/posix/spawni.c
@@ -0,0 +1,46 @@
+/* Guts of POSIX spawn interface.  Stub version.
+   Copyright (C) 2001 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 <errno.h>
+#include <spawn.h>
+#include "spawn_int.h"
+
+
+/* The Unix standard contains a long explanation of the way to signal
+   an error after the fork() was successful.  Since no new wait status
+   was wanted there is no way to signal an error using one of the
+   available methods.  The committee chose to signal an error by a
+   normal program exit with the exit code 127.  */
+#define SPAWN_ERROR	127
+
+
+/* Spawn a new process executing PATH with the attributes describes in *ATTRP.
+   Before running the process perform the actions described in FILE-ACTIONS. */
+int
+__spawni (pid_t *pid, const char *file,
+	  const posix_spawn_file_actions_t *file_actions,
+	  const posix_spawnattr_t *attrp, char *const argv[],
+	  char *const envp[], int use_path)
+{
+  __set_errno (ENOSYS);
+  return -1;
+}
+
+stub_warning (__spawni)
+#include <stub-tag.h>
diff --git a/posix/sysconf.c b/posix/sysconf.c
new file mode 100644
index 0000000000..f22685cb29
--- /dev/null
+++ b/posix/sysconf.c
@@ -0,0 +1,273 @@
+/* Copyright (C) 1991,1993,1995-1997,2001,2002,2003
+   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 <errno.h>
+#include <grp.h>
+#include <pwd.h>
+#include <stdio.h>
+#include <unistd.h>
+#include <time.h>
+#include <limits.h>
+#include <sys/param.h>
+#include <sys/sysinfo.h>
+
+
+/* Get the value of the system variable NAME.  */
+long int
+__sysconf (name)
+     int name;
+{
+  switch (name)
+    {
+    default:
+      __set_errno (EINVAL);
+      return -1;
+
+    case _SC_TZNAME_MAX:
+      return MAX (__tzname_max (), _POSIX_TZNAME_MAX);
+
+    case _SC_CHARCLASS_NAME_MAX:
+#ifdef	CHARCLASS_NAME_MAX
+      return CHARCLASS_NAME_MAX;
+#else
+      return -1;
+#endif
+
+    case _SC_COLL_WEIGHTS_MAX:
+#ifdef	COLL_WEIGHTS_MAX
+      return COLL_WEIGHTS_MAX;
+#else
+      return -1;
+#endif
+
+    case _SC_EQUIV_CLASS_MAX:
+#ifdef	EQUIV_CLASS_MAX
+      return EQUIV_CLASS_MAX;
+#else
+      return -1;
+#endif
+
+    case _SC_2_LOCALEDEF:
+#ifdef	_POSIX2_LOCALEDEF
+      return _POSIX2_LOCALEDEF;
+#else
+      return -1;
+#endif
+
+    case _SC_NPROCESSORS_CONF:
+      return __get_nprocs_conf ();
+
+    case _SC_NPROCESSORS_ONLN:
+      return __get_nprocs ();
+
+    case _SC_PHYS_PAGES:
+      return __get_phys_pages ();
+
+    case _SC_AVPHYS_PAGES:
+      return __get_avphys_pages ();
+
+    case _SC_ATEXIT_MAX:
+      /* We have no limit since we use lists.  */
+      return INT_MAX;
+
+    case _SC_PASS_MAX:
+      /* We have no limit but since the return value might be used to
+	 allocate a buffer we restrict the value.  */
+      return BUFSIZ;
+
+    case _SC_CHAR_BIT:
+      return CHAR_BIT;
+
+    case _SC_CHAR_MAX:
+      return CHAR_MAX;
+
+    case _SC_CHAR_MIN:
+      return CHAR_MIN;
+
+    case _SC_INT_MAX:
+      return INT_MAX;
+
+    case _SC_INT_MIN:
+      return INT_MIN;
+
+    case _SC_LONG_BIT:
+      return sizeof (long int) * CHAR_BIT;
+
+    case _SC_WORD_BIT:
+      return sizeof (int) * CHAR_BIT;
+
+    case _SC_MB_LEN_MAX:
+      return MB_LEN_MAX;
+
+    case _SC_NZERO:
+      return NZERO;
+
+    case _SC_SSIZE_MAX:
+      return _POSIX_SSIZE_MAX;
+
+    case _SC_SCHAR_MAX:
+      return SCHAR_MAX;
+
+    case _SC_SCHAR_MIN:
+      return SCHAR_MIN;
+
+    case _SC_SHRT_MAX:
+      return SHRT_MAX;
+
+    case _SC_SHRT_MIN:
+      return SHRT_MIN;
+
+    case _SC_UCHAR_MAX:
+      return UCHAR_MAX;
+
+    case _SC_UINT_MAX:
+      return UINT_MAX;
+
+    case _SC_ULONG_MAX:
+      return ULONG_MAX;
+
+    case _SC_USHRT_MAX:
+      return USHRT_MAX;
+
+    case _SC_GETGR_R_SIZE_MAX:
+      return NSS_BUFLEN_GROUP;
+
+    case _SC_GETPW_R_SIZE_MAX:
+      return NSS_BUFLEN_PASSWD;
+
+    case _SC_ARG_MAX:
+    case _SC_CHILD_MAX:
+    case _SC_CLK_TCK:
+    case _SC_NGROUPS_MAX:
+    case _SC_OPEN_MAX:
+    case _SC_STREAM_MAX:
+    case _SC_JOB_CONTROL:
+    case _SC_SAVED_IDS:
+    case _SC_REALTIME_SIGNALS:
+    case _SC_PRIORITY_SCHEDULING:
+    case _SC_TIMERS:
+    case _SC_ASYNCHRONOUS_IO:
+    case _SC_PRIORITIZED_IO:
+    case _SC_SYNCHRONIZED_IO:
+    case _SC_FSYNC:
+    case _SC_MAPPED_FILES:
+    case _SC_MEMLOCK:
+    case _SC_MEMLOCK_RANGE:
+    case _SC_MEMORY_PROTECTION:
+    case _SC_MESSAGE_PASSING:
+    case _SC_SEMAPHORES:
+    case _SC_SHARED_MEMORY_OBJECTS:
+
+    case _SC_AIO_LISTIO_MAX:
+    case _SC_AIO_MAX:
+    case _SC_AIO_PRIO_DELTA_MAX:
+    case _SC_DELAYTIMER_MAX:
+    case _SC_MQ_OPEN_MAX:
+    case _SC_MQ_PRIO_MAX:
+    case _SC_VERSION:
+    case _SC_PAGESIZE:
+    case _SC_RTSIG_MAX:
+    case _SC_SEM_NSEMS_MAX:
+    case _SC_SEM_VALUE_MAX:
+    case _SC_SIGQUEUE_MAX:
+    case _SC_TIMER_MAX:
+
+    case _SC_PII:
+    case _SC_PII_XTI:
+    case _SC_PII_SOCKET:
+    case _SC_PII_OSI:
+    case _SC_POLL:
+    case _SC_SELECT:
+    case _SC_UIO_MAXIOV:
+    case _SC_PII_INTERNET_STREAM:
+    case _SC_PII_INTERNET_DGRAM:
+    case _SC_PII_OSI_COTS:
+    case _SC_PII_OSI_CLTS:
+    case _SC_PII_OSI_M:
+    case _SC_T_IOV_MAX:
+
+    case _SC_BC_BASE_MAX:
+    case _SC_BC_DIM_MAX:
+    case _SC_BC_SCALE_MAX:
+    case _SC_BC_STRING_MAX:
+    case _SC_EXPR_NEST_MAX:
+    case _SC_LINE_MAX:
+    case _SC_RE_DUP_MAX:
+    case _SC_2_VERSION:
+    case _SC_2_C_BIND:
+    case _SC_2_C_DEV:
+    case _SC_2_FORT_DEV:
+    case _SC_2_SW_DEV:
+    case _SC_2_CHAR_TERM:
+    case _SC_2_C_VERSION:
+    case _SC_2_UPE:
+
+    case _SC_THREADS:
+    case _SC_THREAD_SAFE_FUNCTIONS:
+    case _SC_LOGIN_NAME_MAX:
+    case _SC_TTY_NAME_MAX:
+    case _SC_THREAD_DESTRUCTOR_ITERATIONS:
+    case _SC_THREAD_KEYS_MAX:
+    case _SC_THREAD_STACK_MIN:
+    case _SC_THREAD_THREADS_MAX:
+    case _SC_THREAD_ATTR_STACKADDR:
+    case _SC_THREAD_ATTR_STACKSIZE:
+    case _SC_THREAD_PRIORITY_SCHEDULING:
+    case _SC_THREAD_PRIO_INHERIT:
+    case _SC_THREAD_PRIO_PROTECT:
+    case _SC_THREAD_PROCESS_SHARED:
+
+    case _SC_XOPEN_VERSION:
+    case _SC_XOPEN_XCU_VERSION:
+    case _SC_XOPEN_UNIX:
+    case _SC_XOPEN_CRYPT:
+    case _SC_XOPEN_ENH_I18N:
+    case _SC_XOPEN_SHM:
+    case _SC_XOPEN_XPG2:
+    case _SC_XOPEN_XPG3:
+    case _SC_XOPEN_XPG4:
+
+    case _SC_NL_ARGMAX:
+    case _SC_NL_LANGMAX:
+    case _SC_NL_MSGMAX:
+    case _SC_NL_NMAX:
+    case _SC_NL_SETMAX:
+    case _SC_NL_TEXTMAX:
+
+    case _SC_XBS5_ILP32_OFF32:
+    case _SC_XBS5_ILP32_OFFBIG:
+    case _SC_XBS5_LP64_OFF64:
+    case _SC_XBS5_LPBIG_OFFBIG:
+
+    case _SC_XOPEN_LEGACY:
+    case _SC_XOPEN_REALTIME:
+    case _SC_XOPEN_REALTIME_THREADS:
+
+      break;
+    }
+
+  __set_errno (ENOSYS);
+  return -1;
+}
+
+weak_alias (__sysconf, sysconf)
+libc_hidden_def (__sysconf)
+
+stub_warning (sysconf)
+#include <stub-tag.h>
diff --git a/posix/times.c b/posix/times.c
new file mode 100644
index 0000000000..b4e08156ae
--- /dev/null
+++ b/posix/times.c
@@ -0,0 +1,43 @@
+/* Copyright (C) 1991, 1995, 1996, 1997 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 <errno.h>
+#include <sys/times.h>
+#include <stddef.h>
+
+/* Store the CPU time used by this process and all its
+   dead children (and their dead children) in BUFFER.
+   Return the elapsed real time, or (clock_t) -1 for errors.
+   All times are in CLK_TCKths of a second.  */
+clock_t
+__times (buffer)
+     struct tms *buffer;
+{
+  if (buffer == NULL)
+    {
+      __set_errno (EINVAL);
+      return (clock_t) -1;
+    }
+
+  __set_errno (ENOSYS);
+  return (clock_t) -1;
+}
+stub_warning (times)
+
+weak_alias (__times, times)
+#include <stub-tag.h>
diff --git a/posix/uname.c b/posix/uname.c
new file mode 100644
index 0000000000..e7c41648ed
--- /dev/null
+++ b/posix/uname.c
@@ -0,0 +1,66 @@
+/* Copyright (C) 1991,92,96,97,2000,02 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 <errno.h>
+#include <string.h>
+#include <sys/utsname.h>
+#include <unistd.h>
+
+/* This file is created by the configuration process, and defines UNAME_*.  */
+#include <config-name.h>
+
+/* Put information about the system in NAME.  */
+int
+__uname (name)
+     struct utsname *name;
+{
+  int save;
+
+  if (name == NULL)
+    {
+      __set_errno (EINVAL);
+      return -1;
+    }
+
+  save = errno;
+  if (__gethostname (name->nodename, sizeof (name->nodename)) < 0)
+    {
+      if (errno == ENOSYS)
+	{
+	  /* Hostname is meaningless for this machine.  */
+	  name->nodename[0] = '\0';
+	  __set_errno (save);
+	}
+#ifdef	ENAMETOOLONG
+      else if (errno == ENAMETOOLONG)
+	/* The name was truncated.  */
+	__set_errno (save);
+#endif
+      else
+	return -1;
+    }
+  strncpy (name->sysname, UNAME_SYSNAME, sizeof (name->sysname));
+  strncpy (name->release, UNAME_RELEASE, sizeof (name->release));
+  strncpy (name->version, UNAME_VERSION, sizeof (name->version));
+  strncpy (name->machine, UNAME_MACHINE, sizeof (name->machine));
+
+  return 0;
+}
+weak_alias (__uname, uname)
+libc_hidden_def (__uname)
+libc_hidden_def (uname)
diff --git a/posix/vfork.c b/posix/vfork.c
new file mode 100644
index 0000000000..d15841d712
--- /dev/null
+++ b/posix/vfork.c
@@ -0,0 +1,31 @@
+/* Copyright (C) 1992, 1995, 1997, 2000, 2002 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 <errno.h>
+#include <unistd.h>
+
+/* If we don't have vfork, fork is close enough.  */
+
+__pid_t
+__vfork (void)
+{
+  return __fork ();
+}
+libc_hidden_def (__vfork)
+
+weak_alias (__vfork, vfork)
diff --git a/posix/wait.c b/posix/wait.c
new file mode 100644
index 0000000000..b1c512ed39
--- /dev/null
+++ b/posix/wait.c
@@ -0,0 +1,33 @@
+/* Copyright (C) 1991, 1995, 1996, 1997 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 <sys/wait.h>
+#include <errno.h>
+
+/* Wait for a child to die.  When one does, put its status in *STAT_LOC
+   and return its process ID.  For errors, return (pid_t) -1.  */
+__pid_t
+__wait (__WAIT_STATUS_DEFN stat_loc)
+{
+  __set_errno (ENOSYS);
+  return -1;
+}
+stub_warning (wait)
+
+weak_alias (__wait, wait)
+#include <stub-tag.h>
diff --git a/posix/wait3.c b/posix/wait3.c
new file mode 100644
index 0000000000..479d99e3da
--- /dev/null
+++ b/posix/wait3.c
@@ -0,0 +1,43 @@
+/* Copyright (C) 1991, 1993, 1995, 1996, 1997 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 <errno.h>
+#include <sys/wait.h>
+#include <sys/types.h>
+
+/* Wait for a child to exit.  When one does, put its status in *STAT_LOC and
+   return its process ID.  For errors return (pid_t) -1.  If USAGE is not nil,
+   store information about the child's resource usage (as a `struct rusage')
+   there.  If the WUNTRACED bit is set in OPTIONS, return status for stopped
+   children; otherwise don't.  */
+pid_t
+__wait3 (__WAIT_STATUS_DEFN stat_loc, int options, struct rusage *usage)
+{
+  if ((options & ~(WNOHANG|WUNTRACED)) != 0)
+    {
+      __set_errno (EINVAL);
+      return (pid_t) -1;
+    }
+
+  __set_errno (ENOSYS);
+  return (pid_t) -1;
+}
+stub_warning (wait3)
+
+weak_alias (__wait3, wait3)
+#include <stub-tag.h>
diff --git a/posix/wait4.c b/posix/wait4.c
new file mode 100644
index 0000000000..b59bf87ffc
--- /dev/null
+++ b/posix/wait4.c
@@ -0,0 +1,33 @@
+/* Copyright (C) 1991, 1992, 1995, 1996, 1997 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 <sys/types.h>
+#include <sys/wait.h>
+#include <errno.h>
+
+pid_t
+__wait4 (__pid_t pid, __WAIT_STATUS stat_loc, int options, 
+	 struct rusage *usage)
+{
+  __set_errno (ENOSYS);
+  return (pid_t) -1;
+}
+stub_warning (wait4)
+
+weak_alias (__wait4, wait4)
+#include <stub-tag.h>
diff --git a/posix/waitid.c b/posix/waitid.c
new file mode 100644
index 0000000000..a9de1a19a5
--- /dev/null
+++ b/posix/waitid.c
@@ -0,0 +1,35 @@
+/* Stub version of waitid.
+   Copyright (C) 1997, 2002 Free Software Foundation, Inc.
+   This file is part of the GNU C Library.
+   Contributed by Ulrich Drepper <drepper@cygnus.com>, 1997.
+
+   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 <sys/types.h>
+#include <sys/wait.h>
+
+int
+__waitid (idtype, id, infop, options)
+     idtype_t idtype;
+     id_t id;
+     siginfo_t *infop;
+     int options;
+{
+  __set_errno (ENOSYS);
+  return -1;
+}
+weak_alias (__waitid, waitid)
diff --git a/posix/waitpid.c b/posix/waitpid.c
new file mode 100644
index 0000000000..9c7736e669
--- /dev/null
+++ b/posix/waitpid.c
@@ -0,0 +1,53 @@
+/* Copyright (C) 1991,95,96,97,2002 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 <errno.h>
+#include <sys/wait.h>
+#include <sys/types.h>
+
+
+/* Wait for a child matching PID to die.
+   If PID is greater than 0, match any process whose process ID is PID.
+   If PID is (pid_t) -1, match any process.
+   If PID is (pid_t) 0, match any process with the
+   same process group as the current process.
+   If PID is less than -1, match any process whose
+   process group is the absolute value of PID.
+   If the WNOHANG bit is set in OPTIONS, and that child
+   is not already dead, return (pid_t) 0.  If successful,
+   return PID and store the dead child's status in STAT_LOC.
+   Return (pid_t) -1 for errors.  If the WUNTRACED bit is set in OPTIONS,
+   return status for stopped children; otherwise don't.  */
+pid_t
+__libc_waitpid (pid_t pid, int *stat_loc, int options)
+{
+  if ((options & ~(WNOHANG|WUNTRACED)) != 0)
+    {
+      __set_errno (EINVAL);
+      return (pid_t) -1;
+    }
+
+  __set_errno (ENOSYS);
+  return (pid_t) -1;
+}
+weak_alias (__libc_waitpid, __waitpid)
+libc_hidden_weak (__waitpid)
+weak_alias (__libc_waitpid, waitpid)
+
+stub_warning (waitpid)
+#include <stub-tag.h>
diff --git a/posix/wordexp.c b/posix/wordexp.c
new file mode 100644
index 0000000000..2eb58089c4
--- /dev/null
+++ b/posix/wordexp.c
@@ -0,0 +1,2457 @@
+/* POSIX.2 wordexp implementation.
+   Copyright (C) 1997-2002, 2003, 2005 Free Software Foundation, Inc.
+   This file is part of the GNU C Library.
+   Contributed by Tim Waugh <tim@cyberelk.demon.co.uk>.
+
+   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 <alloca.h>
+#include <ctype.h>
+#include <errno.h>
+#include <fcntl.h>
+#include <fnmatch.h>
+#include <glob.h>
+#include <libintl.h>
+#include <paths.h>
+#include <pwd.h>
+#include <signal.h>
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+#include <sys/param.h>
+#include <sys/stat.h>
+#include <sys/time.h>
+#include <sys/types.h>
+#include <sys/types.h>
+#include <sys/wait.h>
+#include <unistd.h>
+#ifdef USE_IN_LIBIO
+# include <wchar.h>
+#endif
+#include <wordexp.h>
+
+#include <bits/libc-lock.h>
+#include <stdio-common/_itoa.h>
+
+/* Undefine the following line for the production version.  */
+/* #define NDEBUG 1 */
+#include <assert.h>
+
+/* Get some device information.  */
+#include <device-nrs.h>
+
+/*
+ * This is a recursive-descent-style word expansion routine.
+ */
+
+/* These variables are defined and initialized in the startup code.  */
+extern int __libc_argc attribute_hidden;
+extern char **__libc_argv attribute_hidden;
+
+/* Some forward declarations */
+static int parse_dollars (char **word, size_t *word_length, size_t *max_length,
+			  const char *words, size_t *offset, int flags,
+			  wordexp_t *pwordexp, const char *ifs,
+			  const char *ifs_white, int quoted)
+     internal_function;
+static int parse_backtick (char **word, size_t *word_length,
+			   size_t *max_length, const char *words,
+			   size_t *offset, int flags, wordexp_t *pwordexp,
+			   const char *ifs, const char *ifs_white)
+     internal_function;
+static int parse_dquote (char **word, size_t *word_length, size_t *max_length,
+			 const char *words, size_t *offset, int flags,
+			 wordexp_t *pwordexp, const char *ifs,
+			 const char *ifs_white)
+     internal_function;
+static int eval_expr (char *expr, long int *result) internal_function;
+
+/* The w_*() functions manipulate word lists. */
+
+#define W_CHUNK	(100)
+
+/* Result of w_newword will be ignored if it's the last word. */
+static inline char *
+w_newword (size_t *actlen, size_t *maxlen)
+{
+  *actlen = *maxlen = 0;
+  return NULL;
+}
+
+static char *
+w_addchar (char *buffer, size_t *actlen, size_t *maxlen, char ch)
+     /* (lengths exclude trailing zero) */
+{
+  /* Add a character to the buffer, allocating room for it if needed.  */
+
+  if (*actlen == *maxlen)
+    {
+      char *old_buffer = buffer;
+      assert (buffer == NULL || *maxlen != 0);
+      *maxlen += W_CHUNK;
+      buffer = (char *) realloc (buffer, 1 + *maxlen);
+
+      if (buffer == NULL)
+	free (old_buffer);
+    }
+
+  if (buffer != NULL)
+    {
+      buffer[*actlen] = ch;
+      buffer[++(*actlen)] = '\0';
+    }
+
+  return buffer;
+}
+
+static char *
+internal_function
+w_addmem (char *buffer, size_t *actlen, size_t *maxlen, const char *str,
+	  size_t len)
+{
+  /* Add a string to the buffer, allocating room for it if needed.
+   */
+  if (*actlen + len > *maxlen)
+    {
+      char *old_buffer = buffer;
+      assert (buffer == NULL || *maxlen != 0);
+      *maxlen += MAX (2 * len, W_CHUNK);
+      buffer = realloc (old_buffer, 1 + *maxlen);
+
+      if (buffer == NULL)
+	free (old_buffer);
+    }
+
+  if (buffer != NULL)
+    {
+      *((char *) __mempcpy (&buffer[*actlen], str, len)) = '\0';
+      *actlen += len;
+    }
+
+  return buffer;
+}
+
+static char *
+internal_function
+w_addstr (char *buffer, size_t *actlen, size_t *maxlen, const char *str)
+     /* (lengths exclude trailing zero) */
+{
+  /* Add a string to the buffer, allocating room for it if needed.
+   */
+  size_t len;
+
+  assert (str != NULL); /* w_addstr only called from this file */
+  len = strlen (str);
+
+  return w_addmem (buffer, actlen, maxlen, str, len);
+}
+
+static int
+internal_function
+w_addword (wordexp_t *pwordexp, char *word)
+{
+  /* Add a word to the wordlist */
+  size_t num_p;
+  char **new_wordv;
+
+  /* Internally, NULL acts like "".  Convert NULLs to "" before
+   * the caller sees them.
+   */
+  if (word == NULL)
+    {
+      word = __strdup ("");
+      if (word == NULL)
+	goto no_space;
+    }
+
+  num_p = 2 + pwordexp->we_wordc + pwordexp->we_offs;
+  new_wordv = realloc (pwordexp->we_wordv, sizeof (char *) * num_p);
+  if (new_wordv != NULL)
+    {
+      pwordexp->we_wordv = new_wordv;
+      pwordexp->we_wordv[pwordexp->we_offs + pwordexp->we_wordc++] = word;
+      pwordexp->we_wordv[pwordexp->we_offs + pwordexp->we_wordc] = NULL;
+      return 0;
+    }
+
+no_space:
+  return WRDE_NOSPACE;
+}
+
+/* The parse_*() functions should leave *offset being the offset in 'words'
+ * to the last character processed.
+ */
+
+static int
+internal_function
+parse_backslash (char **word, size_t *word_length, size_t *max_length,
+		 const char *words, size_t *offset)
+{
+  /* We are poised _at_ a backslash, not in quotes */
+
+  switch (words[1 + *offset])
+    {
+    case 0:
+      /* Backslash is last character of input words */
+      return WRDE_SYNTAX;
+
+    case '\n':
+      ++(*offset);
+      break;
+
+    default:
+      *word = w_addchar (*word, word_length, max_length, words[1 + *offset]);
+      if (*word == NULL)
+	return WRDE_NOSPACE;
+
+      ++(*offset);
+      break;
+    }
+
+  return 0;
+}
+
+static int
+internal_function
+parse_qtd_backslash (char **word, size_t *word_length, size_t *max_length,
+		     const char *words, size_t *offset)
+{
+  /* We are poised _at_ a backslash, inside quotes */
+
+  switch (words[1 + *offset])
+    {
+    case 0:
+      /* Backslash is last character of input words */
+      return WRDE_SYNTAX;
+
+    case '\n':
+      ++(*offset);
+      break;
+
+    case '$':
+    case '`':
+    case '"':
+    case '\\':
+      *word = w_addchar (*word, word_length, max_length, words[1 + *offset]);
+      if (*word == NULL)
+	return WRDE_NOSPACE;
+
+      ++(*offset);
+      break;
+
+    default:
+      *word = w_addchar (*word, word_length, max_length, words[*offset]);
+      if (*word != NULL)
+	*word = w_addchar (*word, word_length, max_length, words[1 + *offset]);
+
+      if (*word == NULL)
+	return WRDE_NOSPACE;
+
+      ++(*offset);
+      break;
+    }
+
+  return 0;
+}
+
+static int
+internal_function
+parse_tilde (char **word, size_t *word_length, size_t *max_length,
+	     const char *words, size_t *offset, size_t wordc)
+{
+  /* We are poised _at_ a tilde */
+  size_t i;
+
+  if (*word_length != 0)
+    {
+      if (!((*word)[*word_length - 1] == '=' && wordc == 0))
+	{
+	  if (!((*word)[*word_length - 1] == ':'
+		&& strchr (*word, '=') && wordc == 0))
+	    {
+	      *word = w_addchar (*word, word_length, max_length, '~');
+	      return *word ? 0 : WRDE_NOSPACE;
+	    }
+	}
+    }
+
+  for (i = 1 + *offset; words[i]; i++)
+    {
+      if (words[i] == ':' || words[i] == '/' || words[i] == ' ' ||
+	  words[i] == '\t' || words[i] == 0 )
+	break;
+
+      if (words[i] == '\\')
+	{
+	  *word = w_addchar (*word, word_length, max_length, '~');
+	  return *word ? 0 : WRDE_NOSPACE;
+	}
+    }
+
+  if (i == 1 + *offset)
+    {
+      /* Tilde appears on its own */
+      uid_t uid;
+      struct passwd pwd, *tpwd;
+      int buflen = 1000;
+      char* home;
+      char* buffer;
+      int result;
+
+      /* POSIX.2 says ~ expands to $HOME and if HOME is unset the
+	 results are unspecified.  We do a lookup on the uid if
+	 HOME is unset. */
+
+      home = getenv ("HOME");
+      if (home != NULL)
+	{
+	  *word = w_addstr (*word, word_length, max_length, home);
+	  if (*word == NULL)
+	    return WRDE_NOSPACE;
+	}
+      else
+	{
+	  uid = __getuid ();
+	  buffer = __alloca (buflen);
+
+	  while ((result = __getpwuid_r (uid, &pwd, buffer, buflen, &tpwd)) != 0
+		 && errno == ERANGE)
+	    buffer = extend_alloca (buffer, buflen, buflen + 1000);
+
+	  if (result == 0 && tpwd != NULL && pwd.pw_dir != NULL)
+	    {
+	      *word = w_addstr (*word, word_length, max_length, pwd.pw_dir);
+	      if (*word == NULL)
+		return WRDE_NOSPACE;
+	    }
+	  else
+	    {
+	      *word = w_addchar (*word, word_length, max_length, '~');
+	      if (*word == NULL)
+		return WRDE_NOSPACE;
+	    }
+	}
+    }
+  else
+    {
+      /* Look up user name in database to get home directory */
+      char *user = strndupa (&words[1 + *offset], i - (1 + *offset));
+      struct passwd pwd, *tpwd;
+      int buflen = 1000;
+      char* buffer = __alloca (buflen);
+      int result;
+
+      while ((result = __getpwnam_r (user, &pwd, buffer, buflen, &tpwd)) != 0
+	     && errno == ERANGE)
+	buffer = extend_alloca (buffer, buflen, buflen + 1000);
+
+      if (result == 0 && tpwd != NULL && pwd.pw_dir)
+	*word = w_addstr (*word, word_length, max_length, pwd.pw_dir);
+      else
+	{
+	  /* (invalid login name) */
+	  *word = w_addchar (*word, word_length, max_length, '~');
+	  if (*word != NULL)
+	    *word = w_addstr (*word, word_length, max_length, user);
+	}
+
+      *offset = i - 1;
+    }
+  return *word ? 0 : WRDE_NOSPACE;
+}
+
+
+static int
+internal_function
+do_parse_glob (const char *glob_word, char **word, size_t *word_length,
+	       size_t *max_length, wordexp_t *pwordexp, const char *ifs,
+	       const char *ifs_white)
+{
+  int error;
+  unsigned int match;
+  glob_t globbuf;
+
+  error = glob (glob_word, GLOB_NOCHECK, NULL, &globbuf);
+
+  if (error != 0)
+    {
+      /* We can only run into memory problems.  */
+      assert (error == GLOB_NOSPACE);
+      return WRDE_NOSPACE;
+    }
+
+  if (ifs && !*ifs)
+    {
+      /* No field splitting allowed. */
+      assert (globbuf.gl_pathv[0] != NULL);
+      *word = w_addstr (*word, word_length, max_length, globbuf.gl_pathv[0]);
+      for (match = 1; match < globbuf.gl_pathc && *word != NULL; ++match)
+	{
+	  *word = w_addchar (*word, word_length, max_length, ' ');
+	  if (*word != NULL)
+	    *word = w_addstr (*word, word_length, max_length,
+			      globbuf.gl_pathv[match]);
+	}
+
+      globfree (&globbuf);
+      return *word ? 0 : WRDE_NOSPACE;
+    }
+
+  assert (ifs == NULL || *ifs != '\0');
+  if (*word != NULL)
+    {
+      free (*word);
+      *word = w_newword (word_length, max_length);
+    }
+
+  for (match = 0; match < globbuf.gl_pathc; ++match)
+    {
+      char *matching_word = __strdup (globbuf.gl_pathv[match]);
+      if (matching_word == NULL || w_addword (pwordexp, matching_word))
+	{
+	  globfree (&globbuf);
+	  return WRDE_NOSPACE;
+	}
+    }
+
+  globfree (&globbuf);
+  return 0;
+}
+
+static int
+internal_function
+parse_glob (char **word, size_t *word_length, size_t *max_length,
+	    const char *words, size_t *offset, int flags,
+	    wordexp_t *pwordexp, const char *ifs, const char *ifs_white)
+{
+  /* We are poised just after a '*', a '[' or a '?'. */
+  int error = WRDE_NOSPACE;
+  int quoted = 0; /* 1 if singly-quoted, 2 if doubly */
+  size_t i;
+  wordexp_t glob_list; /* List of words to glob */
+
+  glob_list.we_wordc = 0;
+  glob_list.we_wordv = NULL;
+  glob_list.we_offs = 0;
+  for (; words[*offset] != '\0'; ++*offset)
+    {
+      if ((ifs && strchr (ifs, words[*offset])) ||
+	  (!ifs && strchr (" \t\n", words[*offset])))
+	/* Reached IFS */
+	break;
+
+      /* Sort out quoting */
+      if (words[*offset] == '\'')
+	{
+	  if (quoted == 0)
+	    {
+	      quoted = 1;
+	      continue;
+	    }
+	  else if (quoted == 1)
+	    {
+	      quoted = 0;
+	      continue;
+	    }
+	}
+      else if (words[*offset] == '"')
+	{
+	  if (quoted == 0)
+	    {
+	      quoted = 2;
+	      continue;
+	    }
+	  else if (quoted == 2)
+	    {
+	      quoted = 0;
+	      continue;
+	    }
+	}
+
+      /* Sort out other special characters */
+      if (quoted != 1 && words[*offset] == '$')
+	{
+	  error = parse_dollars (word, word_length, max_length, words,
+				 offset, flags, &glob_list, ifs, ifs_white,
+				 quoted == 2);
+	  if (error)
+	    goto tidy_up;
+
+	  continue;
+	}
+      else if (words[*offset] == '\\')
+	{
+	  if (quoted)
+	    error = parse_qtd_backslash (word, word_length, max_length,
+					 words, offset);
+	  else
+	    error = parse_backslash (word, word_length, max_length,
+				     words, offset);
+
+	  if (error)
+	    goto tidy_up;
+
+	  continue;
+	}
+
+      *word = w_addchar (*word, word_length, max_length, words[*offset]);
+      if (*word == NULL)
+	goto tidy_up;
+    }
+
+  /* Don't forget to re-parse the character we stopped at. */
+  --*offset;
+
+  /* Glob the words */
+  error = w_addword (&glob_list, *word);
+  *word = w_newword (word_length, max_length);
+  for (i = 0; error == 0 && i < glob_list.we_wordc; i++)
+    error = do_parse_glob (glob_list.we_wordv[i], word, word_length,
+			   max_length, pwordexp, ifs, ifs_white);
+
+  /* Now tidy up */
+tidy_up:
+  wordfree (&glob_list);
+  return error;
+}
+
+static int
+internal_function
+parse_squote (char **word, size_t *word_length, size_t *max_length,
+	      const char *words, size_t *offset)
+{
+  /* We are poised just after a single quote */
+  for (; words[*offset]; ++(*offset))
+    {
+      if (words[*offset] != '\'')
+	{
+	  *word = w_addchar (*word, word_length, max_length, words[*offset]);
+	  if (*word == NULL)
+	    return WRDE_NOSPACE;
+	}
+      else return 0;
+    }
+
+  /* Unterminated string */
+  return WRDE_SYNTAX;
+}
+
+/* Functions to evaluate an arithmetic expression */
+static int
+internal_function
+eval_expr_val (char **expr, long int *result)
+{
+  char *digit;
+
+  /* Skip white space */
+  for (digit = *expr; digit && *digit && isspace (*digit); ++digit);
+
+  if (*digit == '(')
+    {
+      /* Scan for closing paren */
+      for (++digit; **expr && **expr != ')'; ++(*expr));
+
+      /* Is there one? */
+      if (!**expr)
+	return WRDE_SYNTAX;
+
+      *(*expr)++ = 0;
+
+      if (eval_expr (digit, result))
+	return WRDE_SYNTAX;
+
+      return 0;
+    }
+
+  /* POSIX requires that decimal, octal, and hexadecimal constants are
+     recognized.  Therefore we pass 0 as the third parameter to strtol.  */
+  *result = strtol (digit, expr, 0);
+  if (digit == *expr)
+    return WRDE_SYNTAX;
+
+  return 0;
+}
+
+static int
+internal_function
+eval_expr_multdiv (char **expr, long int *result)
+{
+  long int arg;
+
+  /* Read a Value */
+  if (eval_expr_val (expr, result) != 0)
+    return WRDE_SYNTAX;
+
+  while (**expr)
+    {
+      /* Skip white space */
+      for (; *expr && **expr && isspace (**expr); ++(*expr));
+
+      if (**expr == '*')
+	{
+	  ++(*expr);
+	  if (eval_expr_val (expr, &arg) != 0)
+	    return WRDE_SYNTAX;
+
+	  *result *= arg;
+	}
+      else if (**expr == '/')
+	{
+	  ++(*expr);
+	  if (eval_expr_val (expr, &arg) != 0)
+	    return WRDE_SYNTAX;
+
+	  *result /= arg;
+	}
+      else break;
+    }
+
+  return 0;
+}
+
+static int
+internal_function
+eval_expr (char *expr, long int *result)
+{
+  long int arg;
+
+  /* Read a Multdiv */
+  if (eval_expr_multdiv (&expr, result) != 0)
+    return WRDE_SYNTAX;
+
+  while (*expr)
+    {
+      /* Skip white space */
+      for (; expr && *expr && isspace (*expr); ++expr);
+
+      if (*expr == '+')
+	{
+	  ++expr;
+	  if (eval_expr_multdiv (&expr, &arg) != 0)
+	    return WRDE_SYNTAX;
+
+	  *result += arg;
+	}
+      else if (*expr == '-')
+	{
+	  ++expr;
+	  if (eval_expr_multdiv (&expr, &arg) != 0)
+	    return WRDE_SYNTAX;
+
+	  *result -= arg;
+	}
+      else break;
+    }
+
+  return 0;
+}
+
+static int
+internal_function
+parse_arith (char **word, size_t *word_length, size_t *max_length,
+	     const char *words, size_t *offset, int flags, int bracket)
+{
+  /* We are poised just after "$((" or "$[" */
+  int error;
+  int paren_depth = 1;
+  size_t expr_length;
+  size_t expr_maxlen;
+  char *expr;
+
+  expr = w_newword (&expr_length, &expr_maxlen);
+  for (; words[*offset]; ++(*offset))
+    {
+      switch (words[*offset])
+	{
+	case '$':
+	  error = parse_dollars (&expr, &expr_length, &expr_maxlen,
+				 words, offset, flags, NULL, NULL, NULL, 1);
+	  /* The ``1'' here is to tell parse_dollars not to
+	   * split the fields.
+	   */
+	  if (error)
+	    {
+	      free (expr);
+	      return error;
+	    }
+	  break;
+
+	case '`':
+	  (*offset)++;
+	  error = parse_backtick (&expr, &expr_length, &expr_maxlen,
+				  words, offset, flags, NULL, NULL, NULL);
+	  /* The first NULL here is to tell parse_backtick not to
+	   * split the fields.
+	   */
+	  if (error)
+	    {
+	      free (expr);
+	      return error;
+	    }
+	  break;
+
+	case '\\':
+	  error = parse_qtd_backslash (&expr, &expr_length, &expr_maxlen,
+				       words, offset);
+	  if (error)
+	    {
+	      free (expr);
+	      return error;
+	    }
+	  /* I think that a backslash within an
+	   * arithmetic expansion is bound to
+	   * cause an error sooner or later anyway though.
+	   */
+	  break;
+
+	case ')':
+	  if (--paren_depth == 0)
+	    {
+	      char result[21];	/* 21 = ceil(log10(2^64)) + 1 */
+	      long int numresult = 0;
+	      long long int convertme;
+
+	      if (bracket || words[1 + *offset] != ')')
+		{
+		  free (expr);
+		  return WRDE_SYNTAX;
+		}
+
+	      ++(*offset);
+
+	      /* Go - evaluate. */
+	      if (*expr && eval_expr (expr, &numresult) != 0)
+		{
+		  free (expr);
+		  return WRDE_SYNTAX;
+		}
+
+	      if (numresult < 0)
+		{
+		  convertme = -numresult;
+		  *word = w_addchar (*word, word_length, max_length, '-');
+		  if (!*word)
+		    {
+		      free (expr);
+		      return WRDE_NOSPACE;
+		    }
+		}
+	      else
+		convertme = numresult;
+
+	      result[20] = '\0';
+	      *word = w_addstr (*word, word_length, max_length,
+				_itoa (convertme, &result[20], 10, 0));
+	      free (expr);
+	      return *word ? 0 : WRDE_NOSPACE;
+	    }
+	  expr = w_addchar (expr, &expr_length, &expr_maxlen, words[*offset]);
+	  if (expr == NULL)
+	    return WRDE_NOSPACE;
+
+	  break;
+
+	case ']':
+	  if (bracket && paren_depth == 1)
+	    {
+	      char result[21];	/* 21 = ceil(log10(2^64)) + 1 */
+	      long int numresult = 0;
+
+	      /* Go - evaluate. */
+	      if (*expr && eval_expr (expr, &numresult) != 0)
+		{
+		  free (expr);
+		  return WRDE_SYNTAX;
+		}
+
+	      result[20] = '\0';
+	      *word = w_addstr (*word, word_length, max_length,
+				_itoa_word (numresult, &result[20], 10, 0));
+	      free (expr);
+	      return *word ? 0 : WRDE_NOSPACE;
+	    }
+
+	  free (expr);
+	  return WRDE_SYNTAX;
+
+	case '\n':
+	case ';':
+	case '{':
+	case '}':
+	  free (expr);
+	  return WRDE_BADCHAR;
+
+	case '(':
+	  ++paren_depth;
+	default:
+	  expr = w_addchar (expr, &expr_length, &expr_maxlen, words[*offset]);
+	  if (expr == NULL)
+	    return WRDE_NOSPACE;
+	}
+    }
+
+  /* Premature end */
+  free (expr);
+  return WRDE_SYNTAX;
+}
+
+/* Function called by child process in exec_comm() */
+static inline void
+internal_function __attribute__ ((always_inline))
+exec_comm_child (char *comm, int *fildes, int showerr, int noexec)
+{
+  const char *args[4] = { _PATH_BSHELL, "-c", comm, NULL };
+
+  /* Execute the command, or just check syntax? */
+  if (noexec)
+    args[1] = "-nc";
+
+  /* Redirect output.  */
+  __dup2 (fildes[1], STDOUT_FILENO);
+  __close (fildes[1]);
+
+  /* Redirect stderr to /dev/null if we have to.  */
+  if (showerr == 0)
+    {
+      struct stat64 st;
+      int fd;
+      __close (2);
+      fd = __open (_PATH_DEVNULL, O_WRONLY);
+      if (fd >= 0 && fd != 2)
+	{
+	  __dup2 (fd, STDERR_FILENO);
+	  __close (fd);
+	}
+      /* Be paranoid.  Check that we actually opened the /dev/null
+         device.  */
+      if (__builtin_expect (__fxstat64 (_STAT_VER, STDERR_FILENO, &st), 0) != 0
+	  || __builtin_expect (S_ISCHR (st.st_mode), 1) == 0
+#if defined DEV_NULL_MAJOR && defined DEV_NULL_MINOR
+	  || st.st_rdev != makedev (DEV_NULL_MAJOR, DEV_NULL_MINOR)
+#endif
+	  )
+	/* It's not the /dev/null device.  Stop right here.  The
+           problem is: how do we stop?  We use _exit() with an
+           hopefully unusual exit code.  */
+	_exit (90);
+    }
+
+  /* Make sure the subshell doesn't field-split on our behalf. */
+  __unsetenv ("IFS");
+
+  __close (fildes[0]);
+  __execve (_PATH_BSHELL, (char *const *) args, __environ);
+
+  /* Bad.  What now?  */
+  abort ();
+}
+
+/* Function to execute a command and retrieve the results */
+/* pwordexp contains NULL if field-splitting is forbidden */
+static int
+internal_function
+exec_comm (char *comm, char **word, size_t *word_length, size_t *max_length,
+	   int flags, wordexp_t *pwordexp, const char *ifs,
+	   const char *ifs_white)
+{
+  int fildes[2];
+#define bufsize 128
+  int buflen;
+  int i;
+  int status = 0;
+  size_t maxnewlines = 0;
+  char buffer[bufsize];
+  pid_t pid;
+  int noexec = 0;
+
+  /* Don't fork() unless necessary */
+  if (!comm || !*comm)
+    return 0;
+
+  if (__pipe (fildes))
+    /* Bad */
+    return WRDE_NOSPACE;
+
+ again:
+  if ((pid = __fork ()) < 0)
+    {
+      /* Bad */
+      if (fildes[0] != -1)
+	__close (fildes[0]);
+      if (fildes[1] != -1)
+	__close (fildes[1]);
+      return WRDE_NOSPACE;
+    }
+
+  if (pid == 0)
+    exec_comm_child (comm, fildes, noexec ? 0 : flags & WRDE_SHOWERR, noexec);
+
+  /* Parent */
+
+  /* If we are just testing the syntax, only wait.  */
+  if (noexec)
+    return (TEMP_FAILURE_RETRY (__waitpid (pid, &status, 0)) == pid
+	    && status != 0) ? WRDE_SYNTAX : 0;
+
+  __close (fildes[1]);
+  fildes[1] = -1;
+
+  if (!pwordexp)
+    /* Quoted - no field splitting */
+    {
+      while (1)
+	{
+	  if ((buflen = TEMP_FAILURE_RETRY (__read (fildes[0], buffer,
+						    bufsize))) < 1)
+	    {
+	      if (TEMP_FAILURE_RETRY (__waitpid (pid, &status, WNOHANG)) == 0)
+		continue;
+	      if ((buflen = TEMP_FAILURE_RETRY (__read (fildes[0], buffer,
+							bufsize))) < 1)
+		break;
+	    }
+
+	  maxnewlines += buflen;
+
+	  *word = w_addmem (*word, word_length, max_length, buffer, buflen);
+	  if (*word == NULL)
+	    goto no_space;
+	}
+    }
+  else
+    /* Not quoted - split fields */
+    {
+      int copying = 0;
+      /* 'copying' is:
+       *  0 when searching for first character in a field not IFS white space
+       *  1 when copying the text of a field
+       *  2 when searching for possible non-whitespace IFS
+       *  3 when searching for non-newline after copying field
+       */
+
+      while (1)
+	{
+	  if ((buflen = TEMP_FAILURE_RETRY (__read (fildes[0], buffer,
+						    bufsize))) < 1)
+	    {
+	      if (TEMP_FAILURE_RETRY (__waitpid (pid, &status, WNOHANG)) == 0)
+		continue;
+	      if ((buflen = TEMP_FAILURE_RETRY (__read (fildes[0], buffer,
+							bufsize))) < 1)
+		break;
+	    }
+
+	  for (i = 0; i < buflen; ++i)
+	    {
+	      if (strchr (ifs, buffer[i]) != NULL)
+		{
+		  /* Current character is IFS */
+		  if (strchr (ifs_white, buffer[i]) == NULL)
+		    {
+		      /* Current character is IFS but not whitespace */
+		      if (copying == 2)
+			{
+			  /*            current character
+			   *                   |
+			   *                   V
+			   * eg: text<space><comma><space>moretext
+			   *
+			   * So, strip whitespace IFS (like at the start)
+			   */
+			  copying = 0;
+			  continue;
+			}
+
+		      copying = 0;
+		      /* fall through and delimit field.. */
+		    }
+		  else
+		    {
+		      if (buffer[i] == '\n')
+			{
+			  /* Current character is (IFS) newline */
+
+			  /* If copying a field, this is the end of it,
+			     but maybe all that's left is trailing newlines.
+			     So start searching for a non-newline. */
+			  if (copying == 1)
+			    copying = 3;
+
+			  continue;
+			}
+		      else
+			{
+			  /* Current character is IFS white space, but
+			     not a newline */
+
+			  /* If not either copying a field or searching
+			     for non-newline after a field, ignore it */
+			  if (copying != 1 && copying != 3)
+			    continue;
+
+			  /* End of field (search for non-ws IFS afterwards) */
+			  copying = 2;
+			}
+		    }
+
+		  /* First IFS white space (non-newline), or IFS non-whitespace.
+		   * Delimit the field.  Nulls are converted by w_addword. */
+		  if (w_addword (pwordexp, *word) == WRDE_NOSPACE)
+		    goto no_space;
+
+		  *word = w_newword (word_length, max_length);
+
+		  maxnewlines = 0;
+		  /* fall back round the loop.. */
+		}
+	      else
+		{
+		  /* Not IFS character */
+
+		  if (copying == 3)
+		    {
+		      /* Nothing but (IFS) newlines since the last field,
+		         so delimit it here before starting new word */
+		      if (w_addword (pwordexp, *word) == WRDE_NOSPACE)
+			goto no_space;
+
+		      *word = w_newword (word_length, max_length);
+		    }
+
+		  copying = 1;
+
+		  if (buffer[i] == '\n') /* happens if newline not in IFS */
+		    maxnewlines++;
+		  else
+		    maxnewlines = 0;
+
+		  *word = w_addchar (*word, word_length, max_length,
+				     buffer[i]);
+		  if (*word == NULL)
+		    goto no_space;
+		}
+	    }
+	}
+    }
+
+  /* Chop off trailing newlines (required by POSIX.2)  */
+  /* Ensure we don't go back further than the beginning of the
+     substitution (i.e. remove maxnewlines bytes at most) */
+  while (maxnewlines-- != 0 &&
+         *word_length > 0 && (*word)[*word_length - 1] == '\n')
+    {
+      (*word)[--*word_length] = '\0';
+
+      /* If the last word was entirely newlines, turn it into a new word
+       * which can be ignored if there's nothing following it. */
+      if (*word_length == 0)
+	{
+	  free (*word);
+	  *word = w_newword (word_length, max_length);
+	  break;
+	}
+    }
+
+  __close (fildes[0]);
+  fildes[0] = -1;
+
+  /* Check for syntax error (re-execute but with "-n" flag) */
+  if (buflen < 1 && status != 0)
+    {
+      noexec = 1;
+      goto again;
+    }
+
+  return 0;
+
+no_space:
+  __kill (pid, SIGKILL);
+  TEMP_FAILURE_RETRY (__waitpid (pid, NULL, 0));
+  __close (fildes[0]);
+  return WRDE_NOSPACE;
+}
+
+static int
+internal_function
+parse_comm (char **word, size_t *word_length, size_t *max_length,
+	    const char *words, size_t *offset, int flags, wordexp_t *pwordexp,
+	    const char *ifs, const char *ifs_white)
+{
+  /* We are poised just after "$(" */
+  int paren_depth = 1;
+  int error = 0;
+  int quoted = 0; /* 1 for singly-quoted, 2 for doubly-quoted */
+  size_t comm_length;
+  size_t comm_maxlen;
+  char *comm = w_newword (&comm_length, &comm_maxlen);
+
+  for (; words[*offset]; ++(*offset))
+    {
+      switch (words[*offset])
+	{
+	case '\'':
+	  if (quoted == 0)
+	    quoted = 1;
+	  else if (quoted == 1)
+	    quoted = 0;
+
+	  break;
+
+	case '"':
+	  if (quoted == 0)
+	    quoted = 2;
+	  else if (quoted == 2)
+	    quoted = 0;
+
+	  break;
+
+	case ')':
+	  if (!quoted && --paren_depth == 0)
+	    {
+	      /* Go -- give script to the shell */
+	      if (comm)
+		{
+#ifdef __libc_ptf_call
+		  /* We do not want the exec_comm call to be cut short
+		     by a thread cancellation since cleanup is very
+		     ugly.  Therefore disable cancellation for
+		     now.  */
+		  // XXX Ideally we do want the thread being cancelable.
+		  // XXX If demand is there we'll change it.
+		  int state = PTHREAD_CANCEL_ENABLE;
+		  __libc_ptf_call (pthread_setcancelstate,
+				   (PTHREAD_CANCEL_DISABLE, &state), 0);
+#endif
+
+		  error = exec_comm (comm, word, word_length, max_length,
+				     flags, pwordexp, ifs, ifs_white);
+
+#ifdef __libc_ptf_call
+		  __libc_ptf_call (pthread_setcancelstate, (state, NULL), 0);
+#endif
+
+		  free (comm);
+		}
+
+	      return error;
+	    }
+
+	  /* This is just part of the script */
+	  break;
+
+	case '(':
+	  if (!quoted)
+	    ++paren_depth;
+	}
+
+      comm = w_addchar (comm, &comm_length, &comm_maxlen, words[*offset]);
+      if (comm == NULL)
+	return WRDE_NOSPACE;
+    }
+
+  /* Premature end */
+  if (comm)
+    free (comm);
+
+  return WRDE_SYNTAX;
+}
+
+static int
+internal_function
+parse_param (char **word, size_t *word_length, size_t *max_length,
+	     const char *words, size_t *offset, int flags, wordexp_t *pwordexp,
+	     const char *ifs, const char *ifs_white, int quoted)
+{
+  /* We are poised just after "$" */
+  enum action
+  {
+    ACT_NONE,
+    ACT_RP_SHORT_LEFT = '#',
+    ACT_RP_LONG_LEFT = 'L',
+    ACT_RP_SHORT_RIGHT = '%',
+    ACT_RP_LONG_RIGHT = 'R',
+    ACT_NULL_ERROR = '?',
+    ACT_NULL_SUBST = '-',
+    ACT_NONNULL_SUBST = '+',
+    ACT_NULL_ASSIGN = '='
+  };
+  size_t env_length;
+  size_t env_maxlen;
+  size_t pat_length;
+  size_t pat_maxlen;
+  size_t start = *offset;
+  char *env;
+  char *pattern;
+  char *value = NULL;
+  enum action action = ACT_NONE;
+  int depth = 0;
+  int colon_seen = 0;
+  int seen_hash = 0;
+  int free_value = 0;
+  int pattern_is_quoted = 0; /* 1 for singly-quoted, 2 for doubly-quoted */
+  int error;
+  int special = 0;
+  char buffer[21];
+  int brace = words[*offset] == '{';
+
+  env = w_newword (&env_length, &env_maxlen);
+  pattern = w_newword (&pat_length, &pat_maxlen);
+
+  if (brace)
+    ++*offset;
+
+  /* First collect the parameter name. */
+
+  if (words[*offset] == '#')
+    {
+      seen_hash = 1;
+      if (!brace)
+	goto envsubst;
+      ++*offset;
+    }
+
+  if (isalpha (words[*offset]) || words[*offset] == '_')
+    {
+      /* Normal parameter name. */
+      do
+	{
+	  env = w_addchar (env, &env_length, &env_maxlen,
+			   words[*offset]);
+	  if (env == NULL)
+	    goto no_space;
+	}
+      while (isalnum (words[++*offset]) || words[*offset] == '_');
+    }
+  else if (isdigit (words[*offset]))
+    {
+      /* Numeric parameter name. */
+      special = 1;
+      do
+	{
+	  env = w_addchar (env, &env_length, &env_maxlen,
+			   words[*offset]);
+	  if (env == NULL)
+	    goto no_space;
+	  if (!brace)
+	    goto envsubst;
+	}
+      while (isdigit(words[++*offset]));
+    }
+  else if (strchr ("*@$", words[*offset]) != NULL)
+    {
+      /* Special parameter. */
+      special = 1;
+      env = w_addchar (env, &env_length, &env_maxlen,
+		       words[*offset]);
+      if (env == NULL)
+	goto no_space;
+      ++*offset;
+    }
+  else
+    {
+      if (brace)
+	goto syntax;
+    }
+
+  if (brace)
+    {
+      /* Check for special action to be applied to the value. */
+      switch (words[*offset])
+	{
+	case '}':
+	  /* Evaluate. */
+	  goto envsubst;
+
+	case '#':
+	  action = ACT_RP_SHORT_LEFT;
+	  if (words[1 + *offset] == '#')
+	    {
+	      ++*offset;
+	      action = ACT_RP_LONG_LEFT;
+	    }
+	  break;
+
+	case '%':
+	  action = ACT_RP_SHORT_RIGHT;
+	  if (words[1 + *offset] == '%')
+	    {
+	      ++*offset;
+	      action = ACT_RP_LONG_RIGHT;
+	    }
+	  break;
+
+	case ':':
+	  if (strchr ("-=?+", words[1 + *offset]) == NULL)
+	    goto syntax;
+
+	  colon_seen = 1;
+	  action = words[++*offset];
+	  break;
+
+	case '-':
+	case '=':
+	case '?':
+	case '+':
+	  action = words[*offset];
+	  break;
+
+	default:
+	  goto syntax;
+	}
+
+      /* Now collect the pattern, but don't expand it yet. */
+      ++*offset;
+      for (; words[*offset]; ++(*offset))
+	{
+	  switch (words[*offset])
+	    {
+	    case '{':
+	      if (!pattern_is_quoted)
+		++depth;
+	      break;
+
+	    case '}':
+	      if (!pattern_is_quoted)
+		{
+		  if (depth == 0)
+		    goto envsubst;
+		  --depth;
+		}
+	      break;
+
+	    case '\\':
+	      if (pattern_is_quoted)
+		/* Quoted; treat as normal character. */
+		break;
+
+	      /* Otherwise, it's an escape: next character is literal. */
+	      if (words[++*offset] == '\0')
+		goto syntax;
+
+	      pattern = w_addchar (pattern, &pat_length, &pat_maxlen, '\\');
+	      if (pattern == NULL)
+		goto no_space;
+
+	      break;
+
+	    case '\'':
+	      if (pattern_is_quoted == 0)
+		pattern_is_quoted = 1;
+	      else if (pattern_is_quoted == 1)
+		pattern_is_quoted = 0;
+
+	      break;
+
+	    case '"':
+	      if (pattern_is_quoted == 0)
+		pattern_is_quoted = 2;
+	      else if (pattern_is_quoted == 2)
+		pattern_is_quoted = 0;
+
+	      break;
+	    }
+
+	  pattern = w_addchar (pattern, &pat_length, &pat_maxlen,
+			       words[*offset]);
+	  if (pattern == NULL)
+	    goto no_space;
+	}
+    }
+
+  /* End of input string -- remember to reparse the character that we
+   * stopped at.  */
+  --(*offset);
+
+envsubst:
+  if (words[start] == '{' && words[*offset] != '}')
+    goto syntax;
+
+  if (env == NULL)
+    {
+      if (seen_hash)
+	{
+	  /* $# expands to the number of positional parameters */
+	  buffer[20] = '\0';
+	  value = _itoa_word (__libc_argc - 1, &buffer[20], 10, 0);
+	  seen_hash = 0;
+	}
+      else
+	{
+	  /* Just $ on its own */
+	  *offset = start - 1;
+	  *word = w_addchar (*word, word_length, max_length, '$');
+	  return *word ? 0 : WRDE_NOSPACE;
+	}
+    }
+  /* Is it a numeric parameter? */
+  else if (isdigit (env[0]))
+    {
+      int n = atoi (env);
+
+      if (n >= __libc_argc)
+	/* Substitute NULL. */
+	value = NULL;
+      else
+	/* Replace with appropriate positional parameter. */
+	value = __libc_argv[n];
+    }
+  /* Is it a special parameter? */
+  else if (special)
+    {
+      /* Is it `$$'? */
+      if (*env == '$')
+	{
+	  buffer[20] = '\0';
+	  value = _itoa_word (__getpid (), &buffer[20], 10, 0);
+	}
+      /* Is it `${#*}' or `${#@}'? */
+      else if ((*env == '*' || *env == '@') && seen_hash)
+	{
+	  buffer[20] = '\0';
+	  value = _itoa_word (__libc_argc > 0 ? __libc_argc - 1 : 0,
+			      &buffer[20], 10, 0);
+	  *word = w_addstr (*word, word_length, max_length, value);
+	  free (env);
+	  if (pattern)
+	    free (pattern);
+	  return *word ? 0 : WRDE_NOSPACE;
+	}
+      /* Is it `$*' or `$@' (unquoted) ? */
+      else if (*env == '*' || (*env == '@' && !quoted))
+	{
+	  size_t plist_len = 0;
+	  int p;
+	  char *end;
+
+	  /* Build up value parameter by parameter (copy them) */
+	  for (p = 1; __libc_argv[p]; ++p)
+	    plist_len += strlen (__libc_argv[p]) + 1; /* for space */
+	  value = malloc (plist_len);
+	  if (value == NULL)
+	    goto no_space;
+	  end = value;
+	  *end = 0;
+	  for (p = 1; __libc_argv[p]; ++p)
+	    {
+	      if (p > 1)
+		*end++ = ' ';
+	      end = __stpcpy (end, __libc_argv[p]);
+	    }
+
+	  free_value = 1;
+	}
+      else
+	{
+	  /* Must be a quoted `$@' */
+	  assert (*env == '@' && quoted);
+
+	  /* Each parameter is a separate word ("$@") */
+	  if (__libc_argc == 2)
+	    value = __libc_argv[1];
+	  else if (__libc_argc > 2)
+	    {
+	      int p;
+
+	      /* Append first parameter to current word. */
+	      value = w_addstr (*word, word_length, max_length,
+				__libc_argv[1]);
+	      if (value == NULL || w_addword (pwordexp, value))
+		goto no_space;
+
+	      for (p = 2; __libc_argv[p + 1]; p++)
+		{
+		  char *newword = __strdup (__libc_argv[p]);
+		  if (newword == NULL || w_addword (pwordexp, newword))
+		    goto no_space;
+		}
+
+	      /* Start a new word with the last parameter. */
+	      *word = w_newword (word_length, max_length);
+	      value = __libc_argv[p];
+	    }
+	  else
+	    {
+	      free (env);
+	      free (pattern);
+	      return 0;
+	    }
+	}
+    }
+  else
+    value = getenv (env);
+
+  if (value == NULL && (flags & WRDE_UNDEF))
+    {
+      /* Variable not defined. */
+      error = WRDE_BADVAL;
+      goto do_error;
+    }
+
+  if (action != ACT_NONE)
+    {
+      int expand_pattern = 0;
+
+      /* First, find out if we need to expand pattern (i.e. if we will
+       * use it). */
+      switch (action)
+	{
+	case ACT_RP_SHORT_LEFT:
+	case ACT_RP_LONG_LEFT:
+	case ACT_RP_SHORT_RIGHT:
+	case ACT_RP_LONG_RIGHT:
+	  /* Always expand for these. */
+	  expand_pattern = 1;
+	  break;
+
+	case ACT_NULL_ERROR:
+	case ACT_NULL_SUBST:
+	case ACT_NULL_ASSIGN:
+	  if (!value || (!*value && colon_seen))
+	    /* If param is unset, or set but null and a colon has been seen,
+	       the expansion of the pattern will be needed. */
+	    expand_pattern = 1;
+
+	  break;
+
+	case ACT_NONNULL_SUBST:
+	  /* Expansion of word will be needed if parameter is set and not null,
+	     or set null but no colon has been seen. */
+	  if (value && (*value || !colon_seen))
+	    expand_pattern = 1;
+
+	  break;
+
+	default:
+	  assert (! "Unrecognised action!");
+	}
+
+      if (expand_pattern)
+	{
+	  /* We need to perform tilde expansion, parameter expansion,
+             command substitution, and arithmetic expansion.  We also
+	     have to be a bit careful with wildcard characters, as
+	     pattern might be given to fnmatch soon.  To do this, we
+	     convert quotes to escapes. */
+
+	  char *expanded;
+	  size_t exp_len;
+	  size_t exp_maxl;
+	  char *p;
+	  int quoted = 0; /* 1: single quotes; 2: double */
+
+	  expanded = w_newword (&exp_len, &exp_maxl);
+	  for (p = pattern; p && *p; p++)
+	    {
+	      size_t offset;
+
+	      switch (*p)
+		{
+		case '"':
+		  if (quoted == 2)
+		    quoted = 0;
+		  else if (quoted == 0)
+		    quoted = 2;
+		  else break;
+
+		  continue;
+
+		case '\'':
+		  if (quoted == 1)
+		    quoted = 0;
+		  else if (quoted == 0)
+		    quoted = 1;
+		  else break;
+
+		  continue;
+
+		case '*':
+		case '?':
+		  if (quoted)
+		    {
+		      /* Convert quoted wildchar to escaped wildchar. */
+		      expanded = w_addchar (expanded, &exp_len,
+					    &exp_maxl, '\\');
+
+		      if (expanded == NULL)
+			goto no_space;
+		    }
+		  break;
+
+		case '$':
+		  offset = 0;
+		  error = parse_dollars (&expanded, &exp_len, &exp_maxl, p,
+					 &offset, flags, NULL, NULL, NULL, 1);
+		  if (error)
+		    {
+		      if (free_value)
+			free (value);
+
+		      if (expanded)
+			free (expanded);
+
+		      goto do_error;
+		    }
+
+		  p += offset;
+		  continue;
+
+		case '~':
+		  if (quoted || exp_len)
+		    break;
+
+		  offset = 0;
+		  error = parse_tilde (&expanded, &exp_len, &exp_maxl, p,
+				       &offset, 0);
+		  if (error)
+		    {
+		      if (free_value)
+			free (value);
+
+		      if (expanded)
+			free (expanded);
+
+		      goto do_error;
+		    }
+
+		  p += offset;
+		  continue;
+
+		case '\\':
+		  expanded = w_addchar (expanded, &exp_len, &exp_maxl, '\\');
+		  ++p;
+		  assert (*p); /* checked when extracted initially */
+		  if (expanded == NULL)
+		    goto no_space;
+		}
+
+	      expanded = w_addchar (expanded, &exp_len, &exp_maxl, *p);
+
+	      if (expanded == NULL)
+		goto no_space;
+	    }
+
+	  if (pattern)
+		  free (pattern);
+
+	  pattern = expanded;
+	}
+
+      switch (action)
+	{
+	case ACT_RP_SHORT_LEFT:
+	case ACT_RP_LONG_LEFT:
+	case ACT_RP_SHORT_RIGHT:
+	case ACT_RP_LONG_RIGHT:
+	  {
+	    char *p;
+	    char c;
+	    char *end;
+
+	    if (value == NULL || pattern == NULL || *pattern == '\0')
+	      break;
+
+	    end = value + strlen (value);
+
+	    switch (action)
+	      {
+	      case ACT_RP_SHORT_LEFT:
+		for (p = value; p <= end; ++p)
+		  {
+		    c = *p;
+		    *p = '\0';
+		    if (fnmatch (pattern, value, 0) != FNM_NOMATCH)
+		      {
+			*p = c;
+			if (free_value)
+			  {
+			    char *newval = __strdup (p);
+			    if (newval == NULL)
+			      {
+				free (value);
+				goto no_space;
+			      }
+			    free (value);
+			    value = newval;
+			  }
+			else
+			  value = p;
+			break;
+		      }
+		    *p = c;
+		  }
+
+		break;
+
+	      case ACT_RP_LONG_LEFT:
+		for (p = end; p >= value; --p)
+		  {
+		    c = *p;
+		    *p = '\0';
+		    if (fnmatch (pattern, value, 0) != FNM_NOMATCH)
+		      {
+			*p = c;
+			if (free_value)
+			  {
+			    char *newval = __strdup (p);
+			    if (newval == NULL)
+			      {
+				free (value);
+				goto no_space;
+			      }
+			    free (value);
+			    value = newval;
+			  }
+			else
+			  value = p;
+			break;
+		      }
+		    *p = c;
+		  }
+
+		break;
+
+	      case ACT_RP_SHORT_RIGHT:
+		for (p = end; p >= value; --p)
+		  {
+		    if (fnmatch (pattern, p, 0) != FNM_NOMATCH)
+		      {
+			char *newval;
+			newval = malloc (p - value + 1);
+
+			if (newval == NULL)
+			  {
+			    if (free_value)
+			      free (value);
+			    goto no_space;
+			  }
+
+			*(char *) __mempcpy (newval, value, p - value) = '\0';
+			if (free_value)
+			  free (value);
+			value = newval;
+			free_value = 1;
+			break;
+		      }
+		  }
+
+		break;
+
+	      case ACT_RP_LONG_RIGHT:
+		for (p = value; p <= end; ++p)
+		  {
+		    if (fnmatch (pattern, p, 0) != FNM_NOMATCH)
+		      {
+			char *newval;
+			newval = malloc (p - value + 1);
+
+			if (newval == NULL)
+			  {
+			    if (free_value)
+			      free (value);
+			    goto no_space;
+			  }
+
+			*(char *) __mempcpy (newval, value, p - value) = '\0';
+			if (free_value)
+			  free (value);
+			value = newval;
+			free_value = 1;
+			break;
+		      }
+		  }
+
+		break;
+
+	      default:
+		break;
+	      }
+
+	    break;
+	  }
+
+	case ACT_NULL_ERROR:
+	  if (value && *value)
+	    /* Substitute parameter */
+	    break;
+
+	  error = 0;
+	  if (!colon_seen && value)
+	    /* Substitute NULL */
+	    ;
+	  else
+	    {
+	      const char *str = pattern;
+
+	      if (str[0] == '\0')
+		str = _("parameter null or not set");
+
+	      __fxprintf (NULL, "%s: %s\n", env, str);
+	    }
+
+	  if (free_value)
+	    free (value);
+	  goto do_error;
+
+	case ACT_NULL_SUBST:
+	  if (value && *value)
+	    /* Substitute parameter */
+	    break;
+
+	  if (free_value && value)
+	    free (value);
+
+	  if (!colon_seen && value)
+	    /* Substitute NULL */
+	    goto success;
+
+	  value = pattern ? __strdup (pattern) : pattern;
+	  free_value = 1;
+
+	  if (pattern && !value)
+	    goto no_space;
+
+	  break;
+
+	case ACT_NONNULL_SUBST:
+	  if (value && (*value || !colon_seen))
+	    {
+	      if (free_value && value)
+		free (value);
+
+	      value = pattern ? __strdup (pattern) : pattern;
+	      free_value = 1;
+
+	      if (pattern && !value)
+		goto no_space;
+
+	      break;
+	    }
+
+	  /* Substitute NULL */
+	  if (free_value)
+	    free (value);
+	  goto success;
+
+	case ACT_NULL_ASSIGN:
+	  if (value && *value)
+	    /* Substitute parameter */
+	    break;
+
+	  if (!colon_seen && value)
+	    {
+	      /* Substitute NULL */
+	      if (free_value)
+		free (value);
+	      goto success;
+	    }
+
+	  if (free_value && value)
+	    free (value);
+
+	  value = pattern ? __strdup (pattern) : pattern;
+	  free_value = 1;
+
+	  if (pattern && !value)
+	    goto no_space;
+
+	  __setenv (env, value, 1);
+	  break;
+
+	default:
+	  assert (! "Unrecognised action!");
+	}
+    }
+
+  free (env); env = NULL;
+  free (pattern); pattern = NULL;
+
+  if (seen_hash)
+    {
+      char param_length[21];
+      param_length[20] = '\0';
+      *word = w_addstr (*word, word_length, max_length,
+			_itoa_word (value ? strlen (value) : 0,
+				    &param_length[20], 10, 0));
+      if (free_value)
+	{
+	  assert (value != NULL);
+	  free (value);
+	}
+
+      return *word ? 0 : WRDE_NOSPACE;
+    }
+
+  if (value == NULL)
+    return 0;
+
+  if (quoted || !pwordexp)
+    {
+      /* Quoted - no field split */
+      *word = w_addstr (*word, word_length, max_length, value);
+      if (free_value)
+	free (value);
+
+      return *word ? 0 : WRDE_NOSPACE;
+    }
+  else
+    {
+      /* Need to field-split */
+      char *value_copy = __strdup (value); /* Don't modify value */
+      char *field_begin = value_copy;
+      int seen_nonws_ifs = 0;
+
+      if (free_value)
+	free (value);
+
+      if (value_copy == NULL)
+	goto no_space;
+
+      do
+	{
+	  char *field_end = field_begin;
+	  char *next_field;
+
+	  /* If this isn't the first field, start a new word */
+	  if (field_begin != value_copy)
+	    {
+	      if (w_addword (pwordexp, *word) == WRDE_NOSPACE)
+		{
+		  free (value_copy);
+		  goto no_space;
+		}
+
+	      *word = w_newword (word_length, max_length);
+	    }
+
+	  /* Skip IFS whitespace before the field */
+	  field_begin += strspn (field_begin, ifs_white);
+
+	  if (!seen_nonws_ifs && *field_begin == 0)
+	    /* Nothing but whitespace */
+	    break;
+
+	  /* Search for the end of the field */
+	  field_end = field_begin + strcspn (field_begin, ifs);
+
+	  /* Set up pointer to the character after end of field and
+             skip whitespace IFS after it. */
+	  next_field = field_end + strspn (field_end, ifs_white);
+
+	  /* Skip at most one non-whitespace IFS character after the field */
+	  seen_nonws_ifs = 0;
+	  if (*next_field && strchr (ifs, *next_field))
+	    {
+	      seen_nonws_ifs = 1;
+	      next_field++;
+	    }
+
+	  /* Null-terminate it */
+	  *field_end = 0;
+
+	  /* Tag a copy onto the current word */
+	  *word = w_addstr (*word, word_length, max_length, field_begin);
+
+	  if (*word == NULL && *field_begin != '\0')
+	    {
+	      free (value_copy);
+	      goto no_space;
+	    }
+
+	  field_begin = next_field;
+	}
+      while (seen_nonws_ifs || *field_begin);
+
+      free (value_copy);
+    }
+
+  return 0;
+
+success:
+  error = 0;
+  goto do_error;
+
+no_space:
+  error = WRDE_NOSPACE;
+  goto do_error;
+
+syntax:
+  error = WRDE_SYNTAX;
+
+do_error:
+  if (env)
+    free (env);
+
+  if (pattern)
+    free (pattern);
+
+  return error;
+}
+
+static int
+internal_function
+parse_dollars (char **word, size_t *word_length, size_t *max_length,
+	       const char *words, size_t *offset, int flags,
+	       wordexp_t *pwordexp, const char *ifs, const char *ifs_white,
+	       int quoted)
+{
+  /* We are poised _at_ "$" */
+  switch (words[1 + *offset])
+    {
+    case '"':
+    case '\'':
+    case 0:
+      *word = w_addchar (*word, word_length, max_length, '$');
+      return *word ? 0 : WRDE_NOSPACE;
+
+    case '(':
+      if (words[2 + *offset] == '(')
+	{
+	  /* Differentiate between $((1+3)) and $((echo);(ls)) */
+	  int i = 3 + *offset;
+	  int depth = 0;
+	  while (words[i] && !(depth == 0 && words[i] == ')'))
+	    {
+	      if (words[i] == '(')
+		++depth;
+	      else if (words[i] == ')')
+		--depth;
+
+	      ++i;
+	    }
+
+	  if (words[i] == ')' && words[i + 1] == ')')
+	    {
+	      (*offset) += 3;
+	      /* Call parse_arith -- 0 is for "no brackets" */
+	      return parse_arith (word, word_length, max_length, words, offset,
+				  flags, 0);
+	    }
+	}
+
+      if (flags & WRDE_NOCMD)
+	return WRDE_CMDSUB;
+
+      (*offset) += 2;
+      return parse_comm (word, word_length, max_length, words, offset, flags,
+			 quoted? NULL : pwordexp, ifs, ifs_white);
+
+    case '[':
+      (*offset) += 2;
+      /* Call parse_arith -- 1 is for "brackets" */
+      return parse_arith (word, word_length, max_length, words, offset, flags,
+			  1);
+
+    case '{':
+    default:
+      ++(*offset);	/* parse_param needs to know if "{" is there */
+      return parse_param (word, word_length, max_length, words, offset, flags,
+			   pwordexp, ifs, ifs_white, quoted);
+    }
+}
+
+static int
+internal_function
+parse_backtick (char **word, size_t *word_length, size_t *max_length,
+		const char *words, size_t *offset, int flags,
+		wordexp_t *pwordexp, const char *ifs, const char *ifs_white)
+{
+  /* We are poised just after "`" */
+  int error;
+  int squoting = 0;
+  size_t comm_length;
+  size_t comm_maxlen;
+  char *comm = w_newword (&comm_length, &comm_maxlen);
+
+  for (; words[*offset]; ++(*offset))
+    {
+      switch (words[*offset])
+	{
+	case '`':
+	  /* Go -- give the script to the shell */
+	  error = exec_comm (comm, word, word_length, max_length, flags,
+			     pwordexp, ifs, ifs_white);
+	  free (comm);
+	  return error;
+
+	case '\\':
+	  if (squoting)
+	    {
+	      error = parse_qtd_backslash (&comm, &comm_length, &comm_maxlen,
+					   words, offset);
+
+	      if (error)
+		{
+		  free (comm);
+		  return error;
+		}
+
+	      break;
+	    }
+
+	  ++(*offset);
+	  error = parse_backslash (&comm, &comm_length, &comm_maxlen, words,
+				   offset);
+
+	  if (error)
+	    {
+	      free (comm);
+	      return error;
+	    }
+
+	  break;
+
+	case '\'':
+	  squoting = 1 - squoting;
+	default:
+	  comm = w_addchar (comm, &comm_length, &comm_maxlen, words[*offset]);
+	  if (comm == NULL)
+	    return WRDE_NOSPACE;
+	}
+    }
+
+  /* Premature end */
+  free (comm);
+  return WRDE_SYNTAX;
+}
+
+static int
+internal_function
+parse_dquote (char **word, size_t *word_length, size_t *max_length,
+	      const char *words, size_t *offset, int flags,
+	      wordexp_t *pwordexp, const char * ifs, const char * ifs_white)
+{
+  /* We are poised just after a double-quote */
+  int error;
+
+  for (; words[*offset]; ++(*offset))
+    {
+      switch (words[*offset])
+	{
+	case '"':
+	  return 0;
+
+	case '$':
+	  error = parse_dollars (word, word_length, max_length, words, offset,
+				 flags, pwordexp, ifs, ifs_white, 1);
+	  /* The ``1'' here is to tell parse_dollars not to
+	   * split the fields.  It may need to, however ("$@").
+	   */
+	  if (error)
+	    return error;
+
+	  break;
+
+	case '`':
+	  if (flags & WRDE_NOCMD)
+	    return WRDE_CMDSUB;
+
+	  ++(*offset);
+	  error = parse_backtick (word, word_length, max_length, words,
+				  offset, flags, NULL, NULL, NULL);
+	  /* The first NULL here is to tell parse_backtick not to
+	   * split the fields.
+	   */
+	  if (error)
+	    return error;
+
+	  break;
+
+	case '\\':
+	  error = parse_qtd_backslash (word, word_length, max_length, words,
+				       offset);
+
+	  if (error)
+	    return error;
+
+	  break;
+
+	default:
+	  *word = w_addchar (*word, word_length, max_length, words[*offset]);
+	  if (*word == NULL)
+	    return WRDE_NOSPACE;
+	}
+    }
+
+  /* Unterminated string */
+  return WRDE_SYNTAX;
+}
+
+/*
+ * wordfree() is to be called after pwordexp is finished with.
+ */
+
+void
+wordfree (wordexp_t *pwordexp)
+{
+
+  /* wordexp can set pwordexp to NULL */
+  if (pwordexp && pwordexp->we_wordv)
+    {
+      char **wordv = pwordexp->we_wordv;
+
+      for (wordv += pwordexp->we_offs; *wordv; ++wordv)
+	free (*wordv);
+
+      free (pwordexp->we_wordv);
+      pwordexp->we_wordv = NULL;
+    }
+}
+libc_hidden_def (wordfree)
+
+/*
+ * wordexp()
+ */
+
+int
+wordexp (const char *words, wordexp_t *pwordexp, int flags)
+{
+  size_t words_offset;
+  size_t word_length;
+  size_t max_length;
+  char *word = w_newword (&word_length, &max_length);
+  int error;
+  char *ifs;
+  char ifs_white[4];
+  wordexp_t old_word = *pwordexp;
+
+  if (flags & WRDE_REUSE)
+    {
+      /* Minimal implementation of WRDE_REUSE for now */
+      wordfree (pwordexp);
+      old_word.we_wordv = NULL;
+    }
+
+  if ((flags & WRDE_APPEND) == 0)
+    {
+      pwordexp->we_wordc = 0;
+
+      if (flags & WRDE_DOOFFS)
+	{
+	  pwordexp->we_wordv = calloc (1 + pwordexp->we_offs, sizeof (char *));
+	  if (pwordexp->we_wordv == NULL)
+	    {
+	      error = WRDE_NOSPACE;
+	      goto do_error;
+	    }
+	}
+      else
+	{
+	  pwordexp->we_wordv = calloc (1, sizeof (char *));
+	  if (pwordexp->we_wordv == NULL)
+	    {
+	      error = WRDE_NOSPACE;
+	      goto do_error;
+	    }
+
+	  pwordexp->we_offs = 0;
+	}
+    }
+
+  /* Find out what the field separators are.
+   * There are two types: whitespace and non-whitespace.
+   */
+  ifs = getenv ("IFS");
+
+  if (!ifs)
+    /* IFS unset - use <space><tab><newline>. */
+    ifs = strcpy (ifs_white, " \t\n");
+  else
+    {
+      char *ifsch = ifs;
+      char *whch = ifs_white;
+
+      /* Start off with no whitespace IFS characters */
+      ifs_white[0] = '\0';
+
+      while (*ifsch != '\0')
+	{
+	  if ((*ifsch == ' ') || (*ifsch == '\t') || (*ifsch == '\n'))
+	    {
+	      /* Whitespace IFS.  See first whether it is already in our
+		 collection.  */
+	      char *runp = ifs_white;
+
+	      while (runp < whch && *runp != '\0' && *runp != *ifsch)
+		++runp;
+
+	      if (runp == whch)
+		*whch++ = *ifsch;
+	    }
+
+	  ++ifsch;
+	}
+      *whch = '\0';
+    }
+
+  for (words_offset = 0 ; words[words_offset] ; ++words_offset)
+    switch (words[words_offset])
+      {
+      case '\\':
+	error = parse_backslash (&word, &word_length, &max_length, words,
+				 &words_offset);
+
+	if (error)
+	  goto do_error;
+
+	break;
+
+      case '$':
+	error = parse_dollars (&word, &word_length, &max_length, words,
+			       &words_offset, flags, pwordexp, ifs, ifs_white,
+			       0);
+
+	if (error)
+	  goto do_error;
+
+	break;
+
+      case '`':
+	if (flags & WRDE_NOCMD)
+	  {
+	    error = WRDE_CMDSUB;
+	    goto do_error;
+	  }
+
+	++words_offset;
+	error = parse_backtick (&word, &word_length, &max_length, words,
+				&words_offset, flags, pwordexp, ifs,
+				ifs_white);
+
+	if (error)
+	  goto do_error;
+
+	break;
+
+      case '"':
+	++words_offset;
+	error = parse_dquote (&word, &word_length, &max_length, words,
+			      &words_offset, flags, pwordexp, ifs, ifs_white);
+
+	if (error)
+	  goto do_error;
+
+	if (!word_length)
+	  {
+	    error = w_addword (pwordexp, NULL);
+
+	    if (error)
+	      return error;
+	  }
+
+	break;
+
+      case '\'':
+	++words_offset;
+	error = parse_squote (&word, &word_length, &max_length, words,
+			      &words_offset);
+
+	if (error)
+	  goto do_error;
+
+	if (!word_length)
+	  {
+	    error = w_addword (pwordexp, NULL);
+
+	    if (error)
+	      return error;
+	  }
+
+	break;
+
+      case '~':
+	error = parse_tilde (&word, &word_length, &max_length, words,
+			     &words_offset, pwordexp->we_wordc);
+
+	if (error)
+	  goto do_error;
+
+	break;
+
+      case '*':
+      case '[':
+      case '?':
+	error = parse_glob (&word, &word_length, &max_length, words,
+			    &words_offset, flags, pwordexp, ifs, ifs_white);
+
+	if (error)
+	  goto do_error;
+
+	break;
+
+      default:
+	/* Is it a word separator? */
+	if (strchr (" \t", words[words_offset]) == NULL)
+	  {
+	    char ch = words[words_offset];
+
+	    /* Not a word separator -- but is it a valid word char? */
+	    if (strchr ("\n|&;<>(){}", ch))
+	      {
+		/* Fail */
+		error = WRDE_BADCHAR;
+		goto do_error;
+	      }
+
+	    /* "Ordinary" character -- add it to word */
+	    word = w_addchar (word, &word_length, &max_length,
+			      ch);
+	    if (word == NULL)
+	      {
+		error = WRDE_NOSPACE;
+		goto do_error;
+	      }
+
+	    break;
+	  }
+
+	/* If a word has been delimited, add it to the list. */
+	if (word != NULL)
+	  {
+	    error = w_addword (pwordexp, word);
+	    if (error)
+	      goto do_error;
+	  }
+
+	word = w_newword (&word_length, &max_length);
+      }
+
+  /* End of string */
+
+  /* There was a word separator at the end */
+  if (word == NULL) /* i.e. w_newword */
+    return 0;
+
+  /* There was no field separator at the end */
+  return w_addword (pwordexp, word);
+
+do_error:
+  /* Error:
+   *	free memory used (unless error is WRDE_NOSPACE), and
+   *	set pwordexp members back to what they were.
+   */
+
+  if (word != NULL)
+    free (word);
+
+  if (error == WRDE_NOSPACE)
+    return WRDE_NOSPACE;
+
+  if ((flags & WRDE_APPEND) == 0)
+    wordfree (pwordexp);
+
+  *pwordexp = old_word;
+  return error;
+}