Annotation of /trunk/mkinitrd-magellan/klibc/usr/include/stdio.h
Parent Directory | Revision Log
Revision 1297 -
(hide annotations)
(download)
Fri May 27 15:12:11 2011 UTC (13 years ago) by niro
File MIME type: text/plain
File size: 3420 byte(s)
Fri May 27 15:12:11 2011 UTC (13 years ago) by niro
File MIME type: text/plain
File size: 3420 byte(s)
-updated to klibc-1.5.22 with mntproc definitions patch included
1 | niro | 532 | /* |
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 | #ifndef EOF | ||
19 | # define EOF (-1) | ||
20 | #endif | ||
21 | |||
22 | #ifndef BUFSIZ | ||
23 | # define BUFSIZ 4096 | ||
24 | #endif | ||
25 | |||
26 | #define SEEK_SET 0 | ||
27 | #define SEEK_CUR 1 | ||
28 | #define SEEK_END 2 | ||
29 | |||
30 | /* | ||
31 | * Convert between a FILE * and a file descriptor. We don't actually | ||
32 | * have any in-memory data, so we just abuse the pointer itself to | ||
33 | * hold the data. Note, however, that for file descriptors, -1 is | ||
34 | * error and 0 is a valid value; for FILE *, NULL (0) is error and | ||
35 | * non-NULL are valid. | ||
36 | */ | ||
37 | static __inline__ int fileno(FILE * __f) | ||
38 | { | ||
39 | /* This should really be intptr_t, but size_t should be the same size */ | ||
40 | return (int)(size_t) __f - 1; | ||
41 | } | ||
42 | |||
43 | /* This is a macro so it can be used as initializer */ | ||
44 | #define __create_file(__fd) ((FILE *)(size_t)((__fd) + 1)) | ||
45 | |||
46 | #define stdin __create_file(0) | ||
47 | #define stdout __create_file(1) | ||
48 | #define stderr __create_file(2) | ||
49 | |||
50 | __extern FILE *fopen(const char *, const char *); | ||
51 | |||
52 | niro | 1297 | __static_inline FILE *fdopen(int __fd, const char *__m) |
53 | niro | 532 | { |
54 | (void)__m; | ||
55 | return __create_file(__fd); | ||
56 | } | ||
57 | niro | 1297 | __static_inline int fclose(FILE * __f) |
58 | niro | 532 | { |
59 | extern int close(int); | ||
60 | return close(fileno(__f)); | ||
61 | } | ||
62 | niro | 1297 | __static_inline int fseek(FILE * __f, off_t __o, int __w) |
63 | niro | 532 | { |
64 | extern off_t lseek(int, off_t, int); | ||
65 | return (lseek(fileno(__f), __o, __w) == (off_t) - 1) ? -1 : 0; | ||
66 | } | ||
67 | niro | 1297 | __static_inline off_t ftell(FILE * __f) |
68 | niro | 532 | { |
69 | extern off_t lseek(int, off_t, int); | ||
70 | return lseek(fileno(__f), 0, SEEK_CUR); | ||
71 | } | ||
72 | |||
73 | __extern int fputs(const char *, FILE *); | ||
74 | __extern int puts(const char *); | ||
75 | __extern int fputc(int, FILE *); | ||
76 | #define putc(c,f) fputc((c),(f)) | ||
77 | #define putchar(c) fputc((c),stdout) | ||
78 | |||
79 | __extern int fgetc(FILE *); | ||
80 | __extern char *fgets(char *, int, FILE *); | ||
81 | #define getc(f) fgetc(f) | ||
82 | #define getchar() fgetc(stdin) | ||
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 | niro | 1297 | __extern_inline size_t |
89 | fread(void *__p, size_t __s, size_t __n, FILE * __f) | ||
90 | niro | 532 | { |
91 | return _fread(__p, __s * __n, __f) / __s; | ||
92 | } | ||
93 | |||
94 | niro | 1297 | __extern_inline size_t |
95 | niro | 532 | fwrite(const 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 | __extern int asprintf(char **, const char *, ...); | ||
110 | __extern int vasprintf(char **, const char *, va_list); | ||
111 | |||
112 | /* No buffering, so no flushing needed */ | ||
113 | niro | 1297 | __static_inline int fflush(FILE * __f) |
114 | niro | 532 | { |
115 | (void)__f; | ||
116 | return 0; | ||
117 | } | ||
118 | |||
119 | niro | 1122 | /* stream errors are not kept track of by klibc implementation */ |
120 | niro | 1297 | __static_inline int ferror(FILE * __f) |
121 | niro | 1122 | { |
122 | (void)__f; | ||
123 | return 0; | ||
124 | } | ||
125 | |||
126 | niro | 532 | __extern int sscanf(const char *, const char *, ...); |
127 | __extern int vsscanf(const char *, const char *, va_list); | ||
128 | |||
129 | __extern void perror(const char *); | ||
130 | |||
131 | __extern int rename(const char *, const char *); | ||
132 | __extern int renameat(int, const char *, int, const char *); | ||
133 | |||
134 | __extern int remove(const char *); | ||
135 | |||
136 | #endif /* _STDIO_H */ |