make got_canonpath() return a got_error
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46
diff --git a/lib/got_lib_path.h b/lib/got_lib_path.h
index 435ee1d..af17675 100644
--- a/lib/got_lib_path.h
+++ b/lib/got_lib_path.h
@@ -39,4 +39,4 @@ char *got_path_normalize(const char *);
* and resolving references to parent directories ("/../").
* Relative paths are copied from input to buf as-is.
*/
-int got_canonpath(const char *input, char *buf, size_t bufsize)
+const struct got_error *got_canonpath(const char *, char *, size_t);
diff --git a/lib/path.c b/lib/path.c
index fa26c7a..d14f81c 100644
--- a/lib/path.c
+++ b/lib/path.c
@@ -64,8 +64,8 @@ got_path_normalize(const char *path)
return resolved;
}
-/* canonpath() from kern_pledge.c */
-int
+/* based on canonpath() from kern_pledge.c */
+const struct got_error *
got_canonpath(const char *input, char *buf, size_t bufsize)
{
const char *p;
@@ -74,8 +74,8 @@ got_canonpath(const char *input, char *buf, size_t bufsize)
/* can't canon relative paths, don't bother */
if (!got_path_is_absolute(input)) {
if (strlcpy(buf, input, bufsize) >= bufsize)
- return ENAMETOOLONG;
- return 0;
+ return got_error(GOT_ERR_NO_SPACE);
+ return NULL;
}
p = input;
@@ -101,7 +101,7 @@ got_canonpath(const char *input, char *buf, size_t bufsize)
}
if ((*p == '\0') && (q - buf < bufsize)) {
*q = 0;
- return 0;
+ return NULL;
} else
- return ENAMETOOLONG;
+ return got_error(GOT_ERR_NO_SPACE);
}