diff options
| author | Laurent Bercot <ska-skaware@skarnet.org> | 2023-12-15 10:35:41 +0000 |
|---|---|---|
| committer | Laurent Bercot <ska@appnovation.com> | 2023-12-15 10:35:41 +0000 |
| commit | d2959364ef8d6bc948474a8facf497788b4e768b (patch) | |
| tree | e1459c1c94e9b7556c21c0b43d7144a162601b0a /src/tipideed/util.c | |
| parent | 66844097454a8f2b4eddec64d4f276602c4cdd3a (diff) | |
| download | tipidee-d2959364ef8d6bc948474a8facf497788b4e768b.tar.gz | |
Prepare for 0.0.3.0; add XXX_no_translate
Signed-off-by: Laurent Bercot <ska@appnovation.com>
Diffstat (limited to 'src/tipideed/util.c')
| -rw-r--r-- | src/tipideed/util.c | 29 |
1 files changed, 29 insertions, 0 deletions
diff --git a/src/tipideed/util.c b/src/tipideed/util.c new file mode 100644 index 0000000..2891306 --- /dev/null +++ b/src/tipideed/util.c @@ -0,0 +1,29 @@ +/* ISC license. */ + +#include <errno.h> +#include <string.h> + +#include <skalibs/stralloc.h> +#include <skalibs/djbunix.h> + +#include "tipideed-internal.h" + +size_t translate_path (char const *path) +{ + size_t n = g.sa.len ; + if (g.flagnoxlate) + { + if (!stralloc_readyplus(&g.sa, strlen(path) + 2)) return 0 ; + path_canonicalize(g.sa.s + n, path, 0) ; + return n ; + } + if (sarealpath(&g.sa, path) == -1 || !stralloc_0(&g.sa)) + { + g.sa.len = n ; + return 0 ; + } + g.sa.len = n ; + if (strncmp(g.sa.s + n, g.sa.s, g.cwdlen) || g.sa.s[n + g.cwdlen] != '/') + return (errno = EPERM, 0) ; + return n + g.cwdlen + 1 ; +} |
