1 /* 2 * Copyright 2004-2009, Haiku Inc. All Rights Reserved. 3 * Distributed under the terms of the MIT License. 4 */ 5 #ifndef _STDIO_H_ 6 #define _STDIO_H_ 7 8 9 #include <sys/types.h> 10 #include <null.h> 11 #include <stdarg.h> 12 13 14 /* Dodge gcc 2.95.3's fixincludes hack stdio_va_list by including this string: 15 * __gnuc_va_list */ 16 17 18 #define BUFSIZ 8192 19 #define _IOFBF 0 /* fully buffered */ 20 #define _IOLBF 1 /* line buffered */ 21 #define _IONBF 2 /* not buffered */ 22 23 /* 24 * FOPEN_MAX is a minimum maximum, and should be the number of descriptors 25 * that the kernel can provide without allocation of a resource that can 26 * fail without the process sleeping. Do not use this for anything 27 */ 28 #define FOPEN_MAX 128 29 #define STREAM_MAX FOPEN_MAX 30 #define FILENAME_MAX 256 31 #define TMP_MAX 32768 32 33 #define L_ctermid 32 34 #define L_cuserid 32 35 #define L_tmpnam 512 36 37 #define P_tmpdir "/tmp/" 38 39 #ifdef EOF 40 # undef EOF 41 #endif 42 #define EOF -1 43 44 #ifndef SEEK_SET 45 # define SEEK_SET 0 46 #endif 47 #ifndef SEEK_CUR 48 # define SEEK_CUR 1 49 #endif 50 #ifndef SEEK_END 51 # define SEEK_END 2 52 #endif 53 54 55 typedef off_t fpos_t; 56 57 #include <stdio_pre.h> 58 59 extern FILE *stdin; 60 extern FILE *stdout; 61 extern FILE *stderr; 62 63 64 #ifdef __cplusplus 65 extern "C" { 66 #endif 67 68 /* file operations */ 69 extern FILE *fopen(const char *name, const char *mode); 70 extern FILE *freopen(const char *name, const char *mode, FILE *stream); 71 extern FILE *fdopen(int fd, const char *mode); 72 extern int fclose(FILE *stream); 73 74 extern int fileno(FILE *stream); 75 extern int fileno_unlocked(FILE *stream); 76 77 extern int ferror(FILE *stream); 78 extern int ferror_unlocked(FILE *stream); 79 extern void clearerr(FILE *stream); 80 extern void clearerr_unlocked(FILE *stream); 81 82 extern int feof(FILE *stream); 83 extern int feof_unlocked(FILE *stream); 84 85 extern void flockfile(FILE *stream); 86 extern void funlockfile(FILE *stream); 87 extern int ftrylockfile(FILE *stream); 88 89 extern int remove(const char *name); 90 extern int rename(const char *from, const char *to); 91 extern int renameat(int fromFD, const char *from, int toFD, const char *to); 92 93 /* pipes */ 94 extern FILE *popen(const char *command, const char *mode); 95 extern int pclose(FILE *stream); 96 extern void perror(const char *errorPrefix); 97 98 /* file I/O */ 99 extern int fflush(FILE *stream); 100 extern int fflush_unlocked(FILE *stream); 101 extern int fpurge(FILE *stream); 102 103 extern int fgetpos(FILE *stream, fpos_t *position); 104 extern int fsetpos(FILE *stream, const fpos_t *position); 105 extern int fseek(FILE *stream, long offset, int seekType); 106 extern int fseeko(FILE *stream, off_t offset, int seekType); 107 extern int _fseek(FILE *stream, fpos_t offset, int seekType); 108 extern long ftell(FILE *stream); 109 extern off_t ftello(FILE *stream); 110 extern fpos_t _ftell(FILE *stream); 111 112 extern void rewind(FILE *stream); 113 114 extern void setbuf (FILE *file, char *buff); 115 extern int setvbuf(FILE *file, char *buff, int mode, size_t size); 116 extern int setbuffer(FILE *stream, char *buf, size_t size); 117 extern int setlinebuf(FILE *stream); 118 119 extern size_t fwrite(const void *buffer, size_t size, size_t numItems, FILE *stream); 120 extern size_t fread(void *buffer, size_t size, size_t numItems, FILE *stream); 121 122 extern int putc(int c, FILE *stream); 123 extern int putchar(int c); 124 extern int putc_unlocked(int c, FILE *stream); 125 extern int putchar_unlocked(int c); 126 extern int fputc(int c, FILE *stream); 127 extern int fputc_unlocked(int c, FILE *stream); 128 extern int puts(const char *string); 129 extern int fputs(const char *string, FILE *stream); 130 131 extern int getc(FILE *stream); 132 extern int getc_unlocked(FILE *stream); 133 extern int ungetc(int c, FILE *stream); 134 extern int getchar(void); 135 extern int getchar_unlocked(void); 136 extern int fgetc(FILE *stream); 137 extern char *gets(char *buffer); 138 extern char *fgets(char *string, int stringLength, FILE *stream); 139 140 /* formatted I/O */ 141 extern int printf(char const *format, ...) __PRINTFLIKE(1,2); 142 extern int fprintf(FILE *stream, char const *format, ...) __PRINTFLIKE(2,3); 143 extern int sprintf(char *string, char const *format, ...) __PRINTFLIKE(2,3); 144 extern int snprintf(char *string, size_t size, char const *format, ...) __PRINTFLIKE(3,4); 145 extern int asprintf(char **ret, char const *format, ...) __PRINTFLIKE(2,3); 146 extern int vprintf(char const *format, va_list ap); 147 extern int vfprintf(FILE *stream, char const *format, va_list ap); 148 extern int vsprintf(char *string, char const *format, va_list ap); 149 extern int vsnprintf(char *string, size_t size, char const *format, va_list ap); 150 extern int vasprintf(char **ret, char const *format, va_list ap); 151 152 extern int scanf(char const *format, ...); 153 extern int fscanf(FILE *stream, char const *format, ...); 154 extern int sscanf(char const *str, char const *format, ...); 155 extern int vscanf(char const *format, va_list ap); 156 extern int vsscanf(char const *str, char const *format, va_list ap); 157 extern int vfscanf(FILE *stream, char const *format, va_list ap); 158 159 /* misc */ 160 extern char *ctermid(char *controllingTerminal); 161 extern char *cuserid(char *s); 162 163 /* temporary files */ 164 extern char *tempnam(char *path, char *prefix); 165 extern FILE *tmpfile(void); 166 extern char *tmpnam(char *nameBuffer); 167 extern char *tmpnam_r(char *nameBuffer); 168 169 #include <stdio_post.h> 170 171 #ifdef __cplusplus 172 } 173 #endif 174 175 #endif /* _STDIO_H_ */ 176