Make gcc3-compatible.  Call fread() and fwrite() by their proper names.

diff --git a/abort.c b/abort.c
index 57b5d60..16557ed 100644
--- a/abort.c
+++ b/abort.c
@@ -3,11 +3,17 @@
  */
 
 #include <stdlib.h>
+#include <unistd.h>
 #include <signal.h>
 
 void abort(void)
 {
+  sigset_t set;
+
+  sigemptyset(&set);
+  sigaddset(&set, SIGABRT);
+  rt_sigprocmask(SIG_UNBLOCK, &set, NULL, sizeof set);
   raise(SIGABRT);
-  _exit(255);
+  _exit(255);			/* raise() should have killed us */
 }
   
diff --git a/fputs.c b/fputs.c
index 73fbad7..cde2cf9 100644
--- a/fputs.c
+++ b/fputs.c
@@ -8,9 +8,8 @@
 
 #include <stdio.h>
 #include <string.h>
-#include <xio.h>
 
 int fputs(const char *s, FILE *file)
 {
-  return __xwrite((int)file, s, strlen(s));
+  return __fwrite(s, strlen(s), file);
 }
diff --git a/klibc/xread.c b/fread.c
similarity index 71%
rename from klibc/xread.c
rename to fread.c
index cf1ade7..8580423 100644
--- a/klibc/xread.c
+++ b/fread.c
@@ -1,19 +1,19 @@
 /*
- * xread.c
+ * fread.c
  */
 
 #include <errno.h>
 #include <unistd.h>
-#include <xio.h>
+#include <stdio.h>
 
