about summary refs log tree commit diff
path: root/sysdeps/unix/sysv
diff options
context:
space:
mode:
Diffstat (limited to 'sysdeps/unix/sysv')
-rw-r--r--sysdeps/unix/sysv/linux/Dist1
-rw-r--r--sysdeps/unix/sysv/linux/alpha/Dist1
-rw-r--r--sysdeps/unix/sysv/linux/alpha/bits/dirent.h9
-rw-r--r--sysdeps/unix/sysv/linux/alpha/bits/stat.h48
-rw-r--r--sysdeps/unix/sysv/linux/alpha/bits/types.h56
-rw-r--r--sysdeps/unix/sysv/linux/alpha/fxstat64.c1
-rw-r--r--sysdeps/unix/sysv/linux/alpha/kernel_stat.h26
-rw-r--r--sysdeps/unix/sysv/linux/alpha/lxstat64.c1
-rw-r--r--sysdeps/unix/sysv/linux/alpha/xstat64.c1
-rw-r--r--sysdeps/unix/sysv/linux/alpha/xstatconv.c90
-rw-r--r--sysdeps/unix/sysv/linux/bits/stat.h1
-rw-r--r--sysdeps/unix/sysv/linux/fxstat.c74
-rw-r--r--sysdeps/unix/sysv/linux/lxstat.c74
-rw-r--r--sysdeps/unix/sysv/linux/xstat.c74
-rw-r--r--sysdeps/unix/sysv/linux/xstatconv.c83
15 files changed, 331 insertions, 209 deletions
diff --git a/sysdeps/unix/sysv/linux/Dist b/sysdeps/unix/sysv/linux/Dist
index bdc333a5af..cfe5202ba1 100644
--- a/sysdeps/unix/sysv/linux/Dist
+++ b/sysdeps/unix/sysv/linux/Dist
@@ -48,3 +48,4 @@ sys/sysmacros.h
 sys/timex.h
 sys/user.h
 sys/vt.h
+xstatconv.c
diff --git a/sysdeps/unix/sysv/linux/alpha/Dist b/sysdeps/unix/sysv/linux/alpha/Dist
index ae71c2feb3..ebbf300eac 100644
--- a/sysdeps/unix/sysv/linux/alpha/Dist
+++ b/sysdeps/unix/sysv/linux/alpha/Dist
@@ -12,3 +12,4 @@ kernel_termios.h
 sys/acct.h
 sys/io.h
 sys/procfs.h
+xstatconv.c
\ No newline at end of file
diff --git a/sysdeps/unix/sysv/linux/alpha/bits/dirent.h b/sysdeps/unix/sysv/linux/alpha/bits/dirent.h
index 4d717e4194..a371a552ff 100644
--- a/sysdeps/unix/sysv/linux/alpha/bits/dirent.h
+++ b/sysdeps/unix/sysv/linux/alpha/bits/dirent.h
@@ -19,10 +19,14 @@
 #ifndef _BITS_DIRENT_H
 #define _BITS_DIRENT_H	1
 
-/* We don't have to make a difference for __USE_FILE_OFFSET64.  */
 struct dirent
   {
-    long int d_ino;
+#ifdef __USE_FILE_OFFSET64
+    __ino64_t d_ino;
+#else
+    __ino_t d_ino;
+    int __pad;
+#endif
     __off_t d_off;
     unsigned short int d_reclen;
     unsigned char d_type;
@@ -30,6 +34,7 @@ struct dirent
   };
 
 #ifdef __USE_LARGEFILE64
