filesize_check.c 688 B

123456789101112131415161718192021222324252627282930313233343536
  1. #if defined(_WIN32) || defined(_WIN64)
  2. #define _CRT_SECURE_NO_WARNINGS
  3. #endif
  4. #include <stdio.h>
  5. #include <stdlib.h>
  6. static long filesize(const char *const path)
  7. {
  8. FILE *const f = fopen(path, "rb");
  9. if (0 == f)
  10. {
  11. fprintf(stderr, "Bad file: %s\n", path);
  12. exit(1);
  13. }
  14. fseek(f, 0, SEEK_END);
  15. const long sz = (unsigned)ftell(f);
  16. fclose(f);
  17. return sz;
  18. }
  19. int main(int argc, const char *argv[])
  20. {
  21. if (2 >= argc)
  22. {
  23. fprintf(stderr, "Usage: prog f1_path f2_path\n");
  24. return 1;
  25. }
  26. const long f1_sz = filesize(argv[1]);
  27. const long f2_sz = filesize(argv[2]);
  28. if (f1_sz < f2_sz)
  29. {
  30. fprintf(stderr, "New size is larger: %li < %li\n", f1_sz, f2_sz);
  31. return 1;
  32. }
  33. return 0;
  34. }