stdio.h 8.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244
  1. /*
  2. * Copyright (C) 2001-2003 by egnite Software GmbH. All rights reserved.
  3. *
  4. * Copyright (c) 1990, 1993
  5. * The Regents of the University of California. All rights reserved.
  6. *
  7. * This code is partly derived from software contributed to Berkeley by
  8. * Chris Torek, but heavily rewritten for Nut/OS.
  9. *
  10. * Redistribution and use in source and binary forms, with or without
  11. * modification, are permitted provided that the following conditions
  12. * are met:
  13. *
  14. * 1. Redistributions of source code must retain the above copyright
  15. * notice, this list of conditions and the following disclaimer.
  16. * 2. Redistributions in binary form must reproduce the above copyright
  17. * notice, this list of conditions and the following disclaimer in the
  18. * documentation and/or other materials provided with the distribution.
  19. * 3. Neither the name of the copyright holders nor the names of
  20. * contributors may be used to endorse or promote products derived
  21. * from this software without specific prior written permission.
  22. *
  23. * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
  24. * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
  25. * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
  26. * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
  27. * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
  28. * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
  29. * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
  30. * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
  31. * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
  32. * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF
  33. * THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
  34. * SUCH DAMAGE.
  35. *
  36. * For additional information see http://www.ethernut.de/
  37. *
  38. */
  39. #ifndef _STDIO_H_
  40. #ifndef _STDIO_VIRTUAL_H_
  41. #define _STDIO_VIRTUAL_H_
  42. #ifdef __NUT_EMULATION__
  43. // on an emulation platform, we need to have both
  44. // a) the native stdio headers and libs and
  45. #include "stdio_orig.h"
  46. // b) the nut os header and implementation
  47. // the nut os function calls and defines are renamed by the stdio_nut_wrapper.h
  48. // some defines in /usr/include/stdio.h we need to overload
  49. #ifndef NO_STDIO_NUT_WRAPPER
  50. #undef getc
  51. #undef putc
  52. #undef stdin
  53. #undef stdout
  54. #undef stderr
  55. #undef clearerr
  56. #undef feof
  57. #undef ferror
  58. #undef getchar
  59. #undef putchar
  60. #include <stdio_nut_wrapper.h>
  61. #endif /* NO_STDIO_NUT_WRAPPER */
  62. #endif /* __NUT_EMULATION__ */
  63. #ifndef _STDIO_H_
  64. #define _STDIO_H_
  65. #endif
  66. #ifdef NO_STDIO_NUT_WRAPPER
  67. // this is for unix device drivers, they want to see their native functions
  68. // and don't need nut stdio
  69. #else
  70. #include <sys/types.h>
  71. #include <stdarg.h>
  72. /*!
  73. * \file stdio.h
  74. * \brief C Standard I/O
  75. */
  76. /*!
  77. * \addtogroup xgCrtStdio
  78. */
  79. /*@{*/
  80. #ifndef EOF
  81. /*!
  82. * \brief End of file.
  83. *
  84. * Returned by an input or output operation when the end of a file is
  85. * encountered. Some routines return this value to indicate an error.
  86. */
  87. #define EOF (-1)
  88. #endif
  89. #ifndef _IOFBF
  90. #define _IOFBF 0x00 /*!< \brief Fully buffered. */
  91. #define _IOLBF 0x01 /*!< \brief Line buffered. */
  92. #define _IONBF 0x02 /*!< \brief Unbuffered. */
  93. #endif
  94. /*!
  95. * \brief Stream structure type.
  96. *
  97. * A pointer to this type is used for all standard I/O functions to
  98. * specify a stream.
  99. *
  100. * \note Applications should make any assumptions about the contents
  101. * of this structure as it may change without further notice.
  102. */
  103. typedef struct __iobuf FILE;
  104. extern FILE *__iob[]; /*!< \internal Stream slots. */
  105. #define stdin (__iob[0]) /*!< \brief Standard input stream. */
  106. #define stdout (__iob[1]) /*!< \brief Standard output stream. */
  107. #define stderr (__iob[2]) /*!< \brief Standard error output stream. */
  108. /*@}*/
  109. #ifndef SEEK_SET
  110. #define SEEK_SET 0
  111. #endif
  112. #ifndef SEEK_CUR
  113. #define SEEK_CUR 1
  114. #endif
  115. #ifndef SEEK_END
  116. #define SEEK_END 2
  117. #endif
  118. extern int asprintf(char **strp, const char *fmt, ...);
  119. extern void clearerr(FILE * stream);
  120. extern int fclose(FILE * stream);
  121. extern void fcloseall(void);
  122. extern FILE *_fdopen(int fd, const char *mode);
  123. extern int feof(FILE * stream);
  124. extern int ferror(FILE * stream);
  125. extern int fflush(FILE * stream);
  126. extern int fgetc(FILE * stream);
  127. extern char *fgets(char *buffer, int count, FILE * stream);
  128. extern int _fileno(FILE * stream);
  129. extern void _flushall(void);
  130. extern FILE *fopen(const char *name, const char *mode);
  131. extern FILE *funopen(void *cookie, int (*readfn) (void *, char *, int), int (*writefn) (void *, const char *, int), long (*seekfn)(void *, long, int), int (*closefn)(void *));
  132. extern int fprintf(FILE * stream, const char *fmt, ...);
  133. extern int fpurge(FILE * stream);
  134. extern int fputc(int c, FILE * stream);
  135. extern int fputs(const char *string, FILE * stream);
  136. extern size_t fread(void *buffer, size_t size, size_t count, FILE * stream);
  137. extern FILE *freopen(const char *name, const char *mode, FILE * stream);
  138. extern int fscanf(FILE * stream, const char *fmt, ...);
  139. extern int fseek(FILE * stream, long offset, int origin);
  140. extern long ftell(FILE * stream);
  141. extern size_t fwrite(const void *data, size_t size, size_t count, FILE * stream);
  142. extern int getc(FILE * stream);
  143. extern int getchar(void);
  144. extern int kbhit(void);
  145. extern char *gets(char *buffer);
  146. extern int printf(const char *fmt, ...);
  147. extern int putc(int c, FILE * stream);
  148. extern int putchar(int c);
  149. extern int puts(const char *string);
  150. extern int scanf(const char *fmt, ...);
  151. extern int sprintf(char *buffer, const char *fmt, ...);
  152. extern int snprintf(char *buffer, size_t size, const char *fmt, ...);
  153. extern int sscanf(const char *string, const char *fmt, ...);
  154. extern int ungetc(int c, FILE * stream);
  155. extern int vasprintf(char **strp, const char *fmt, va_list ap);
  156. extern int vfprintf(FILE * stream, const char *fmt, va_list ap);
  157. extern int vfscanf(FILE * stream, const char *fmt, va_list ap);
  158. extern int vsprintf(char *buffer, const char *fmt, va_list ap);
  159. extern int vsnprintf(char *buffer, size_t size, const char *fmt, va_list ap);
  160. extern int vsscanf(const char *string, const char *fmt, va_list ap);
  161. extern int rename(const char *old_name, const char *new_name);
  162. #ifdef __HARVARD_ARCH__
  163. /* Strings in program space need special handling for Harvard architectures. */
  164. extern int fprintf_P(FILE * stream, PGM_P fmt, ...) __attribute__((format(printf, 2, 3)));
  165. extern int fputs_P(PGM_P string, FILE * stream);
  166. extern int fscanf_P(FILE * stream, PGM_P fmt, ...) __attribute__((format(scanf, 2, 3)));
  167. extern size_t fwrite_P(PGM_P data, size_t size, size_t count, FILE * stream);
  168. extern int printf_P(PGM_P fmt, ...) __attribute__((format(printf, 1, 2)));
  169. extern int puts_P(PGM_P string);
  170. extern int scanf_P(PGM_P fmt, ...) __attribute__((format(scanf, 1, 2)));
  171. extern int sprintf_P(char *buffer, PGM_P fmt, ...) __attribute__((format(printf, 2, 3)));
  172. extern int snprintf_P(char *buffer, size_t size, PGM_P fmt, ...) __attribute__((format(printf, 3, 4)));
  173. extern int sscanf_P(const char *string, const char *fmt, ...) __attribute__((format(scanf, 2, 3)));
  174. extern int vfprintf_P(FILE * stream, PGM_P fmt, va_list ap);
  175. extern int vfscanf_P(FILE * stream, PGM_P fmt, va_list ap);
  176. extern int vsprintf_P(char *buffer, PGM_P fmt, va_list ap);
  177. extern int vsnprintf_P(char *buffer, size_t size, PGM_P fmt, va_list ap);
  178. extern int vsscanf_P(const char *string, PGM_P fmt, va_list ap);
  179. #else /* __HARVARD_ARCH__ */
  180. #if !defined(NUT_STDIO_PREFIXED)
  181. /* Map to standard functions, if program and data space are equally accessable. */
  182. #define fputs_P(string, stream) fputs(string, stream)
  183. #define fwrite_P(data, size, count, stream) fwrite(data, size, count, stream)
  184. #define puts_P(string) puts(string)
  185. #define vfprintf_P(stream, fmt, ap) vfprintf(stream, fmt, ap)
  186. #define vfscanf_P(stream, fmt, ap) vfscanf(stream, fmt, ap)
  187. #define vsprintf_P(buffer, fmt, ap) vsprintf(buffer, fmt, ap)
  188. #define vsnprintf_P(buffer, size, fmt, ap) vsnprintf(buffer, size, fmt, ap)
  189. #define vsscanf_P(string, fmt, ap) vsscanf(string, fmt, ap)
  190. #if defined(__GNUC__)
  191. #define fprintf_P(...) fprintf(__VA_ARGS__)
  192. #define fscanf_P(...) fscanf(__VA_ARGS__)
  193. #define printf_P(...) printf(__VA_ARGS__)
  194. #define scanf_P(...) scanf(__VA_ARGS__)
  195. #define sprintf_P(...) sprintf(__VA_ARGS__)
  196. #define snprintf_P(...) snprintf(__VA_ARGS__)
  197. #define sscanf_P(...) sscanf(__VA_ARGS__)
  198. #else /* __GNUC__ */
  199. #define fprintf_P fprintf
  200. #define fscanf_P fscanf
  201. #define printf_P printf
  202. #define scanf_P scanf
  203. #define sprintf_P sprintf
  204. #define snprintf_P snprintf
  205. #define sscanf_P sscanf
  206. #endif /* __GNUC__ */
  207. #endif /* NUT_STDIO_PREFIXED */
  208. #endif /* __HARVARD_ARCH__ */
  209. #endif /* NO_STDIO_NUT_WRAPPER */
  210. #endif /* _STDIO_VIRTUAL_H_ */
  211. #endif /* _STDIO_H_ */