+/* Note dirent64 is the same as dirent.  */
 struct dirent64
   {
     __ino64_t d_ino;
diff --git a/sysdeps/unix/sysv/linux/alpha/bits/stat.h b/sysdeps/unix/sysv/linux/alpha/bits/stat.h
index cc2a2eac90..de8752ea8b 100644
--- a/sysdeps/unix/sysv/linux/alpha/bits/stat.h
+++ b/sysdeps/unix/sysv/linux/alpha/bits/stat.h
@@ -24,9 +24,10 @@
 #define	_BITS_STAT_H	1
 
 /* Versions of the `struct stat' data structure.  */
-#define _STAT_VER_LINUX_OLD	0
-#define _STAT_VER_LINUX		1
-#define _STAT_VER		_STAT_VER_LINUX
+#define _STAT_VER_KERNEL	0
+#define _STAT_VER_GLIBC2	1
+#define _STAT_VER_GLIBC2_1	2
+#define _STAT_VER		_STAT_VER_GLIBC2_1
 
 /* Versions of the `xmknod' interface.  */
 #define _MKNOD_VER_LINUX	0
@@ -34,7 +35,12 @@
 struct stat
   {
     __dev_t st_dev;		/* Device.  */
+#ifdef __USE_FILE_OFFSET64
+    __ino64_t st_ino;		/* File serial number.  */
+#else
     __ino_t st_ino;		/* File serial number.	*/
+    int __pad1;
+#endif
     __mode_t st_mode;		/* File mode.  */
     __nlink_t st_nlink;		/* Link count.  */
     __uid_t st_uid;		/* User ID of the file's owner.	*/
@@ -44,13 +50,45 @@ struct stat
     __time_t st_atime;		/* Time of last access.  */
     __time_t st_mtime;		/* Time of last modification.  */
     __time_t st_ctime;		/* Time of last status change.  */
+#ifdef __USE_FILE_OFFSET64
+    __blkcnt64_t st_blocks;	/* Nr. 512-byte blocks allocated.  */
+#else
+    __blkcnt_t st_blocks;	/* Nr. 512-byte blocks allocated.  */
+    int __pad2;
+#endif
     unsigned int st_blksize;	/* Optimal block size for I/O.  */
-#define	_STATBUF_ST_BLKSIZE	/* Tell code we have this member.  */
-    __blkcnt_t st_blocks;	/* Nr. of 512-byte blocks allocated.  */
     unsigned int st_flags;
     unsigned int st_gen;
+    int __pad3;
+    long __unused[4];
   };
 
+#ifdef __USE_LARGEFILE64
+/* Note stat64 is the same shape as stat.  */
+struct stat64
+  {
+    __dev_t st_dev;		/* Device.  */
+    __ino64_t st_ino;		/* File serial number.  */
+    __mode_t st_mode;		/* File mode.  */
+    __nlink_t st_nlink;		/* Link count.  */
+    __uid_t st_uid;		/* User ID of the file's owner.	*/
+    __gid_t st_gid;		/* Group ID of the file's group.*/
+    __dev_t st_rdev;		/* Device number, if device.  */
+    __off_t st_size;		/* Size of file, in bytes.  */
+    __time_t st_atime;		/* Time of last access.  */
+    __time_t st_mtime;		/* Time of last modification.  */
+    __time_t st_ctime;		/* Time of last status change.  */
+    __blkcnt64_t st_blocks;	/* Nr. 512-byte blocks allocated.  */
+    unsigned int st_blksize;	/* Optimal block size for I/O.  */
+    unsigned int st_flags;
+    unsigned int st_gen;
+    int __pad3;
+    long __unused[4];
+  };
+#endif
+
+#define	_STATBUF_ST_BLKSIZE	/* Tell code we have this member.  */
+
 /* Encoding of the file mode.  */
 
 #define	__S_IFMT	0170000	/* These bits determine file type.  */
diff --git a/sysdeps/unix/sysv/linux/alpha/bits/types.h b/sysdeps/unix/sysv/linux/alpha/bits/types.h
index cf2668a0e6..b9e6dd779a 100644
--- a/sysdeps/unix/sysv/linux/alpha/bits/types.h
+++ b/sysdeps/unix/sysv/linux/alpha/bits/types.h
@@ -42,18 +42,26 @@ typedef signed long int __int64_t;
 typedef unsigned long int __uint64_t;
 typedef __quad_t *__qaddr_t;
 
-typedef __u_long __dev_t;		/* Type of device numbers.  */
-typedef __u_int __uid_t;		/* Type of user identifications.  */
-typedef __u_int __gid_t;		/* Type of group identifications.  */
-typedef __u_int __ino_t;		/* Type of file serial numbers.  */
-typedef __u_int __mode_t;		/* Type of file attribute bitmasks.  */
-typedef __u_int __nlink_t; 		/* Type of file link counts.  */
-typedef long int __off_t;		/* Type of file sizes and offsets.  */
-typedef __quad_t __loff_t;		/* Type of file sizes and offsets.  */
-typedef int __pid_t;			/* Type of process identifications.  */
-typedef long int __ssize_t;		/* Type of a byte count, or error.  */
-typedef long int __rlim_t;		/* Type of resource counts.  */
-typedef long int __rlim64_t;		/* Type of resource counts (LFS).  */
+typedef __uint64_t __dev_t;		/* Type of device numbers.  */
+typedef __uint32_t __uid_t;		/* Type of user identifications.  */
+typedef __uint32_t __gid_t;		/* Type of group identifications.  */
+typedef __uint32_t __ino_t;		/* Type of file serial numbers.  */
+typedef __uint64_t __ino64_t;		/*  "" (LFS) */
+typedef __uint32_t __mode_t;		/* Type of file attribute bitmasks.  */
+typedef __uint32_t __nlink_t; 		/* Type of file link counts.  */
+typedef __int64_t  __off_t;		/* Type of file sizes and offsets.  */
+typedef __int64_t  __off64_t;		/*  "" (LFS) */
+typedef __int64_t  __loff_t;		/* Type of file sizes and offsets.  */
+typedef __int32_t  __pid_t;		/* Type of process identifications.  */
+typedef __int64_t  __ssize_t;		/* Type of a byte count, or error.  */
+typedef __int64_t  __rlim_t;		/* Type of resource counts.  */
+typedef __int64_t  __rlim64_t;		/*  "" (LFS) */
+typedef __int32_t  __blkcnt_t;		/* Type to count nr disk blocks.  */
+typedef __int64_t  __blkcnt64_t;	/*  "" (LFS) */
+typedef __uint32_t __fsblkcnt_t;	/* Type to count file system blocks.  */
+typedef __uint64_t __fsblkcnt64_t;	/*  "" (LFS) */
+typedef __uint64_t __fsfilcnt_t;	/* Type to count file system inodes.  */
+typedef __uint64_t __fsfilcnt64_t;	/*  "" (LFS) */
 
 typedef struct
   {
@@ -61,12 +69,12 @@ typedef struct
   } __fsid_t;				/* Type of file system IDs.  */
 
 /* Everythin' else.  */
-typedef int __daddr_t;			/* The type of a disk address.  */
-typedef char *__caddr_t;
+typedef int __daddr_t;			/* Type of a disk address.  */
+typedef char *__caddr_t;		/* Type of a core address.  */
 typedef long int __time_t;
 typedef long int __swblk_t;		/* Type of a swap block maybe?  */
-
 typedef long int __clock_t;
+typedef int __key_t;			/* Type of a SYSV IPC key. */
 
 /* One element in the file descriptor mask array.  */
 typedef unsigned long int __fd_mask;
@@ -91,22 +99,4 @@ typedef struct
     __fd_mask fds_bits[__FD_SETSIZE / __NFDBITS];
   } __fd_set;
 
