Added support for old*stat syscalls for Linux
Changed referenced to LINUX to linux in file.c
Fix include for ldt.h in mem.c while we're at it
diff --git a/file.c b/file.c
index df6c551..e528bf2 100644
--- a/file.c
+++ b/file.c
@@ -34,6 +34,9 @@
 #include <dirent.h>
 
 #include <sys/stat.h>
+#ifdef linux
+#include <asm/stat.h>
+#endif
 #include <fcntl.h>
 
 #ifdef SVR4
@@ -267,7 +270,7 @@
 	return RVAL_UDECIMAL;
 }
 
-#ifdef LINUX
+#ifdef linux
 int
 sys_llseek (tcp)
 struct tcb *tcp;
@@ -453,21 +456,70 @@
 }
 #endif
 
-#ifdef LINUX
-/* Get the kernel's idea of struct stat. */
-#define stat kernel_stat
-#include <asm/stat.h>
-#undef stat
-#else /* LINUX */
-#define kernel_stat stat
-#endif /* LINUX */
+static void
+realprintstat(tcp, statbuf)
+struct tcb *tcp;
+#ifdef linux
+struct new_stat *statbuf;
+#else
+struct stat *statbuf;
+#endif
+{
+    if (!abbrev(tcp)) {
+	    tprintf("{st_dev=makedev(%lu, %lu), st_ino=%lu, st_mode=%s, ",
+		    (unsigned long) major(statbuf->st_dev),
+		    (unsigned long) minor(statbuf->st_dev),
+		    (unsigned long) statbuf->st_ino,
+		    sprintmode(statbuf->st_mode));
+	    tprintf("st_nlink=%lu, st_uid=%lu, st_gid=%lu, ",
+		    (unsigned long) statbuf->st_nlink,
+		    (unsigned long) statbuf->st_uid,
+		    (unsigned long) statbuf->st_gid);
+#ifdef HAVE_ST_BLKSIZE
+	    tprintf("st_blksize=%lu, ", (unsigned long) statbuf->st_blksize);
+#endif /* HAVE_ST_BLKSIZE */
+#ifdef HAVE_ST_BLOCKS
+	    tprintf("st_blocks=%lu, ", (unsigned long) statbuf->st_blocks);
+#endif /* HAVE_ST_BLOCKS */
+    }
+    else
+	    tprintf("{st_mode=%s, ", sprintmode(statbuf->st_mode));
+    switch (statbuf->st_mode & S_IFMT) {
+    case S_IFCHR: case S_IFBLK:
+#ifdef HAVE_ST_RDEV
+	    tprintf("st_rdev=makedev(%lu, %lu), ",
+		    (unsigned long) major(statbuf->st_rdev),
+		    (unsigned long) minor(statbuf->st_rdev));
+#else /* !HAVE_ST_RDEV */
+	    tprintf("st_size=makedev(%lu, %lu), ",
+		    (unsigned long) major(statbuf->st_size),
+		    (unsigned long) minor(statbuf->st_size));
+#endif /* !HAVE_ST_RDEV */
+	    break;
+    default:
+	    tprintf("st_size=%lu, ", statbuf->st_size);
+	    break;
+    }
+    if (!abbrev(tcp)) {
+	    tprintf("st_atime=%s, ", sprinttime(statbuf->st_atime));
+	    tprintf("st_mtime=%s, ", sprinttime(statbuf->st_mtime));
+	    tprintf("st_ctime=%s}", sprinttime(statbuf->st_ctime));
+    }
+    else
+	    tprintf("...}");
+}
+
 
 static void
 printstat(tcp, addr)
 struct tcb *tcp;
 int addr;
 {
-	struct kernel_stat statbuf;
+#ifdef linux
+	struct new_stat statbuf;
+#else
+	struct stat statbuf;
+#endif
 
 #ifdef LINUXSPARC
  	if (current_personality == 1) {
@@ -488,50 +540,68 @@
 		tprintf("{...}");
 		return;
 	}
-	if (!abbrev(tcp)) {
-		tprintf("{st_dev=makedev(%lu, %lu), st_ino=%lu, st_mode=%s, ",
-			(unsigned long) major(statbuf.st_dev),
-			(unsigned long) minor(statbuf.st_dev),
-			(unsigned long) statbuf.st_ino,
-			sprintmode(statbuf.st_mode));
-		tprintf("st_nlink=%lu, st_uid=%lu, st_gid=%lu, ",
-			(unsigned long) statbuf.st_nlink,
-			(unsigned long) statbuf.st_uid,
-			(unsigned long) statbuf.st_gid);
-#ifdef HAVE_ST_BLKSIZE
-		tprintf("st_blksize=%lu, ", (unsigned long) statbuf.st_blksize);
-#endif /* HAVE_ST_BLKSIZE */
-#ifdef HAVE_ST_BLOCKS
-		tprintf("st_blocks=%lu, ", (unsigned long) statbuf.st_blocks);
-#endif /* HAVE_ST_BLOCKS */
-	}
-	else
-		tprintf("{st_mode=%s, ", sprintmode(statbuf.st_mode));
-	switch (statbuf.st_mode & S_IFMT) {
-	case S_IFCHR: case S_IFBLK:
-#ifdef HAVE_ST_RDEV
-		tprintf("st_rdev=makedev(%lu, %lu), ",
-			(unsigned long) major(statbuf.st_rdev),
-			(unsigned long) minor(statbuf.st_rdev));
-#else /* !HAVE_ST_RDEV */
-		tprintf("st_size=makedev(%lu, %lu), ",
-			(unsigned long) major(statbuf.st_size),
-			(unsigned long) minor(statbuf.st_size));
-#endif /* !HAVE_ST_RDEV */
-		break;
-	default:
-		tprintf("st_size=%lu, ", statbuf.st_size);
-		break;
-	}
-	if (!abbrev(tcp)) {
-		tprintf("st_atime=%s, ", sprinttime(statbuf.st_atime));
-		tprintf("st_mtime=%s, ", sprinttime(statbuf.st_mtime));
-		tprintf("st_ctime=%s}", sprinttime(statbuf.st_ctime));
-	}
-	else
-		tprintf("...}");
+
+	realprintstat(tcp, &statbuf);
 }
 
