/uspace/lib/posix/include/posix/stdio.h

https://gitlab.com/vhelen/vhelen · C Header · 222 lines · 115 code · 40 blank · 67 comment · 0 complexity · 72c3cd22bd44c89192f4194f665ac9e1 MD5 · raw file

  1. /*
  2. * Copyright (c) 2011 Jiri Zarevucky
  3. * Copyright (c) 2011 Petr Koupy
  4. * All rights reserved.
  5. *
  6. * Redistribution and use in source and binary forms, with or without
  7. * modification, are permitted provided that the following conditions
  8. * are met:
  9. *
  10. * - Redistributions of source code must retain the above copyright
  11. * notice, this list of conditions and the following disclaimer.
  12. * - Redistributions in binary form must reproduce the above copyright
  13. * notice, this list of conditions and the following disclaimer in the
  14. * documentation and/or other materials provided with the distribution.
  15. * - The name of the author may not be used to endorse or promote products
  16. * derived from this software without specific prior written permission.
  17. *
  18. * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
  19. * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
  20. * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
  21. * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
  22. * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
  23. * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
  24. * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
  25. * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
  26. * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
  27. * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  28. */
  29. /** @addtogroup libposix
  30. * @{
  31. */
  32. /** @file Standard buffered input/output.
  33. */
  34. #ifndef POSIX_STDIO_H_
  35. #define POSIX_STDIO_H_
  36. #ifndef __POSIX_DEF__
  37. #define __POSIX_DEF__(x) x
  38. /* DEBUG macro does not belong to POSIX stdio.h. Its unconditional
  39. * definition in the native stdio.h causes unexpected behaviour of
  40. * applications which uses their own DEBUG macro (e.g. debugging
  41. * output is printed even if not desirable). */
  42. #undef DEBUG
  43. #endif
  44. #include "stddef.h"
  45. #include "unistd.h"
  46. #include "libc/io/verify.h"
  47. #include "sys/types.h"
  48. #include "stdarg.h"
  49. #include "limits.h"
  50. /*
  51. * These are the same as in HelenOS libc.
  52. * It would be possible to directly include <stdio.h> but
  53. * it is better not to pollute POSIX namespace with other functions
  54. * defined in that header.
  55. *
  56. * Because libposix is always linked with libc, providing only these
  57. * forward declarations ought to be enough.
  58. */
  59. #define EOF (-1)
  60. /** Size of buffers used in stdio header. */
  61. #define BUFSIZ 4096
  62. /** Maximum size in bytes of the longest filename. */
  63. #define FILENAME_MAX 4096
  64. typedef struct _IO_FILE FILE;
  65. #ifndef LIBPOSIX_INTERNAL
  66. enum _buffer_type {
  67. /** No buffering */
  68. _IONBF,
  69. /** Line buffering */
  70. _IOLBF,
  71. /** Full buffering */
  72. _IOFBF
  73. };
  74. #endif
  75. extern FILE *stdin;
  76. extern FILE *stdout;
  77. extern FILE *stderr;
  78. extern int fgetc(FILE *);
  79. extern char *fgets(char *, int, FILE *);
  80. extern int getchar(void);
  81. extern char *gets(char *, size_t);
  82. extern int fputc(wchar_t, FILE *);
  83. extern int fputs(const char *, FILE *);
  84. extern int putchar(wchar_t);
  85. extern int puts(const char *);
  86. extern int fprintf(FILE *, const char*, ...) PRINTF_ATTRIBUTE(2, 3);
  87. extern int vfprintf(FILE *, const char *, va_list);
  88. extern int printf(const char *, ...) PRINTF_ATTRIBUTE(1, 2);
  89. extern int vprintf(const char *, va_list);
  90. extern int snprintf(char *, size_t , const char *, ...) PRINTF_ATTRIBUTE(3, 4);
  91. #ifdef _GNU_SOURCE
  92. extern int vasprintf(char **, const char *, va_list);
  93. extern int asprintf(char **, const char *, ...) PRINTF_ATTRIBUTE(2, 3);
  94. #endif
  95. extern int vsnprintf(char *, size_t, const char *, va_list);
  96. extern FILE *fopen(const char *, const char *);
  97. extern FILE *fdopen(int, const char *);
  98. extern int fclose(FILE *);
  99. extern size_t fread(void *, size_t, size_t, FILE *);
  100. extern size_t fwrite(const void *, size_t, size_t, FILE *);
  101. extern void rewind(FILE *);
  102. extern int feof(FILE *);
  103. extern int fileno(FILE *);
  104. extern int fflush(FILE *);
  105. extern int ferror(FILE *);
  106. extern void clearerr(FILE *);
  107. extern void setvbuf(FILE *, void *, int, size_t);
  108. extern void setbuf(FILE *, void *);
  109. /* POSIX specific stuff. */
  110. /* Identifying the Terminal */
  111. #undef L_ctermid
  112. #define L_ctermid PATH_MAX
  113. extern char *__POSIX_DEF__(ctermid)(char *s);
  114. /* Error Recovery */
  115. extern void __POSIX_DEF__(clearerr)(FILE *stream);
  116. /* Input/Output */
  117. #undef putc
  118. #define putc fputc
  119. extern int __POSIX_DEF__(fputs)(const char *restrict s, FILE *restrict stream);
  120. #undef getc
  121. #define getc fgetc
  122. extern int __POSIX_DEF__(ungetc)(int c, FILE *stream);
  123. extern ssize_t __POSIX_DEF__(getdelim)(char **restrict lineptr, size_t *restrict n,
  124. int delimiter, FILE *restrict stream);
  125. extern ssize_t __POSIX_DEF__(getline)(char **restrict lineptr, size_t *restrict n,
  126. FILE *restrict stream);
  127. /* Opening Streams */
  128. extern FILE *__POSIX_DEF__(freopen)(const char *restrict filename,
  129. const char *restrict mode, FILE *restrict stream);
  130. /* Error Messages */
  131. extern void __POSIX_DEF__(perror)(const char *s);
  132. /* File Positioning */
  133. typedef struct {
  134. off64_t offset;
  135. } __POSIX_DEF__(fpos_t);
  136. extern int __POSIX_DEF__(fsetpos)(FILE *stream, const __POSIX_DEF__(fpos_t) *pos);
  137. extern int __POSIX_DEF__(fgetpos)(FILE *restrict stream, __POSIX_DEF__(fpos_t) *restrict pos);
  138. extern int __POSIX_DEF__(fseek)(FILE *stream, long offset, int whence);
  139. extern int __POSIX_DEF__(fseeko)(FILE *stream, __POSIX_DEF__(off_t) offset, int whence);
  140. extern long __POSIX_DEF__(ftell)(FILE *stream);
  141. extern __POSIX_DEF__(off_t) __POSIX_DEF__(ftello)(FILE *stream);
  142. /* Flushing Buffers */
  143. extern int __POSIX_DEF__(fflush)(FILE *stream);
  144. /* Formatted Output */
  145. extern int __POSIX_DEF__(dprintf)(int fildes, const char *restrict format, ...)
  146. PRINTF_ATTRIBUTE(2, 3);
  147. extern int __POSIX_DEF__(vdprintf)(int fildes, const char *restrict format, va_list ap);
  148. extern int __POSIX_DEF__(sprintf)(char *restrict s, const char *restrict format, ...)
  149. PRINTF_ATTRIBUTE(2, 3);
  150. extern int __POSIX_DEF__(vsprintf)(char *restrict s, const char *restrict format, va_list ap);
  151. /* Formatted Input */
  152. extern int __POSIX_DEF__(fscanf)(
  153. FILE *restrict stream, const char *restrict format, ...);
  154. extern int __POSIX_DEF__(vfscanf)(
  155. FILE *restrict stream, const char *restrict format, va_list arg);
  156. extern int __POSIX_DEF__(scanf)(const char *restrict format, ...);
  157. extern int __POSIX_DEF__(vscanf)(const char *restrict format, va_list arg);
  158. extern int __POSIX_DEF__(sscanf)(
  159. const char *restrict s, const char *restrict format, ...);
  160. extern int __POSIX_DEF__(vsscanf)(
  161. const char *restrict s, const char *restrict format, va_list arg);
  162. /* File Locking */
  163. extern void __POSIX_DEF__(flockfile)(FILE *file);
  164. extern int __POSIX_DEF__(ftrylockfile)(FILE *file);
  165. extern void __POSIX_DEF__(funlockfile)(FILE *file);
  166. extern int __POSIX_DEF__(getc_unlocked)(FILE *stream);
  167. extern int __POSIX_DEF__(getchar_unlocked)(void);
  168. extern int __POSIX_DEF__(putc_unlocked)(int c, FILE *stream);
  169. extern int __POSIX_DEF__(putchar_unlocked)(int c);
  170. /* Deleting Files */
  171. extern int __POSIX_DEF__(remove)(const char *path);
  172. /* Renaming Files */
  173. extern int __POSIX_DEF__(rename)(const char *oldname, const char *newname);
  174. /* Temporary Files */
  175. #undef L_tmpnam
  176. #define L_tmpnam PATH_MAX
  177. extern char *__POSIX_DEF__(tmpnam)(char *s);
  178. extern char *__POSIX_DEF__(tempnam)(const char *dir, const char *pfx);
  179. extern FILE *__POSIX_DEF__(tmpfile)(void);
  180. #endif /* POSIX_STDIO_H_ */
  181. /** @}
  182. */