-
-typedef int __key_t;
-
-
-/* Types from the Large File Support interface.  */
-
-/* Type to count number os disk blocks.  */
-typedef int __blkcnt_t;
-typedef __quad_t __blkcnt64_t;
-
-/* Type to count file system blocks.  */
-typedef unsigned int __fsblkcnt_t;
-typedef __u_quad_t __fsblkcnt64_t;
-
-/* Type to count file system inodes.  */
-typedef unsigned long int __fsfilcnt_t;
-typedef __u_quad_t __fsfilcnt64_t;
-
 #endif /* bits/types.h */
diff --git a/sysdeps/unix/sysv/linux/alpha/fxstat64.c b/sysdeps/unix/sysv/linux/alpha/fxstat64.c
new file mode 100644
index 0000000000..9eff9ebeb7
--- /dev/null
+++ b/sysdeps/unix/sysv/linux/alpha/fxstat64.c
@@ -0,0 +1 @@
+/* fxstat64 is in fxstat.c */
diff --git a/sysdeps/unix/sysv/linux/alpha/kernel_stat.h b/sysdeps/unix/sysv/linux/alpha/kernel_stat.h
index 7109677269..2633b42525 100644
--- a/sysdeps/unix/sysv/linux/alpha/kernel_stat.h
+++ b/sysdeps/unix/sysv/linux/alpha/kernel_stat.h
@@ -1,4 +1,4 @@
-/* Definition of `struct stat' used in the kernel..  */
+/* Definition of `struct stat' used in the kernel.  */
 struct kernel_stat
   {
     unsigned int st_dev;
@@ -17,3 +17,27 @@ struct kernel_stat
     unsigned int st_flags;
     unsigned int st_gen;
   };
