stdio.h 8.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227
  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 EGNITE SOFTWARE GMBH 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 EGNITE
  27. * SOFTWARE GMBH 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. #if defined(__linux__) || defined(__APPLE__) || defined(__CYGWIN__)
  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 /* __linux__ || __APPLE__ */
  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 void clearerr(FILE * stream);
  119. extern int fclose(FILE * stream);
  120. extern void fcloseall(void);
  121. extern FILE *_fdopen(int fd, CONST char *mode);
  122. extern int feof(FILE * stream);
  123. extern int ferror(FILE * stream);
  124. extern int fflush(FILE * stream);
  125. extern int fgetc(FILE * stream);
  126. extern char *fgets(char *buffer, int count, FILE * stream);
  127. extern int _fileno(FILE * stream);
  128. extern void _flushall(void);
  129. extern FILE *fopen(CONST char *name, CONST char *mode);
  130. extern int fprintf(FILE * stream, CONST char *fmt, ...);
  131. extern int fpurge(FILE * stream);
  132. extern int fputc(int c, FILE * stream);
  133. extern int fputs(CONST char *string, FILE * stream);
  134. extern size_t fread(void *buffer, size_t size, size_t count, FILE * stream);
  135. extern FILE *freopen(CONST char *name, CONST char *mode, FILE * stream);
  136. extern int fscanf(FILE * stream, CONST char *fmt, ...);
  137. extern int fseek(FILE * stream, long offset, int origin);
  138. extern long ftell(FILE * stream);
  139. extern size_t fwrite(CONST void *data, size_t size, size_t count, FILE * stream);
  140. extern int getc(FILE * stream);
  141. extern int getchar(void);
  142. extern int kbhit(void);
  143. extern char *gets(char *buffer);
  144. extern int printf(CONST char *fmt, ...);
  145. extern int putc(int c, FILE * stream);
  146. extern int putchar(int c);
  147. extern int puts(CONST char *string);
  148. extern int scanf(CONST char *fmt, ...);
  149. extern int sprintf(char *buffer, CONST char *fmt, ...);
  150. extern int sscanf(CONST char *string, CONST char *fmt, ...);
  151. extern int ungetc(int c, FILE * stream);
  152. extern int vfprintf(FILE * stream, CONST char *fmt, va_list ap);
  153. extern int vfscanf(FILE * stream, CONST char *fmt, va_list ap);
  154. extern int vsprintf(char *buffer, CONST char *fmt, va_list ap);
  155. extern int vsscanf(CONST char *string, CONST char *fmt, va_list ap);
  156. #ifdef __HARVARD_ARCH__
  157. /* Strings in program space need special handling for Harvard architectures. */
  158. extern int fprintf_P(FILE * stream, PGM_P fmt, ...) __attribute__((format(printf, 2, 3)));
  159. extern int fputs_P(PGM_P string, FILE * stream);
  160. extern int fscanf_P(FILE * stream, PGM_P fmt, ...) __attribute__((format(scanf, 2, 3)));
  161. extern size_t fwrite_P(PGM_P data, size_t size, size_t count, FILE * stream);
  162. extern int printf_P(PGM_P fmt, ...) __attribute__((format(printf, 1, 2)));
  163. extern int puts_P(PGM_P string);
  164. extern int scanf_P(PGM_P fmt, ...) __attribute__((format(scanf, 1, 2)));
  165. extern int sprintf_P(char *buffer, PGM_P fmt, ...) __attribute__((format(printf, 2, 3)));
  166. extern int sscanf_P(CONST char *string, CONST char *fmt, ...) __attribute__((format(scanf, 2, 3)));
  167. extern int vfprintf_P(FILE * stream, PGM_P fmt, va_list ap);
  168. extern int vfscanf_P(FILE * stream, PGM_P fmt, va_list ap);
  169. extern int vsprintf_P(char *buffer, PGM_P fmt, va_list ap);
  170. extern int vsscanf_P(CONST char *string, PGM_P fmt, va_list ap);
  171. #else /* __HARVARD_ARCH__ */
  172. /* Map to standard functions, if program and data space are equally accessable. */
  173. #define fputs_P(string, stream) fputs(string, stream)
  174. #define fwrite_P(data, size, count, stream) fwrite(data, size, count, stream)
  175. #define puts_P(string) puts(string)
  176. #define vfprintf_P(stream, fmt, ap) vfprintf(stream, fmt, ap)
  177. #define vfscanf_P(stream, fmt, ap) vfscanf(stream, fmt, ap)
  178. #define vsprintf_P(buffer, fmt, ap) vsprintf(buffer, fmt, ap)
  179. #define vsscanf_P(string, fmt, ap) vsscanf(string, fmt, ap)
  180. #if defined(__GNUC__)
  181. #define fprintf_P(...) fprintf(__VA_ARGS__)
  182. #define fscanf_P(...) fscanf(__VA_ARGS__)
  183. #define printf_P(...) printf(__VA_ARGS__)
  184. #define scanf_P(...) scanf(__VA_ARGS__)
  185. #define sprintf_P(...) sprintf(__VA_ARGS__)
  186. #define sscanf_P(...) sscanf(__VA_ARGS__)
  187. #else /* __GNUC__ */
  188. #define fprintf_P fprintf
  189. #define fscanf_P fscanf
  190. #define printf_P printf
  191. #define scanf_P scanf
  192. #define sprintf_P sprintf
  193. #define sscanf_P sscanf
  194. #endif /* __GNUC__ */
  195. #endif /* __HARVARD_ARCH__ */
  196. #endif /* NO_STDIO_NUT_WRAPPER */
  197. #endif /* _STDIO_VIRTUAL_H_ */
  198. #endif /* _STDIO_H_ */