chiark / gitweb /
[PATCH] update klibc to version 0.98
[elogind.git] / klibc / klibc / include / stdio.h
1 /*
2  * stdio.h
3  */
4
5 #ifndef _STDIO_H
6 #define _STDIO_H
7
8 #include <klibc/extern.h>
9 #include <stdarg.h>
10 #include <stddef.h>
11 #include <unistd.h>
12
13 /* This structure doesn't really exist, but it gives us something
14    to define FILE * with */
15 struct _IO_file;
16 typedef struct _IO_file FILE;
17
18 #define stdin  ((FILE *)0)
19 #define stdout ((FILE *)1)
20 #define stderr ((FILE *)2)
21
22 #ifndef EOF
23 # define EOF (-1)
24 #endif
25
26 #ifndef BUFSIZ
27 # define BUFSIZ 4096
28 #endif
29
30 #define SEEK_SET 0
31 #define SEEK_CUR 1
32 #define SEEK_END 2
33
34 /*
35  * Convert between a FILE * and a file descriptor.  We don't actually
36  * have any in-memory data, so we just abuse the pointer itself to
37  * hold the data.  Note, however, that for file descriptors, -1 is
38  * error and 0 is a valid value; for FILE *, NULL (0) is error and
39  * non-NULL are valid.
40  */
41 static __inline__ int fileno(FILE *__f)
42 {
43   /* This should really be intptr_t, but size_t should be the same size */
44   return (int)(size_t)__f - 1;
45 }
46
47 static __inline__ FILE * __create_file(int __fd)
48 {
49   return (FILE *)(size_t)(__fd + 1);
50 }
51
52 __extern FILE *fopen(const char *, const char *);
53
54 static __inline__ FILE *fdopen(int __fd, const char *__m)
55 {
56   (void)__m; return __create_file(__fd);
57 }
58 static __inline__ int fclose(FILE *__f)
59 {
60   extern int close(int);
61   return close(fileno(__f));
62 }
63 static __inline__ int fseek(FILE *__f, off_t __o, int __w)
64 {
65   extern off_t lseek(int, off_t, int);
66   return (lseek(fileno(__f), __o, __w) == (off_t)-1) ? -1 : 0;
67 }
68 static __inline__ off_t ftell(FILE *__f)
69 {
70   extern off_t lseek(int, off_t, int);
71   return lseek(fileno(__f), 0, SEEK_CUR);
72 }
73
74 __extern int fputs(const char *, FILE *);
75 __extern int puts(const char *);
76 __extern int fputc(int, FILE *);
77 #define putc(c,f)  fputc((c),(f))
78 #define putchar(c) fputc((c),stdout)
79
80 __extern int    fgetc(FILE *);
81 __extern char * fgets(char *, int, FILE *);
82 #define getc(f) fgetc(f)
83
84 __extern size_t _fread(void *, size_t, FILE *);
85 __extern size_t _fwrite(const void *, size_t, FILE *);
86
87 #ifndef __NO_FREAD_FWRITE_INLINES
88 extern __inline__ size_t
89 fread(void *__p, size_t __s, size_t __n, FILE *__f)
90 {
91   return _fread(__p, __s*__n, __f)/__s;
92 }
93
94 extern __inline__ size_t
95 fwrite(void *__p, size_t __s, size_t __n, FILE *__f)
96 {
97   return _fwrite(__p, __s*__n, __f)/__s;
98 }
99 #endif
100
101 __extern int printf(const char *, ...);
102 __extern int vprintf(const char *, va_list);
103 __extern int fprintf(FILE *, const char *, ...);
104 __extern int vfprintf(FILE *, const char *, va_list);
105 __extern int sprintf(char *, const char *, ...);
106 __extern int vsprintf(char *, const char *, va_list);
107 __extern int snprintf(char *, size_t n, const char *, ...);
108 __extern int vsnprintf(char *, size_t n, const char *, va_list);
109
110 __extern int sscanf(const char *, const char *, ...);
111 __extern int vsscanf(const char *, const char *, va_list);
112
113 __extern void perror(const char *);
114
115 __extern int rename(const char *, const char *);
116
117 #endif /* _STDIO_H */