aboutsummaryrefslogtreecommitdiffstats
path: root/safepath.c
diff options
context:
space:
mode:
Diffstat (limited to 'safepath.c')
-rw-r--r--safepath.c21
1 files changed, 21 insertions, 0 deletions
diff --git a/safepath.c b/safepath.c
index ba4996c..862b5ed 100644
--- a/safepath.c
+++ b/safepath.c
@@ -337,6 +337,27 @@ out:
return ret;
}
+const char *safepath_strerr(int err)
+{
+ const char *str[] = {
+ [SAFEPATH_OK] = "path appears safe",
+ [SAFEPATH_UNSAFE] = "path contains untrusted component",
+ [SAFEPATH_PERM] = "path contains inaccessible component",
+ [SAFEPATH_NOENT] = "path contains nonexistent component",
+ [SAFEPATH_INVAL] = "path is syntactically invalid",
+ [SAFEPATH_NOMEM] = "out of memory",
+ [SAFEPATH_LOOP] = "too many symlink resolutions"
+ };
+ const char *ret = "SAFEPATH_BAD_ERROR_CODE";
+
+ if (err >= 0 && err <= (int) (sizeof str / sizeof str[0]) && str[err] != 0)
+ {
+ ret = str[err];
+ }
+
+ return ret;
+}
+
int safepath_open(const char *name, int flags)
{
int res = safepath_check(name);