Commit f7d20e8910435defc9367c68c5af4418123d088e

Stefan Sperling 2018-06-17T11:55:08

make got_canonpath() return a got_error

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);
 }