+
+/* Definition of `struct stat' used by glibc 2.0.  */
+struct glibc2_stat
+  {
+    __dev_t st_dev;
+    __ino_t st_ino;
+    __mode_t st_mode;
+    __nlink_t st_nlink;
+    __uid_t st_uid;
+    __gid_t st_gid;
+    __dev_t st_rdev;
+    __off_t st_size;
+    __time_t st_atime;
+    __time_t st_mtime;
+    __time_t st_ctime;
+    unsigned int st_blksize;
+    int st_blocks;
+    unsigned int st_flags;
+    unsigned int st_gen;
+  };
+
+extern int __xstat_conv (int vers, struct kernel_stat *kbuf, void *ubuf);
+
+#define XSTAT_IS_XSTAT64 1
diff --git a/sysdeps/unix/sysv/linux/alpha/lxstat64.c b/sysdeps/unix/sysv/linux/alpha/lxstat64.c
new file mode 100644
index 0000000000..bb5dbd0fff
--- /dev/null
+++ b/sysdeps/unix/sysv/linux/alpha/lxstat64.c
@@ -0,0 +1 @@
+/* lxstat64 is in lxstat.c */
diff --git a/sysdeps/unix/sysv/linux/alpha/xstat64.c b/sysdeps/unix/sysv/linux/alpha/xstat64.c
new file mode 100644
index 0000000000..e7acd3b45e
--- /dev/null
+++ b/sysdeps/unix/sysv/linux/alpha/xstat64.c
@@ -0,0 +1 @@
+/* xstat64 is in xstat.c */
diff --git a/sysdeps/unix/sysv/linux/alpha/xstatconv.c b/sysdeps/unix/sysv/linux/alpha/xstatconv.c
new file mode 100644
index 0000000000..d1005e7302
--- /dev/null
+++ b/sysdeps/unix/sysv/linux/alpha/xstatconv.c
@@ -0,0 +1,90 @@
+/* Convert between the kernel's `struct stat' format, and libc's.
+   Copyright (C) 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 Library General Public License as
+   published by the Free Software Foundation; either version 2 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
+   Library General Public License for more details.
+
+   You should have received a copy of the GNU Library General Public
+   License along with the GNU C Library; see the file COPYING.LIB.  If not,
+   write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
+   Boston, MA 02111-1307, USA.  */
+
+#include <string.h>
+
+
+static inline int
+xstat_conv (int vers, struct kernel_stat *kbuf, void *ubuf)
+{
+  switch (vers)
+    {
+    case _STAT_VER_KERNEL:
+      /* Nothing to do.  The struct is in the form the kernel expects.
+	 We should have short-circuted before we got here, but for
+	 completeness... */
+      memcpy ((struct kernel_stat *) ubuf, kbuf, sizeof (*kbuf));
+      break;
+
+    case _STAT_VER_GLIBC2:
+      {
+	struct glibc2_stat *buf = ubuf;
+
+	buf->st_dev = kbuf->st_dev;
+	buf->st_ino = kbuf->st_ino;
+	buf->st_mode = kbuf->st_mode;
+	buf->st_nlink = kbuf->st_nlink;
+	buf->st_uid = kbuf->st_uid;
+	buf->st_gid = kbuf->st_gid;
+	buf->st_rdev = kbuf->st_rdev;
+	buf->st_size = kbuf->st_size;
+	buf->st_atime = kbuf->st_atime;
+	buf->st_mtime = kbuf->st_mtime;
+	buf->st_ctime = kbuf->st_ctime;
+	buf->st_blksize = kbuf->st_blksize;
+	buf->st_blocks = kbuf->st_blocks;
+	buf->st_flags = kbuf->st_flags;
+	buf->st_gen = kbuf->st_gen;
+      }
+      break;
+
+    case _STAT_VER_GLIBC2_1:
+      {
+	struct stat64 *buf = ubuf;
+
+	buf->st_dev = kbuf->st_dev;
+	buf->st_ino = kbuf->st_ino;
+	buf->st_mode = kbuf->st_mode;
+	buf->st_nlink = kbuf->st_nlink;
+	buf->st_uid = kbuf->st_uid;
+	buf->st_gid = kbuf->st_gid;
+	buf->st_rdev = kbuf->st_rdev;
+	buf->st_size = kbuf->st_size;
+	buf->st_atime = kbuf->st_atime;
+	buf->st_mtime = kbuf->st_mtime;
+	buf->st_ctime = kbuf->st_ctime;
+	buf->st_blocks = kbuf->st_blocks;
+	buf->st_blksize = kbuf->st_blksize;
+	buf->st_flags = kbuf->st_flags;
+	buf->st_gen = kbuf->st_gen;
+	buf->__pad3 = 0;
+	buf->__unused[0] = 0;
+	buf->__unused[1] = 0;
+	buf->__unused[2] = 0;
+	buf->__unused[3] = 0;
+      }
+      break;
+
+    default:
+      __set_errno (EINVAL);
+      return -1;
+    }
+
+  return 0;
+}
diff --git a/sysdeps/unix/sysv/linux/bits/stat.h b/sysdeps/unix/sysv/linux/bits/stat.h
index aab025890c..1b98448ff4 100644
--- a/sysdeps/unix/sysv/linux/bits/stat.h
+++ b/sysdeps/unix/sysv/linux/bits/stat.h
@@ -25,6 +25,7 @@
 
 /* Versions of the `struct stat' data structure.  */
 #define _STAT_VER_LINUX_OLD	1
