about summary refs log tree commit diff
path: root/sysdeps/unix
diff options
context:
space:
mode:
Diffstat (limited to 'sysdeps/unix')
-rw-r--r--sysdeps/unix/sysv/linux/alpha/fxstatat.c100
-rw-r--r--sysdeps/unix/sysv/linux/fchownat.c73
-rw-r--r--sysdeps/unix/sysv/linux/futimesat.c97
-rw-r--r--sysdeps/unix/sysv/linux/fxstatat.c106
-rw-r--r--sysdeps/unix/sysv/linux/fxstatat64.c135
-rw-r--r--sysdeps/unix/sysv/linux/i386/fchownat.c177
-rw-r--r--sysdeps/unix/sysv/linux/i386/fxstatat.c148
-rw-r--r--sysdeps/unix/sysv/linux/m68k/fchownat.c121
-rw-r--r--sysdeps/unix/sysv/linux/m68k/fxstatat.c1
-rw-r--r--sysdeps/unix/sysv/linux/openat.c47
-rw-r--r--sysdeps/unix/sysv/linux/powerpc/chown.c140
-rw-r--r--sysdeps/unix/sysv/linux/powerpc/fchownat.c205
-rw-r--r--sysdeps/unix/sysv/linux/powerpc/powerpc32/fxstatat.c1
-rw-r--r--sysdeps/unix/sysv/linux/renameat.c121
-rw-r--r--sysdeps/unix/sysv/linux/s390/s390-32/fchownat.c140
-rw-r--r--sysdeps/unix/sysv/linux/s390/s390-32/fxstatat.c1
-rw-r--r--sysdeps/unix/sysv/linux/sh/fchownat.c1
-rw-r--r--sysdeps/unix/sysv/linux/sh/fxstatat.c1
-rw-r--r--sysdeps/unix/sysv/linux/sparc/sparc32/fchownat.c1
-rw-r--r--sysdeps/unix/sysv/linux/sparc/sparc32/fxstatat.c1
-rw-r--r--sysdeps/unix/sysv/linux/sparc/sparc64/fxstatat.c1
-rw-r--r--sysdeps/unix/sysv/linux/unlinkat.c74
-rw-r--r--sysdeps/unix/sysv/linux/wordsize-64/fxstatat.c78
-rw-r--r--sysdeps/unix/sysv/linux/wordsize-64/fxstatat64.c1
24 files changed, 1684 insertions, 87 deletions
diff --git a/sysdeps/unix/sysv/linux/alpha/fxstatat.c b/sysdeps/unix/sysv/linux/alpha/fxstatat.c
new file mode 100644
index 0000000000..65b7ad97a3
--- /dev/null
+++ b/sysdeps/unix/sysv/linux/alpha/fxstatat.c
@@ -0,0 +1,100 @@
+/* Copyright (C) 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.  */
+
+#define __fxstatat64 __fxstatat64_disable
+
+#include <errno.h>
+#include <fcntl.h>
+#include <stddef.h>
+#include <stdio.h>
+#include <sys/stat.h>
+#include <kernel_stat.h>
+#include <sysdep.h>
+#include <sys/syscall.h>
+#include <xstatconv.h>
+
+#undef __fxstatat64
+
+
+/* Get information about the file NAME in BUF.  */
+int
+__fxstatat (int vers, int fd, const char *file, struct stat *st, int flag)
+{
+  if (flag & ~AT_SYMLINK_NOFOLLOW)
+    {
+      __set_errno (EINVAL);
+      return -1;
+    }
+
+  char *buf = NULL;
+
+  if (fd != AT_FDCWD && file[0] != '/')
+    {
+      size_t filelen = strlen (file);
+      static const char procfd[] = "/proc/self/fd/%d/%s";
+      /* Buffer for the path name we are going to use.  It consists of
+	 - the string /proc/self/fd/
+	 - the file descriptor number
+	 - the file name provided.
+	 The final NUL is included in the sizeof.   A bit of overhead
+	 due to the format elements compensates for possible negative
+	 numbers.  */
+      size_t buflen = sizeof (procfd) + sizeof (int) * 3 + filelen;
+      buf = alloca (buflen);
+
+      __snprintf (buf, buflen, procfd, fd, file);
+      file = buf;
+    }
+
+  INTERNAL_SYSCALL_DECL (err);
+  int result, errno_out;
+  struct kernel_stat kst;
+
+  if (vers == _STAT_VER_KERNEL64 && !__libc_missing_axp_stat64)
+    {
+      if (flags & AT_SYMLINK_NOFOLLOW)
+	result = INTERNAL_SYSCALL (lstat64, err, 2, file, st);
+      else
+	result = INTERNAL_SYSCALL (stat64, err, 2, file, st);
+
+      if (__builtin_expect (!INTERNAL_SYSCALL_ERROR_P (result, err), 1))
+	return result;
+      errno_out = INTERNAL_SYSCALL_ERRNO (result, err);
+      if (errno_out != ENOSYS)
+	goto fail;
+      __libc_missing_axp_stat64 = 1;
+    }
+
+  if (flag & AT_SYMLINK_NOFOLLOW)
+    result = INTERNAL_SYSCALL (lstat, err, 2, file, &kst);
+  else
+    result = INTERNAL_SYSCALL (stat, err, 2, file, &kst);
+
+  if (__builtin_expect (!INTERNAL_SYSCALL_ERROR_P (result, err), 1))
+    return __xstat_conv (vers, &kst, st);
+  errno_out = INTERNAL_SYSCALL_ERRNO (result, err);
+
+ fail:
+  __atfct_seterrno (errno_out, fd, buf);
+
+  return -1;
+}
+hidden_def (__xstat)
+weak_alias (__xstat, _xstat);
+strong_alias (__xstat, __xstat64);
+hidden_ver (__xstat, __xstat64)
diff --git a/sysdeps/unix/sysv/linux/fchownat.c b/sysdeps/unix/sysv/linux/fchownat.c
new file mode 100644
index 0000000000..d3cb992a09
--- /dev/null
+++ b/sysdeps/unix/sysv/linux/fchownat.c
@@ -0,0 +1,73 @@
+/* Copyright (C) 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 <fcntl.h>
+#include <stddef.h>
+#include <stdio.h>
+#include <unistd.h>
+#include <sys/types.h>
+
+/* Change the owner and group of FILE.  */
+int
+fchownat (fd, file, owner, group, flag)
+     int fd;
+     const char *file;
+     uid_t owner;
+     gid_t group;
+     int flag;
+{
+  if (flag & ~AT_SYMLINK_NOFOLLOW)
+    {
+      __set_errno (EINVAL);
+      return -1;
+    }
+
+  char *buf = NULL;
+
+  if (fd != AT_FDCWD && file[0] != '/')
+    {
+      size_t filelen = strlen (file);
+      static const char procfd[] = "/proc/self/fd/%d/%s";
+      /* Buffer for the path name we are going to use.  It consists of
+	 - the string /proc/self/fd/
+	 - the file descriptor number
+	 - the file name provided.
+	 The final NUL is included in the sizeof.   A bit of overhead
+	 due to the format elements compensates for possible negative
+	 numbers.  */
+      size_t buflen = sizeof (procfd) + sizeof (int) * 3 + filelen;
+      buf = alloca (buflen);
+
+      __snprintf (buf, buflen, procfd, fd, file);
+      file = buf;
+    }
+
+  int result;
+  INTERNAL_SYSCALL_DECL (err);
+
+  if (flag & AT_SYMLINK_NOFOLLOW)
+    result = INTERNAL_SYSCALL (lchown, err, 3, file, owner, group);
+  else
+    result = INTERNAL_SYSCALL (chown, err, 3, file, owner, group);
+
+  if (__builtin_expect (INTERNAL_SYSCALL_ERROR_P (result, err), 0))
+    __atfct_seterrno (INTERNAL_SYSCALL_ERRNO (result, err), fd, buf);
+
+  return result;
+}
diff --git a/sysdeps/unix/sysv/linux/futimesat.c b/sysdeps/unix/sysv/linux/futimesat.c
new file mode 100644
index 0000000000..2fdedb0ff4
--- /dev/null
+++ b/sysdeps/unix/sysv/linux/futimesat.c
@@ -0,0 +1,97 @@
+/* Copyright (C) 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 <fcntl.h>
+#include <stddef.h>
+#include <stdio.h>
+#include <utime.h>
+#include <sys/time.h>
+#include <sysdep.h>
+#include "kernel-features.h"
+
+
+/* Change the access time of FILE relative to FD to TVP[0] and
+   the modification time of FILE to TVP[1].  */
+int
+futimesat (fd, file, tvp)
+     int fd;
+     const char *file;
+     const struct timeval tvp[2];
+{
+  char *buf = NULL;
+
+  if (fd != AT_FDCWD && file[0] != '/')
+    {
+      size_t filelen = strlen (file);
+      static const char procfd[] = "/proc/self/fd/%d/%s";
+      /* Buffer for the path name we are going to use.  It consists of
+	 - the string /proc/self/fd/
+	 - the file descriptor number
+	 - the file name provided.
+	 The final NUL is included in the sizeof.   A bit of overhead
+	 due to the format elements compensates for possible negative
+	 numbers.  */
+      size_t buflen = sizeof (procfd) + sizeof (int) * 3 + filelen;
+      buf = alloca (buflen);
+
+      __snprintf (buf, buflen, procfd, fd, file);
+      file = buf;
+    }
+
+  int result;
+  INTERNAL_SYSCALL_DECL (err);
+
+#ifdef __NR_utimes
+  result = INTERNAL_SYSCALL (utimes, err, 2, file, tvp);
+  if (__builtin_expect (!INTERNAL_SYSCALL_ERROR_P (result, err), 1))
+    return result;
+
+# ifndef __ASSUME_UTIMES
+  if (INTERNAL_SYSCALL_ERRNO (result, err) != ENOSYS)
+    goto fail;
+# endif
+#endif
+
+  /* The utimes() syscall does not exist or is not available in the
+     used kernel.  Use utime().  For this we have to convert to the
+     data format utime() expects.  */
+#ifndef __ASSUME_UTIMES
+  struct utimbuf tmp;
+  struct utimbuf *times;
+
+  if (tvp != NULL)
+    {
+      times = &tmp;
+      tmp.actime = tvp[0].tv_sec + tvp[0].tv_usec / 1000000;
+      tmp.modtime = tvp[1].tv_sec + tvp[1].tv_usec / 1000000;
+    }
+  else
+    times = NULL;
+
+  result = INTERNAL_SYSCALL (utime, err, 2, file, times);
+  if (__builtin_expect (!INTERNAL_SYSCALL_ERROR_P (result, err), 1))
+    return result;
+
+ fail:
+#endif
+
+  __atfct_seterrno (INTERNAL_SYSCALL_ERRNO (result, err), fd, buf);
+
+  return -1;
+}
diff --git a/sysdeps/unix/sysv/linux/fxstatat.c b/sysdeps/unix/sysv/linux/fxstatat.c
new file mode 100644
index 0000000000..9bc3dbc459
--- /dev/null
+++ b/sysdeps/unix/sysv/linux/fxstatat.c
@@ -0,0 +1,106 @@
+/* Copyright (C) 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.  */
+
+/* Ho hum, if fxstatat == fxstatat64 we must get rid of the prototype or gcc
+   will complain since they don't strictly match.  */
+#define __fxstatat64 __fxstatat64_disable
+
+#include <errno.h>
+#include <fcntl.h>
+#include <stddef.h>
+#include <stdio.h>
+#include <sys/stat.h>
+#include <kernel_stat.h>
+
+#include <sysdep.h>
+#include <sys/syscall.h>
+#include <bp-checks.h>
+
+#include <xstatconv.h>
+
+/* Get information about the file NAME in BUF.  */
+int
+__fxstatat (int vers, int fd, const char *file, struct stat *st, int flag)
+{
+  if (flag & ~AT_SYMLINK_NOFOLLOW)
+    {
+      __set_errno (EINVAL);
+      return -1;
+    }
+
+  char *buf = NULL;
+
+  if (fd != AT_FDCWD && file[0] != '/')
+    {
+      size_t filelen = strlen (file);
+      static const char procfd[] = "/proc/self/fd/%d/%s";
+      /* Buffer for the path name we are going to use.  It consists of
+	 - the string /proc/self/fd/
+	 - the file descriptor number
+	 - the file name provided.
+	 The final NUL is included in the sizeof.   A bit of overhead
+	 due to the format elements compensates for possible negative
+	 numbers.  */
+      size_t buflen = sizeof (procfd) + sizeof (int) * 3 + filelen;
+      buf = alloca (buflen);
+
+      __snprintf (buf, buflen, procfd, fd, file);
+      file = buf;
+    }
+
+  int result;
+  INTERNAL_SYSCALL_DECL (err);
+
+  if (vers == _STAT_VER_KERNEL)
+    {
+      if (flag & AT_SYMLINK_NOFOLLOW)
+	result = INTERNAL_SYSCALL (lstat, err, 2, CHECK_STRING (file),
+				   CHECK_1 ((struct kernel_stat *) st));
+      else
+	result = INTERNAL_SYSCALL (stat, err, 2, CHECK_STRING (file),
+				   CHECK_1 ((struct kernel_stat *) st));
+
+      if (__builtin_expect (!INTERNAL_SYSCALL_ERROR_P (result, err), 1))
+	return result;
+    }
+
+#ifdef STAT_IS_KERNEL_STAT
+  __set_errno (EINVAL);
+  return -1;
+#else
+  struct kernel_stat kst;
+
+  if (flag & AT_SYMLINK_NOFOLLOW)
+    result = INTERNAL_SYSCALL (lstat, err, 2, CHECK_STRING (file),
+			       __ptrvalue (&kst));
+  else
+    result = INTERNAL_SYSCALL (stat, err, 2, CHECK_STRING (file),
+			       __ptrvalue (&kst));
+
+  if (__builtin_expect (!INTERNAL_SYSCALL_ERROR_P (result, err), 1))
+    return __xstat_conv (vers, &kst, st);
+#endif
+
+  __atfct_seterrno (INTERNAL_SYSCALL_ERRNO (result, err), fd, buf);
+
+  return -1;
+}
+#ifdef XSTAT_IS_XSTAT64
+# undef __fxstatat64
+strong_alias (__fxstatat, __fxstatat64);
+#endif
diff --git a/sysdeps/unix/sysv/linux/fxstatat64.c b/sysdeps/unix/sysv/linux/fxstatat64.c
new file mode 100644
index 0000000000..8c41db710c
--- /dev/null
+++ b/sysdeps/unix/sysv/linux/fxstatat64.c
@@ -0,0 +1,135 @@
+/* Copyright (C) 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 <fcntl.h>
+#include <stddef.h>
+#include <stdio.h>
+#include <sys/stat.h>
+#include <kernel_stat.h>
+
+#include <sysdep.h>
+#include <sys/syscall.h>
+#include <bp-checks.h>
+
+#include "kernel-features.h"
+
+#if __ASSUME_STAT64_SYSCALL == 0
+# include <xstatconv.h>
+#endif
+
+#ifdef __NR_stat64
+# if  __ASSUME_STAT64_SYSCALL == 0
+/* The variable is shared between all wrappers around *stat64 calls.
+   This is the definition.  */
+extern int __have_no_stat64;
+# endif
+#endif
+
+/* Get information about the file NAME in BUF.  */
+
+int
+__fxstatat64 (int vers, int fd, const char *file, struct stat64 *st, int flag)
+{
+  if (flag & ~AT_SYMLINK_NOFOLLOW)
+    {
+      __set_errno (EINVAL);
+      return -1;
+    }
+
+  char *buf = NULL;
+
+  if (fd != AT_FDCWD && file[0] != '/')
+    {
+      size_t filelen = strlen (file);
+      static const char procfd[] = "/proc/self/fd/%d/%s";
+      /* Buffer for the path name we are going to use.  It consists of
+	 - the string /proc/self/fd/
+	 - the file descriptor number
+	 - the file name provided.
+	 The final NUL is included in the sizeof.   A bit of overhead
+	 due to the format elements compensates for possible negative
+	 numbers.  */
+      size_t buflen = sizeof (procfd) + sizeof (int) * 3 + filelen;
+      buf = alloca (buflen);
+
+      __snprintf (buf, buflen, procfd, fd, file);
+      file = buf;
+    }
+
+  int result;
+  INTERNAL_SYSCALL_DECL (err);
+
+#if __ASSUME_STAT64_SYSCALL > 0
+  if (flag & AT_SYMLINK_NOFOLLOW)
+    result = INTERNAL_SYSCALL (lstat64, err, 2, CHECK_STRING (file),
+			       CHECK_1 (st));
+  else
+    result = INTERNAL_SYSCALL (stat64, err, 2, CHECK_STRING (file),
+			       CHECK_1 (st));
+  if (__builtin_expect (!INTERNAL_SYSCALL_ERROR_P (result, err), 1))
+    {
+# if defined _HAVE_STAT64___ST_INO && __ASSUME_ST_INO_64_BIT == 0
+      if (st->__st_ino != (__ino_t) st->st_ino)
+	st->st_ino = st->__st_ino;
+# endif
+      return result;
+    }
+#else
+  struct kernel_stat kst;
+# if defined __NR_stat64
+  if (! __have_no_stat64)
+    {
+      if (flag & AT_SYMLINK_NOFOLLOW)
+	result = INTERNAL_SYSCALL (lstat64, err, 2, CHECK_STRING (file),
+				   CHECK_1 (st));
+      else
+	result = INTERNAL_SYSCALL (stat64, err, 2, CHECK_STRING (file),
+				   CHECK_1 (st));
+
+      if (__builtin_expect (!INTERNAL_SYSCALL_ERROR_P (result, err), 1))
+	{
+#  if defined _HAVE_STAT64___ST_INO && __ASSUME_ST_INO_64_BIT == 0
+	  if (st->__st_ino != (__ino_t) st->st_ino)
+	    st->st_ino = st->__st_ino;
+#  endif
+	  return result;
+	}
+      if (INTERNAL_SYSCALL_ERRNO (result, err) != ENOSYS)
+	goto fail;
+
+      __have_no_stat64 = 1;
+    }
+# endif
+
+  if (flag & AT_SYMLINK_NOFOLLOW)
+    result = INTERNAL_SYSCALL (lstat, err, 2, CHECK_STRING (file),
+			       __ptrvalue (&kst));
+  else
+    result = INTERNAL_SYSCALL (stat, err, 2, CHECK_STRING (file),
+			       __ptrvalue (&kst));
+
+  if (__builtin_expect (!INTERNAL_SYSCALL_ERROR_P (result, err), 1))
+    return __xstat64_conv (vers, &kst, st);
+
+ fail:
+  __atfct_seterrno (INTERNAL_SYSCALL_ERRNO (result, err), fd, buf);
+
+  return -1;
+#endif
+}
diff --git a/sysdeps/unix/sysv/linux/i386/fchownat.c b/sysdeps/unix/sysv/linux/i386/fchownat.c
new file mode 100644
index 0000000000..331623f73d
--- /dev/null
+++ b/sysdeps/unix/sysv/linux/i386/fchownat.c
@@ -0,0 +1,177 @@
+/* Copyright (C) 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 <fcntl.h>
+#include <stdio.h>
+#include <unistd.h>
+
+#include <sysdep.h>
+#include <sys/syscall.h>
+#include <shlib-compat.h>
+#include <bp-checks.h>
+
+#include <linux/posix_types.h>
+#include "kernel-features.h"
+
+/*
+  In Linux 2.1.x the chown functions have been changed.  A new function lchown
+  was introduced.  The new chown now follows symlinks - the old chown and the
+  new lchown do not follow symlinks.
+  The new lchown function has the same number as the old chown had and the
+  new chown has a new number.  When compiling with headers from Linux > 2.1.8x
+  it's impossible to run this libc with older kernels.  In these cases libc
+  has therefore to route calls to chown to the old chown function.
+*/
+
+extern int __chown_is_lchown (const char *__file, uid_t __owner,
+			      gid_t __group);
+extern int __real_chown (const char *__file, uid_t __owner, gid_t __group);
+
+
+#if defined __NR_lchown || __ASSUME_LCHOWN_SYSCALL > 0
+/* Running under Linux > 2.1.80.  */
+
+# ifdef __NR_chown32
+#  if __ASSUME_32BITUIDS == 0
+/* This variable is shared with all files that need to check for 32bit
+   uids.  */
+extern int __libc_missing_32bit_uids;
+#  endif
+# endif /* __NR_chown32 */
+#endif
+
+
+int
+fchownat (int fd, const char *file, uid_t owner, gid_t group, int flag)
+{
+  if (flag & ~AT_SYMLINK_NOFOLLOW)
+    {
+      __set_errno (EINVAL);
+      return -1;
+    }
+
+  char *buf = NULL;
+
+  if (fd != AT_FDCWD && file[0] != '/')
+    {
+      size_t filelen = strlen (file);
+      static const char procfd[] = "/proc/self/fd/%d/%s";
+      /* Buffer for the path name we are going to use.  It consists of
+	 - the string /proc/self/fd/
+	 - the file descriptor number
+	 - the file name provided.
+	 The final NUL is included in the sizeof.   A bit of overhead
+	 due to the format elements compensates for possible negative
+	 numbers.  */
+      size_t buflen = sizeof (procfd) + sizeof (int) * 3 + filelen;
+      buf = alloca (buflen);
+
+      __snprintf (buf, buflen, procfd, fd, file);
+      file = buf;
+    }
+
+  int result;
+  INTERNAL_SYSCALL_DECL (err);
+
+#if defined __NR_lchown || __ASSUME_LCHOWN_SYSCALL > 0
+# if __ASSUME_LCHOWN_SYSCALL == 0
+  static int __libc_old_chown;
+
+#  ifdef __NR_chown32
+  if (__libc_missing_32bit_uids <= 0)
+    {
+      if (flag & AT_SYMLINK_NOFOLLOW)
+	result = INTERNAL_SYSCALL (lchown32, err, 3, CHECK_STRING (file),
+				   owner, group);
+      else
+	result = INTERNAL_SYSCALL (chown32, err, 3, CHECK_STRING (file),
+				   owner, group);
+
+      if (!INTERNAL_SYSCALL_ERROR_P (result, err))
+	return result;
+      if (INTERNAL_SYSCALL_ERRNO (result, err) != ENOSYS)
+	goto fail;
+
+      __libc_missing_32bit_uids = 1;
+    }
+#  endif /* __NR_chown32 */
+
+  if (((owner + 1) > (uid_t) ((__kernel_uid_t) -1U))
+      || ((group + 1) > (gid_t) ((__kernel_gid_t) -1U)))
+    {
+      __set_errno (EINVAL);
+      return -1;
+    }
+
+  if (!__libc_old_chown && (flag & AT_SYMLINK_NOFOLLOW) == 0)
+    {
+      result = INTERNAL_SYSCALL (chown, err, 3, CHECK_STRING (file), owner,
+				 group);
+
+      if (!INTERNAL_SYSCALL_ERROR_P (result, err))
+	return result;
+      if (INTERNAL_SYSCALL_ERRNO (result, err) != ENOSYS)
+	goto fail;
+
+      __libc_old_chown = 1;
+    }
+
+  result = INTERNAL_SYSCALL (lchown, err, 3, CHECK_STRING (file), owner,
+			     group);
+# elif __ASSUME_32BITUIDS
+  /* This implies __ASSUME_LCHOWN_SYSCALL.  */
+  result = INTERNAL_SYSCALL (chown32, err, 3, CHECK_STRING (file), owner,
+			     group);
+# else
+  /* !__ASSUME_32BITUIDS && ASSUME_LCHOWN_SYSCALL  */
+#  ifdef __NR_chown32
+  if (__libc_missing_32bit_uids <= 0)
+    {
+      result = INTERNAL_SYSCALL (chown32, err, 3, CHECK_STRING (file), owner,
+				 group);
+      if (__builtin_expect (!INTERNAL_SYSCALL_ERROR_P (result, err), 1))
+	return result;
+      if (INTERNAL_SYSCALL_ERRNO (result, err) != ENOSYS)
+	goto fail;
+
+      __libc_missing_32bit_uids = 1;
+    }
+#  endif /* __NR_chown32 */
+  if (((owner + 1) > (uid_t) ((__kernel_uid_t) -1U))
+      || ((group + 1) > (gid_t) ((__kernel_gid_t) -1U)))
+    {
+      __set_errno (EINVAL);
+      return -1;
+    }
+
+  result = INTERNAL_SYSCALL (chown, err, 3, CHECK_STRING (file), owner, group);
+# endif
+#else
+  result = INTERNAL_SYSCALL (chown, err, 3, CHECK_STRING (file), owner, group);
+#endif
+
+  if (__builtin_expect (INTERNAL_SYSCALL_ERROR_P (result, err), 0))
+    {
+    fail:
+      __atfct_seterrno (INTERNAL_SYSCALL_ERRNO (result, err), fd, buf);
+      result = -1;
+    }
+
+  return result;
+}
diff --git a/sysdeps/unix/sysv/linux/i386/fxstatat.c b/sysdeps/unix/sysv/linux/i386/fxstatat.c
new file mode 100644
index 0000000000..2fc89e69c4
--- /dev/null
+++ b/sysdeps/unix/sysv/linux/i386/fxstatat.c
@@ -0,0 +1,148 @@
+/* Copyright (C) 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.  */
+
+/* Ho hum, if fxstatat == fxstatat64 we must get rid of the prototype or gcc
+   will complain since they don't strictly match.  */
+#define __fxstatat64 __fxstatat64_disable
+
+#include <errno.h>
+#include <fcntl.h>
+#include <stddef.h>
+#include <stdio.h>
+#include <sys/stat.h>
+#include <kernel_stat.h>
+
+#include <sysdep.h>
+#include <sys/syscall.h>
+#include <bp-checks.h>
+
+#include "kernel-features.h"
+
+#include <xstatconv.h>
+
+#ifdef __NR_stat64
+# if __ASSUME_STAT64_SYSCALL == 0
+/* The variable is shared between all wrappers around *stat64 calls.  */
+extern int __have_no_stat64;
+# endif
+#endif
+
+
+/* Get information about the file NAME relative to FD in ST.  */
+int
+__fxstatat (int vers, int fd, const char *file, struct stat *st, int flag)
+{
+  if (flag & ~AT_SYMLINK_NOFOLLOW)
+    {
+      __set_errno (EINVAL);
+      return -1;
+    }
+
+  char *buf = NULL;
+
+  if (fd != AT_FDCWD && file[0] != '/')
+    {
+      size_t filelen = strlen (file);
+      static const char procfd[] = "/proc/self/fd/%d/%s";
+      /* Buffer for the path name we are going to use.  It consists of
+	 - the string /proc/self/fd/
+	 - the file descriptor number
+	 - the file name provided.
+	 The final NUL is included in the sizeof.   A bit of overhead
+	 due to the format elements compensates for possible negative
+	 numbers.  */
+      size_t buflen = sizeof (procfd) + sizeof (int) * 3 + filelen;
+      buf = alloca (buflen);
+
+      __snprintf (buf, buflen, procfd, fd, file);
+      file = buf;
+    }
+
+#if __ASSUME_STAT64_SYSCALL == 0
+  struct kernel_stat kst;
+#endif
+  int result;
+  INTERNAL_SYSCALL_DECL (err);
+
+  if (vers == _STAT_VER_KERNEL)
+    {
+      if (flag & AT_SYMLINK_NOFOLLOW)
+	result = INTERNAL_SYSCALL (lstat, err, 2, CHECK_STRING (file),
+				   CHECK_1 ((struct kernel_stat *) st));
+      else
+	result = INTERNAL_SYSCALL (stat, err, 2, CHECK_STRING (file),
+				   CHECK_1 ((struct kernel_stat *) st));
+      goto out;
+    }
+
+#if __ASSUME_STAT64_SYSCALL > 0
+  struct stat64 st64;
+
+  if (flag & AT_SYMLINK_NOFOLLOW)
+    result = INTERNAL_SYSCALL (lstat64, err, 2, CHECK_STRING (file),
+			       __ptrvalue (&st64));
+  else
+    result = INTERNAL_SYSCALL (stat64, err, 2, CHECK_STRING (file),
+			       __ptrvalue (&st64));
+  if (__builtin_expect (!INTERNAL_SYSCALL_ERROR_P (result, err), 1))
+    return __xstat32_conv (vers, &st64, st);
+#else
+# if defined __NR_stat64
+  /* To support 32 bit UIDs, we have to use stat64.  The normal stat
+     call only returns 16 bit UIDs.  */
+  if (! __have_no_stat64)
+    {
+      struct stat64 st64;
+
+      if (flag & AT_SYMLINK_NOFOLLOW)
+	result = INTERNAL_SYSCALL (lstat64, err, 2, CHECK_STRING (file),
+				   __ptrvalue (&st64));
+      else
+	result = INTERNAL_SYSCALL (stat64, err, 2, CHECK_STRING (file),
+				   __ptrvalue (&st64));
+
+      if (__builtin_expect (!INTERNAL_SYSCALL_ERROR_P (result, err), 1))
+	result = __xstat32_conv (vers, &st64, st);
+
+      if (__builtin_expect (!INTERNAL_SYSCALL_ERROR_P (result, err), 1)
+	  || INTERNAL_SYSCALL_ERRNO (result, err) != ENOSYS)
+	goto out;
+
+      __have_no_stat64 = 1;
+    }
+# endif
+  if (flag & AT_SYMLINK_NOFOLLOW)
+    result = INTERNAL_SYSCALL (lstat, err, 2, CHECK_STRING (file),
+			       __ptrvalue (&kst));
+  else
+    result = INTERNAL_SYSCALL (stat, err, 2, CHECK_STRING (file),
+			       __ptrvalue (&kst));
+  if (__builtin_expect (!INTERNAL_SYSCALL_ERROR_P (result, err), 1))
+    return __xstat_conv (vers, &kst, st);
+#endif  /* __ASSUME_STAT64_SYSCALL  */
+
+ out:
+  if (__builtin_expect (INTERNAL_SYSCALL_ERROR_P (result, err), 0))
+    __atfct_seterrno (INTERNAL_SYSCALL_ERRNO (result, err), fd, buf);
+
+  return result;
+}
+#ifdef XSTAT_IS_XSTAT64
+# undef __fxstatat64
+strong_alias (__fxstatat, __fxstatat64);
+#endif
diff --git a/sysdeps/unix/sysv/linux/m68k/fchownat.c b/sysdeps/unix/sysv/linux/m68k/fchownat.c
new file mode 100644
index 0000000000..71df4feda7
--- /dev/null
+++ b/sysdeps/unix/sysv/linux/m68k/fchownat.c
@@ -0,0 +1,121 @@
+/* Copyright (C) 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 <fcntl.h>
+#include <stdio.h>
+#include <unistd.h>
+
+#include <sysdep.h>
+#include <sys/syscall.h>
+#include <bp-checks.h>
+
+#include <linux/posix_types.h>
+#include "kernel-features.h"
+
+#ifdef __NR_chown32
+# if __ASSUME_32BITUIDS == 0
+/* This variable is shared with all files that need to check for 32bit
+   uids.  */
+extern int __libc_missing_32bit_uids;
+# endif
+#endif /* __NR_chown32 */
+
+int
+fchownat (int fd, const char *file, uid_t owner, gid_t group, int flag)
+{
+  if (flag & ~AT_SYMLINK_NOFOLLOW)
+    {
+      __set_errno (EINVAL);
+      return -1;
+    }
+
+  char *buf = NULL;
+
+  if (fd != AT_FDCWD && file[0] != '/')
+    {
+      size_t filelen = strlen (file);
+      static const char procfd[] = "/proc/self/fd/%d/%s";
+      /* Buffer for the path name we are going to use.  It consists of
+	 - the string /proc/self/fd/
+	 - the file descriptor number
+	 - the file name provided.
+	 The final NUL is included in the sizeof.   A bit of overhead
+	 due to the format elements compensates for possible negative
+	 numbers.  */
+      size_t buflen = sizeof (procfd) + sizeof (int) * 3 + filelen;
+      buf = alloca (buflen);
+
+      __snprintf (buf, buflen, procfd, fd, file);
+      file = buf;
+    }
+
+  int result;
+  INTERNAL_SYSCALL_DECL (err);
+
+#if __ASSUME_32BITUIDS > 0
+  if (flag & AT_SYMLINK_NOFOLLOW)
+    result = INTERNAL_SYSCALL (lchown32, err, 3, CHECK_STRING (file), owner,
+			       group);
+  else
+    result = INTERNAL_SYSCALL (chown32, err, 3, CHECK_STRING (file), owner,
+			       group);
+#else
+# ifdef __NR_chown32
+  if (__libc_missing_32bit_uids <= 0)
+    {
+      if (flag & AT_SYMLINK_NOFOLLOW)
+	result = INTERNAL_SYSCALL (lchown32, err, 3, CHECK_STRING (file),
+				   owner, group);
+      else
+	result = INTERNAL_SYSCALL (chown32, err, 3, CHECK_STRING (file), owner,
+				   group);
+
+      if (__builtin_expect (!INTERNAL_SYSCALL_ERROR_P (result, err), 1))
+	return result;
+      if (INTERNAL_SYSCALL_ERRNO (result, err) != ENOSYS)
+	goto fail;
+
+      __libc_missing_32bit_uids = 1;
+    }
+# endif /* __NR_chown32 */
+
+  if (((owner + 1) > (gid_t) ((__kernel_uid_t) -1U))
+      || ((group + 1) > (gid_t) ((__kernel_gid_t) -1U)))
+    {
+      __set_errno (EINVAL);
+      return -1;
+    }
+
+  if (flag & AT_SYMLINK_NOFOLLOW)
+    result = INTERNAL_SYSCALL (lchown, err, 3, CHECK_STRING (file), owner,
+			       group);
+  else
+    result = INTERNAL_SYSCALL (chown, err, 3, CHECK_STRING (file), owner,
+			       group);
+#endif
+
+  if (__builtin_expect (INTERNAL_SYSCALL_ERROR_P (result, err), 0))
+    {
+    fail:
+      __atfct_seterrno (INTERNAL_SYSCALL_ERRNO (result, err), fd, buf);
+      result = -1;
+    }
+
+  return result;
+}
diff --git a/sysdeps/unix/sysv/linux/m68k/fxstatat.c b/sysdeps/unix/sysv/linux/m68k/fxstatat.c
new file mode 100644
index 0000000000..0f8b3135d8
--- /dev/null
+++ b/sysdeps/unix/sysv/linux/m68k/fxstatat.c
@@ -0,0 +1 @@
+#include <sysdeps/unix/sysv/linux/i386/fxstatat.c>
diff --git a/sysdeps/unix/sysv/linux/openat.c b/sysdeps/unix/sysv/linux/openat.c
index a89f172b62..d5d976cbc4 100644
--- a/sysdeps/unix/sysv/linux/openat.c
+++ b/sysdeps/unix/sysv/linux/openat.c
@@ -29,6 +29,30 @@
 #ifndef OPENAT
 # define OPENAT openat
 # define MORE_OFLAGS 0
