From 0297e9db976aa2c3f17e237c6c5c37f3fde454a9 Mon Sep 17 00:00:00 2001 From: dzwdz Date: Sun, 8 Aug 2021 23:23:27 +0200 Subject: path_simplify now returns int, has better tests --- src/kernel/vfs/path.c | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) (limited to 'src/kernel/vfs/path.c') diff --git a/src/kernel/vfs/path.c b/src/kernel/vfs/path.c index 8662f03..bd17e29 100644 --- a/src/kernel/vfs/path.c +++ b/src/kernel/vfs/path.c @@ -1,9 +1,9 @@ #include #include -bool path_simplify(const char *in, char *out, size_t len) { - if (len == 0) return false; // empty paths are invalid - if (in[0] != '/') return false; // so are relative paths +int path_simplify(const char *in, char *out, size_t len) { + if (len == 0) return -1; // empty paths are invalid + if (in[0] != '/') return -1; // so are relative paths int depth = 0; int seg_len; // the length of the current path segment @@ -33,12 +33,12 @@ bool path_simplify(const char *in, char *out, size_t len) { } else if (seg_len == 2 && in[i + 1] == '.' && in[i + 2] == '.') { // the segment is /../ if (--depth < 0) - return false; + return -1; } else { // normal segment depth++; } } - return true; + return 1; // TODO } -- cgit v1.2.3