+#define _STAT_VER_KERNEL	1
 #define _STAT_VER_SVR4		2
 #define _STAT_VER_LINUX		3
 #define _STAT_VER		_STAT_VER_LINUX	/* The one defined below.  */
diff --git a/sysdeps/unix/sysv/linux/fxstat.c b/sysdeps/unix/sysv/linux/fxstat.c
index 5aa02dcac8..afed300267 100644
--- a/sysdeps/unix/sysv/linux/fxstat.c
+++ b/sysdeps/unix/sysv/linux/fxstat.c
@@ -17,76 +17,38 @@
    write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
    Boston, MA 02111-1307, USA.  */
 
+/* Ho hum, if xstat == xstat64 we must get rid of the prototype or gcc
+   will complain since they don't strictly match.  */
+#define __fxstat64 __fxstat64_disable
+
 #include <errno.h>
 #include <stddef.h>
 #include <sys/stat.h>
-
 #include <kernel_stat.h>
 
+#include <xstatconv.c>
+
 extern int __syscall_fstat (int, struct kernel_stat *);
 
-/* Get information about the file descriptor FD in BUF.  */
+/* Get information about the file FD in BUF.  */
 int
 __fxstat (int vers, int fd, struct stat *buf)
 {
   struct kernel_stat kbuf;
   int result;
 
-  switch (vers)
-    {
-    case _STAT_VER_LINUX_OLD:
-      /* Nothing to do.  The struct is in the form the kernel expects
-	 it to be.  */
-      result = __syscall_fstat (fd, (struct kernel_stat *) buf);
-      break;
-
-    case _STAT_VER_LINUX:
-      /* Do the system call.  */
-      result = __syscall_fstat (fd, &kbuf);
-
-      /* Convert to current kernel version of `struct stat'.  */
-      buf->st_dev = kbuf.st_dev;
-#ifdef _HAVE___PAD1
-      buf->__pad1 = 0;
-#endif
-      buf->st_ino = kbuf.st_ino;
-      buf->st_mode = kbuf.st_mode;
-      buf->st_nlink = kbuf.st_nlink;
-      buf->st_uid = kbuf.st_uid;
-      buf->st_gid = kbuf.st_gid;
-      buf->st_rdev = kbuf.st_rdev;
-#ifdef _HAVE___PAD2
-      buf->__pad2 = 0;
-#endif
-      buf->st_size = kbuf.st_size;
-      buf->st_blksize = kbuf.st_blksize;
-      buf->st_blocks = kbuf.st_blocks;
-      buf->st_atime = kbuf.st_atime;
-#ifdef _HAVE___UNUSED1
-      buf->__unused1 = 0;
-#endif
-      buf->st_mtime = kbuf.st_mtime;
-#ifdef _HAVE___UNUSED2
-      buf->__unused2 = 0;
-#endif
-      buf->st_ctime = kbuf.st_ctime;
-#ifdef _HAVE___UNUSED3
-      buf->__unused3 = 0;
-#endif
-#ifdef _HAVE___UNUSED4
-      buf->__unused4 = 0;
-#endif
-#ifdef _HAVE___UNUSED5
-      buf->__unused5 = 0;
-#endif
-      break;
+  if (vers == _STAT_VER_KERNEL)
+    return __syscall_fstat (fd, (struct kernel_stat *) buf);
 
-    default:
-      __set_errno (EINVAL);
-      result = -1;
-      break;
-    }
+  result =  __syscall_fstat (fd, &kbuf);
+  if (result == 0)
+    result = xstat_conv (vers, &kbuf, buf);
 
   return result;
 }
