Commit Diff


commit - a1fd68d829c4e5eb0496107b9ac3d94968f81a8e
commit + f334529ed243c898cbf0cc8ee1058a769444f448
blob - 8f4ae1a3a30d63c209f8f08cd86d333b4b0fd863
blob + 59101dc2bb6cbc53f2bf0eb0f4f422fc393b595f
--- include/got_error.h
+++ include/got_error.h
@@ -15,7 +15,7 @@
  */
 
 /* 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
@@ -38,7 +38,7 @@ static const struct got_error {
 	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" },
@@ -59,3 +59,4 @@ static const struct got_error {
 };
 
 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
@@ -14,6 +14,10 @@
  * 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
@@ -30,5 +34,15 @@ got_error(int code)
 			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
@@ -284,7 +284,7 @@ got_object_open(struct got_object **obj, struct got_re
 	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
@@ -346,7 +346,7 @@ dump_packed_object(FILE **f, FILE *packfile, off_t off
 	}
 
 	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;
 	}
 
@@ -450,7 +450,7 @@ extract_object(FILE **f, const char *path_packdir,
 
 	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;
 	}
 
@@ -465,8 +465,8 @@ extract_object(FILE **f, const char *path_packdir,
 
 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;
 }
 
@@ -486,7 +486,7 @@ got_packfile_extract_object(FILE **f, struct got_objec
 
 	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;
 	}
 
@@ -517,7 +517,7 @@ got_packfile_extract_object(FILE **f, struct got_objec
 
 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;
 }