+#ifdef linux
+static void
+convertoldstat(oldbuf, newbuf)
+const struct old_stat *oldbuf;
+struct new_stat *newbuf;
+{
+    newbuf->st_dev=oldbuf->st_dev;
+    newbuf->st_ino=oldbuf->st_ino;
+    newbuf->st_mode=oldbuf->st_mode;
+    newbuf->st_nlink=oldbuf->st_nlink;
+    newbuf->st_uid=oldbuf->st_uid;
+    newbuf->st_gid=oldbuf->st_gid;
+    newbuf->st_rdev=oldbuf->st_rdev;
+    newbuf->st_size=oldbuf->st_size;
+    newbuf->st_atime=oldbuf->st_atime;
+    newbuf->st_mtime=oldbuf->st_mtime;
+    newbuf->st_ctime=oldbuf->st_ctime;
+    newbuf->st_blksize=0;	/* not supported in old_stat */
+    newbuf->st_blocks=0;		/* not supported in old_stat */
+}
+#endif
+
+
+#ifdef linux
+static void
+printoldstat(tcp, addr)
+struct tcb *tcp;
+int addr;
+{
+	struct old_stat statbuf;
+	struct new_stat newstatbuf;
+
+#ifdef LINUXSPARC
+ 	if (current_personality == 1) {
+ 		printstatsol(tcp, addr);
+ 		return;
+ 	}
+#endif /* LINUXSPARC */
+
+	if (!addr) {
+		tprintf("NULL");
+		return;
+	}
+	if (syserror(tcp) || !verbose(tcp)) {
+		tprintf("%#x", addr);
+		return;
+	}
+	if (umove(tcp, addr, &statbuf) < 0) {
+		tprintf("{...}");
+		return;
+	}
+
+	convertoldstat(&statbuf, &newstatbuf);
+	realprintstat(tcp, &newstatbuf);
+}
+#endif
+
+
 int
 sys_stat(tcp)
 struct tcb *tcp;
@@ -545,6 +615,21 @@
 	return 0;
 }
 
+#ifdef linux
+int
+sys_oldstat(tcp)
+struct tcb *tcp;
+{
+	if (entering(tcp)) {
+		printpath(tcp, tcp->u_arg[0]);
+		tprintf(", ");
+	} else {
+		printoldstat(tcp, tcp->u_arg[1]);
+	}
+	return 0;
+}
+#endif
+
 int
 sys_fstat(tcp)
 struct tcb *tcp;
@@ -557,6 +642,20 @@
 	return 0;
 }
 
+#ifdef linux
+int
+sys_oldfstat(tcp)
+struct tcb *tcp;
+{
+	if (entering(tcp))
+		tprintf("%ld, ", tcp->u_arg[0]);
+	else {
+		printoldstat(tcp, tcp->u_arg[1]);
+	}
+	return 0;
+}
+#endif
+
 int
 sys_lstat(tcp)
 struct tcb *tcp;
