MCPcopy Create free account
hub / github.com/F-Stack/f-stack / fsize_orDie

Function fsize_orDie

freebsd/contrib/zstd/examples/common.h:71–91  ·  view source on GitHub ↗

! fsize_orDie() : * Get the size of a given file path. * * @return The size of a given file path. */

Source from the content-addressed store, hash-verified

69 * @return The size of a given file path.
70 */
71static 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.

Callers 3

createResources_orDieFunction · 0.85
loadFile_orDieFunction · 0.85
mallocAndLoadFile_orDieFunction · 0.85

Calls 1

statClass · 0.70

Tested by

no test coverage detected