18#ifndef PROTOCORE_FS_PATH_H
19#define PROTOCORE_FS_PATH_H
29inline bool fs_path_join(
const char *root,
const char *sub,
char *out,
size_t cap)
31 size_t rlen = strnlen(root, cap);
32 bool root_slash = (rlen > 0 && root[rlen - 1] ==
'/');
33 if (root_slash && sub[0] ==
'/')
37 bool sub_slash = (sub[0] ==
'/');
38 const char *sep = (root_slash || sub_slash) ?
"" :
"/";
39 pc_sb sb_out = {out, cap, 0,
true};
50 return wn > 0 && wn < (int)cap;
58inline int fs_path_resolve(
const char *root,
const char *sub,
char *out,
size_t cap)
60 if (strstr(sub,
".."))
68 size_t fpl = strnlen(out, cap);
69 if (fpl > 1 && out[fpl - 1] ==
'/')
bool fs_path_join(const char *root, const char *sub, char *out, size_t cap)
Join a filesystem root and a sub path into out, normalizing the separator.
int fs_path_resolve(const char *root, const char *sub, char *out, size_t cap)
Resolve a mount root + a request sub path to an on-disk path in out: reject any .....
User-facing configuration for ProtoCore.
Bounded no-heap string builder that fails closed on overflow (one shared copy).
size_t pc_sb_finish(pc_sb *b)
NUL-terminate and return the built length, or 0 if the build overflowed.
void pc_sb_put(pc_sb *b, const char *s)
Append NUL-terminated s; leaves the buffer untouched and clears ok if it would not fit.
Bump-append target; ok latches false once an append would overflow cap.