Nut/OS  4.10.3
API Reference
stdio.h
Go to the documentation of this file.
00001 /*
00002  * Copyright (C) 2001-2003 by egnite Software GmbH. All rights reserved.
00003  *
00004  * Copyright (c) 1990, 1993
00005  *      The Regents of the University of California.  All rights reserved.
00006  *
00007  * This code is partly derived from software contributed to Berkeley by
00008  * Chris Torek, but heavily rewritten for Nut/OS.
00009  *
00010  * Redistribution and use in source and binary forms, with or without
00011  * modification, are permitted provided that the following conditions
00012  * are met:
00013  *
00014  * 1. Redistributions of source code must retain the above copyright
00015  *    notice, this list of conditions and the following disclaimer.
00016  * 2. Redistributions in binary form must reproduce the above copyright
00017  *    notice, this list of conditions and the following disclaimer in the
00018  *    documentation and/or other materials provided with the distribution.
00019  * 3. Neither the name of the copyright holders nor the names of
00020  *    contributors may be used to endorse or promote products derived
00021  *    from this software without specific prior written permission.
00022  *
00023  * THIS SOFTWARE IS PROVIDED BY EGNITE SOFTWARE GMBH AND CONTRIBUTORS
00024  * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
00025  * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
00026  * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL EGNITE
00027  * SOFTWARE GMBH OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
00028  * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
00029  * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
00030  * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
00031  * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
00032  * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF
00033  * THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
00034  * SUCH DAMAGE.
00035  *
00036  * For additional information see http://www.ethernut.de/
00037  *
00038  */
00039 
00040 #ifndef _STDIO_H_
00041 
00042 #ifndef _STDIO_VIRTUAL_H_
00043 #define _STDIO_VIRTUAL_H_
00044 
00045 #ifdef __NUT_EMULATION__
00046 //  on an emulation platform, we need to have both
00047 //              a) the native stdio headers and libs and
00048 #include "stdio_orig.h"
00049 //              b) the nut os header and implementation
00050 //              the nut os function calls and defines are renamed by the stdio_nut_wrapper.h
00051 
00052 // some defines in /usr/include/stdio.h we need to overload
00053 #ifndef NO_STDIO_NUT_WRAPPER
00054 
00055 #undef getc
00056 #undef putc
00057 #undef stdin
00058 #undef stdout
00059 #undef stderr
00060 #undef clearerr
00061 #undef feof
00062 #undef ferror
00063 #undef getchar
00064 #undef putchar
00065 
00066 #include <stdio_nut_wrapper.h>
00067 
00068 #endif                          /* NO_STDIO_NUT_WRAPPER */
00069 
00070 #endif                          /* __NUT_EMULATION__ */
00071 
00072 #ifndef _STDIO_H_
00073 #define _STDIO_H_
00074 #endif
00075 
00076 #ifdef NO_STDIO_NUT_WRAPPER
00077 // this is for unix device drivers, they want to see their native functions
00078 // and don't need nut stdio
00079 #else
00080 
00081 #include <sys/types.h>
00082 #include <stdarg.h>
00083 
00093 
00094 #ifndef EOF
00095 
00101 #define EOF     (-1)
00102 #endif
00103 
00104 #ifndef _IOFBF
00105 #define _IOFBF      0x00        
00106 #define _IOLBF      0x01        
00107 #define _IONBF      0x02        
00108 #endif
00109 
00119 typedef struct __iobuf FILE;
00120 
00121 extern FILE *__iob[];           
00123 #define stdin (__iob[0])        
00124 #define stdout (__iob[1])       
00125 #define stderr (__iob[2])       
00128 
00129 #ifndef SEEK_SET
00130 #define SEEK_SET 0
00131 #endif
00132 
00133 #ifndef SEEK_CUR
00134 #define SEEK_CUR 1
00135 #endif
00136 
00137 #ifndef SEEK_END
00138 #define SEEK_END 2
00139 #endif
00140 
00141 
00142 extern void clearerr(FILE * stream);
00143 extern int fclose(FILE * stream);
00144 extern void fcloseall(void);
00145 extern FILE *_fdopen(int fd, CONST char *mode);
00146 extern int feof(FILE * stream);
00147 extern int ferror(FILE * stream);
00148 extern int fflush(FILE * stream);
00149 extern int fgetc(FILE * stream);
00150 extern char *fgets(char *buffer, int count, FILE * stream);
00151 extern int _fileno(FILE * stream);
00152 extern void _flushall(void);
00153 extern FILE *fopen(CONST char *name, CONST char *mode);
00154 extern int fprintf(FILE * stream, CONST char *fmt, ...);
00155 extern int fpurge(FILE * stream);
00156 extern int fputc(int c, FILE * stream);
00157 extern int fputs(CONST char *string, FILE * stream);
00158 extern size_t fread(void *buffer, size_t size, size_t count, FILE * stream);
00159 extern FILE *freopen(CONST char *name, CONST char *mode, FILE * stream);
00160 extern int fscanf(FILE * stream, CONST char *fmt, ...);
00161 extern int fseek(FILE * stream, long offset, int origin);
00162 extern long ftell(FILE * stream);
00163 extern size_t fwrite(CONST void *data, size_t size, size_t count, FILE * stream);
00164 extern int getc(FILE * stream);
00165 extern int getchar(void);
00166 extern int kbhit(void);
00167 extern char *gets(char *buffer);
00168 extern int printf(CONST char *fmt, ...);
00169 extern int putc(int c, FILE * stream);
00170 extern int putchar(int c);
00171 extern int puts(CONST char *string);
00172 extern int scanf(CONST char *fmt, ...);
00173 extern int sprintf(char *buffer, CONST char *fmt, ...);
00174 extern int sscanf(CONST char *string, CONST char *fmt, ...);
00175 extern int ungetc(int c, FILE * stream);
00176 extern int vfprintf(FILE * stream, CONST char *fmt, va_list ap);
00177 extern int vfscanf(FILE * stream, CONST char *fmt, va_list ap);
00178 extern int vsprintf(char *buffer, CONST char *fmt, va_list ap);
00179 extern int vsscanf(CONST char *string, CONST char *fmt, va_list ap);
00180 extern int rename(CONST char *old_name, CONST char *new_name);
00181 
00182 #ifdef __HARVARD_ARCH__
00183 /* Strings in program space need special handling for Harvard architectures. */
00184 extern int fprintf_P(FILE * stream, PGM_P fmt, ...) __attribute__((format(printf, 2, 3)));
00185 extern int fputs_P(PGM_P string, FILE * stream);
00186 extern int fscanf_P(FILE * stream, PGM_P fmt, ...) __attribute__((format(scanf, 2, 3)));
00187 extern size_t fwrite_P(PGM_P data, size_t size, size_t count, FILE * stream);
00188 extern int printf_P(PGM_P fmt, ...) __attribute__((format(printf, 1, 2)));
00189 extern int puts_P(PGM_P string);
00190 extern int scanf_P(PGM_P fmt, ...) __attribute__((format(scanf, 1, 2)));
00191 extern int sprintf_P(char *buffer, PGM_P fmt, ...) __attribute__((format(printf, 2, 3)));
00192 extern int sscanf_P(CONST char *string, CONST char *fmt, ...) __attribute__((format(scanf, 2, 3)));
00193 extern int vfprintf_P(FILE * stream, PGM_P fmt, va_list ap);
00194 extern int vfscanf_P(FILE * stream, PGM_P fmt, va_list ap);
00195 extern int vsprintf_P(char *buffer, PGM_P fmt, va_list ap);
00196 extern int vsscanf_P(CONST char *string, PGM_P fmt, va_list ap);
00197 
00198 #else /* __HARVARD_ARCH__ */
00199 
00200 #if !defined(NUT_STDIO_PREFIXED)
00201 /* Map to standard functions, if program and data space are equally accessable. */
00202 #define fputs_P(string, stream) fputs(string, stream)
00203 #define fwrite_P(data, size, count, stream) fwrite(data, size, count, stream)
00204 #define puts_P(string) puts(string)
00205 #define vfprintf_P(stream, fmt, ap) vfprintf(stream, fmt, ap)
00206 #define vfscanf_P(stream, fmt, ap) vfscanf(stream, fmt, ap)
00207 #define vsprintf_P(buffer, fmt, ap) vsprintf(buffer, fmt, ap)
00208 #define vsscanf_P(string, fmt, ap) vsscanf(string, fmt, ap)
00209 
00210 #if defined(__GNUC__)
00211 #define fprintf_P(...)  fprintf(__VA_ARGS__)
00212 #define fscanf_P(...)   fscanf(__VA_ARGS__)
00213 #define printf_P(...)   printf(__VA_ARGS__)
00214 #define scanf_P(...)    scanf(__VA_ARGS__)
00215 #define sprintf_P(...)  sprintf(__VA_ARGS__)
00216 #define sscanf_P(...)   sscanf(__VA_ARGS__)
00217 #else /* __GNUC__ */
00218 #define fprintf_P       fprintf
00219 #define fscanf_P        fscanf
00220 #define printf_P        printf
00221 #define scanf_P         scanf
00222 #define sprintf_P       sprintf
00223 #define sscanf_P        sscanf
00224 #endif /* __GNUC__ */
00225 
00226 #endif /* NUT_STDIO_PREFIXED */
00227 
00228 #endif /* __HARVARD_ARCH__ */
00229 
00230 #endif /* NO_STDIO_NUT_WRAPPER */
00231 
00232 #endif                          /* _STDIO_VIRTUAL_H_ */
00233 
00234 #endif                          /* _STDIO_H_ */