+
+
+void
+attribute_hidden
+__atfct_seterrno (int errval, int fd, const char *buf)
+{
+  if (buf != NULL && errval == ENOTDIR)
+    {
+      /* This can mean either the file descriptor is invalid or
+	 /proc is not mounted.  */
+      struct stat64 st;
+      if (__fxstat64 (_STAT_VER, fd, &st) != 0)
+	/* errno is already set correctly.  */
+	return;
+
+      /* If /proc is not mounted there is nothing we can do.  */
+      if (S_ISDIR (st.st_mode)
+	  && (__xstat64 (_STAT_VER, "/proc/self/fd", &st) != 0
+	      || !S_ISDIR (st.st_mode)))
+	errval = ENOSYS;
+    }
+
+  __set_errno (errval);
+}
 #endif
 
 /* Open FILE with access OFLAG.  Interpret relative paths relative to
@@ -42,7 +66,7 @@ OPENAT (fd, file, oflag)
 {
   char *buf = NULL;
 
-  if (file[0] != '/')
+  if (fd != AT_FDCWD && file[0] != '/')
     {
       size_t filelen = strlen (file);
       static const char procfd[] = "/proc/self/fd/%d/%s";
@@ -85,26 +109,9 @@ OPENAT (fd, file, oflag)
 
   if (__builtin_expect (INTERNAL_SYSCALL_ERROR_P (res, err), 0))
     {
-      int errval = INTERNAL_SYSCALL_ERRNO (res, err);
-      if (buf != NULL && errval == ENOTDIR)
-	{
-	  /* This can mean either the file desriptor is invalid or
-	     /proc is not mounted.  */
-	  struct stat64 st;
-	  if (__fxstat64 (_STAT_VER, fd, &st) != 0)
-	    /* errno is already set correctly.  */
-	    goto out;
-
-	  /* If /proc is not mounted there is nothing we can do.  */
-	  if (S_ISDIR (st.st_mode)
-	      && (__xstat64 (_STAT_VER, "/proc/self/fd", &st) != 0
-		  || !S_ISDIR (st.st_mode)))
-	    errval = ENOSYS;
-	}
-
-      __set_errno (errval);
+      __atfct_seterrno (INTERNAL_SYSCALL_ERRNO (res, err), fd, buf);
+      res = -1;
     }
 
