aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorH. Peter Anvin <hpa@zytor.com>2002-08-10 10:40:39 +0000
committerH. Peter Anvin <hpa@zytor.com>2002-08-10 10:40:39 +0000
commit69d9cddf564734c3730fa44344b74d6b29722988 (patch)
tree195381f6ca5048bc47ca2c1926c9a2d6af6241e1
parentc905cc3d98ded943bfc090de0710dc976cc034a3 (diff)
downloadklibc-69d9cddf564734c3730fa44344b74d6b29722988.tar.gz
Actually implement fileno()klibc-0.10
-rw-r--r--crt0.c67
-rw-r--r--fread.c2
-rw-r--r--fwrite.c2
-rw-r--r--include/stdio.h7
-rw-r--r--klibc/fread.c2
-rw-r--r--klibc/fwrite.c2
-rw-r--r--klibc/include/stdio.h7
7 files changed, 18 insertions, 71 deletions
diff --git a/crt0.c b/crt0.c
deleted file mode 100644
index a0e6b9b1f428d..0000000000000
--- 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 8580423336e90..f0610893b7284 100644
--- a/fread.c
+++ b/fread.c
@@ -13,7 +13,7 @@ size_t __fread(void *buf, size_t count, FILE *f)
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 8213c336c3f3d..5b49dfbb709b0 100644
--- a/fwrite.c
+++ b/fwrite.c
@@ -13,7 +13,7 @@ size_t __fwrite(const void *buf, size_t count, FILE *f)
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 ef7353a9c2757..dcda46e2f05e4 100644
--- a/include/stdio.h
+++ b/include/stdio.h
@@ -18,6 +18,13 @@ typedef struct _IO_file FILE;
#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 8580423336e90..f0610893b7284 100644
--- a/klibc/fread.c
+++ b/klibc/fread.c
@@ -13,7 +13,7 @@ size_t __fread(void *buf, size_t count, FILE *f)
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 8213c336c3f3d..5b49dfbb709b0 100644
--- a/klibc/fwrite.c
+++ b/klibc/fwrite.c
@@ -13,7 +13,7 @@ size_t __fwrite(const void *buf, size_t count, FILE *f)
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 ef7353a9c2757..dcda46e2f05e4 100644
--- a/klibc/include/stdio.h
+++ b/klibc/include/stdio.h
@@ -18,6 +18,13 @@ typedef struct _IO_file FILE;
#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 *);