-weak_alias (__fxstat, _fxstat)
+
+weak_alias (__fxstat, _fxstat);
+#ifdef XSTAT_IS_XSTAT64
+#undef __fxstat64
+strong_alias (__fxstat, __fxstat64);
+#endif
diff --git a/sysdeps/unix/sysv/linux/lxstat.c b/sysdeps/unix/sysv/linux/lxstat.c
index 11c9038646..7fbe14e138 100644
--- a/sysdeps/unix/sysv/linux/lxstat.c
+++ b/sysdeps/unix/sysv/linux/lxstat.c
@@ -1,4 +1,4 @@
-/* lxstat using old-style Unix fstat system call.
+/* lxstat using old-style Unix lstat system call.
    Copyright (C) 1991, 1995, 1996, 1997 Free Software Foundation, Inc.
    This file is part of the GNU C Library.
 
@@ -17,12 +17,17 @@
    write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
    Boston, MA 02111-1307, USA.  */
 
+/* Ho hum, if xstat == xstat64 we must get rid of the prototype or gcc
+   will complain since they don't strictly match.  */
+#define __lxstat64 __lxstat64_disable
+
 #include <errno.h>
 #include <stddef.h>
 #include <sys/stat.h>
-
 #include <kernel_stat.h>
 
+#include <xstatconv.c>
+
 extern int __syscall_lstat (const char *, struct kernel_stat *);
 
 /* Get information about the file NAME in BUF.  */
@@ -32,61 +37,18 @@ __lxstat (int vers, const char *name, struct stat *buf)
   struct kernel_stat kbuf;
   int result;
 
