Use fcntl64() where applicable.  The handling of "struct flock" is
now broken on MIPS, but it was previously broken on all 32-bit arches.

diff --git a/include/fcntl.h b/include/fcntl.h
index b9336ab..a97ae8d 100644
--- a/include/fcntl.h
+++ b/include/fcntl.h
@@ -10,6 +10,27 @@
 #include <sys/types.h>
 #include <linux/fcntl.h>
 
+/* This is ugly, but "struct flock" has actually been defined with
+   a long off_t, so it's really "struct flock64".  It just happens
+   to work.  Gag.  Barf.
+
+   FIX THIS: It's broken on MIPS. */
+
+#ifdef F_GETLK64
+# undef F_GETLK
+# define F_GETLK F_GETLK64
+#endif
+
+#ifdef F_SETLK64
+# undef F_SETLK
+# define F_SETLK F_SETLK64
+#endif
+
+#ifdef F_SETLKW64
+# undef F_SETLKW
+# define F_SETLKW F_SETLKW64
+#endif
+
 /* This is defined here as well as in <unistd.h> since old-style code
    would still include <fcntl.h> when using open(), and open() being
    a varadic function changes its calling convention on some architectures. */
@@ -17,4 +38,6 @@
 __extern int open(const char *, int, ...);
 #endif
 
+__extern int fcntl(int, int, ...);
+
 #endif /* _FCNTL_H */
diff --git a/include/unistd.h b/include/unistd.h
index d80ddbf..aff3c20 100644
--- a/include/unistd.h
+++ b/include/unistd.h
@@ -93,7 +93,7 @@
 
 __extern int dup(int);
 __extern int dup2(int, int);
-__extern int fcntl(int, int, long);
+__extern int fcntl(int, int, ...);
 __extern int ioctl(int, int, void *);
 __extern int flock(int, int);
 __extern int fsync(int);
diff --git a/klibc/SYSCALLS.def b/klibc/SYSCALLS.def
index f458e13..b9c7cac 100644
--- a/klibc/SYSCALLS.def
+++ b/klibc/SYSCALLS.def
@@ -120,7 +120,8 @@
 <32> int _llseek::__llseek(int, unsigned long, unsigned long, off_t *, int)
 int dup(int)
 int dup2(int, int)
-int fcntl(int, int, long)
+<i386> int fcntl64@varadic::fcntl(int, int, unsigned long)
+<!i386> int fcntl64,fcntl::fcntl(int, int, unsigned long)
 int ioctl(int, int, void *)
 int flock(int, int)
 int _newselect,select::select(int, fd_set *, fd_set *, fd_set *, struct timeval *)
diff --git a/klibc/arch/i386/open.S b/klibc/arch/i386/open.S
index adc7f1d..4f492a1 100644
--- a/klibc/arch/i386/open.S
+++ b/klibc/arch/i386/open.S
@@ -2,7 +2,8 @@
  * arch/i386/open.S
  *
  * Handle the open() system call - oddball due to the varadic
- * prototype, which forces the use of the cdecl calling convention.
+ * prototype, which forces the use of the cdecl calling convention,
+ * and the need for O_LARGEFILE.
  */
 
 #include <asm/unistd.h>
diff --git a/klibc/arch/i386/sysstub.ph b/klibc/arch/i386/sysstub.ph
index a1c8d5c..eaa8180 100644
--- a/klibc/arch/i386/sysstub.ph
+++ b/klibc/arch/i386/sysstub.ph
@@ -14,6 +14,15 @@
     print OUT "\t.type ${fname},\@function\n";
     print OUT "\t.globl ${fname}\n";
     print OUT "${fname}:\n";
+
+    if ( $stype eq 'varadic' ) {
+	print OUT "#ifdef REGPARM\n";
+	print OUT "\tmovl  4(%esp),%eax\n";
+	print OUT "\tmovl  8(%esp),%edx\n";
+	print OUT "\tmovl 12(%esp),%ecx\n";
+	print OUT "#endif\n";
+    }
+
     print OUT "\tpushl \$__NR_${sname}\n";
     print OUT "\tjmp __syscall_common\n";
     print OUT "\t.size ${fname},.-${fname}\n";
diff --git a/klibc/include/fcntl.h b/klibc/include/fcntl.h
index b9336ab..a97ae8d 100644
--- a/klibc/include/fcntl.h
+++ b/klibc/include/fcntl.h
@@ -10,6 +10,27 @@
 #include <sys/types.h>
 #include <linux/fcntl.h>
 
+/* This is ugly, but "struct flock" has actually been defined with
+   a long off_t, so it's really "struct flock64".  It just happens
+   to work.  Gag.  Barf.
+
+   FIX THIS: It's broken on MIPS. */
+
+#ifdef F_GETLK64
+# undef F_GETLK
+# define F_GETLK F_GETLK64
+#endif
+
+#ifdef F_SETLK64
+# undef F_SETLK
+# define F_SETLK F_SETLK64
+#endif
+
+#ifdef F_SETLKW64
+# undef F_SETLKW
+# define F_SETLKW F_SETLKW64
+#endif
+
 /* This is defined here as well as in <unistd.h> since old-style code
    would still include <fcntl.h> when using open(), and open() being
    a varadic function changes its calling convention on some architectures. */
@@ -17,4 +38,6 @@
 __extern int open(const char *, int, ...);
 #endif
 
+__extern int fcntl(int, int, ...);
+
 #endif /* _FCNTL_H */
diff --git a/klibc/include/unistd.h b/klibc/include/unistd.h
index d80ddbf..aff3c20 100644
--- a/klibc/include/unistd.h
+++ b/klibc/include/unistd.h
@@ -93,7 +93,7 @@
 
 __extern int dup(int);
 __extern int dup2(int, int);
-__extern int fcntl(int, int, long);
+__extern int fcntl(int, int, ...);
 __extern int ioctl(int, int, void *);
 __extern int flock(int, int);
 __extern int fsync(int);