- out:
   return res;
 }
diff --git a/sysdeps/unix/sysv/linux/powerpc/chown.c b/sysdeps/unix/sysv/linux/powerpc/chown.c
index 4b283e720c..fdcbd3683a 100644
--- a/sysdeps/unix/sysv/linux/powerpc/chown.c
+++ b/sysdeps/unix/sysv/linux/powerpc/chown.c
@@ -1,5 +1,5 @@
 /* chown() compatibility.
-   Copyright (C) 1998, 2000, 2002, 2003 Free Software Foundation, Inc.
+   Copyright (C) 1998, 2000, 2002, 2003, 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
@@ -24,6 +24,8 @@
 #include <sysdep.h>
 #include <stdlib.h>
 
+#include <kernel-features.h>
+
 /*
   In Linux 2.1.x the chown functions have been changed.  A new function lchown
   was introduced.  The new chown now follows symlinks - the old chown and the
@@ -34,58 +36,61 @@
 int
 __chown (const char *file, uid_t owner, gid_t group)
 {
-   int err;
-   int old_errno;
-   char link[PATH_MAX+2];
-   char path[2*PATH_MAX+4];
-   int loopct;
-   size_t filelen;
-   static int libc_old_chown = 0 /* -1=old linux, 1=new linux, 0=unknown */;
-
-   if (libc_old_chown == 1)
-     return INLINE_SYSCALL (chown, 3, __ptrvalue (file), owner, group);
-
-   old_errno = errno;
-
-#ifdef __NR_lchown
-   if (libc_old_chown == 0)
-     {
-       err = INLINE_SYSCALL (chown, 3, __ptrvalue (file), owner, group);
-       if (err != -1 || errno != ENOSYS)
-	 {
-	   libc_old_chown = 1;
-	   return err;
-	 }
-       libc_old_chown = -1;
-     }
-#endif
-
-   err = __readlink (file, link, PATH_MAX+1);
-   if (err == -1)
-     {
-       errno = old_errno;
-       return __lchown(file, owner, group);
-     }
-
-   filelen = strlen (file) + 1;
-   if (filelen > sizeof(path))
-     {
-       errno = ENAMETOOLONG;
-       return -1;
-     }
-   memcpy (path, file, filelen);
-
-   /* 'The system has an arbitrary limit...'  In practise, we'll hit
-      ENAMETOOLONG before this, usually.  */
-   for (loopct = 0; loopct < 128; loopct++)
-   {
-     size_t linklen;
-
-     if (err >= PATH_MAX+1)
-       {
-	 errno = ENAMETOOLONG;
-	 return -1;
-       }
+#if __ASSUME_LCHOWN_SYSCALL
+  return INLINE_SYSCALL (chown, 3, file, owner, group);
+#else
+  int err;
+  int old_errno;
+  char link[PATH_MAX + 2];
+  char path[2 * PATH_MAX + 4];
+  int loopct;
+  size_t filelen;
+  static int libc_old_chown = 0 /* -1=old linux, 1=new linux, 0=unknown */;
+
+  if (libc_old_chown == 1)
+    return INLINE_SYSCALL (chown, 3, __ptrvalue (file), owner, group);
+
+  old_errno = errno;
+
+# ifdef __NR_lchown
+  if (libc_old_chown == 0)
+    {
+      err = INLINE_SYSCALL (chown, 3, __ptrvalue (file), owner, group);
+      if (err != -1 || errno != ENOSYS)
+	{
+	  libc_old_chown = 1;
+	  return err;
+	}
+      libc_old_chown = -1;
+    }
+# endif
+
+  err = __readlink (file, link, PATH_MAX + 1);
+  if (err == -1)
+    {
+      __set_errno (old_errno);
+      return __lchown (file, owner, group);
+    }
+
+  filelen = strlen (file) + 1;
+  if (filelen > sizeof (path))
+    {
+      __set_errno (ENAMETOOLONG);
+      return -1;
+    }
+  memcpy (path, file, filelen);
+
+  /* 'The system has an arbitrary limit...'  In practise, we'll hit
+     ENAMETOOLONG before this, usually.  */
+  for (loopct = 0; loopct < 128; ++loopct)
+    {
+      size_t linklen;
+
+      if (err >= PATH_MAX + 1)
+	{
+	  __set_errno (ENAMETOOLONG);
+	  return -1;
+	}
 
       link[err] = 0;  /* Null-terminate string, just-in-case.  */
 
@@ -97,28 +102,29 @@ __chown (const char *file, uid_t owner, gid_t group)
 	{
 	  filelen = strlen (path);
 
-	  while (filelen > 1 && path[filelen-1] == '/')
-	    filelen--;
-	  while (filelen > 0 && path[filelen-1] != '/')
-	    filelen--;
-	  if (filelen + linklen > sizeof(path))
+	  while (filelen > 1 && path[filelen - 1] == '/')
+	    --filelen;
+	  while (filelen > 0 && path[filelen - 1] != '/')
+	    --filelen;
+	  if (filelen + linklen > sizeof (path))
 	    {
 	      errno = ENAMETOOLONG;
 	      return -1;
 	    }
-	  memcpy (path+filelen, link, linklen);
+	  memcpy (path + filelen, link, linklen);
 	}
 
-      err = __readlink(path, link, PATH_MAX+1);
+      err = __readlink (path, link, PATH_MAX + 1);
 
       if (err == -1)
-      {
-	errno = old_errno;
-	return __lchown(path, owner, group);
-      }
-   }
-   errno = ELOOP;
-   return -1;
+	{
+	  __set_errno (old_errno);
+	  return __lchown (path, owner, group);
+	}
+    }
+  __set_errno (ELOOP);
+  return -1;
+#endif
 }
 libc_hidden_def (__chown)
 
