commit - a1fd68d829c4e5eb0496107b9ac3d94968f81a8e
commit + f334529ed243c898cbf0cc8ee1058a769444f448
blob - 8f4ae1a3a30d63c209f8f08cd86d333b4b0fd863
blob + 59101dc2bb6cbc53f2bf0eb0f4f422fc393b595f
--- include/got_error.h
+++ include/got_error.h
*/
/* Error codes */
-#define GOT_ERR_UNKNOWN 0
+#define GOT_ERR_ERRNO 0
#define GOT_ERR_NO_MEM 1
#define GOT_ERR_NOT_GIT_REPO 2
#define GOT_ERR_NOT_ABSPATH 3
int code;
const char *msg;
} got_errors[] = {
- { GOT_ERR_UNKNOWN, "unknown error" },
+ { GOT_ERR_ERRNO, "see errno" },
{ GOT_ERR_NO_MEM, "out of memory" },
{ GOT_ERR_NOT_GIT_REPO, "no git repository found" },
{ GOT_ERR_NOT_ABSPATH, "absolute path expected" },
};
const struct got_error * got_error(int code);
+const struct got_error *got_error_from_errno();
blob - ab4b7f6352abbd153affdbc7e9599f715ae8e6bf
blob + 5ad5f520105ec783ec3baffafba82f9b23fabcf7
--- lib/error.c
+++ lib/error.c
* OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
*/
+#include <errno.h>
+#include <stdlib.h>
+#include <string.h>
+
#include "got_error.h"
#ifndef nitems
return &got_errors[i];
}
- return &got_errors[GOT_ERR_UNKNOWN];
+ abort();
}
+
+const struct got_error *
+got_error_from_errno()
+{
+ static struct got_error err;
+
+ err.code = GOT_ERR_ERRNO;
+ err.msg = strerror(errno);
+ return &err;
+}
blob - 2beacfb382bf9e479a9039320ec767d7564a03da
blob + c0dae35c24f682c791d930ea7bd8df600884a950
--- lib/object.c
+++ lib/object.c
f = fopen(path, "rb");
if (f == NULL) {
if (errno != ENOENT) {
- err = got_error(GOT_ERR_BAD_PATH);
+ err = got_error_from_errno();
goto done;
}
err = got_packfile_extract_object(&f, id, repo);
blob - 6f0e06cbee2c22585c03b3bb96b3396835605179
blob + 9e1a9b8db3b262c35d1665c49b4a057dec9afc56
--- lib/pack.c
+++ lib/pack.c
}
if (fseeko(packfile, offset, SEEK_SET) != 0) {
- err = got_error(errno == EIO ? GOT_ERR_IO : GOT_ERR_BAD_PATH);
+ err = got_error_from_errno();
goto done;
}
packfile = fopen(path_packfile, "rb");
if (packfile == NULL) {
- err = got_error(errno == EIO ? GOT_ERR_IO : GOT_ERR_BAD_PATH);
+ err = got_error_from_errno();
goto done;
}
done:
free(path_packfile);
- if (packfile && fclose(packfile) == -1 && errno == EIO && err == 0)
- err = got_error(GOT_ERR_IO);
+ if (packfile && fclose(packfile) == -1 && err == 0)
+ err = got_error_from_errno();
return err;
}
packdir = opendir(path_packdir);
if (packdir == NULL) {
- err = got_error(errno == EIO ? GOT_ERR_IO : GOT_ERR_BAD_PATH);
+ err = got_error_from_errno();
goto done;
}
done:
free(path_packdir);
- if (packdir && closedir(packdir) != 0 && errno == EIO && err == 0)
- err = got_error(GOT_ERR_IO);
+ if (packdir && closedir(packdir) != 0 && err == 0)
+ err = got_error_from_errno();
return err;
}