diff options
Diffstat (limited to 'libc/stdio')
-rw-r--r-- | libc/stdio/scanf.c | 54 | ||||
-rw-r--r-- | libc/stdio/stdio.c | 56 |
2 files changed, 57 insertions, 53 deletions
diff --git a/libc/stdio/scanf.c b/libc/stdio/scanf.c index 7c5f52183..593e01d25 100644 --- a/libc/stdio/scanf.c +++ b/libc/stdio/scanf.c @@ -1,3 +1,5 @@ +#include <stdlib.h> +#include <unistd.h> #include <stdio.h> #include <ctype.h> #include <string.h> @@ -30,27 +32,27 @@ va_dcl #ifdef L_sscanf #ifdef __STDC__ -int sscanf(char * sp, const char * fmt, ...) +int sscanf(const char * sp, const char * fmt, ...) #else int sscanf(sp, fmt, va_alist) -char * sp; +__const char * sp; __const char *fmt; va_dcl #endif { -static FILE string[1] = -{ - {0, (char*)(unsigned) -1, 0, 0, (char*) (unsigned) -1, -1, - _IOFBF | __MODE_READ} -}; - - va_list ptr; - int rv; - va_strt(ptr, fmt); - string->bufpos = sp; - rv = vfscanf(string,fmt,ptr); - va_end(ptr); - return rv; + FILE string[1] = + { + {0, (char*)(unsigned) -1, 0, 0, (char*) (unsigned) -1, -1, + _IOFBF | __MODE_READ} + }; + + va_list ptr; + int rv; + va_strt(ptr, fmt); + string->bufpos = (unsigned char *)((void*)sp); + rv = vfscanf(string,fmt,ptr); + va_end(ptr); + return rv; } #endif @@ -83,18 +85,16 @@ va_list ap; #endif #ifdef L_vsscanf -int vsscanf(sp, fmt, ap) -char * sp; -__const char *fmt; +int vsscanf(__const char *sp, __const char *fmt, va_list ap) { -static FILE string[1] = -{ - {0, (char*)(unsigned) -1, 0, 0, (char*) (unsigned) -1, -1, - _IOFBF | __MODE_READ} -}; - - string->bufpos = sp; - return vfscanf(string,fmt,ap); + FILE string[1] = + { + {0, (char*)(unsigned) -1, 0, 0, (char*) (unsigned) -1, -1, + _IOFBF | __MODE_READ} + }; + + string->bufpos = (unsigned char *)((void*)sp); + return vfscanf(string,fmt,ap); } #endif @@ -170,7 +170,7 @@ int fp_sval[NSTATE] = { int vfscanf(fp, fmt, ap) register FILE *fp; -register char *fmt; +register const char *fmt; va_list ap; { diff --git a/libc/stdio/stdio.c b/libc/stdio/stdio.c index 98d0ba3b4..9043e6199 100644 --- a/libc/stdio/stdio.c +++ b/libc/stdio/stdio.c @@ -6,15 +6,19 @@ /* This is an implementation of the C standard IO package. */ +#include <stdlib.h> #include <stdio.h> - +#include <unistd.h> #include <fcntl.h> #include <sys/types.h> #include <malloc.h> #include <errno.h> +#include <string.h> #undef STUB_FWRITE +void __io_init_vars(void); + extern FILE *__IO_list; /* For fflush at exit */ #define FIXED_BUFFERS 2 @@ -80,10 +84,7 @@ FILE stderr[1] = /* Call the stdio initiliser; it's main job it to call atexit */ -#define STATIC - -STATIC int -__stdio_close_all() +void __stdio_close_all(void) { FILE *fp; fflush(stdout); @@ -103,8 +104,7 @@ static int first_time = 0; struct fixed_buffer _fixed_buffers[2]; -STATIC void -__io_init_vars() +void __io_init_vars(void) { if( first_time ) return; first_time = 1; @@ -206,7 +206,9 @@ FILE *fp; if (fp->mode & __MODE_WRITING) fflush(fp); +#if __MODE_IOTRAN try_again: +#endif /* Can't read or there's been an EOF or error then return EOF */ if ((fp->mode & (__MODE_READ | __MODE_EOF | __MODE_ERR)) != __MODE_READ) return EOF; @@ -319,7 +321,7 @@ FILE *fp; char * fgets(s, count, f) char *s; -size_t count; +int count; FILE *f; { char *ret; @@ -368,7 +370,7 @@ char *str; #ifdef L_fputs int fputs(str, fp) -char *str; +const char *str; FILE *fp; { register int n = 0; @@ -385,7 +387,7 @@ FILE *fp; #ifdef L_puts int puts(str) -char *str; +const char *str; { register int n; @@ -405,12 +407,12 @@ char *str; * This ignores __MODE__IOTRAN; probably exactly what you want. (It _is_ what * fgetc wants) */ -int +size_t fread(buf, size, nelm, fp) -char *buf; -int size; -int nelm; -FILE *fp; +void *buf; +size_t size; +size_t nelm; +FILE *fp; { int len, v; unsigned bytes, got = 0; @@ -467,12 +469,12 @@ FILE *fp; * * Again this ignores __MODE__IOTRAN. */ -int +size_t fwrite(buf, size, nelm, fp) -char *buf; -int size; -int nelm; -FILE *fp; +const void *buf; +size_t size; +size_t nelm; +FILE *fp; { register int v; int len; @@ -606,7 +608,6 @@ int ref; long ftell(fp) FILE * fp; { - long rv; if (fflush(fp) == EOF) return EOF; return lseek(fp->fd, 0L, SEEK_CUR); @@ -620,10 +621,10 @@ FILE * fp; */ FILE * __fopen(fname, fd, fp, mode) -char *fname; +const char *fname; int fd; FILE *fp; -char *mode; +const char *mode; { int open_mode = 0; #if __MODE_IOTRAN @@ -875,8 +876,8 @@ size_t size; if( mode == _IOFBF || mode == _IOLBF ) { - if( size <= 0 ) size = BUFSIZ; - if( buf == 0 ) + if( size <= 0 ) { size = BUFSIZ; } + if( buf == 0 ) { if (size == BUFSIZ) { int i; for(i=0;i<FIXED_BUFFERS;i++) @@ -887,8 +888,10 @@ size_t size; } if(i==FIXED_BUFFERS) buf = malloc(size); - } else + } else { buf = malloc(size); + } + } if( buf == 0 ) return EOF; fp->bufstart = buf; @@ -896,6 +899,7 @@ size_t size; fp->mode |= mode; } fp->bufpos = fp->bufread = fp->bufwrite = fp->bufstart; + return 0; } #endif |