stdio.h 1.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374
  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. #include <sys/types.h>
  18. #include <sys/stat.h>
  19. #include <fcntl.h>
  20. #include <unistd.h>
  21. #include <stdlib.h>
  22. /* Required constants */
  23. /* For file I/O*/
  24. #define EOF -1
  25. #define BUFSIZ 0x140000 /* 20MB */
  26. /* For lseek */
  27. #define SEEK_SET 0
  28. #define SEEK_CUR 1
  29. #define SEEK_END 2
  30. /* Actual format of FILE */
  31. struct __IO_FILE
  32. {
  33. int fd;
  34. int bufmode; /* 0 = no buffer, 1 = read, 2 = write */
  35. int bufpos;
  36. int buflen;
  37. char* buffer;
  38. };
  39. /* Now give us the FILE we all love */
  40. typedef struct __IO_FILE FILE;
  41. /* Required variables */
  42. extern FILE* stdin;
  43. extern FILE* stdout;
  44. extern FILE* stderr;
  45. /* Standard C functions */
  46. /* Getting */
  47. extern int fgetc(FILE* f);
  48. extern int getchar();
  49. extern char* fgets(char* str, int count, FILE* stream);
  50. /* Putting */
  51. extern void fputc(char s, FILE* f);
  52. extern void putchar(char s);
  53. extern int fputs(char const* str, FILE* stream);
  54. extern int puts(char const* str);
  55. /* File management */
  56. extern FILE* fopen(char const* filename, char const* mode);
  57. extern int fclose(FILE* stream);
  58. extern int fflush(FILE* stream);
  59. /* File Positioning */
  60. extern int ungetc(int ch, FILE* stream);
  61. extern long ftell(FILE* stream);
  62. extern int fseek(FILE* f, long offset, int whence);
  63. extern void rewind(FILE* f);