file.c 715 B

123456789101112131415161718192021222324252627282930313233
  1. #include <uefi.h>
  2. /**
  3. * Display file contents
  4. */
  5. int main(int argc, char **argv)
  6. {
  7. (void)argc;
  8. (void)argv;
  9. FILE *f;
  10. char *buff;
  11. long int size;
  12. if((f = fopen("\\05_file\\file.txt", "r"))) {
  13. fseek(f, 0, SEEK_END);
  14. size = ftell(f);
  15. fseek(f, 0, SEEK_SET);
  16. printf("File size: %d bytes\n", size);
  17. buff = malloc(size + 1);
  18. if(!buff) {
  19. fprintf(stderr, "unable to allocate memory\n");
  20. return 1;
  21. }
  22. fread(buff, size, 1, f);
  23. buff[size] = 0;
  24. fclose(f);
  25. printf("File contents:\n%s\n", buff);
  26. free(buff);
  27. } else
  28. fprintf(stderr, "Unable to open file\n");
  29. return 0;
  30. }