@@ -570,6 +669,22 @@
 	return 0;
 }
 
+#ifdef linux
+int
+sys_oldlstat(tcp)
+struct tcb *tcp;
+{
+	if (entering(tcp)) {
+		printpath(tcp, tcp->u_arg[0]);
+		tprintf(", ");
+	} else {
+		printoldstat(tcp, tcp->u_arg[1]);
+	}
+	return 0;
+}
+#endif
+
+
 #if defined(SVR4) || defined(LINUXSPARC)
 
 int
@@ -643,7 +758,7 @@
 
 #endif /* SVR4 || LINUXSPARC */
 
-#ifdef LINUX
+#ifdef linux
 
 static struct xlat fsmagic[] = {
 	{ 0xef51,	"EXT2_OLD_SUPER_MAGIC"	},
@@ -660,7 +775,7 @@
 	{ 0,		NULL			},
 };
 
-#endif /* LINUX */
+#endif /* linux */
 
 #ifndef SVR4
 
@@ -669,7 +784,7 @@
 int magic;
 {
 	static char buf[32];
-#ifdef LINUX
+#ifdef linux
 	char *s;
 
 	s = xlookup(fsmagic, magic);
@@ -677,7 +792,7 @@
 		sprintf(buf, "\"%s\"", s);
 		return buf;
 	}
-#endif /* LINUX */
+#endif /* linux */
 	sprintf(buf, "%#x", magic);
 	return buf;
 }
@@ -713,9 +828,9 @@
 	tprintf("f_files=%lu, f_ffree=%lu",
 		(unsigned long)statbuf.f_files,
 		(unsigned long)statbuf.f_ffree);
-#ifdef LINUX
+#ifdef linux
 	tprintf(", f_namelen=%lu}", (unsigned long)statbuf.f_namelen);
-#endif /* LINUX */
+#endif /* linux */
 #endif /* !ALPHA */
 	tprintf("}");
 }
@@ -745,8 +860,7 @@
 	return 0;
 }
 
-#ifdef LINUX
-#ifdef ALPHA
+#if defined(linux) && defined(alpha)
 
 int
 osf_statfs(tcp)
@@ -774,8 +888,7 @@
 	}
 	return 0;
 }
-#endif /* ALPHA */
-#endif /* LINUX */
+#endif /* linux && alpha */
 
 #endif /* !SVR4 */
 
@@ -1067,7 +1180,7 @@
 	return 0;
 }
 
-#ifdef LINUX
+#ifdef linux
 
 static void
 printdir(tcp, addr)
@@ -1085,14 +1198,6 @@
 		return;
 	}
 	tprintf("{d_ino=%ld, ", (unsigned long) d.d_ino);
-#ifndef LINUX
-	/* This contains garbage under Linux.  */
-	tprintf("d_off=%d, ", d.d_off);
-#endif /* !LINUX */
-#ifndef LINUX
-	/* No point in printing this out since the syscall returns it. */
-	tprintf("d_reclen=%u, ", d.d_reclen);
-#endif /* !LINUX */
 	tprintf("d_name=");
 	printpathn(tcp, (long) ((struct dirent *) addr)->d_name, d.d_reclen);
 	tprintf("}");
@@ -1116,7 +1221,7 @@
 	return 0;
 }
 
-#endif /* LINUX */
+#endif /* linux */
 
 int
 sys_getdents(tcp)
@@ -1153,14 +1258,14 @@
 		tprintf("{");
 	for (i = 0; i < len;) {
 		struct dirent *d = (struct dirent *) &buf[i];
-#ifdef LINUX
+#ifdef linux
 		if (!abbrev(tcp)) {
 			tprintf("%s{d_ino=%lu, d_off=%lu, ",
 				i ? " " : "", d->d_ino, d->d_off);
 			tprintf("d_reclen=%u, d_name=\"%s\"}",
 				d->d_reclen, d->d_name);
 		}
-#endif /* LINUX */
+#endif /* linux */
 #ifdef SVR4
 		if (!abbrev(tcp)) {
 			tprintf("%s{d_ino=%lu, d_off=%lu, ",
@@ -1190,7 +1295,7 @@
 	return 0;
 }
 
-#ifdef LINUX
+#ifdef linux
 
 int
 sys_getcwd(tcp)
@@ -1205,7 +1310,7 @@
     }
     return 0;
 }
-#endif /* LINUX */
+#endif /* linux */
 
 #ifdef HAVE_SYS_ASYNCH_H