pspsdk-1.0+beta2
stdio.h
Go to the documentation of this file.
1 /*
2  * PSP Software Development Kit - http://www.pspdev.org
3  * -----------------------------------------------------------------------
4  * Licensed under the BSD license, see LICENSE in PSPSDK root for details.
5  *
6  * stdio.h
7  *
8  * Copyright (c) 2002-2004 PS2DEV
9  * Copyright (c) 2005 Marcus R. Brown <mrbrown@ocgnet.org>
10  * Copyright (c) 2005 James Forshaw <tyranid@gmail.com>
11  * Copyright (c) 2005 John Kelley <ps2dev@kelley.ca>
12  *
13  * $Id: stdio.h 2335 2007-11-06 07:47:36Z warren $
14  */
15 
16 #ifndef __STDIO_H__
17 #define __STDIO_H__
18 
19 #include <pspkernel.h>
20 #include <stdarg.h>
21 
22 #ifdef __cplusplus
23 extern "C" {
24 #endif
25 
26 
27 /* Some aliases for the unix 'unistd' functions */
28 static __inline__ int open(const char *fname, int flags, ...) { return sceIoOpen(fname, flags, 0777); }
29 static __inline__ int close(int handle) { return sceIoClose(handle); }
30 static __inline__ ssize_t read(int handle, void * buffer, size_t size) { return sceIoRead(handle, buffer, size); }
31 static __inline__ ssize_t write(int handle, const void * buffer, size_t size) { return sceIoWrite(handle, buffer, size); }
32 static __inline__ off_t lseek(int handle, off_t position, int wheel) { return sceIoLseek(handle, position, wheel); }
33 static __inline__ off_t tell(int handle) { return sceIoLseek(handle, 0, 1); }
34 
35 /* Some win32 equivalents... baaah */
36 #define _open open
37 #define _close close
38 #define _read read
39 #define _write write
40 #define _lseek lseek
41 
42 #define _O_APPEND O_APPEND
43 #define _O_BINARY O_BINARY
44 #define _O_CREAT O_CREAT
45 #define _O_RDONKY O_RDONKY
46 #define _O_RDWR O_RDWR
47 #define _O_TEXT O_TEXT
48 #define _O_TRUNC O_TRUNC
49 #define _O_WRONLY O_WRONLY
50 
51 #ifndef O_BINARY
52 #define O_BINARY 0
53 #endif
54 
55 #ifndef O_TEXT
56 #define O_TEXT 0
57 #endif
58 
59 
60 #define BUFSIZ 1024
61 
62 #define _NFILE 16
63 
64 
65 #define _IOFBF 0x0000
66 #define _IOLBF 0x0100
67 #define _IONBF 0x0004
68 #define _IOEOF 0x0020
69 #define _IOERR 0x0040
70 
71 #define _IOREAD 0x0001
72 #define _IOWRT 0x0002
73 #define _IORW 0x0200
74 #define _IOMYBUF 0x0010
75 
76 
77 /* ensure EOF is defined. */
78 #ifndef EOF
79 #define EOF (-1)
80 #endif
81 
82 
83 #define FOPEN_MAX _NFILE
84 #define FILENAME_MAX 1024
85 
86 
87 #define SEEK_SET 0
88 #define SEEK_CUR 1
89 #define SEEK_END 2
90 
91 
92 /* ensure fpos_t is defined. */
93 #ifndef __FPOS_T_DEFINED
94 #define __FPOS_T_DEFINED
95 typedef long fpos_t;
96 #endif // __FPOS_T_DEFINED
97 
98 
99 /* ensure FILE is defined. */
100 #ifndef __FILE_DEFINED
101 #define __FILE_DEFINED
102 typedef struct {
103  int type;
104  int fd;
105  int cnt;
106  int flag;
109 } FILE;
110 #endif // __FILE_DEFINED
111 
112 
113 extern FILE __iob[_NFILE];
114 
115 
116 #define stdin (&__iob[0])
117 #define stdout (&__iob[1])
118 #define stderr (&__iob[2])
119 
120 
121 /* function declarations. */
122 void clearerr(FILE *);
123 int feof(FILE *);
124 int ferror(FILE *);
125 FILE *fopen(const char *, const char *);
126 FILE *fopen64(const char *, const char *);
127 FILE *fdopen(int, const char *);
128 int fclose(FILE *);
129 int fflush(FILE *);
130 int fgetc(FILE *);
131 int fgetpos(FILE *, fpos_t *);
132 int fgetpos64(FILE *, int64_t *);
133 char *fgets(char *, int, FILE *);
134 int fileno(FILE *);
135 int fputc(int, FILE *);
136 int fputs(const char *, FILE *);
137 size_t fread(void *, size_t, size_t, FILE *);
138 FILE *freopen(const char *, const char *, FILE *);
139 int fscanf(FILE *, const char *, ...);
140 int fseek(FILE *, long, int);
141 int fseeko64(FILE *, int64_t, int);
142 int fsetpos(FILE *, const fpos_t *);
143 long ftell(FILE *);
144 int64_t ftello64(FILE *);
145 size_t fwrite(const void *, size_t, size_t, FILE *);
146 int getc(FILE *);
147 int getchar(void);
148 char *gets(char *);
149 void perror(const char *);
150 int putc(int, FILE *);
151 int puts(const char *);
152 int remove(const char *);
153 int rename(const char *, const char *);
154 void rewind(FILE *);
155 int scanf(const char *, ...);
156 int setbuf(FILE *, char *);
157 int setvbuf(FILE *, char *, int, size_t);
158 int sscanf(const char *, const char *, ...);
159 FILE *tmpfile(void);
160 char *tmpnam(char *);
161 int vfscanf(FILE *, const char *, va_list);
162 int vscanf(const char *, va_list);
163 int vsscanf(const char *, const char *, va_list);
164 int vxscanf(int (*xgetc)(void **), void (*xungetc)(int, void **), void *stream, const char *, va_list);
165 int xscanf(int (*xgetc)(void **), void (*xungetc)(int, void **), void *stream, const char *, ...);
166 
167 int ungetc(int, FILE *);
168 
169 int _fcloseall(void);
170 int _fflushall(void);
171 
172 int chdir(const char *path);
173 
174 
175 /* from xprintf */
176 int vxprintf(void (*func)(char*, int, void *), void * arg, const char * format, va_list ap);
177 int vsnprintf(char *buf, size_t n, const char *fmt, va_list ap);
178 int vsprintf(char *buf, const char *fmt, va_list ap);
179 char *vmprintf(const char *zFormat, va_list ap);
180 int vfprintf(FILE *pOut, const char *zFormat, va_list ap);
181 int vprintf(const char *format, va_list ap);
182 int vasprintf(char **strp, const char *format, va_list ap);
183 
184 int xprintf(void (*func)(char*, int, void *), void * arg, const char * format, ...)
185  __attribute__((format(printf,3,4)));
186 int snprintf(char *str, size_t sz, const char *format, ...)
187  __attribute__((format(printf,3,4)));
188 int sprintf(char *buf, const char *fmt, ...)
189  __attribute__((format(printf,2,3)));
190 char *mprintf(const char *zFormat, ...)
191  __attribute__((format(printf,1,2)));
192 int fprintf(FILE *pOut, const char *zFormat, ...)
193  __attribute__((format(printf,2,3)));
194 int printf(const char *format, ...)
195  __attribute__((format(printf,1,2)));
196 int asprintf(char **strp, const char *format, ...)
197  __attribute__((format(printf,2,3)));
198 
199 int putchar(int);
200 
201 int npmPuts(const char *buf);
202 int nprintf(const char *format, ...);
203 int vnprintf(const char *format, va_list args);
204 int sio_printf(const char *format, ...);
205 
206 #ifdef __cplusplus
207 }
208 #endif
209 
210 
211 #endif // __STDIO_H__