diff options
Diffstat (limited to 'mdk-stage1/dietlibc/libstdio')
26 files changed, 0 insertions, 521 deletions
diff --git a/mdk-stage1/dietlibc/libstdio/clearerr.c b/mdk-stage1/dietlibc/libstdio/clearerr.c deleted file mode 100644 index 8bde8c702..000000000 --- a/mdk-stage1/dietlibc/libstdio/clearerr.c +++ /dev/null @@ -1,5 +0,0 @@ -#include "dietstdio.h" - -void clearerr( FILE *stream) { - stream->flags&=~(ERRORINDICATOR|EOFINDICATOR); -} diff --git a/mdk-stage1/dietlibc/libstdio/fclose.c b/mdk-stage1/dietlibc/libstdio/fclose.c deleted file mode 100644 index 6958a48e7..000000000 --- a/mdk-stage1/dietlibc/libstdio/fclose.c +++ /dev/null @@ -1,24 +0,0 @@ -#include "dietstdio.h" -#include <stdlib.h> -#include <unistd.h> - -int fclose(FILE *stream) { - int res; -#ifdef WANT_BUFFERED_STDIO - FILE *f,*fl; -#endif - fflush(stream); - res=close(stream->fd); -#ifdef WANT_BUFFERED_STDIO - for (fl=0,f=__stdio_root; f; fl=f,f=f->next) - if (f==stream) { - if (fl) - fl->next=f->next; - else - __stdio_root=f->next; - break; - } -#endif - free(stream); - return res; -} diff --git a/mdk-stage1/dietlibc/libstdio/fdglue.c b/mdk-stage1/dietlibc/libstdio/fdglue.c deleted file mode 100644 index eeedd513d..000000000 --- a/mdk-stage1/dietlibc/libstdio/fdglue.c +++ /dev/null @@ -1,49 +0,0 @@ -#include "dietstdio.h" -#include <unistd.h> -#include <fcntl.h> -#include <errno.h> -#include <stdlib.h> - -#ifdef WANT_BUFFERED_STDIO -extern int __stdio_atexit; -extern void __stdio_flushall(); -#endif - -int __stdio_parse_mode(const char *mode) { - int f=0; - for (;;) { - switch (*mode) { - case 0: return f; - case 'b': break; - case 'r': f=O_RDONLY; break; - case 'w': f=O_WRONLY|O_CREAT|O_TRUNC; break; - case 'a': f=O_WRONLY|O_CREAT|O_APPEND; break; - case '+': f=(f&(~O_WRONLY))|O_RDWR; break; - } - ++mode; - } -} - -FILE* __stdio_init_file(int fd) { - FILE *tmp=(FILE*)malloc(sizeof(FILE)); - if (!tmp) { - close(fd); - errno=ENOMEM; - return 0; - } - tmp->fd=fd; -#ifdef WANT_BUFFERED_STDIO - tmp->bm=0; - tmp->bs=0; -#endif - tmp->flags=0; -#ifdef WANT_BUFFERED_STDIO - if (__stdio_atexit==0) { - __stdio_atexit=1; - atexit(__stdio_flushall); - } - tmp->next=__stdio_root; - __stdio_root=tmp; -#endif - return tmp; -} diff --git a/mdk-stage1/dietlibc/libstdio/fdopen.c b/mdk-stage1/dietlibc/libstdio/fdopen.c deleted file mode 100644 index aee14fb0c..000000000 --- a/mdk-stage1/dietlibc/libstdio/fdopen.c +++ /dev/null @@ -1,21 +0,0 @@ -#include <sys/types.h> -#include <dietstdio.h> -#include <unistd.h> - -#define SEEK_END 2 - -int __stdio_parse_mode(const char *mode); -FILE* __stdio_init_file(int fd); - -FILE *fdopen (int filedes, const char *mode) { - int f=0; /* O_RDONLY, O_WRONLY or O_RDWR */ - int fd; - - f=__stdio_parse_mode(mode); - if ((fd=filedes)<0) return 0; - { - FILE * ret = __stdio_init_file(fd); - ret->flags |= UNSEEKABLE; - return ret; - } -} diff --git a/mdk-stage1/dietlibc/libstdio/feof.c b/mdk-stage1/dietlibc/libstdio/feof.c deleted file mode 100644 index b7e86fe3b..000000000 --- a/mdk-stage1/dietlibc/libstdio/feof.c +++ /dev/null @@ -1,9 +0,0 @@ -#include <dietstdio.h> - -int feof(FILE *stream) { -#ifdef WANT_UNGETC - /* yuck!!! */ - if (stream->ungotten) return 0; -#endif - return (stream->flags&EOFINDICATOR); -} diff --git a/mdk-stage1/dietlibc/libstdio/ferror.c b/mdk-stage1/dietlibc/libstdio/ferror.c deleted file mode 100644 index e86873be0..000000000 --- a/mdk-stage1/dietlibc/libstdio/ferror.c +++ /dev/null @@ -1,5 +0,0 @@ -#include <dietstdio.h> - -int ferror(FILE *stream) { - return (stream->flags&ERRORINDICATOR); -} diff --git a/mdk-stage1/dietlibc/libstdio/fflush.c b/mdk-stage1/dietlibc/libstdio/fflush.c deleted file mode 100644 index 7078e04f4..000000000 --- a/mdk-stage1/dietlibc/libstdio/fflush.c +++ /dev/null @@ -1,62 +0,0 @@ -#include "dietstdio.h" -#include <unistd.h> -#include <stdlib.h> -#include "dietwarning.h" - -FILE *__stdio_root; - -#ifdef WANT_BUFFERED_STDIO -int __stdio_atexit=0; - -void __stdio_flushall() { - fflush(0); -} - -extern int __fflush_stdin(); -extern int __fflush_stdout(); -extern int __fflush_stderr(); - -int fflush(FILE *stream) { - if (stream==0) { - int res; - FILE *f; - __fflush_stdin(); - __fflush_stdout(); - __fflush_stderr(); - for (res=0, f=__stdio_root; f; f=f->next) - if (fflush(f)) - res=-1; - return res; - } - if (stream->flags&BUFINPUT) { - register int tmp; - if ((tmp=stream->bm-stream->bs)) lseek(stream->fd,tmp,SEEK_CUR); - } else - if (stream->bm && write(stream->fd,stream->buf,stream->bm)!=stream->bm) { - stream->flags|=ERRORINDICATOR; - return -1; - } - stream->bm=0; - return 0; -} - -int __fflush4(FILE *stream,int next) { - if (!__stdio_atexit) { - __stdio_atexit=1; - atexit(__stdio_flushall); - } - if ((stream->flags&BUFINPUT)!=next) { - int res=fflush(stream); - stream->flags=(stream->flags&~BUFINPUT)|next; - return res; - } - return 0; -} - -#else -int fflush(FILE *stream) { - return 0; -} -#endif - -link_warning("fflush","warning: your code uses stdio (several kilobytes of bloat).") diff --git a/mdk-stage1/dietlibc/libstdio/fgetc.c b/mdk-stage1/dietlibc/libstdio/fgetc.c deleted file mode 100644 index 90d83961a..000000000 --- a/mdk-stage1/dietlibc/libstdio/fgetc.c +++ /dev/null @@ -1,40 +0,0 @@ -#include "dietstdio.h" -#include <unistd.h> - -extern int feof(FILE *stream); - -int fgetc(FILE *stream) { - unsigned char c; -#ifdef WANT_UNGETC - if (stream->ungotten) { - stream->ungotten=0; - return stream->ungetbuf; - } -#endif - if (feof(stream)) - return EOF; -#ifdef WANT_BUFFERED_STDIO - if (__fflush4(stream,BUFINPUT)) return EOF; - if (stream->bm>=stream->bs) { - int len=read(stream->fd,stream->buf,BUFSIZE); - if (len==0) { - stream->flags|=EOFINDICATOR; - return EOF; - } else if (len<0) { - stream->flags|=ERRORINDICATOR; - return EOF; - } - stream->bm=0; - stream->bs=len; - } - c=stream->buf[stream->bm]; - ++stream->bm; - return c; -#else - if (read(stream->fd,&c,1)!=1) { - stream->flags|=ERRORINDICATOR; - return EOF; - } - return c; -#endif -} diff --git a/mdk-stage1/dietlibc/libstdio/fgets.c b/mdk-stage1/dietlibc/libstdio/fgets.c deleted file mode 100644 index c613d452d..000000000 --- a/mdk-stage1/dietlibc/libstdio/fgets.c +++ /dev/null @@ -1,20 +0,0 @@ -#include "dietstdio.h" - -extern int ferror(FILE *stream); - -char *fgets(char *s, int size, FILE *stream) { - char *orig=s; - int l; - for (l=size; l>0;) { - int c=fgetc(stream); - if (c==EOF) break; - *s=c; - ++s; - --l; - if (c=='\n') break; - } - if (l==size || ferror(stream)) - return 0; - *s=0; - return orig; -} diff --git a/mdk-stage1/dietlibc/libstdio/fileno.c b/mdk-stage1/dietlibc/libstdio/fileno.c deleted file mode 100644 index f021d3881..000000000 --- a/mdk-stage1/dietlibc/libstdio/fileno.c +++ /dev/null @@ -1,5 +0,0 @@ -#include <dietstdio.h> - -int fileno(FILE *stream) { - return stream->fd; -} diff --git a/mdk-stage1/dietlibc/libstdio/fopen.c b/mdk-stage1/dietlibc/libstdio/fopen.c deleted file mode 100644 index aac17be42..000000000 --- a/mdk-stage1/dietlibc/libstdio/fopen.c +++ /dev/null @@ -1,21 +0,0 @@ -#include <sys/types.h> -#include <dietstdio.h> -#include <unistd.h> - -#define SEEK_END 2 - -extern int __stdio_atexit; -extern void __stdio_flushall(); - -extern int __stdio_parse_mode(const char *mode); -extern FILE* __stdio_init_file(int fd); - -FILE *fopen (const char *path, const char *mode) { - int f=0; /* O_RDONLY, O_WRONLY or O_RDWR */ - int fd; - - f=__stdio_parse_mode(mode); - if ((fd=open(path,f,0666))<0) - return 0; - return __stdio_init_file(fd); -} diff --git a/mdk-stage1/dietlibc/libstdio/fprintf.c b/mdk-stage1/dietlibc/libstdio/fprintf.c deleted file mode 100644 index 237fd1e51..000000000 --- a/mdk-stage1/dietlibc/libstdio/fprintf.c +++ /dev/null @@ -1,23 +0,0 @@ -#include <stdarg.h> -#include <linux/types.h> -#include <stdio.h> -#include <stdlib.h> - -extern int vsnprintf (char *str,size_t size,const char *format, va_list arg_ptr); - -int fprintf(FILE *f,const char *format,...) { - int n; - char *printf_buf; -/* char printf_buf[1024]; */ - va_list arg_ptr; - va_start(arg_ptr, format); - n=vsnprintf(0,1000000,format,arg_ptr); -/* write(1,printf_buf,strlen(printf_buf)); */ - va_end (arg_ptr); - va_start (arg_ptr, format); - printf_buf=alloca(n+2); - n=vsnprintf(printf_buf,n+1,format,arg_ptr); - va_end (arg_ptr); - fwrite(printf_buf,n,1,f); - return n; -} diff --git a/mdk-stage1/dietlibc/libstdio/fputc.c b/mdk-stage1/dietlibc/libstdio/fputc.c deleted file mode 100644 index b816f7c4d..000000000 --- a/mdk-stage1/dietlibc/libstdio/fputc.c +++ /dev/null @@ -1,19 +0,0 @@ -#include <dietstdio.h> -#ifndef WANT_BUFFERED_STDIO -#include <unistd.h> -#endif - -int fputc(int c, FILE *stream) { -#ifdef WANT_BUFFERED_STDIO - if (__fflush4(stream,0)) return EOF; - if (stream->bm>=BUFSIZE-1) - if (fflush(stream)) return EOF; - stream->buf[stream->bm]=c; - ++stream->bm; - if ((stream->flags&BUFLINEWISE) && c=='\n') /* puke */ - if (fflush(stream)) return EOF; -#else - write(stream->fd,&c,1); -#endif - return 0; -} diff --git a/mdk-stage1/dietlibc/libstdio/fputs.c b/mdk-stage1/dietlibc/libstdio/fputs.c deleted file mode 100644 index 51ee9a96e..000000000 --- a/mdk-stage1/dietlibc/libstdio/fputs.c +++ /dev/null @@ -1,6 +0,0 @@ -#include "dietstdio.h" -#include <string.h> - -int fputs(const char *s, FILE *stream) { - return fwrite(s,strlen(s),1,stream); -} diff --git a/mdk-stage1/dietlibc/libstdio/fread.c b/mdk-stage1/dietlibc/libstdio/fread.c deleted file mode 100644 index 29afa1489..000000000 --- a/mdk-stage1/dietlibc/libstdio/fread.c +++ /dev/null @@ -1,51 +0,0 @@ -#include <sys/types.h> -#include "dietstdio.h" -#include <unistd.h> - -size_t fread( void *ptr, size_t size, size_t nmemb, FILE *stream) { - int res; -#ifdef WANT_BUFFERED_STDIO - unsigned long i,j; - j=size*nmemb; -#ifdef WANT_UNGETC - if (stream->ungotten) { - *(char*)ptr=stream->ungetbuf; - ptr=((char*)ptr)+1; - --j; - } - if (!j) return 1; -#endif - for (i=0; i<j; ++i) { - res=fgetc(stream); - if (res==EOF) - return i/size; - else - ((unsigned char*)ptr)[i]=(unsigned char)res; - } - return nmemb; -#else -#ifdef WANT_UNGETC - unsigned long j=size*nmemb; -#endif - fflush(stream); -#ifdef WANT_UNGETC - if (stream->ungotten) { - *(char*)ptr=stream->ungetbuf; - ptr=((char*)ptr)+1; - --j; - } - if (!j) return 1; - res=read(stream->fd,ptr,j); -#else - res=read(stream->fd,ptr,size*nmemb); -#endif - if (res<0) { - stream->flags|=ERRORINDICATOR; - return 0; - } else if (res<size*nmemb) - if (!(stream->flags & UNSEEKABLE) - || ((stream->flags & UNSEEKABLE) && res == 0)) - stream->flags|=EOFINDICATOR; - return res/size; -#endif -} diff --git a/mdk-stage1/dietlibc/libstdio/freopen.c b/mdk-stage1/dietlibc/libstdio/freopen.c deleted file mode 100644 index 8d4644a10..000000000 --- a/mdk-stage1/dietlibc/libstdio/freopen.c +++ /dev/null @@ -1,9 +0,0 @@ -#include <sys/types.h> -#include <dietstdio.h> -#include <unistd.h> - -FILE *freopen (const char *path, const char *mode, FILE *stream) { - fclose(stream); - stream=fopen(path,mode); - return stream; -} diff --git a/mdk-stage1/dietlibc/libstdio/fseek.c b/mdk-stage1/dietlibc/libstdio/fseek.c deleted file mode 100644 index 5bb96bc6e..000000000 --- a/mdk-stage1/dietlibc/libstdio/fseek.c +++ /dev/null @@ -1,11 +0,0 @@ -#include <dietstdio.h> -#include <unistd.h> - -long fseek(FILE *stream, long offset, int whence) { - fflush(stream); -#ifdef WANT_BUFFERED_STDIO - stream->bm=0; stream->bs=0; -#endif - stream->flags&=~(ERRORINDICATOR|EOFINDICATOR); - return (lseek(stream->fd,offset,whence)); -} diff --git a/mdk-stage1/dietlibc/libstdio/ftell.c b/mdk-stage1/dietlibc/libstdio/ftell.c deleted file mode 100644 index 42d2c9f26..000000000 --- a/mdk-stage1/dietlibc/libstdio/ftell.c +++ /dev/null @@ -1,7 +0,0 @@ -#include <dietstdio.h> -#include <unistd.h> - -long ftell(FILE *stream) { - fflush(stream); - return (lseek(stream->fd,0,SEEK_CUR)); -} diff --git a/mdk-stage1/dietlibc/libstdio/fwrite.c b/mdk-stage1/dietlibc/libstdio/fwrite.c deleted file mode 100644 index 5691661a5..000000000 --- a/mdk-stage1/dietlibc/libstdio/fwrite.c +++ /dev/null @@ -1,30 +0,0 @@ -#include <sys/types.h> -#include "dietstdio.h" -#include <unistd.h> - -size_t fwrite( const void *ptr, size_t size, size_t nmemb, FILE *stream) { - int res; -#ifdef WANT_BUFFERED_STDIO - long len=size*nmemb; - long i; - if (len>BUFSIZE || (stream->flags&NOBUF)) { - if (!(stream->flags&NOBUF)) fflush(stream); - res=write(stream->fd,ptr,size*nmemb); - } else { - register const unsigned char *c=ptr; - for (i=size*nmemb; i>0; --i,++c) - if (fputc(*c,stream)) { - res=-1; - break; - } - res=size*nmemb; - } -#else - res=write(stream->fd,ptr,size*nmemb); -#endif - if (res<0) { - stream->flags|=ERRORINDICATOR; - return 0; - } - return size?res/size:0; -} diff --git a/mdk-stage1/dietlibc/libstdio/printf.c b/mdk-stage1/dietlibc/libstdio/printf.c deleted file mode 100644 index 571420dc3..000000000 --- a/mdk-stage1/dietlibc/libstdio/printf.c +++ /dev/null @@ -1,29 +0,0 @@ -#include <stdarg.h> -#include <linux/types.h> -#include <unistd.h> -#include <stdlib.h> -#include "dietstdio.h" - -int vsnprintf (char *str,size_t size,const char *format, va_list arg_ptr); - -int printf(const char *format,...) -{ - int n; - char *printf_buf; -/* char printf_buf[1024]; */ - va_list arg_ptr; - va_start(arg_ptr, format); - n=vsnprintf(0,1000000,format,arg_ptr); -/* write(1,printf_buf,strlen(printf_buf)); */ - va_end (arg_ptr); - va_start (arg_ptr, format); - printf_buf=alloca(n+2); - n=vsnprintf(printf_buf,n+1,format,arg_ptr); -#ifdef WANT_BUFFERED_STDIO - fwrite(printf_buf,n,1,stdout); -#else - write(1,printf_buf,n); -#endif - va_end (arg_ptr); - return n; -} diff --git a/mdk-stage1/dietlibc/libstdio/putchar.c b/mdk-stage1/dietlibc/libstdio/putchar.c deleted file mode 100644 index 7e5285a48..000000000 --- a/mdk-stage1/dietlibc/libstdio/putchar.c +++ /dev/null @@ -1,6 +0,0 @@ -#include <stdio.h> - -#undef putchar -int putchar(int c) { - return fputc(c,stdout); -} diff --git a/mdk-stage1/dietlibc/libstdio/setvbuf.c b/mdk-stage1/dietlibc/libstdio/setvbuf.c deleted file mode 100644 index d0b1b7640..000000000 --- a/mdk-stage1/dietlibc/libstdio/setvbuf.c +++ /dev/null @@ -1,18 +0,0 @@ -#include <sys/types.h> -#include "dietstdio.h" -#include <unistd.h> -#include "dietwarning.h" - -int setvbuf(FILE *stream, char *buf, int flags , size_t size) { -#ifdef WANT_BUFFERED_STDIO - switch (flags) { - case _IONBF: stream->flags = (stream->flags & ~(BUFLINEWISE)) | NOBUF; break; - case _IOLBF: stream->flags = (stream->flags & ~(BUFLINEWISE|NOBUF)) | BUFLINEWISE; break; - case _IOFBF: stream->flags = stream->flags & ~(NOBUF | BUFLINEWISE); break; - default: return -1; - } -#endif - return 0; -} - -link_warning("setvbuf","setvbuf does not implement changing the buffer in diet libc.") diff --git a/mdk-stage1/dietlibc/libstdio/stderr.c b/mdk-stage1/dietlibc/libstdio/stderr.c deleted file mode 100644 index a82b1b727..000000000 --- a/mdk-stage1/dietlibc/libstdio/stderr.c +++ /dev/null @@ -1,13 +0,0 @@ -#include <dietstdio.h> - -#ifdef WANT_BUFFERED_STDIO -static FILE __stderr = { 2, NOBUF, 0, 0 }; - -int __fflush_stderr() { - return fflush(stderr); -} -#else -static FILE __stderr = { 2, 0 }; -#endif - -FILE *stderr=&__stderr; diff --git a/mdk-stage1/dietlibc/libstdio/stdin.c b/mdk-stage1/dietlibc/libstdio/stdin.c deleted file mode 100644 index 2db82f9ab..000000000 --- a/mdk-stage1/dietlibc/libstdio/stdin.c +++ /dev/null @@ -1,13 +0,0 @@ -#include <dietstdio.h> - -#ifdef WANT_BUFFERED_STDIO -static FILE __stdin = { 0, BUFINPUT, 0, 0 }; - -int __fflush_stdin() { - return fflush(stdin); -} -#else -static FILE __stdin = { 0, 0 }; -#endif - -FILE *stdin=&__stdin; diff --git a/mdk-stage1/dietlibc/libstdio/stdout.c b/mdk-stage1/dietlibc/libstdio/stdout.c deleted file mode 100644 index 481fb1014..000000000 --- a/mdk-stage1/dietlibc/libstdio/stdout.c +++ /dev/null @@ -1,14 +0,0 @@ -#include <dietstdio.h> - -#ifdef WANT_BUFFERED_STDIO -static FILE __stdout = { 1, BUFLINEWISE, 0, 0 }; - -int __fflush_stdout() { - return fflush(stdout); -} -#else -static FILE __stdout = { 1, 0 }; -#endif - -FILE *stdout=&__stdout; - diff --git a/mdk-stage1/dietlibc/libstdio/ungetc.c b/mdk-stage1/dietlibc/libstdio/ungetc.c deleted file mode 100644 index ae03e9381..000000000 --- a/mdk-stage1/dietlibc/libstdio/ungetc.c +++ /dev/null @@ -1,11 +0,0 @@ -#include "dietstdio.h" - -#ifdef WANT_UNGETC -int ungetc(int c, FILE *stream) { - if (stream->ungotten) - return EOF; - stream->ungotten=1; - stream->ungetbuf=(char)(unsigned char)c; - return c; -} -#endif |