Actually implement fileno()

diff --git a/crt0.c b/crt0.c
deleted file mode 100644
index a0e6b9b..0000000
--- a/crt0.c
+++ /dev/null
@@ -1,67 +0,0 @@
-/* crt0.c - Run-time initialization */
-
-#include <stdlib.h>
-#include <stdint.h>
-
-int errno;			/* It has to go somewhere... */
-char **environ;
-
-extern int main(int argc, char **argv, char **envp);
-
-#if defined(__i386__)
-register uintptr_t *params asm("%esp");
-#elif defined(__x86_64__)
-register uintptr_t *params asm("%rsp");
-#elif defined(__sparc64__)
-register uintptr_t sp asm("%sp");
-#define BIAS 2047
-#define params ((uintptr_t *)(sp+BIAS) + 16)
-#elif defined(__sparc__) && !defined(__sparc64__)
-register uintptr_t *sp asm("%sp");
-#define params (sp+16)
-#elif defined(__mips__) || defined(__mips64__)
-register uintptr_t *params asm("$sp");
-#elif defined(__powerpc__)
-register uintptr_t *params asm("r9");
-#elif defined(__hppa__)
-# define STACK_GROWS_UP
-register uintptr_t *params asm("%r25");
-#elif defined(__s390__)
-register uintptr_t *params asm("%r15");
-#elif defined(__alpha__)
-register uintptr_t *params asm("$sp");
-#elif defined(__arm__)
-register uintptr_t *params asm("sp");
-#elif defined(__sh__)
-register uintptr_t *params asm("r15");
-#elif defined(__h8300__)
-register uintptr_t *params asm("sp");
-#else
-#error "Need crt0.c port for this architecture!"
-#endif
-
-void _start(void)
-{
-  /*
-   * The argument block begins above the current stack frame, because we
-   * have no return address.
-   *
-   * FIXME: this needs to be ported to all platforms...
-   */
-
-  int argc;
-  char **argv;
-
-  /* These seem to be standard for all the ELF ABIs... */
-#ifdef STACK_GROWS_UP
-  argc    = (int) *params;
-  argv    = (char **)(params-1);
-  environ = argv-argc-1;
-#else
-  argc    = (int) *params;
-  argv    = (char **)(params+1);
-  environ = argv+argc+1;
-#endif
-
-  exit(main(argc,argv,environ));
-}
diff --git a/fread.c b/fread.c
index 8580423..f061089 100644
--- a/fread.c
+++ b/fread.c
@@ -13,7 +13,7 @@
   char *p = buf;
 
   while ( count ) {
-    rv = read((int)f, p, count);
+    rv = read(fileno(f), p, count);
     if ( rv == -1 ) {
       if ( errno == EINTR )
 	continue;
diff --git a/fwrite.c b/fwrite.c
index 8213c33..5b49dfb 100644
--- a/fwrite.c
+++ b/fwrite.c
@@ -13,7 +13,7 @@
   const char *p = buf;
 
   while ( count ) {
-    rv = write((int)f, p, count);
+    rv = write(fileno(f), p, count);
     if ( rv == -1 ) {
       if ( errno == EINTR )
 	continue;
diff --git a/include/stdio.h b/include/stdio.h
index ef7353a..dcda46e 100644
--- a/include/stdio.h
+++ b/include/stdio.h
@@ -18,6 +18,13 @@
 #define stdout ((FILE *)1)
 #define stderr ((FILE *)2)
 
+static __inline__
+int fileno(FILE *__f)
+{
+  /* This should really be intptr_t, but size_t should be the same size */
+  return (int)(size_t)__f;
+}
+
 __extern int fputs(const char *, FILE *);
 __extern int puts(const char *);
 
diff --git a/klibc/fread.c b/klibc/fread.c
index 8580423..f061089 100644
--- a/klibc/fread.c
+++ b/klibc/fread.c
@@ -13,7 +13,7 @@
   char *p = buf;
 
   while ( count ) {
-    rv = read((int)f, p, count);
+    rv = read(fileno(f), p, count);
     if ( rv == -1 ) {
       if ( errno == EINTR )
 	continue;
diff --git a/klibc/fwrite.c b/klibc/fwrite.c
index 8213c33..5b49dfb 100644
--- a/klibc/fwrite.c
+++ b/klibc/fwrite.c
@@ -13,7 +13,7 @@
   const char *p = buf;
 
   while ( count ) {
-    rv = write((int)f, p, count);
+    rv = write(fileno(f), p, count);
     if ( rv == -1 ) {
       if ( errno == EINTR )
 	continue;
diff --git a/klibc/include/stdio.h b/klibc/include/stdio.h
index ef7353a..dcda46e 100644
--- a/klibc/include/stdio.h
+++ b/klibc/include/stdio.h
@@ -18,6 +18,13 @@
 #define stdout ((FILE *)1)
 #define stderr ((FILE *)2)
 
+static __inline__
+int fileno(FILE *__f)
+{
+  /* This should really be intptr_t, but size_t should be the same size */
+  return (int)(size_t)__f;
+}
+
 __extern int fputs(const char *, FILE *);
 __extern int puts(const char *);