-  switch (vers)
-    {
-    case _STAT_VER_LINUX_OLD:
-      /* Nothing to do.  The struct is in the form the kernel expects
-	 it to be.  */
-      result = __syscall_lstat (name, (struct kernel_stat *) buf);
-      break;
-
-    case _STAT_VER_LINUX:
-      /* Do the system call.  */
-      result = __syscall_lstat (name, &kbuf);
-
-      /* Convert to current kernel version of `struct stat'.  */
-      buf->st_dev = kbuf.st_dev;
-#ifdef _HAVE___PAD1
-      buf->__pad1 = 0;
-#endif
-      buf->st_ino = kbuf.st_ino;
-      buf->st_mode = kbuf.st_mode;
-      buf->st_nlink = kbuf.st_nlink;
-      buf->st_uid = kbuf.st_uid;
-      buf->st_gid = kbuf.st_gid;
-      buf->st_rdev = kbuf.st_rdev;
-#ifdef _HAVE___PAD2
-      buf->__pad2 = 0;
-#endif
-      buf->st_size = kbuf.st_size;
-      buf->st_blksize = kbuf.st_blksize;
-      buf->st_blocks = kbuf.st_blocks;
-      buf->st_atime = kbuf.st_atime;
-#ifdef _HAVE___UNUSED1
-      buf->__unused1 = 0;
-#endif
-      buf->st_mtime = kbuf.st_mtime;
-#ifdef _HAVE___UNUSED2
-      buf->__unused2 = 0;
-#endif
-      buf->st_ctime = kbuf.st_ctime;
-#ifdef _HAVE___UNUSED3
-      buf->__unused3 = 0;
-#endif
-#ifdef _HAVE___UNUSED4
-      buf->__unused4 = 0;
-#endif
-#ifdef _HAVE___UNUSED5
-      buf->__unused5 = 0;
-#endif
-      break;
+  if (vers == _STAT_VER_KERNEL)
+    return __syscall_lstat (name, (struct kernel_stat *) buf);
 
-    default:
-      __set_errno (EINVAL);
-      result = -1;
-      break;
-    }
+  result =  __syscall_lstat (name, &kbuf);
+  if (result == 0)
+    result = xstat_conv (vers, &kbuf, buf);
 
   return result;
 }
-weak_alias (__lxstat, _lxstat)
+
+weak_alias (__lxstat, _lxstat);
+#ifdef XSTAT_IS_XSTAT64
+#undef __lxstat64
+strong_alias (__lxstat, __lxstat64);
+#endif
diff --git a/sysdeps/unix/sysv/linux/xstat.c b/sysdeps/unix/sysv/linux/xstat.c
index aa120f5193..85328574cf 100644
--- a/sysdeps/unix/sysv/linux/xstat.c
+++ b/sysdeps/unix/sysv/linux/xstat.c
@@ -1,4 +1,4 @@
-/* xstat using old-style Unix fstat system call.
+/* xstat using old-style Unix stat system call.
    Copyright (C) 1991, 1995, 1996, 1997 Free Software Foundation, Inc.
    This file is part of the GNU C Library.
 
@@ -17,12 +17,17 @@
    write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
    Boston, MA 02111-1307, USA.  */
 
+/* Ho hum, if xstat == xstat64 we must get rid of the prototype or gcc
+   will complain since they don't strictly match.  */
+#define __xstat64 __xstat64_disable
+
 #include <errno.h>
 #include <stddef.h>
 #include <sys/stat.h>
-
 #include <kernel_stat.h>
 
+#include <xstatconv.c>
+
 extern int __syscall_stat (const char *, struct kernel_stat *);
 
 /* Get information about the file NAME in BUF.  */
@@ -32,61 +37,18 @@ __xstat (int vers, const char *name, struct stat *buf)
   struct kernel_stat kbuf;
   int result;
 
-  switch (vers)
-    {
-    case _STAT_VER_LINUX_OLD:
-      /* Nothing to do.  The struct is in the form the kernel expects
-	 it to be.  */
-      result = __syscall_stat (name, (struct kernel_stat *) buf);
-      break;
-
-    case _STAT_VER_LINUX:
-      /* Do the system call.  */
-      result = __syscall_stat (name, &kbuf);
-
-      /* Convert to current kernel version of `struct stat'.  */
-      buf->st_dev = kbuf.st_dev;
-#ifdef _HAVE___PAD1
-      buf->__pad1 = 0;
-#endif
-      buf->st_ino = kbuf.st_ino;
-      buf->st_mode = kbuf.st_mode;
-      buf->st_nlink = kbuf.st_nlink;
-      buf->st_uid = kbuf.st_uid;
-      buf->st_gid = kbuf.st_gid;
-      buf->st_rdev = kbuf.st_rdev;
-#ifdef _HAVE___PAD2
-      buf->__pad2 = 0;
-#endif
-      buf->st_size = kbuf.st_size;
-      buf->st_blksize = kbuf.st_blksize;
-      buf->st_blocks = kbuf.st_blocks;
-      buf->st_atime = kbuf.st_atime;
-#ifdef _HAVE___UNUSED1
-      buf->__unused1 = 0;
-#endif
-      buf->st_mtime = kbuf.st_mtime;
-#ifdef _HAVE___UNUSED2
-      buf->__unused2 = 0;
-#endif
-      buf->st_ctime = kbuf.st_ctime;
-#ifdef _HAVE___UNUSED3
-      buf->__unused3 = 0;
-#endif
-#ifdef _HAVE___UNUSED4
-      buf->__unused4 = 0;
-#endif
-#ifdef _HAVE___UNUSED5
-      buf->__unused5 = 0;
-#endif
-      break;
+  if (vers == _STAT_VER_KERNEL)
+    return __syscall_stat (name, (struct kernel_stat *) buf);
 
-    default:
-      __set_errno (EINVAL);
-      result = -1;
-      break;
-    }
+  result =  __syscall_stat (name, &kbuf);
+  if (result == 0)
+    result = xstat_conv (vers, &kbuf, buf);
 
   return result;
 }