-ssize_t __xread(int fd, void *buf, size_t count)
+size_t __fread(void *buf, size_t count, FILE *f)
 {
-  ssize_t bytes = 0;
+  size_t bytes = 0;
   ssize_t rv;
   char *p = buf;
 
   while ( count ) {
-    rv = read(fd, p, count);
+    rv = read((int)f, p, count);
     if ( rv == -1 ) {
       if ( errno == EINTR )
 	continue;
diff --git a/fread2.c b/fread2.c
new file mode 100644
index 0000000..6172f9d
--- /dev/null
+++ b/fread2.c
@@ -0,0 +1,13 @@
+/*
+ * fread2.c
+ *
+ * The actual fread() function as a non-inline
+ */
+
+#define __NO_FREAD_FWRITE_INLINES
+#include <stdio.h>
+
+size_t fread(void *ptr, size_t size, size_t nmemb, FILE *f)
+{
+  return __fread(ptr, size*nmemb, f)/size;
+}
diff --git a/free.c b/free.c
deleted file mode 100644
index b370130..0000000
--- a/free.c
+++ /dev/null
@@ -1,67 +0,0 @@
-/*
- * free.c
- */
-
-#include <assert.h>
-#include <stdlib.h>
-
-#include "malloc.h"
-
-void free(void *ptr)
-{
-  struct free_arena_header *ah, *pah, *nah;
-
-  if ( !ptr )
-    return;
-
-  ah = (struct free_arena_header *)
-    ((struct arena_header *)ptr - 1);
-
-#ifdef DEBUG_MALLOC
-  assert( ah->a.type == ARENA_TYPE_USED );
-#endif
-  
-  pah = ah->a.prev;
-  nah = ah->a.next;
-  if ( pah->a.type == ARENA_TYPE_FREE &&
-       (char *)pah+pah->a.size == (char *)ah ) {
-    /* Coalesce into the previous block */
-    pah->a.size += ah->a.size;
-    pah->a.next = nah;
-    nah->a.prev = pah;
-
-#ifdef DEBUG_MALLOC
-    ah->a.type = ARENA_TYPE_DEAD;
-#endif
-
-    ah = pah;
-    pah = ah->a.prev;
-  } else {
-    /* Need to add this block to the free chain */
-    ah->a.type = ARENA_TYPE_FREE;
-
-    ah->next_free = __malloc_head.next_free;
-    ah->prev_free = &__malloc_head;
-    __malloc_head.next_free = ah;
-    ah->next_free->prev_free = ah;
-  }
-
-  /* In either of the previous cases, we might be able to merge
-     with the subsequent block... */
-  if ( nah->a.type == ARENA_TYPE_FREE &&
-       (char *)ah+ah->a.size == (char *)nah ) {
-    ah->a.size += nah->a.size;
-
-    /* Remove the old block from the chains */
-    nah->next_free->prev_free = nah->prev_free;
-    nah->prev_free->next_free = nah->next_free;
-    ah->a.next = nah->a.next;
-    nah->a.next->a.prev = ah;
-
-#ifdef DEBUG_MALLOC
-    nah->a.type = ARENA_TYPE_DEAD;
-#endif
-  }
-}
-
-
diff --git a/klibc/xwrite.c b/fwrite.c
similarity index 65%
rename from klibc/xwrite.c
rename to fwrite.c
index 7a5ddd2..8213c33 100644
--- a/klibc/xwrite.c
+++ b/fwrite.c
@@ -1,24 +1,24 @@
 /*
- * xwrite.c
+ * fwrite.c
  */
 
 #include <errno.h>
 #include <unistd.h>
-#include <xio.h>
+#include <stdio.h>
 
-ssize_t __xwrite(int fd, const void *buf, size_t count)
+size_t __fwrite(const void *buf, size_t count, FILE *f)
 {
-  ssize_t bytes = 0;
+  size_t bytes = 0;
   ssize_t rv;
   const char *p = buf;
 
   while ( count ) {
-    rv = write(fd, p, count);
+    rv = write((int)f, p, count);
     if ( rv == -1 ) {
       if ( errno == EINTR )
 	continue;
       else
-	return bytes ? bytes : -1;
+	break;
     } else if ( rv == 0 ) {
       break;
     }
diff --git a/fwrite2.c b/fwrite2.c
new file mode 100644
index 0000000..a869c4f
--- /dev/null
+++ b/fwrite2.c
@@ -0,0 +1,13 @@
+/*
+ * fwrite2.c
+ *
+ * The actual fwrite() function as a non-inline
+ */
+
+#define __NO_FREAD_FWRITE_INLINES
+#include <stdio.h>
+
+size_t fwrite(const void *ptr, size_t size, size_t nmemb, FILE *f)
+{
+  return __fwrite(ptr, size*nmemb, f)/size;
+}
diff --git a/include/stdio.h b/include/stdio.h
index 9ffda49..ef7353a 100644
--- a/include/stdio.h
+++ b/include/stdio.h
@@ -19,6 +19,23 @@
 #define stderr ((FILE *)2)
 
 __extern int fputs(const char *, FILE *);
+__extern int puts(const char *);
+
+__extern size_t __fread(void *, size_t, FILE *);
+__extern size_t __fwrite(const void *, size_t, FILE *);
+
+#ifndef __NO_FREAD_FWRITE_INLINES
+__extern __inline__ size_t
+fread(void *__p, size_t __s, size_t __n, FILE *__f)
+{
+  return __fread(__p, __s*__n, __f)/__s;
+}
+__extern __inline__ size_t
+fwrite(void *__p, size_t __s, size_t __n, FILE *__f)
+{
+  return __fwrite(__p, __s*__n, __f)/__s;
+}
+#endif
 
 __extern int printf(const char *, ...);
 __extern int vprintf(const char *, va_list);
diff --git a/include/xio.h b/include/xio.h
deleted file mode 100644
index fe7ef3f..0000000
--- a/include/xio.h
+++ /dev/null
@@ -1,13 +0,0 @@
-/*
- * xio.h
- */
-
-#ifndef _XIO_H
-#define _XIO_H
-
-#include <unistd.h>
-
-ssize_t __xwrite(int, const void *, size_t);
-ssize_t __xread(int, void *, size_t);
-
-#endif /* _XIO_H */
diff --git a/klibc/Makefile b/klibc/Makefile
index 7775e09..73ecbc1 100644
--- a/klibc/Makefile
+++ b/klibc/Makefile
@@ -22,7 +22,8 @@
 	  exitc.o exits.o atexit.o onexit.o \
 	  execl.o execle.o execv.o execvpe.o execvp.o execlp.o execlpe.o \
 	  fork.o wait.o wait3.o waitpid.o setpgrp.o \
-	  printf.o vprintf.o fprintf.o vfprintf.o xread.o xwrite.o fputs.o \
+	  printf.o vprintf.o fprintf.o vfprintf.o \
+	  fread.o fread2.o fwrite.o fwrite2.o fputs.o puts.o \
 	  sleep.o usleep.o raise.o abort.o assert.o alarm.o pause.o \
 	  signal.o sigaction.o sigpending.o sigprocmask.o sigsuspend.o \
 	  brk.o sbrk.o malloc.o realloc.o calloc.o mmap.o \
diff --git a/klibc/abort.c b/klibc/abort.c
index 57b5d60..16557ed 100644
--- a/klibc/abort.c
+++ b/klibc/abort.c
@@ -3,11 +3,17 @@
  */
 
 #include <stdlib.h>
+#include <unistd.h>
 #include <signal.h>
 
 void abort(void)
 {
+  sigset_t set;
+
+  sigemptyset(&set);
+  sigaddset(&set, SIGABRT);
+  rt_sigprocmask(SIG_UNBLOCK, &set, NULL, sizeof set);
   raise(SIGABRT);
-  _exit(255);
+  _exit(255);			/* raise() should have killed us */
 }
   
diff --git a/klibc/fputs.c b/klibc/fputs.c
index 73fbad7..cde2cf9 100644
--- a/klibc/fputs.c
+++ b/klibc/fputs.c
@@ -8,9 +8,8 @@
 
 #include <stdio.h>
 #include <string.h>
-#include <xio.h>
 
 int fputs(const char *s, FILE *file)
 {
-  return __xwrite((int)file, s, strlen(s));
+  return __fwrite(s, strlen(s), file);
 }
diff --git a/klibc/xread.c b/klibc/fread.c
similarity index 71%
copy from klibc/xread.c
copy to klibc/fread.c
index cf1ade7..8580423 100644
--- a/klibc/xread.c
+++ b/klibc/fread.c
@@ -1,19 +1,19 @@
 /*
- * xread.c
+ * fread.c
  */
 
 #include <errno.h>
 #include <unistd.h>
-#include <xio.h>
+#include <stdio.h>
 
-ssize_t __xread(int fd, void *buf, size_t count)
+size_t __fread(void *buf, size_t count, FILE *f)
 {
-  ssize_t bytes = 0;
+  size_t bytes = 0;
   ssize_t rv;
   char *p = buf;
 
   while ( count ) {
-    rv = read(fd, p, count);
+    rv = read((int)f, p, count);
     if ( rv == -1 ) {
       if ( errno == EINTR )
 	continue;
diff --git a/klibc/fread2.c b/klibc/fread2.c
new file mode 100644
index 0000000..6172f9d
--- /dev/null
+++ b/klibc/fread2.c
@@ -0,0 +1,13 @@
+/*
+ * fread2.c
+ *
+ * The actual fread() function as a non-inline
+ */
+
+#define __NO_FREAD_FWRITE_INLINES
+#include <stdio.h>
+
+size_t fread(void *ptr, size_t size, size_t nmemb, FILE *f)
+{
+  return __fread(ptr, size*nmemb, f)/size;
+}
diff --git a/klibc/xwrite.c b/klibc/fwrite.c
similarity index 65%
copy from klibc/xwrite.c
copy to klibc/fwrite.c
index 7a5ddd2..8213c33 100644
--- a/klibc/xwrite.c
+++ b/klibc/fwrite.c
@@ -1,24 +1,24 @@
 /*
- * xwrite.c
+ * fwrite.c
  */
 
 #include <errno.h>
 #include <unistd.h>
-#include <xio.h>
+#include <stdio.h>
 
-ssize_t __xwrite(int fd, const void *buf, size_t count)
+size_t __fwrite(const void *buf, size_t count, FILE *f)
 {
-  ssize_t bytes = 0;
+  size_t bytes = 0;
   ssize_t rv;
   const char *p = buf;
 
   while ( count ) {
-    rv = write(fd, p, count);
+    rv = write((int)f, p, count);
     if ( rv == -1 ) {
       if ( errno == EINTR )
 	continue;
       else
-	return bytes ? bytes : -1;
+	break;
     } else if ( rv == 0 ) {
       break;
     }
diff --git a/klibc/fwrite2.c b/klibc/fwrite2.c
new file mode 100644
index 0000000..a869c4f
--- /dev/null
+++ b/klibc/fwrite2.c
@@ -0,0 +1,13 @@
+/*
+ * fwrite2.c
+ *
+ * The actual fwrite() function as a non-inline
+ */
+
+#define __NO_FREAD_FWRITE_INLINES
+#include <stdio.h>
+
+size_t fwrite(const void *ptr, size_t size, size_t nmemb, FILE *f)
+{
+  return __fwrite(ptr, size*nmemb, f)/size;
+}
diff --git a/klibc/include/stdio.h b/klibc/include/stdio.h
index 9ffda49..ef7353a 100644
--- a/klibc/include/stdio.h
+++ b/klibc/include/stdio.h
@@ -19,6 +19,23 @@
 #define stderr ((FILE *)2)
 
 __extern int fputs(const char *, FILE *);
+__extern int puts(const char *);
+
+__extern size_t __fread(void *, size_t, FILE *);
+__extern size_t __fwrite(const void *, size_t, FILE *);
+
+#ifndef __NO_FREAD_FWRITE_INLINES
+__extern __inline__ size_t
+fread(void *__p, size_t __s, size_t __n, FILE *__f)
+{
+  return __fread(__p, __s*__n, __f)/__s;
+}
+__extern __inline__ size_t
+fwrite(void *__p, size_t __s, size_t __n, FILE *__f)
+{
+  return __fwrite(__p, __s*__n, __f)/__s;
+}
+#endif
 
 __extern int printf(const char *, ...);
 __extern int vprintf(const char *, va_list);
diff --git a/klibc/include/xio.h b/klibc/include/xio.h
deleted file mode 100644
index fe7ef3f..0000000
--- a/klibc/include/xio.h
+++ /dev/null
@@ -1,13 +0,0 @@
-/*
- * xio.h
- */
-
-#ifndef _XIO_H
-#define _XIO_H
-
-#include <unistd.h>
-
-ssize_t __xwrite(int, const void *, size_t);
-ssize_t __xread(int, void *, size_t);
-
-#endif /* _XIO_H */
diff --git a/klibc/microhello.c b/klibc/microhello.c
index c139e5e..7c081d6 100644
--- a/klibc/microhello.c
+++ b/klibc/microhello.c
@@ -1,10 +1,9 @@
 #include <stdio.h>
 #include <unistd.h>
-#include <xio.h>
 
 int main(void)
 {
   const char hello[] = "Hello, World!\n";
-  write(1, hello, sizeof hello-1);
+  __fwrite(hello, sizeof hello-1, stdout);
   return 0;
 }
diff --git a/klibc/onexit.c b/klibc/onexit.c
index aea3964..70a9c01 100644
--- a/klibc/onexit.c
+++ b/klibc/onexit.c
@@ -3,6 +3,7 @@
  */
 
 #include <stdlib.h>
+#include <unistd.h>
 #include "atexit.h"
 
 extern __noreturn (*__exit_handler)(int);
diff --git a/klibc/puts.c b/klibc/puts.c
new file mode 100644
index 0000000..52bea83
--- /dev/null
+++ b/klibc/puts.c
@@ -0,0 +1,13 @@
+/*
+ * puts.c
+ */
+
+#include <stdio.h>
+
+int puts(const char *s)
+{
+  if ( fputs(s, stdout) < 0 )
+    return -1;
+
+  return __fwrite("\n", 1, stdout);
+}
diff --git a/klibc/vfprintf.c b/klibc/vfprintf.c
index 95215f8..62124b7 100644
--- a/klibc/vfprintf.c
+++ b/klibc/vfprintf.c
@@ -6,7 +6,6 @@
 #include <string.h>
 #include <stdarg.h>
 #include <unistd.h>
-#include <xio.h>
 
 #define BUFFER_SIZE	32768
 
@@ -23,5 +22,5 @@
   if ( rv > BUFFER_SIZE-1 )
     rv = BUFFER_SIZE-1;
 
-  return __xwrite((int)file, buffer, rv);
+  return __fwrite(buffer, rv, file);
 }
diff --git a/microhello.c b/microhello.c
index c139e5e..7c081d6 100644
--- a/microhello.c
+++ b/microhello.c
@@ -1,10 +1,9 @@
 #include <stdio.h>
 #include <unistd.h>
-#include <xio.h>
 
 int main(void)
 {
   const char hello[] = "Hello, World!\n";
-  write(1, hello, sizeof hello-1);
+  __fwrite(hello, sizeof hello-1, stdout);
   return 0;
 }
diff --git a/onexit.c b/onexit.c
index aea3964..70a9c01 100644
--- a/onexit.c
+++ b/onexit.c
@@ -3,6 +3,7 @@
  */
 
 #include <stdlib.h>
+#include <unistd.h>
 #include "atexit.h"
 
 extern __noreturn (*__exit_handler)(int);
diff --git a/puts.c b/puts.c
new file mode 100644
index 0000000..52bea83
--- /dev/null
+++ b/puts.c
@@ -0,0 +1,13 @@
+/*
+ * puts.c
+ */
+
+#include <stdio.h>
+
+int puts(const char *s)
+{
+  if ( fputs(s, stdout) < 0 )
+    return -1;
+
+  return __fwrite("\n", 1, stdout);
+}
diff --git a/vfprintf.c b/vfprintf.c
index 95215f8..62124b7 100644
--- a/vfprintf.c
+++ b/vfprintf.c
@@ -6,7 +6,6 @@
 #include <string.h>
 #include <stdarg.h>
 #include <unistd.h>
-#include <xio.h>
 
 #define BUFFER_SIZE	32768
 
@@ -23,5 +22,5 @@
   if ( rv > BUFFER_SIZE-1 )
     rv = BUFFER_SIZE-1;
 
-  return __xwrite((int)file, buffer, rv);
+  return __fwrite(buffer, rv, file);
 }
diff --git a/xread.c b/xread.c
deleted file mode 100644
index cf1ade7..0000000
--- a/xread.c
+++ /dev/null
@@ -1,35 +0,0 @@
-/*
- * xread.c
- */
-
-#include <errno.h>
-#include <unistd.h>
-#include <xio.h>
-
-ssize_t __xread(int fd, void *buf, size_t count)
-{
-  ssize_t bytes = 0;
-  ssize_t rv;
-  char *p = buf;
-
-  while ( count ) {
-    rv = read(fd, p, count);
-    if ( rv == -1 ) {
-      if ( errno == EINTR )
-	continue;
-      else
-	return bytes ? bytes : -1;
-    } else if ( rv == 0 ) {
-      break;
-    }
-
-    p += rv;
-    bytes += rv;
-    count -= rv;
-  }
-
-  return bytes;
-}
-
-    
-      
diff --git a/xwrite.c b/xwrite.c
deleted file mode 100644
index 7a5ddd2..0000000
--- a/xwrite.c
+++ /dev/null
@@ -1,35 +0,0 @@
-/*
- * xwrite.c
- */
-
-#include <errno.h>
-#include <unistd.h>
-#include <xio.h>
-
-ssize_t __xwrite(int fd, const void *buf, size_t count)
-{
-  ssize_t bytes = 0;
-  ssize_t rv;
-  const char *p = buf;
-
-  while ( count ) {
-    rv = write(fd, p, count);
-    if ( rv == -1 ) {
-      if ( errno == EINTR )
-	continue;
-      else
-	return bytes ? bytes : -1;
-    } else if ( rv == 0 ) {
-      break;
-    }
-
-    p += rv;
-    bytes += rv;
-    count -= rv;
-  }
-
-  return bytes;
-}
-
-    
-