commit - 72bcf0f9f354aa395c61c7846287a7af638554a2
commit + 8251fdbcd71582c610ee8e416cae5c67e4f93796
blob - 59101dc2bb6cbc53f2bf0eb0f4f422fc393b595f
blob + 65bbcded88384d5d5c7e151f84e6271868044a5d
--- include/got_error.h
+++ include/got_error.h
const struct got_error * got_error(int code);
const struct got_error *got_error_from_errno();
+const struct got_error *got_ferror(FILE *, int);
blob - 183e6da09dee8316f23a8ae9c65b57dffa7c7886
blob + d3b27c7b3c12ab39f0d540327d2e92a792b03eda
--- lib/error.c
+++ lib/error.c
*/
#include <errno.h>
+#include <stdio.h>
#include <stdlib.h>
#include <string.h>
strerror_r(errno, msg, sizeof(msg));
return &err;
}
+
+const struct got_error *
+got_ferror(FILE *f, int code)
+{
+ if (ferror(f))
+ return got_error_from_errno();
+ return got_error(code);
+}
blob - 9e1a9b8db3b262c35d1665c49b4a057dec9afc56
blob + 8519e443701a5f873894589949d2854b5a2e04ec
--- lib/pack.c
+++ lib/pack.c
if (stat(path_pack, &sb) != 0) {
free(path_pack);
- return got_error(GOT_ERR_IO);
-
+ return got_error_from_errno();
}
free(path_pack);
n = fread(&p->magic, sizeof(p->magic), 1, f);
if (n != 1) {
- err = got_error(ferror(f) ? GOT_ERR_IO : GOT_ERR_BAD_PACKIDX);
+ err = got_ferror(f, GOT_ERR_BAD_PACKIDX);
goto done;
}
n = fread(&p->version, sizeof(p->version), 1, f);
if (n != 1) {
- err = got_error(ferror(f) ? GOT_ERR_IO : GOT_ERR_BAD_PACKIDX);
+ err = got_ferror(f, GOT_ERR_BAD_PACKIDX);
goto done;
}
n = fread(&p->fanout_table, sizeof(p->fanout_table), 1, f);
if (n != 1) {
- err = got_error(ferror(f) ? GOT_ERR_IO : GOT_ERR_BAD_PACKIDX);
+ err = got_ferror(f, GOT_ERR_BAD_PACKIDX);
goto done;
}
n = fread(p->sorted_ids, sizeof(*p->sorted_ids), nobj, f);
if (n != nobj) {
- err = got_error(ferror(f) ? GOT_ERR_IO : GOT_ERR_BAD_PACKIDX);
+ err = got_ferror(f, GOT_ERR_BAD_PACKIDX);
goto done;
}
n = fread(p->crc32, sizeof(*p->crc32), nobj, f);
if (n != nobj) {
- err = got_error(ferror(f) ? GOT_ERR_IO : GOT_ERR_BAD_PACKIDX);
+ err = got_ferror(f, GOT_ERR_BAD_PACKIDX);
goto done;
}
n = fread(p->offsets, sizeof(*p->offsets), nobj, f);
if (n != nobj) {
- err = got_error(ferror(f) ? GOT_ERR_IO : GOT_ERR_BAD_PACKIDX);
+ err = got_ferror(f, GOT_ERR_BAD_PACKIDX);
goto done;
}
n = fread(p->large_offsets, sizeof(*p->large_offsets), nobj, f);
if (n != nobj) {
- err = got_error(ferror(f) ? GOT_ERR_IO : GOT_ERR_BAD_PACKIDX);
+ err = got_ferror(f, GOT_ERR_BAD_PACKIDX);
goto done;
}
checksum:
n = fread(&p->trailer, sizeof(p->trailer), 1, f);
if (n != 1) {
- err = got_error(ferror(f) ? GOT_ERR_IO : GOT_ERR_BAD_PACKIDX);
+ err = got_ferror(f, GOT_ERR_BAD_PACKIDX);
goto done;
}
n = fread(&hdr, sizeof(hdr), 1, f);
if (n != 1)
- return got_error(ferror(f) ? GOT_ERR_IO : GOT_ERR_BAD_PACKFILE);
+ return got_ferror(f, GOT_ERR_BAD_PACKIDX);
if (betoh32(hdr.signature) != GOT_PACKFILE_SIGNATURE ||
betoh32(hdr.version) != GOT_PACKFILE_VERSION ||
n = fread(&sizeN, sizeof(sizeN), 1, packfile);
if (n != 1) {
- err = got_error(ferror(packfile) ?
- GOT_ERR_IO : GOT_ERR_BAD_PACKFILE);
+ err = got_ferror(packfile, GOT_ERR_BAD_PACKIDX);
goto done;
}
+
if (i == 0) {
type = (sizeN & GOT_PACK_OBJ_SIZE0_TYPE_MASK) >>
GOT_PACK_OBJ_SIZE0_TYPE_MASK_SHIFT;
n = fread(data, len, 1, packfile);
if (n != 1) {
- err = got_error(ferror(packfile) ?
- GOT_ERR_IO : GOT_ERR_BAD_PACKFILE);
+ err = got_ferror(packfile, GOT_ERR_BAD_PACKIDX);
goto done;
}
n = fwrite(data, len, 1, *f);
if (n != 1) {
- err = got_error(ferror(*f) ?
- GOT_ERR_IO : GOT_ERR_BAD_PACKFILE);
+ err = got_ferror(*f, GOT_ERR_BAD_PACKIDX);
goto done;
}