8 #include <klibc/extern.h>
13 /* This structure doesn't really exist, but it gives us something
14 to define FILE * with */
16 typedef struct _IO_file FILE;
18 #define stdin ((FILE *)0)
19 #define stdout ((FILE *)1)
20 #define stderr ((FILE *)2)
34 static __inline__ int fileno(FILE *__f)
36 /* This should really be intptr_t, but size_t should be the same size */
37 return (int)(size_t)__f;
40 static __inline__ FILE * __create_file(int __fd)
42 return (FILE *)(size_t)__fd;
45 __extern FILE *fopen(const char *, const char *);
47 static __inline__ FILE *fdopen(int __fd, const char *__m)
49 (void)__m; return __create_file(__fd);
51 static __inline__ int fclose(FILE *__f)
53 extern int close(int);
54 return close(fileno(__f));
56 static __inline__ int fseek(FILE *__f, off_t __o, int __w)
58 extern off_t lseek(int, off_t, int);
59 return (lseek(fileno(__f), __o, __w) == (off_t)-1) ? -1 : 0;
61 static __inline__ off_t ftell(FILE *__f)
63 extern off_t lseek(int, off_t, int);
64 return lseek(fileno(__f), 0, SEEK_CUR);
67 __extern int fputs(const char *, FILE *);
68 __extern int puts(const char *);
69 __extern int fputc(int, FILE *);
70 #define putc(c,f) fputc((c),(f))
71 #define putchar(c) fputc((c),stdout)
73 __extern int fgetc(FILE *);
74 __extern char * fgets(char *, int, FILE *);
75 #define getc(f) fgetc(f)
77 __extern size_t _fread(void *, size_t, FILE *);
78 __extern size_t _fwrite(const void *, size_t, FILE *);
80 #ifndef __NO_FREAD_FWRITE_INLINES
81 static __inline__ size_t
82 fread(void *__p, size_t __s, size_t __n, FILE *__f)
84 return _fread(__p, __s*__n, __f)/__s;
86 static __inline__ size_t
87 fwrite(void *__p, size_t __s, size_t __n, FILE *__f)
89 return _fwrite(__p, __s*__n, __f)/__s;
93 __extern int printf(const char *, ...);
94 __extern int vprintf(const char *, va_list);
95 __extern int fprintf(FILE *, const char *, ...);
96 __extern int vfprintf(FILE *, const char *, va_list);
97 __extern int sprintf(char *, const char *, ...);
98 __extern int vsprintf(char *, const char *, va_list);
99 __extern int snprintf(char *, size_t n, const char *, ...);
100 __extern int vsnprintf(char *, size_t n, const char *, va_list);
102 __extern int sscanf(const char *, const char *, ...);
103 __extern int vsscanf(const char *, const char *, va_list);
105 __extern void perror(const char *);
107 __extern int rename(const char *, const char *);
109 #endif /* _STDIO_H */