aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorH. Peter Anvin <hpa@zytor.com>2002-08-10 08:01:55 +0000
committerH. Peter Anvin <hpa@zytor.com>2002-08-10 08:01:55 +0000
commit203d299ce7dcfe846766ed3e8d35ec32452a10ae (patch)
tree0d8285c24f0111259425ccb799737ef08747c29b
parentfe6d77d3a3d59bcab3d13be98b1280522db49531 (diff)
downloadklibc-203d299ce7dcfe846766ed3e8d35ec32452a10ae.tar.gz
Make gcc3-compatible. Call fread() and fwrite() by their proper names.klibc-0.9
-rw-r--r--abort.c8
-rw-r--r--fputs.c3
-rw-r--r--fread.c (renamed from xread.c)10
-rw-r--r--fread2.c13
-rw-r--r--free.c67
-rw-r--r--fwrite.c (renamed from klibc/xwrite.c)12
-rw-r--r--fwrite2.c13
-rw-r--r--include/stdio.h17
-rw-r--r--include/xio.h13
-rw-r--r--klibc/Makefile3
-rw-r--r--klibc/abort.c8
-rw-r--r--klibc/fputs.c3
-rw-r--r--klibc/fread.c (renamed from klibc/xread.c)10
-rw-r--r--klibc/fread2.c13
-rw-r--r--klibc/fwrite.c (renamed from xwrite.c)12
-rw-r--r--klibc/fwrite2.c13
-rw-r--r--klibc/include/stdio.h17
-rw-r--r--klibc/include/xio.h13
-rw-r--r--klibc/microhello.c3
-rw-r--r--klibc/onexit.c1
-rw-r--r--klibc/puts.c13
-rw-r--r--klibc/vfprintf.c3
-rw-r--r--microhello.c3
-rw-r--r--onexit.c1
-rw-r--r--puts.c13
-rw-r--r--vfprintf.c3
26 files changed, 158 insertions, 130 deletions
diff --git a/abort.c b/abort.c
index 57b5d607d9ad3..16557edf41c9f 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 73fbad7bc16b3..cde2cf9624d2b 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/xread.c b/fread.c
index cf1ade7482d73..8580423336e90 100644
--- a/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 0000000000000..6172f9d7bda40
--- /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 b370130c51712..0000000000000
--- 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
index 7a5ddd2356fac..8213c336c3f3d 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 0000000000000..a869c4fc6ded5
--- /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 9ffda494e4ebe..ef7353a9c2757 100644
--- a/include/stdio.h
+++ b/include/stdio.h
@@ -19,6 +19,23 @@ typedef struct _IO_file FILE;
#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 fe7ef3f0332e7..0000000000000
--- 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 7775e0945891d..73ecbc135f4df 100644
--- a/klibc/Makefile
+++ b/klibc/Makefile
@@ -22,7 +22,8 @@ LIBOBJS = vsnprintf.o snprintf.o vsprintf.o sprintf.o \
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 57b5d607d9ad3..16557edf41c9f 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 73fbad7bc16b3..cde2cf9624d2b 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
index cf1ade7482d73..8580423336e90 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 0000000000000..6172f9d7bda40
--- /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/xwrite.c b/klibc/fwrite.c
index 7a5ddd2356fac..8213c336c3f3d 100644
--- a/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 0000000000000..a869c4fc6ded5
--- /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 9ffda494e4ebe..ef7353a9c2757 100644
--- a/klibc/include/stdio.h
+++ b/klibc/include/stdio.h
@@ -19,6 +19,23 @@ typedef struct _IO_file FILE;
#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 fe7ef3f0332e7..0000000000000
--- 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 c139e5e51ad22..7c081d600dbf1 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 aea3964ef8582..70a9c01f615ee 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 0000000000000..52bea830b61cf
--- /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 95215f8742360..62124b7dff0f0 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 @@ int vfprintf(FILE *file, const char *format, va_list ap)
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 c139e5e51ad22..7c081d600dbf1 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 aea3964ef8582..70a9c01f615ee 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 0000000000000..52bea830b61cf
--- /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 95215f8742360..62124b7dff0f0 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 @@ int vfprintf(FILE *file, const char *format, va_list ap)
if ( rv > BUFFER_SIZE-1 )
rv = BUFFER_SIZE-1;
- return __xwrite((int)file, buffer, rv);
+ return __fwrite(buffer, rv, file);
}