2 meinOS - A unix-like x86 microkernel operating system
3 Copyright (C) 2008 Janosch Gräf <janosch.graef@gmx.net>
5 This program is free software: you can redistribute it and/or modify
6 it under the terms of the GNU Lesser General Public License as published by
7 the Free Software Foundation, either version 3 of the License, or
8 (at your option) any later version.
10 This program is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 GNU Lesser General Public License for more details.
15 You should have received a copy of the GNU Lesser General Public License
16 along with this program. If not, see <http://www.gnu.org/licenses/>.
22 #include <sys/types.h>
39 #define NULL ((void*)0)
42 #define L_tmpnam PATH_MAX
43 #define P_tmpdir "/tmp"
61 void clearerr(FILE *file
);
62 int feof(FILE *stream
);
63 int ferror(FILE *stream
);
64 int fclose(FILE *stream
);
65 FILE *fdopen(int fh
,const char *oflag
);
66 int fileno(FILE *stream
);
67 FILE *fopen(const char *name
,const char *oflag
);
68 int fflush(FILE *stream
);
69 int fgetpos(FILE *stream
,fpos_t *pos
);
70 int fsetpos(FILE *stream
,fpos_t *pos
);
71 FILE *freopen(const char *filename
,const char *oflag
,FILE *stream
);
73 int rename(const char *old
, const char *new);
75 int puts(const char *s
);
76 size_t _fwrite(const void *ptr
,size_t size
,FILE *stream
);
78 char *fgets(char *s
,int n
,FILE *stream
);
79 size_t _fread(void *ptr
,size_t size
,FILE *stream
);
80 int ungetc(int c
,FILE *stream
);
82 int printf(const char * format
, ...);
83 int sprintf(char * buffer
, const char * format
, ...);
84 int snprintf(char * buffer
, size_t size
, const char * format
, ...);
85 int fprintf(FILE * fp
, const char * format
, ...);
86 int asprintf(char ** buffer
, const char * format
, ...);
88 int vprintf(const char * format
, va_list);
89 int vsprintf(char * buffer
, const char * format
, va_list);
90 int vsnprintf(char * buffer
, size_t size
, const char * format
, va_list);
91 int vfprintf(FILE * fp
, const char * format
, va_list);
92 int vasprintf(char ** buffer
, const char * format
, va_list);
94 int sscanf(const char *str
,const char *format
,...);
96 int vsscanf(const char *buffer
,const char *format
,va_list ap
);
99 static __inline__
int remove(const char *path
) {
104 * Puts a char on stream
106 * @param stream Stream
107 * @return Char written
109 static __inline__
int fputc(int c
,FILE *stream
) {
111 return _fwrite(&chr
,1,stream
)==1?c
:EOF
;
115 * Puts a string on a stream
116 * @param s String to put on stream
117 * @param stream Stream
118 * @return How many bytes written
120 static __inline__
int fputs(const char *s
,FILE *stream
) {
121 return _fwrite(s
,strlen(s
),stream
);
126 * @param ptr Buffer to get data from
127 * @param size Size of each element
128 * @param nitems How many items to write
129 * @param stream Stream to write to
130 * @return How many elements written
132 static __inline__
size_t fwrite(const void *ptr
,size_t size
,size_t nelem
,FILE *stream
) {
133 return _fwrite(ptr
,size
*nelem
,stream
);
138 * @param stream Stream
139 * @param offset Offset
140 * @param whence Whence
143 static __inline__
int fseeko(FILE *stream
,off_t offset
,int whence
) {
145 return lseek(stream
->fh
,offset
,whence
)==offset
?0:-1;
150 * @param stream Stream
151 * @param offset Offset
152 * @param whence Whence
155 static __inline__
int fseek(FILE *stream
,long offset
,int whence
) {
156 return fseeko(stream
,(off_t
)offset
,whence
);
160 * Returns file offset in stream
161 * @param stream Stream
164 static __inline__ off_t
ftello(FILE *stream
) {
165 return lseek(stream
->fh
,0,SEEK_CUR
);
169 * Returns file offset in stream
170 * @param stream Stream
173 static __inline__
long ftell(FILE *stream
) {
175 return (long)ftello(stream
);
179 * Resets the file position idicator
180 * @param stream Stream
182 static __inline__
void rewind(FILE *stream
) {
183 fseek(stream
,0,SEEK_SET
);
187 * Puts a character on stream
189 * @param stream Stream
192 static __inline__
int putc(int c
,FILE *stream
) {
193 return fputc(c
,stream
);
197 * Puts a character on stdout
199 * @param stream Stream
202 static __inline__
int putchar(int c
) {
203 return fputc(c
,stdout
);
207 * Gets char from stream
208 * @param stream Stream
211 static __inline__
int fgetc(FILE *stream
) {
214 if (c
==EOF
) stream
->eof
= 1;
219 * Gets string from stdin
220 * @param s Buffer for string
223 static __inline__
char* gets(char *s
) {
224 return fgets(s
,BUFSIZ
,stdin
);
228 * Gets a character from stream
229 * @param stream Stream
232 static __inline__
int getc(FILE *stream
) {
233 return fgetc(stream
);
237 * Gets a character from stdin
240 static __inline__
int getchar(void) {
246 * @param ptr Buffer to store data
247 * @param size Size of each element
248 * @param nitems How many items to read
249 * @param stream Stream to read from
250 * @return How many elements read
252 static __inline__
size_t fread(void *ptr
,size_t size
,size_t nitems
,FILE *stream
) {
253 return _fread(ptr
,size
*nitems
,stream
);
257 * Writes error message to stderr
258 * @param str Additional error text (can be NULL)
260 static __inline__
void perror(const char *str
) {
261 fprintf(stderr
,"%s; %s\n",strerror(errno
),str
!=NULL
?str
:"");