! fsize_orDie() : * Get the size of a given file path. * * @return The size of a given file path. */
| 69 | * @return The size of a given file path. |
| 70 | */ |
| 71 | static size_t fsize_orDie(const char *filename) |
| 72 | { |
| 73 | struct stat st; |
| 74 | if (stat(filename, &st) != 0) { |
| 75 | /* error */ |
| 76 | perror(filename); |
| 77 | exit(ERROR_fsize); |
| 78 | } |
| 79 | |
| 80 | off_t const fileSize = st.st_size; |
| 81 | size_t const size = (size_t)fileSize; |
| 82 | /* 1. fileSize should be non-negative, |
| 83 | * 2. if off_t -> size_t type conversion results in discrepancy, |
| 84 | * the file size is too large for type size_t. |
| 85 | */ |
| 86 | if ((fileSize < 0) || (fileSize != (off_t)size)) { |
| 87 | fprintf(stderr, "%s : filesize too large \n", filename); |
| 88 | exit(ERROR_largeFile); |
| 89 | } |
| 90 | return size; |
| 91 | } |
| 92 | |
| 93 | /*! fopen_orDie() : |
| 94 | * Open a file using given file path and open option. |
no test coverage detected