File.c 443 B

123456789101112131415161718192021222324252627282930313233
  1. #include <stdio.h>
  2. #include <stdlib.h>
  3. #include "tokenizer/File.h"
  4. static FILE* file = NULL;
  5. bool fOpen(const char* path) {
  6. file = fopen(path, "r");
  7. return file == NULL;
  8. }
  9. void fClose() {
  10. fclose(file);
  11. }
  12. int fRead() {
  13. return fgetc(file);
  14. }
  15. int fPeek() {
  16. int c = fRead();
  17. ungetc(c, file);
  18. return c;
  19. }
  20. bool fReadIf(int c) {
  21. if(fPeek() == c) {
  22. fRead();
  23. return true;
  24. }
  25. return false;
  26. }