-weak_alias (__xstat, _xstat)
+
+weak_alias (__xstat, _xstat);
+#ifdef XSTAT_IS_XSTAT64
+#undef __xstat64
+strong_alias (__xstat, __xstat64);
+#endif
diff --git a/sysdeps/unix/sysv/linux/xstatconv.c b/sysdeps/unix/sysv/linux/xstatconv.c
new file mode 100644
index 0000000000..06a28cce30
--- /dev/null
+++ b/sysdeps/unix/sysv/linux/xstatconv.c
@@ -0,0 +1,83 @@
+/* Convert between the kernel's `struct stat' format, and libc's.
+   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 Library General Public License as
+   published by the Free Software Foundation; either version 2 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
+   Library General Public License for more details.
+
+   You should have received a copy of the GNU Library General Public
+   License along with the GNU C Library; see the file COPYING.LIB.  If not,
+   write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
+   Boston, MA 02111-1307, USA.  */
+
+#include <string.h>
+
+
+static inline int
+xstat_conv (int vers, struct kernel_stat *kbuf, void *ubuf)
+{
+  switch (vers)
+    {
+    case _STAT_VER_KERNEL:
+      /* Nothing to do.  The struct is in the form the kernel expects.
+         We should have short-circuted before we got here, but for
+         completeness... */
+      memcpy ((struct kernel_stat *) ubuf, kbuf, sizeof (*kbuf));
+      break;
+
+    case _STAT_VER_LINUX:
+      {
+	struct stat *buf = ubuf;
+
+	/* Convert to current kernel version of `struct stat'.  */
+	buf->st_dev = kbuf->st_dev;
+#ifdef _HAVE___PAD1
+	buf->__pad1 = 0;
+#endif
+	buf->st_ino = kbuf->st_ino;
+	buf->st_mode = kbuf->st_mode;
+	buf->st_nlink = kbuf->st_nlink;
+	buf->st_uid = kbuf->st_uid;
+	buf->st_gid = kbuf->st_gid;
+	buf->st_rdev = kbuf->st_rdev;
+#ifdef _HAVE___PAD2
+	buf->__pad2 = 0;
+#endif
+	buf->st_size = kbuf->st_size;
+	buf->st_blksize = kbuf->st_blksize;
+	buf->st_blocks = kbuf->st_blocks;
+	buf->st_atime = kbuf->st_atime;
+#ifdef _HAVE___UNUSED1
+	buf->__unused1 = 0;
+#endif
+	buf->st_mtime = kbuf->st_mtime;
+#ifdef _HAVE___UNUSED2
+	buf->__unused2 = 0;
+#endif
+	buf->st_ctime = kbuf->st_ctime;
+#ifdef _HAVE___UNUSED3
+	buf->__unused3 = 0;
+#endif
+#ifdef _HAVE___UNUSED4
+	buf->__unused4 = 0;
+#endif
+#ifdef _HAVE___UNUSED5
+	buf->__unused5 = 0;
+#endif
+      }
+      break;
+
+    default:
+      __set_errno (EINVAL);
+      return -1;
+    }
+
+  return 0;
+}