Subversion Repositories Kolibri OS

Rev

Rev 9811 | Blame | Compare with Previous | Last modification | View Log | Download | RSS feed

  1. ///////////////////////////////////////////////////////////////////////////////
  2. // \author (c) Marco Paland (info@paland.com)
  3. //             2014-2019, PALANDesign Hannover, Germany
  4. //
  5. // \license The MIT License (MIT)
  6. //
  7. // Permission is hereby granted, free of charge, to any person obtaining a copy
  8. // of this software and associated documentation files (the "Software"), to deal
  9. // in the Software without restriction, including without limitation the rights
  10. // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
  11. // copies of the Software, and to permit persons to whom the Software is
  12. // furnished to do so, subject to the following conditions:
  13. //
  14. // The above copyright notice and this permission notice shall be included in
  15. // all copies or substantial portions of the Software.
  16. //
  17. // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  18. // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  19. // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
  20. // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
  21. // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
  22. // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
  23. // THE SOFTWARE.
  24. //
  25. // \brief Tiny printf, sprintf and snprintf implementation, optimized for speed on
  26. //        embedded systems with a very limited resources.
  27. //        Use this instead of bloated standard/newlib printf.
  28. //        These routines are thread safe and reentrant.
  29. //
  30. ///////////////////////////////////////////////////////////////////////////////
  31.  
  32. #ifndef _STDIO_H_
  33. #define _STDIO_H_
  34.  
  35. #include <stdarg.h>
  36. #include <stddef.h>
  37.  
  38. DLLAPI int puts(const char* str);
  39. DLLAPI int printf(const char* format, ...);
  40. DLLAPI int sprintf(char* buffer, const char* format, ...);
  41. DLLAPI int snprintf(char* buffer, size_t count, const char* format, ...);
  42. DLLAPI int vsnprintf(char* buffer, size_t count, const char* format, va_list va);
  43. DLLAPI int vsprintf(char* buffer, const char* format, va_list va);
  44. DLLAPI int vprintf(const char* format, va_list va);
  45.  
  46. DLLAPI void debug_printf(const char* format, ...);
  47.  
  48. typedef size_t fpos_t;
  49.  
  50. #define _FILEMODE_R 1 << 0    // Read
  51. #define _FILEMODE_W 1 << 1    // Write
  52. #define _FILEMODE_A 1 << 2    // Append
  53. #define _FILEMODE_PLUS 1 << 3 // Plus
  54.  
  55. typedef struct FILE_s {
  56.     char* name;
  57.     fpos_t position;
  58.     int error;
  59.     int eof;
  60.     int mode;              // flags _FILEMODE_*
  61.     int __ungetc_emu_buff; // Uses __ungetc_emu (temporary solution!)
  62. } FILE;
  63.  
  64. #define _IOFBF 0
  65. #define _IOLBF 1
  66. #define _IONBF 2
  67.  
  68. #define BUFSIZ 1024
  69.  
  70. #define EOF -1
  71.  
  72. #define FOPEN_MAX 0xffffffff
  73.  
  74. #define FILENAME_MAX 255
  75.  
  76. #define L_tmpnam FILENAME_MAX
  77.  
  78. #define SEEK_CUR 0
  79. #define SEEK_END 1
  80. #define SEEK_SET 2
  81.  
  82. #define TMP_MAX FOPEN_MAX
  83.  
  84. #define stderr (FILE*)3
  85. #define stdin (FILE*)1
  86. #define stdout (FILE*)2
  87.  
  88. DLLAPI int fgetc(FILE*);
  89. DLLAPI char* fgets(char* restrict, int, FILE* restrict);
  90. DLLAPI int fprintf(FILE* restrict, const char* restrict, ...);
  91. DLLAPI int fputc(int, FILE*);
  92. DLLAPI int fputs(const char* restrict, FILE* restrict);
  93. DLLAPI size_t fread(void* restrict, size_t size, size_t count, FILE* restrict);
  94. DLLAPI int fscanf(FILE* restrict, const char* restrict, ...);
  95. DLLAPI size_t fwrite(const void* restrict, size_t size, size_t count, FILE* restrict);
  96. DLLAPI int getc(FILE*);
  97. #define getc() fgetc(stdin)
  98. DLLAPI int getchar(void);
  99. DLLAPI int printf(const char* restrict, ...);
  100. #define putc(ch) fputc(ch, stdout)
  101. DLLAPI int puts(const char*);
  102. DLLAPI int scanf(const char* restrict, ...);
  103. DLLAPI char* gets(char* str);
  104. DLLAPI int ungetc(int, FILE*);
  105. DLLAPI int vfprintf(FILE* restrict, const char* restrict, va_list);
  106. DLLAPI int vfscanf(FILE* restrict, const char* restrict, va_list);
  107. DLLAPI int vprintf(const char* restrict, va_list);
  108. DLLAPI int vscanf(const char* restrict, va_list);
  109. DLLAPI int sscanf(const char*, const char* restrict, ...);
  110. DLLAPI int vsscanf(const char*, const char*, va_list);
  111.  
  112. DLLAPI int remove(const char*);
  113. DLLAPI int rename(const char*, const char*);
  114. DLLAPI FILE* tmpfile(void);
  115. DLLAPI char* tmpnam(char*);
  116.  
  117. DLLAPI int fclose(FILE*);
  118. DLLAPI int fflush(FILE*);
  119. DLLAPI FILE* fopen(const char* restrict, const char* restrict);
  120. DLLAPI FILE* freopen(const char* restrict, const char* restrict, FILE* restrict);
  121. DLLAPI void setbuf(FILE* restrict, char* restrict);
  122. DLLAPI int setvbuf(FILE* restrict, char* restrict, int, size_t);
  123.  
  124. DLLAPI int fgetpos(FILE* restrict, fpos_t* restrict);
  125. DLLAPI int fseek(FILE*, long, int);
  126. DLLAPI int fsetpos(FILE*, const fpos_t*);
  127. DLLAPI long ftell(FILE*);
  128. DLLAPI void rewind(FILE*);
  129.  
  130. DLLAPI void clearerr(FILE*);
  131. DLLAPI int feof(FILE*);
  132. DLLAPI int ferror(FILE*);
  133. DLLAPI void perror(const char*);
  134.  
  135. DLLAPI size_t fread(void* restrict, size_t, size_t, FILE* restrict);
  136.  
  137. DLLAPI int getchar(void);
  138.  
  139. #endif // _STDIO_H_
  140.