stdio.h 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102
  1. /* Copyright (C) 2016 Jeremiah Orians
  2. * This file is part of M2-Planet.
  3. *
  4. * M2-Planet is free software: you can redistribute it and/or modify
  5. * it under the terms of the GNU General Public License as published by
  6. * the Free Software Foundation, either version 3 of the License, or
  7. * (at your option) any later version.
  8. *
  9. * M2-Planet is distributed in the hope that it will be useful,
  10. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  11. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  12. * GNU General Public License for more details.
  13. *
  14. * You should have received a copy of the GNU General Public License
  15. * along with M2-Planet. If not, see <http://www.gnu.org/licenses/>.
  16. */
  17. #ifndef _STDIO_H
  18. #define _STDIO_H
  19. #ifdef __M2__
  20. /* Actual format of FILE */
  21. struct __IO_FILE
  22. {
  23. int fd;
  24. int bufmode; /* O_RDONLY = 0, O_WRONLY = 1 */
  25. int bufpos;
  26. int file_pos;
  27. int buflen;
  28. char* buffer;
  29. struct __IO_FILE* next;
  30. struct __IO_FILE* prev;
  31. };
  32. /* Now give us the FILE we all love */
  33. typedef struct __IO_FILE FILE;
  34. #include <stdio.c>
  35. #else
  36. #include <sys/types.h>
  37. #include <sys/stat.h>
  38. #include <fcntl.h>
  39. #include <unistd.h>
  40. #include <stdlib.h>
  41. /* Required constants */
  42. /* For file I/O*/
  43. #define EOF -1
  44. #define BUFSIZ 4096
  45. /* For lseek */
  46. #define SEEK_SET 0
  47. #define SEEK_CUR 1
  48. #define SEEK_END 2
  49. /* Actual format of FILE */
  50. struct __IO_FILE
  51. {
  52. int fd;
  53. int bufmode; /* 0 = no buffer, 1 = read, 2 = write */
  54. int bufpos;
  55. int buflen;
  56. char* buffer;
  57. };
  58. /* Now give us the FILE we all love */
  59. typedef struct __IO_FILE FILE;
  60. /* Required variables */
  61. extern FILE* stdin;
  62. extern FILE* stdout;
  63. extern FILE* stderr;
  64. /* Standard C functions */
  65. /* Getting */
  66. extern int fgetc(FILE* f);
  67. extern int getchar();
  68. extern char* fgets(char* str, int count, FILE* stream);
  69. extern size_t fread( void* buffer, size_t size, size_t count, FILE* stream );
  70. /* Putting */
  71. extern void fputc(char s, FILE* f);
  72. extern void putchar(char s);
  73. extern int fputs(char const* str, FILE* stream);
  74. extern int puts(char const* str);
  75. extern size_t fwrite(void const* buffer, size_t size, size_t count, FILE* stream );
  76. /* File management */
  77. extern FILE* fopen(char const* filename, char const* mode);
  78. extern int fclose(FILE* stream);
  79. extern int fflush(FILE* stream);
  80. /* File Positioning */
  81. extern int ungetc(int ch, FILE* stream);
  82. extern long ftell(FILE* stream);
  83. extern int fseek(FILE* f, long offset, int whence);
  84. extern void rewind(FILE* f);
  85. #endif
  86. #endif