diff --git a/src/include/stdio.h b/src/include/stdio.h index 3ea8373ffa65abf507806672f461e0b814d17c73..6eade0e19e90428ea8124495726a99c63e1abd44 100644 --- a/src/include/stdio.h +++ b/src/include/stdio.h @@ -1,7 +1,12 @@ +/* + * Xlibc implements for stdio + */ + #ifndef _STDIO_H #define _STDIO_H #include +#include #include // NX_Printf @@ -11,6 +16,166 @@ extern "C" { #define printf(...) NX_Printf(__VA_ARGS__) +// Predefined +typedef unsigned long long __STDIO_U64_; +typedef unsigned long __STDIO_U32_; + +#ifdef __SYS_64__ + typedef __STDIO_U64_ __FILE_INT_T; +#else + typedef __STDIO_U32_ __FILE_INT_T; +#endif + +// Standard types + +#ifndef __TYPE_SIZE_DEFINED + #ifdef __SYS_64__ + typedef __STDIO_U64_ size_t; + #define _MAX_SIZE (0xffffffffffffffffull) + #else + typedef __STDIO_U32_ size_t; + #define _MAX_SIZE (0xffffffff) + #endif + #define __TYPE_SIZE_DEFINED +#endif + +#ifndef _FILE_DEFINED + // FILE stream type + typedef __FILE_INT_T FILE; + #define _FILE_DEFINED +#endif + +#ifdef __SYS_64__ + // fpos_t + typedef __STDIO_U64_ fpos_t; +#else + typedef __STDIO_U32_ fpos_t; +#endif + + +// End of file +#define EOF (-1) // End of file + + +// FILE seek modes +#define SEEK_SET 0 // Seek file stream from its start +#define SEEK_CUR 1 // Seek file stream from current location +#define SEEK_END 2 // Seek file stream from its end + + +// Standard FILE stream number +#define STDIN_FILENO 0 // Standard input stream number +#define STDOUT_FILENO 1 // Standard output stream number +#define STDERR_FILENO 2 // Standard error output stream number + + +// The size of the buffer used by the `setbuf` function +#ifdef __BUFSIZ__ +#define BUFSIZ __BUFSIZ__ +#else +#define BUFSIZ 1024 +#endif + + +// The maximum number of files a process can open together +#ifdef __FOPEN_MAX__ +#define FOPEN_MAX __FOPEN_MAX__ +#else +#define FOPEN_MAX 20 +#endif + + +// The maximum length of file path string +#ifdef __FILENAME_MAX__ +#define FILENAME_MAX __FILENAME_MAX__ +#else +#define FILENAME_MAX 1024 +#endif + + +// The maximum number of the names that `tmpnam` function can generate +#define TMP_MAX 32767 + + +// The maximum length of filename generated by `tmpnam` +#ifdef __L_tmpnam__ +#define L_tmpnam __L_tmpnam__ +#else +#define L_tmpnam FILENAME_MAX +#endif + + +// NULL pointer define +#ifndef NULL + #ifdef __cplusplus + #define NULL 0 + #else + #define NULL ((void *)0) + #endif +#endif + + +// `setvbuf` options +#define _IOFBF 0 // Let `setvbuf` function set fully buffered +#define _IOLBF 1 // Let `setvbuf` function set line buffered +#define _IONBF 2 // Let `setvbuf` function set unbuffered + + +// `stdin`, `stdout` and `stderr` +extern const __FILE_INT_T __FILE_STDIN_; +extern const __FILE_INT_T __FILE_STDOUT_; +extern const __FILE_INT_T __FILE_STDERR_; + + +extern const FILE *stdin; +extern const FILE *stdout; +extern const FILE *stderr; + + +extern int fclose (FILE *stream); +extern void clearerr (FILE *stream); +extern int feof (FILE *stream); +extern int ferror (FILE *stream); +extern int fflush (FILE *stream); +extern int fgetpos (FILE *stream, fpos_t *pos); +extern FILE *fopen (const char *filename, const char *mode); +extern size_t fread (void *ptr, size_t size, size_t nmemb, FILE *stream); +extern FILE *freopen (const char *filename, const char *mode, FILE *stream); +extern int fseek (FILE *stream, long int offset, int whence); +extern int fsetpos (FILE *stream, const fpos_t *pos); +extern long int ftell (FILE *stream); +extern size_t fwrite (const void *ptr, size_t size, size_t nmemb, FILE *stream); +extern int remove (const char *filename); +extern int rename (const char *old_filename, const char *new_filename); +extern void rewind (FILE *stream); +extern void setbuf (FILE *stream, char *buffer); +extern int setvbuf (FILE *stream, char *buffer, int mode, size_t size); +extern FILE *tmpfile (void); +extern char *tmpnam (char *str); +extern int fprintf (FILE *stream, const char *format, ...); +// extern int printf (const char *format, ...); +extern int sprintf (char *str, const char *format, ...); +extern int vfprintf (FILE *stream, const char *format, va_list arg); +extern int vprintf (const char *format, va_list arg); +extern int vsprintf (char *str, const char *format, va_list arg); +extern int fscanf (FILE *stream, const char *format, ...); +extern int scanf (const char *format, ...); +extern int sscanf (const char *str, const char *format, ...); +extern int fgetc (FILE *stream); +extern char *fgets (char *str, int n, FILE *stream); +extern int fputc (int ch, FILE *stream); +extern int fputs (const char *str, FILE *stream); +extern int getc (FILE *stream); +extern int getchar (void); +extern char *gets (char *str); +extern int putc (int ch, FILE *stream); +extern int putchar (int ch); +extern int puts (const char *str); +extern int ungetc (int ch, FILE *stream); +extern void perror (const char *str); +extern int snprintf (char *str, size_t size, const char *format, ...); + + #ifdef __cplusplus } #endif