stdio.h 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131
  1. /*
  2. * Copyright (c) mlibc & plct lab
  3. *
  4. * SPDX-License-Identifier: MIT
  5. *
  6. * Change Logs:
  7. * Date Author Notes
  8. * 2023/06/16 bernard the first verison
  9. */
  10. #ifndef MLIBC_STDIO_H__
  11. #define MLIBC_STDIO_H__
  12. #include <sys/types.h>
  13. #include <stdarg.h>
  14. #define _FILE_IND_EOF (1 << 0)
  15. #define _FILE_IND_ERROR (1 << 1)
  16. #define UNGET 8 /* unget size */
  17. #define BUFSIZ 128 /* buffer size */
  18. #define EOF (-1) /* end-of-file descriptor */
  19. #ifndef SEEK_SET
  20. #define SEEK_SET 0 /* set file offset to offset */
  21. #endif
  22. #ifndef SEEK_CUR
  23. #define SEEK_CUR 1 /* set file offset to current plus offset */
  24. #endif
  25. #ifndef SEEK_END
  26. #define SEEK_END 2 /* set file offset to EOF plus offset */
  27. #endif
  28. #define CHAR_BIT 8
  29. #define UCHAR_MAX 255
  30. struct __MLIBC_IO_FILE;
  31. typedef struct __MLIBC_IO_FILE FILE;
  32. struct __MLIBC_IO_FILE{
  33. int fd;
  34. unsigned char *wbase;
  35. unsigned char *wpos, wend;
  36. unsigned char *rpos, rend;
  37. size_t (*write)(FILE *, unsigned char *, size_t);
  38. size_t (*read)(FILE *, unsigned char *, size_t);
  39. off_t (*seek)(FILE *, off_t, int);
  40. int (*close)(FILE *);
  41. unsigned char *buf;
  42. size_t buf_size;
  43. int lbf;
  44. char *getln_buf;
  45. FILE *prev, *next;
  46. volatile int lock;
  47. long lockcount;
  48. FILE *prev_lock, *next_lock;
  49. int mode;
  50. off_t off;
  51. unsigned char indicators;
  52. };
  53. extern FILE* stdin;
  54. extern FILE* stdout;
  55. extern FILE* stderr;
  56. /* File open and close */
  57. int fclose(FILE *);
  58. FILE *fdopen(int, const char *);
  59. int fopen(const char *, const char *);
  60. FILE *freopen(const char *, const char *, FILE *);
  61. /* Formatted I/O status */
  62. int printf(const char *, ...);
  63. void perror(const char *);
  64. int scanf(const char *, ...);
  65. int snprintf(char *, size_t, const char *, ...);
  66. int sprintf(char *, const char *, ...);
  67. int sscanf(const char *, const char *, ...);
  68. int vfprintf(FILE *, const char *, va_list);
  69. int vfscanf(FILE *, const char *, va_list);
  70. int vprintf(const char *, va_list);
  71. int vscanf(const char *, va_list);
  72. int vsnprintf(char *, size_t, const char *, va_list);
  73. int vsprintf(char *, const char *, va_list);
  74. int vsscanf(const char *, const char *, va_list);
  75. /* File read and write operations */
  76. int feof(FILE *);
  77. int ferror(FILE *);
  78. int fflush(FILE *);
  79. int fgetc(FILE *);
  80. char *fgets(char *, int, FILE *);
  81. int fileno(FILE *);
  82. void flockfile(FILE *);
  83. int fprintf(FILE *, const char *, ...);
  84. int fputc(int, FILE *);
  85. int fputs(const char *, FILE *);
  86. size_t fread(void *, size_t, size_t, FILE *);
  87. size_t fwrite(const void *, size_t, size_t, FILE *);
  88. int ftrylockfile(FILE *);
  89. void funlockfile(FILE *);
  90. int getc(FILE *);
  91. int getc_unlocked(FILE *);
  92. int getchar(void);
  93. int getchar_unlocked(void);
  94. char *gets(char *);
  95. int putc(int, FILE *);
  96. int putc_unlocked(int, FILE *);
  97. int putchar(int);
  98. int putchar_unlocked(int);
  99. int puts(const char *);
  100. int ungetc(int, FILE *);
  101. int libc_stdio_set_console(const char* device_name, int mode);
  102. int libc_stdio_get_console(void);
  103. extern char **__environ;
  104. void __env_rm_add(char *old, char *new);
  105. int __putenv(char *s, size_t l, char *r);
  106. int putenv(char *s);
  107. char *getenv(const char *name);
  108. int setenv(const char *var, const char *value, int overwrite);
  109. int unsetenv(const char *name);
  110. int rename(const char *oldpath, const char *newpath);
  111. #endif /*MLIBC_STDIO_H__*/