return EXIT_FAILURE;
}
-static int fsize(FILE *fp)
+static uint32_t fsize(FILE *fp)
{
- int size;
- int origin = ftell(fp);
+ int size, ret, origin;
+
+ origin = ftell(fp);
+ if (origin < 0) {
+ fprintf(stderr, "Incorrect file size\n");
+ fclose(fp);
+ exit(2);
+ }
+
+ ret = fseek(fp, 0L, SEEK_END);
+ if (ret) {
+ fprintf(stderr, "Incorrect file SEEK_END\n");
+ fclose(fp);
+ exit(3);
+ }
- fseek(fp, 0L, SEEK_END);
size = ftell(fp);
+ if (size < 0) {
+ fprintf(stderr, "Incorrect file size\n");
+ fclose(fp);
+ exit(4);
+ }
/* going back */
- fseek(fp, origin, SEEK_SET);
+ ret = fseek(fp, origin, SEEK_SET);
+ if (ret) {
+ fprintf(stderr, "Incorrect file SEEK_SET to %d\n", origin);
+ fclose(fp);
+ exit(3);
+ }
return size;
}