check in work in progress on the arm port
[newos.git] / include / libc / stdio.h
blobc6a0e2df626c497732c2f56a2b0b2269657ebfaf
1 /*
2 ** Copyright 2002, Travis Geiselbrecht. All rights reserved.
3 ** Copyright 2002, Manuel J. Petit. All rights reserved.
4 ** Distributed under the terms of the NewOS License.
5 ** Modified by Justin Smith 2003/06/17. Changed FILE struct.
6 */
8 #ifndef __newos__libc_stdio__hh__
9 #define __newos__libc_stdio__hh__
11 #include <stddef.h>
12 #include <sys/types.h>
13 #include <sys/cdefs.h>
15 #include <stdarg.h>
17 #ifdef __cplusplus
18 namespace std
19 {extern "C" {
20 #endif
22 #define _STDIO_READ 0x0001
23 #define _STDIO_WRITE 0x0002
24 #define _STDIO_EOF 0x0004
25 #define _STDIO_ERROR 0x0008
26 #define _STDIO_UNGET 0x0010
28 //#ifndef __newos__libc_unistd__hh__
29 #define SEEK_SET 0
30 #define SEEK_CUR 1
31 #define SEEK_END 2
32 //#endif
34 typedef off_t fpos_t;
36 struct __FILE {
37 int fd; /* system file descriptor */
38 ptrdiff_t rpos; /* The first unread buffer position */
39 ptrdiff_t buf_pos; /* first unwritten buffer position */
40 unsigned char* buf; /* buffer */
41 ptrdiff_t buf_size; /* buffer size */
42 unsigned char unget; /* for ungetc */
43 int flags; /* for feof and ferror */
44 struct __FILE* next; /* for fflush */
45 sem_id sid; /* semaphore */
47 typedef struct __FILE FILE;
49 extern FILE *stdin;
50 extern FILE *stdout;
51 extern FILE *stderr;
53 #define EOF -1
55 int printf(char const *format, ...) __PRINTFLIKE(1,2);
56 int fprintf(FILE *stream, char const *format, ...) __PRINTFLIKE(2,3);
57 int sprintf(char *str, char const *format, ...) __PRINTFLIKE(2,3);
58 //int snprintf(char *str, size_t size, char const *format, ...) __PRINTFLIKE(3,4);
59 //int asprintf(char **ret, char const *format, ...) __PRINTFLIKE(2,3);
60 int vprintf(char const *format, va_list ap);
61 int vfprintf(FILE *stream, char const *format, va_list ap);
62 int vsprintf(char *str, char const *format, va_list ap);
63 //int vsnprintf(char *str, size_t size, char const *format, va_list ap);
64 //int vasprintf(char **ret, char const *format, va_list ap);
66 size_t fwrite(const void *ptr, size_t size, size_t nmemb, FILE *stream);
67 int putc(int ch, FILE *stream);
68 int fputc(int ch, FILE *stream);
71 FILE *fopen(char const *, char const *);
72 int fflush(FILE *);
73 int fclose(FILE *);
75 long int ftell(FILE *stream);
76 int fgetpos(FILE *stream, fpos_t *pos);
77 int feof(FILE *);
78 int fseek(FILE *stream, long int offset, int whence);
80 int ferror(FILE *);
81 void clearerr(FILE *);
83 int fputs(const char *str, FILE *stream);
85 FILE *freopen(const char *filename, const char *mode, FILE *stream);
86 char* fgets(char *, int, FILE *);
87 size_t fread(void *ptr, size_t size, size_t nmemb, FILE *stream);
88 int getchar(void);
89 int getc(FILE*);
90 int fgetc(FILE *);
91 int ungetc(int c, FILE *stream);
93 int scanf(char const *format, ...);
94 int fscanf(FILE *stream, char const *format, ...);
95 int sscanf(char const *str, char const *format, ...);
96 //int vscanf(char const *format, va_list ap);
97 int vsscanf(char const *str, char const *format, va_list ap);
98 int vfscanf(FILE *stream, char const *format, va_list ap);
100 int _v_printf(int (*_write)(void*, const void *, ssize_t ), void* arg, const char *fmt, va_list args);
102 #ifdef __cplusplus
104 #endif
106 // getchar goes off in it's own little non-standard world
107 // This function will be removed soon
108 # ifdef __cplusplus
109 extern "C"
110 # endif
111 int getchar(void);
115 #endif
117 #if defined(__cplusplus) && !defined(_NEWOS_NO_LIBC_COMPAT)
118 using ::std::FILE;
119 using ::std::fpos_t;
121 using ::std::stdin;
122 using ::std::stdout;
123 using ::std::stderr;
125 using ::std::clearerr;
126 using ::std::fclose;
127 using ::std::feof;
128 using ::std::ferror;
129 using ::std::fflush;
130 using ::std::fgetc;
131 using ::std::fgetpos;
132 using ::std::fgets;
133 using ::std::fopen;
134 using ::std::fprintf;
135 using ::std::fputc;
136 using ::std::fputs;
137 using ::std::fread;
138 using ::std::freopen;
139 using ::std::fscanf;
140 //using ::std::fseek;
141 //using ::std::fsetpos;
142 using ::std::ftell;
143 using ::std::fwrite;
144 using ::std::getc;
145 using ::std::getchar;
146 //using ::std::gets;
147 //using ::std::perror;
148 using ::std::printf;
149 using ::std::putc;
150 //using ::std::remove;
151 //using ::std::rename;
152 //using ::std::rewind;
153 using ::std::scanf;
154 //using ::std::setbuf;
155 //using ::std::setvbuf;
156 using ::std::sprintf;
157 using ::std::sscanf;
158 //using ::std::tmpfile;
159 //using ::std::tmpnam;
160 using ::std::ungetc;
161 using ::std::vfprintf;
162 using ::std::vprintf;
163 using ::std::vsprintf;
164 #endif