stdio.h

Go to the documentation of this file.
00001 /*
00002  * Copyright (c) 2005 Martin Decky
00003  * All rights reserved.
00004  *
00005  * Redistribution and use in source and binary forms, with or without
00006  * modification, are permitted provided that the following conditions
00007  * are met:
00008  *
00009  * - Redistributions of source code must retain the above copyright
00010  *   notice, this list of conditions and the following disclaimer.
00011  * - Redistributions in binary form must reproduce the above copyright
00012  *   notice, this list of conditions and the following disclaimer in the
00013  *   documentation and/or other materials provided with the distribution.
00014  * - The name of the author may not be used to endorse or promote products
00015  *   derived from this software without specific prior written permission.
00016  *
00017  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
00018  * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
00019  * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
00020  * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
00021  * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
00022  * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
00023  * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
00024  * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
00025  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
00026  * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
00027  */
00028 
00035 #ifndef LIBC_STDIO_H_
00036 #define LIBC_STDIO_H_
00037 
00038 #include <sys/types.h>
00039 #include <stdarg.h>
00040 #include <str.h>
00041 #include <adt/list.h>
00042 
00043 #ifndef NVERIFY_PRINTF
00044 
00045 #define PRINTF_ATTRIBUTE(start, end) \
00046         __attribute__((format(gnu_printf, start, end)))
00047 
00048 #else /* NVERIFY_PRINTF */
00049 
00050 #define PRINTF_ATTRIBUTE(start, end)
00051 
00052 #endif /* NVERIFY_PRINTF */
00053 
00054 #define EOF  (-1)
00055 
00057 #define BUFSIZ  4096
00058 
00059 #define DEBUG(fmt, ...) \
00060         { \
00061                 char _buf[256]; \
00062                 int _n = snprintf(_buf, sizeof(_buf), fmt, ##__VA_ARGS__); \
00063                 if (_n > 0) \
00064                         (void) __SYSCALL3(SYS_KLOG, 1, (sysarg_t) _buf, str_size(_buf)); \
00065         }
00066 
00067 #ifndef SEEK_SET
00068         #define SEEK_SET  0
00069 #endif
00070 
00071 #ifndef SEEK_CUR
00072         #define SEEK_CUR  1
00073 #endif
00074 
00075 #ifndef SEEK_END
00076         #define SEEK_END  2
00077 #endif
00078 
00079 enum _buffer_type {
00081         _IONBF,
00083         _IOLBF,
00085         _IOFBF
00086 };
00087 
00088 enum _buffer_state {
00090         _bs_empty,
00091 
00093         _bs_write,
00094 
00096         _bs_read
00097 };
00098 
00099 typedef struct {
00101         link_t link;
00102         
00104         int fd;
00105         
00107         int error;
00108         
00110         int eof;
00111         
00113         int klog;
00114         
00116         int phone;
00117 
00122         int need_sync;
00123 
00125         enum _buffer_type btype;
00126 
00128         uint8_t *buf;
00129 
00131         size_t buf_size;
00132 
00134         enum _buffer_state buf_state;
00135 
00137         uint8_t *buf_head;
00138 
00140         uint8_t *buf_tail;
00141 } FILE;
00142 
00143 extern FILE *stdin;
00144 extern FILE *stdout;
00145 extern FILE *stderr;
00146 
00147 /* Character and string input functions */
00148 extern int fgetc(FILE *);
00149 extern char *fgets(char *, int, FILE *);
00150 
00151 extern int getchar(void);
00152 extern char *gets(char *, size_t);
00153 
00154 /* Character and string output functions */
00155 extern int fputc(wchar_t, FILE *);
00156 extern int fputs(const char *, FILE *);
00157 
00158 extern int putchar(wchar_t);
00159 extern int puts(const char *);
00160 
00161 /* Formatted string output functions */
00162 extern int fprintf(FILE *, const char*, ...)
00163     PRINTF_ATTRIBUTE(2, 3);
00164 extern int vfprintf(FILE *, const char *, va_list);
00165 
00166 extern int printf(const char *, ...)
00167     PRINTF_ATTRIBUTE(1, 2);
00168 extern int vprintf(const char *, va_list);
00169 
00170 extern int snprintf(char *, size_t , const char *, ...)
00171     PRINTF_ATTRIBUTE(3, 4);
00172 extern int asprintf(char **, const char *, ...)
00173     PRINTF_ATTRIBUTE(2, 3);
00174 extern int vsnprintf(char *, size_t, const char *, va_list);
00175 
00176 /* File stream functions */
00177 extern FILE *fopen(const char *, const char *);
00178 extern FILE *fdopen(int, const char *);
00179 extern int fclose(FILE *);
00180 
00181 extern size_t fread(void *, size_t, size_t, FILE *);
00182 extern size_t fwrite(const void *, size_t, size_t, FILE *);
00183 
00184 extern int fseek(FILE *, off64_t, int);
00185 extern void rewind(FILE *);
00186 extern off64_t ftell(FILE *);
00187 extern int feof(FILE *);
00188 extern int fileno(FILE *);
00189 
00190 extern int fflush(FILE *);
00191 extern int ferror(FILE *);
00192 extern void clearerr(FILE *);
00193 
00194 extern void setvbuf(FILE *, void *, int, size_t);
00195 
00196 /* Misc file functions */
00197 extern int rename(const char *, const char *);
00198 
00199 #endif
00200 

Generated on Thu Jun 2 07:45:47 2011 for HelenOS/USB by  doxygen 1.4.7