stdio.h 2.1 KB

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