diff --git a/sysdeps/unix/sysv/linux/powerpc/fchownat.c b/sysdeps/unix/sysv/linux/powerpc/fchownat.c
new file mode 100644
index 0000000000..1fbae5c448
--- /dev/null
+++ b/sysdeps/unix/sysv/linux/powerpc/fchownat.c
@@ -0,0 +1,205 @@
+/* Copyright (C) 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 <fcntl.h>
+#include <stdio.h>
+#include <string.h>
+#include <unistd.h>
+#include <limits.h>
+#include <sysdep.h>
+#include <stdlib.h>
+
+#include <kernel-features.h>
+
+/*
+  In Linux 2.1.x the chown functions have been changed.  A new function lchown
+  was introduced.  The new chown now follows symlinks - the old chown and the
+  new lchown do not follow symlinks.
+  This file emulates chown() under the old kernels.
+*/
+
+int
+fchownat (int fd, const char *file, uid_t owner, gid_t group, int flag)
+{
+  if (flag & ~AT_SYMLINK_NOFOLLOW)
+    {
+      __set_errno (EINVAL);
+      return -1;
+    }
+
+  char *buf = NULL;
+
+  if (fd != AT_FDCWD && file[0] != '/')
+    {
+      size_t filelen = strlen (file);
+      static const char procfd[] = "/proc/self/fd/%d/%s";
+      /* Buffer for the path name we are going to use.  It consists of
+	 - the string /proc/self/fd/
+	 - the file descriptor number
+	 - the file name provided.
+	 The final NUL is included in the sizeof.   A bit of overhead
+	 due to the format elements compensates for possible negative
+	 numbers.  */
+      size_t buflen = sizeof (procfd) + sizeof (int) * 3 + filelen;
+      buf = alloca (buflen);
+
+      __snprintf (buf, buflen, procfd, fd, file);
+      file = buf;
+    }
+
+  int result;
+  INTERNAL_SYSCALL_DECL (err);
+
+#if __ASSUME_LCHOWN_SYSCALL
+  if (flag & AT_SYMLINK_NOFOLLOW)
+    result = INTERNAL_SYSCALL (lchown, err, 3, file, owner, group);
+  else
+    result = INTERNAL_SYSCALL (chown, err, 3, file, owner, group);
+#else
+  char link[PATH_MAX + 2];
+  char path[2 * PATH_MAX + 4];
+  int loopct;
+  size_t filelen;
+  static int libc_old_chown = 0 /* -1=old linux, 1=new linux, 0=unknown */;
+
+  if (libc_old_chown == 1)
+    {
+      if (flag & AT_SYMLINK_NOFOLLOW)
+	result = INTERNAL_SYSCALL (lchown, err, 3, __ptrvalue (file), owner,
+				   group);
+      else
+	result = INTERNAL_SYSCALL (chown, err, 3, __ptrvalue (file), owner,
+				   group);
+      goto out;
+    }
+
+# ifdef __NR_lchown
+  if (flag & AT_SYMLINK_NOFOLLOW)
+    {
+      result = INTERNAL_SYSCALL (lchown, err, 3, __ptrvalue (file), owner,
+				 group);
+      goto out;
+    }
+
+  if (libc_old_chown == 0)
+    {
+      result = INTERNAL_SYSCALL (chown, err, 3, __ptrvalue (file), owner,
+				 group);
+      if (__builtin_expect (!INTERNAL_SYSCALL_ERROR_P (result, err), 1))
+	return result;
+      if (INTERNAL_SYSCALL_ERRNO (result, err) != ENOSYS)
+	{
+	  libc_old_chown = 1;
+	  goto fail;
+	}
+      libc_old_chown = -1;
+    }
+# else
+  if (flag & AT_SYMLINK_NOFOLLOW)
+    {
+      result = INTERNAL_SYSCALL (chown, err, 3, __ptrvalue (file), owner,
+				 group);
+      goto out;
+    }
+# endif
+
+  result = __readlink (file, link, PATH_MAX + 1);
+  if (result == -1)
+    {
+# ifdef __NR_lchown
+      result = INTERNAL_SYSCALL (lchown, err, 3, __ptrvalue (file), owner,
+				 group);
+# else
+      result = INTERNAL_SYSCALL (chown, err, 3, __ptrvalue (file), owner,
+				 group);
+# endif
+      goto out;
+    }
+
+  filelen = strlen (file) + 1;
+  if (filelen > sizeof (path))
+    {
+      errno = ENAMETOOLONG;
+      return -1;
+    }
+  memcpy (path, file, filelen);
+
+  /* 'The system has an arbitrary limit...'  In practise, we'll hit
+     ENAMETOOLONG before this, usually.  */
+  for (loopct = 0; loopct < 128; ++loopct)
+    {
+      size_t linklen;
+
+      if (result >= PATH_MAX + 1)
+	{
+	  errno = ENAMETOOLONG;
+	  return -1;
+	}
+
+      link[result] = 0;  /* Null-terminate string, just-in-case.  */
+
+      linklen = strlen (link) + 1;
+
+      if (link[0] == '/')
+	memcpy (path, link, linklen);
+      else
+	{
+	  filelen = strlen (path);
+
+	  while (filelen > 1 && path[filelen - 1] == '/')
+	    --filelen;
+	  while (filelen > 0 && path[filelen - 1] != '/')
+	    --filelen;
+	  if (filelen + linklen > sizeof (path))
+	    {
+	      errno = ENAMETOOLONG;
+	      return -1;
+	    }
+	  memcpy (path + filelen, link, linklen);
+	}
+
+      result = __readlink (path, link, PATH_MAX + 1);
+
+      if (result == -1)
+	{
+# ifdef __NR_lchown
+	  result = INTERNAL_SYSCALL (lchown, err, 3, path, owner, group);
+# else
+	  result = INTERNAL_SYSCALL (chown, err, 3, path, owner, group);
+# endif
+	  goto out;
+	}
+    }
+  __set_errno (ELOOP);
+  return -1;
+
+ out:
+#endif
+
+  if (__builtin_expect (INTERNAL_SYSCALL_ERROR_P (result, err), 0))
+    {
+#if !__ASSUME_LCHOWN_SYSCALL
+    fail:
+#endif
+      __atfct_seterrno (INTERNAL_SYSCALL_ERRNO (result, err), fd, buf);
+      result = -1;
+    }
+
+  return result;
+}
diff --git a/sysdeps/unix/sysv/linux/powerpc/powerpc32/fxstatat.c b/sysdeps/unix/sysv/linux/powerpc/powerpc32/fxstatat.c
new file mode 100644
index 0000000000..0f8b3135d8
--- /dev/null
+++ b/sysdeps/unix/sysv/linux/powerpc/powerpc32/fxstatat.c
@@ -0,0 +1 @@
+#include <sysdeps/unix/sysv/linux/i386/fxstatat.c>
diff --git a/sysdeps/unix/sysv/linux/renameat.c b/sysdeps/unix/sysv/linux/renameat.c
new file mode 100644
index 0000000000..31662ea053
--- /dev/null
+++ b/sysdeps/unix/sysv/linux/renameat.c
@@ -0,0 +1,121 @@
+/* Copyright (C) 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 <fcntl.h>
+#include <stdio.h>
+#include <sysdep.h>
+
+
+/* Rename the file OLD relative to OLDFD to NEW relative to NEWFD.  */
+int
+renameat (oldfd, old, newfd, new)
+     int oldfd;
+     const char *old;
+     int newfd;
+     const char *new;
+{
+  static const char procfd[] = "/proc/self/fd/%d/%s";
+  char *bufold = NULL;
+
+  if (oldfd != AT_FDCWD && old[0] != '/')
+    {
+      size_t filelen = strlen (old);
+      /* Buffer for the path name we are going to use.  It consists of
+	 - the string /proc/self/fd/
+	 - the file descriptor number
+	 - the file name provided.
+	 The final NUL is included in the sizeof.   A bit of overhead
+	 due to the format elements compensates for possible negative
+	 numbers.  */
+      size_t buflen = sizeof (procfd) + sizeof (int) * 3 + filelen;
+      bufold = alloca (buflen);
+
+      __snprintf (bufold, buflen, procfd, oldfd, old);
+      old = bufold;
+    }
+
+  char *bufnew = NULL;
+
+  if (newfd != AT_FDCWD && new[0] != '/')
+    {
+      size_t filelen = strlen (new);
+      /* Buffer for the path name we are going to use.  It consists of
+	 - the string /proc/self/fd/
+	 - the file descriptor number
+	 - the file name provided.
+	 The final NUL is included in the sizeof.   A bit of overhead
+	 due to the format elements compensates for possible negative
+	 numbers.  */
+      size_t buflen = sizeof (procfd) + sizeof (int) * 3 + filelen;
+      bufnew = alloca (buflen);
+
+      __snprintf (bufnew, buflen, procfd, newfd, new);
+      new = bufnew;
+    }
+
+  INTERNAL_SYSCALL_DECL (err);
+
+  int result = INTERNAL_SYSCALL (rename, err, 2, old,  new);
+
+  if (__builtin_expect (INTERNAL_SYSCALL_ERROR_P (result, err), 0))
+    {
+      int errval = INTERNAL_SYSCALL_ERRNO (result, err);
+      if (errval == ENOTDIR && (bufnew != NULL || bufold != NULL))
+	{
+	  /* This can mean either the file descriptor is invalid or
+	     /proc is not mounted.  */
+	  struct stat64 st;
+
+	  if (bufnew != NULL)
+	    {
+	      if (__fxstat64 (_STAT_VER, newfd, &st) != 0)
+		/* errno is already set correctly.  */
+		return -1;
+
+	      /* If /proc is not mounted there is nothing we can do.  */
+	      if (S_ISDIR (st.st_mode)
+		  && (__xstat64 (_STAT_VER, "/proc/self/fd", &st) != 0
+		      || !S_ISDIR (st.st_mode)))
+		{
+		  errval = ENOSYS;
+		  goto out;
+		}
+	    }
+
+	  if (bufold != NULL)
+	    {
+	      if (__fxstat64 (_STAT_VER, oldfd, &st) != 0)
+		/* errno is already set correctly.  */
+		return -1;
+
+	      /* If /proc is not mounted there is nothing we can do.  */
+	      if (S_ISDIR (st.st_mode)
+		  && (__xstat64 (_STAT_VER, "/proc/self/fd", &st) != 0
+		      || !S_ISDIR (st.st_mode)))
+		errval = ENOSYS;
+	    }
+	}
+
+    out:
+      __set_errno (errval);
+      result = -1;
+    }
+
+  return result;
+}
diff --git a/sysdeps/unix/sysv/linux/s390/s390-32/fchownat.c b/sysdeps/unix/sysv/linux/s390/s390-32/fchownat.c
new file mode 100644
index 0000000000..b95665cad3
--- /dev/null
+++ b/sysdeps/unix/sysv/linux/s390/s390-32/fchownat.c
@@ -0,0 +1,140 @@
+/* Copyright (C) 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 <fcntl.h>
+#include <stdio.h>
+#include <unistd.h>
+
+#include <sysdep.h>
+#include <sys/syscall.h>
+#include <shlib-compat.h>
+#include <bp-checks.h>
+
+#include <linux/posix_types.h>
+#include "kernel-features.h"
+
+/*
+  In Linux 2.1.x the chown functions have been changed.  A new function lchown
+  was introduced.  The new chown now follows symlinks - the old chown and the
+  new lchown do not follow symlinks.
+  The new lchown function has the same number as the old chown had and the
+  new chown has a new number.  When compiling with headers from Linux > 2.1.8x
+  it's impossible to run this libc with older kernels.  In these cases libc
+  has therefore to route calls to chown to the old chown function.
+*/
+
+/* Running under Linux > 2.1.80.  */
+
+#ifdef __NR_chown32
+# if __ASSUME_32BITUIDS == 0
+/* This variable is shared with all files that need to check for 32bit
+   uids.  */
+extern int __libc_missing_32bit_uids;
+# endif
+#endif /* __NR_chown32 */
+
+int
+fchownat (int fd, const char *file, uid_t owner, gid_t group, int flag)
+{
+  if (flag & ~AT_SYMLINK_NOFOLLOW)
+    {
+      __set_errno (EINVAL);
+      return -1;
+    }
+
+  char *buf = NULL;
+
+  if (fd != AT_FDCWD && file[0] != '/')
+    {
+      size_t filelen = strlen (file);
+      static const char procfd[] = "/proc/self/fd/%d/%s";
+      /* Buffer for the path name we are going to use.  It consists of
+	 - the string /proc/self/fd/
+	 - the file descriptor number
+	 - the file name provided.
+	 The final NUL is included in the sizeof.   A bit of overhead
+	 due to the format elements compensates for possible negative
+	 numbers.  */
+      size_t buflen = sizeof (procfd) + sizeof (int) * 3 + filelen;
+      buf = alloca (buflen);
+
+      __snprintf (buf, buflen, procfd, fd, file);
+      file = buf;
+    }
+
+  int result;
+  INTERNAL_SYSCALL_DECL (err);
+
+#if __ASSUME_32BITUIDS > 0
+  result = INTERNAL_SYSCALL (chown32, err, 3, CHECK_STRING (file), owner,
+			     group);
+#else
+  static int __libc_old_chown;
+
+# ifdef __NR_chown32
+  if (__libc_missing_32bit_uids <= 0)
+    {
+      if (flag & AT_SYMLINK_NOFOLLOW)
+	result = INTERNAL_SYSCALL (lchown32, err, 3, CHECK_STRING (file),
+				   owner, group);
+      else
+	result = INTERNAL_SYSCALL (chown32, err, 3, CHECK_STRING (file),
+				   owner, group);
+
+      if (__builtin_expect (!INTERNAL_SYSCALL_ERROR_P (result, err), 1))
+	return result;
+      if (INTERNAL_SYSCALL_ERRNO (result, err) != ENOSYS)
+	goto fail;
+
+      __libc_missing_32bit_uids = 1;
+    }
+# endif /* __NR_chown32 */
+  if (((owner + 1) > (uid_t) ((__kernel_uid_t) -1U))
+      || ((group + 1) > (gid_t) ((__kernel_gid_t) -1U)))
+    {
+      __set_errno (EINVAL);
+      return -1;
+    }
+
+  if (!__libc_old_chown && (flag & AT_SYMLINK_NOFOLLOW) == 0)
+    {
+      result = INTERNAL_SYSCALL (chown, err, 3, CHECK_STRING (file), owner,
+				 group);
+
+      if (!INTERNAL_SYSCALL_ERROR_P (result, err))
+	return result;
+      if (INTERNAL_SYSCALL_ERRNO (result, err) != ENOSYS)
+	goto fail;
+
+      __libc_old_chown = 1;
+    }
+
+  result = INTERNAL_SYSCALL (lchown, err, 3, CHECK_STRING (file), owner,
+			     group);
+#endif
+
+  if (__builtin_expect (INTERNAL_SYSCALL_ERROR_P (result, err), 0))
+    {
+    fail:
+      __atfct_seterrno (INTERNAL_SYSCALL_ERRNO (result, err), fd, buf);
+      result = -1;
+    }
+
+  return result;
+}
diff --git a/sysdeps/unix/sysv/linux/s390/s390-32/fxstatat.c b/sysdeps/unix/sysv/linux/s390/s390-32/fxstatat.c
new file mode 100644
index 0000000000..0f8b3135d8
--- /dev/null
+++ b/sysdeps/unix/sysv/linux/s390/s390-32/fxstatat.c
@@ -0,0 +1 @@
+#include <sysdeps/unix/sysv/linux/i386/fxstatat.c>
diff --git a/sysdeps/unix/sysv/linux/sh/fchownat.c b/sysdeps/unix/sysv/linux/sh/fchownat.c
new file mode 100644
index 0000000000..7acf7918ee
--- /dev/null
+++ b/sysdeps/unix/sysv/linux/sh/fchownat.c
@@ -0,0 +1 @@
+#include <sysdeps/unix/sysv/linux/m68k/fchownat.c>
diff --git a/sysdeps/unix/sysv/linux/sh/fxstatat.c b/sysdeps/unix/sysv/linux/sh/fxstatat.c
new file mode 100644
index 0000000000..0f8b3135d8
--- /dev/null
+++ b/sysdeps/unix/sysv/linux/sh/fxstatat.c
@@ -0,0 +1 @@
+#include <sysdeps/unix/sysv/linux/i386/fxstatat.c>
diff --git a/sysdeps/unix/sysv/linux/sparc/sparc32/fchownat.c b/sysdeps/unix/sysv/linux/sparc/sparc32/fchownat.c
new file mode 100644
index 0000000000..7acf7918ee
--- /dev/null
+++ b/sysdeps/unix/sysv/linux/sparc/sparc32/fchownat.c
@@ -0,0 +1 @@
+#include <sysdeps/unix/sysv/linux/m68k/fchownat.c>
diff --git a/sysdeps/unix/sysv/linux/sparc/sparc32/fxstatat.c b/sysdeps/unix/sysv/linux/sparc/sparc32/fxstatat.c
new file mode 100644
index 0000000000..0f8b3135d8
--- /dev/null
+++ b/sysdeps/unix/sysv/linux/sparc/sparc32/fxstatat.c
@@ -0,0 +1 @@
+#include <sysdeps/unix/sysv/linux/i386/fxstatat.c>
diff --git a/sysdeps/unix/sysv/linux/sparc/sparc64/fxstatat.c b/sysdeps/unix/sysv/linux/sparc/sparc64/fxstatat.c
new file mode 100644
index 0000000000..c2610b2a06
--- /dev/null
+++ b/sysdeps/unix/sysv/linux/sparc/sparc64/fxstatat.c
@@ -0,0 +1 @@
+#include "../../fxstatat.c"
diff --git a/sysdeps/unix/sysv/linux/unlinkat.c b/sysdeps/unix/sysv/linux/unlinkat.c
new file mode 100644
index 0000000000..c590e71ada
--- /dev/null
+++ b/sysdeps/unix/sysv/linux/unlinkat.c
@@ -0,0 +1,74 @@
+/* Copyright (C) 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 <fcntl.h>
+#include <stddef.h>
+#include <stdio.h>
+#include <unistd.h>
+
+
+/* Remove the link named NAME.  */
+int
+unlinkat (fd, file, flag)
+     int fd;
+     const char *file;
+     int flag;
+{
+  if (flag & ~AT_REMOVEDIR)
+    {
+      __set_errno (EINVAL);
+      return -1;
+    }
+
+  char *buf = NULL;
+
+  if (fd != AT_FDCWD && file[0] != '/')
+    {
+      size_t filelen = strlen (file);
+      static const char procfd[] = "/proc/self/fd/%d/%s";
+      /* Buffer for the path name we are going to use.  It consists of
+	 - the string /proc/self/fd/
+	 - the file descriptor number
+	 - the file name provided.
+	 The final NUL is included in the sizeof.   A bit of overhead
+	 due to the format elements compensates for possible negative
+	 numbers.  */
+      size_t buflen = sizeof (procfd) + sizeof (int) * 3 + filelen;
+      buf = alloca (buflen);
+
+      __snprintf (buf, buflen, procfd, fd, file);
+      file = buf;
+    }
+
+  int result;
+  INTERNAL_SYSCALL_DECL (err);
+
+  if (flag & AT_REMOVEDIR)
+    result = INTERNAL_SYSCALL (rmdir, err, 1, file);
+  else
+    result = INTERNAL_SYSCALL (unlink, err, 1, file);
+
+  if (__builtin_expect (INTERNAL_SYSCALL_ERROR_P (result, err), 0))
+    {
+      __atfct_seterrno (INTERNAL_SYSCALL_ERRNO (result, err), fd, buf);
+      result = -1;
+    }
+
+  return result;
+}
diff --git a/sysdeps/unix/sysv/linux/wordsize-64/fxstatat.c b/sysdeps/unix/sysv/linux/wordsize-64/fxstatat.c
new file mode 100644
index 0000000000..70e73571f7
--- /dev/null
+++ b/sysdeps/unix/sysv/linux/wordsize-64/fxstatat.c
@@ -0,0 +1,78 @@
+/* Copyright (C) 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.  */
+
+/* Ho hum, since fxstatat == fxstatat64 we must get rid of the
+   prototype or gcc will complain since they don't strictly match.  */
+#define __fxstatat64 __fxstatat64_disable
+
+#include <errno.h>
+#include <fcntl.h>
+#include <stddef.h>
+#include <stdio.h>
+#include <sys/stat.h>
+
+#include <sysdep.h>
+#include <sys/syscall.h>
+#include <bp-checks.h>
+
+/* Get information about the file NAME relative to FD in ST.  */
+int
+__fxstatat (int vers, int fd, const char *file, struct stat *st, int flag)
+{
+  if ((vers != _STAT_VER_KERNEL && vers != _STAT_VER_LINUX)
+      || (flag & ~AT_SYMLINK_NOFOLLOW) != 0)
+    {
+      __set_errno (EINVAL);
+      return -1;
+    }
+
+  char *buf = NULL;
+
+  if (fd != AT_FDCWD && file[0] != '/')
+    {
+      size_t filelen = strlen (file);
+      static const char procfd[] = "/proc/self/fd/%d/%s";
+      /* Buffer for the path name we are going to use.  It consists of
+	 - the string /proc/self/fd/
+	 - the file descriptor number
+	 - the file name provided.
+	 The final NUL is included in the sizeof.   A bit of overhead
+	 due to the format elements compensates for possible negative
+	 numbers.  */
+      size_t buflen = sizeof (procfd) + sizeof (int) * 3 + filelen;
+      buf = alloca (buflen);
+
+      __snprintf (buf, buflen, procfd, fd, file);
+      file = buf;
+    }
+
+  INTERNAL_SYSCALL_DECL (err);
+  int res;
+
+  if (flag & AT_SYMLINK_NOFOLLOW)
+    res = INTERNAL_SYSCALL (lstat, err, 2, file, CHECK_1 (st));
+  else
+    res = INTERNAL_SYSCALL (stat, err, 2, file, CHECK_1 (st));
+
+  if (__builtin_expect (INTERNAL_SYSCALL_ERROR_P (res, err), 0))
+    __atfct_seterrno (INTERNAL_SYSCALL_ERRNO (res, err), fd, buf);
+
+  return res;
+}
+#undef __fxstatat64
+strong_alias (__fxstatat, __fxstatat64);
diff --git a/sysdeps/unix/sysv/linux/wordsize-64/fxstatat64.c b/sysdeps/unix/sysv/linux/wordsize-64/fxstatat64.c
new file mode 100644
index 0000000000..05e7f413bb
--- /dev/null
+++ b/sysdeps/unix/sysv/linux/wordsize-64/fxstatat64.c
@@ -0,0 +1 @@
+/* fxstatat64 is in fxstatat.c */