MCPcopy Create free account
hub / github.com/DeusData/codebase-memory-mcp / cbm_open_directory_component

Function cbm_open_directory_component

src/foundation/compat_fs.c:1093–1124  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

1091}
1092
1093static int cbm_open_directory_component(int parent, const char *component, int flags,
1094 bool follow_owned) {
1095 int descriptor = openat(parent, component, flags);
1096#if defined(O_NOFOLLOW) && defined(AT_SYMLINK_NOFOLLOW)
1097 if (descriptor < 0) {
1098 /* The caller decides on errno from the FIRST open (ENOENT means
1099 * "create it"); a refused link must not leak a later call's errno. */
1100 int open_errno = errno;
1101 char text[CBM_SZ_4K];
1102 if (cbm_read_trusted_link(parent, component, follow_owned, text, sizeof(text))) {
1103 /* The judged link's own text, resolved from the parent exactly as
1104 * the kernel would resolve it (relative texts against the link's
1105 * directory). Links inside the text are resolved by the kernel as
1106 * before; the target check bounds where the walk lands. */
1107 int followed = openat(parent, text, flags & ~O_NOFOLLOW);
1108 struct stat target;
1109 if (followed >= 0 && fstat(followed, &target) == 0 &&
1110 cbm_walk_target_trusted(&target)) {
1111 descriptor = followed;
1112 } else if (followed >= 0) {
1113 (void)close(followed);
1114 }
1115 }
1116 if (descriptor < 0) {
1117 errno = open_errno;
1118 }
1119 }
1120#else
1121 (void)follow_owned;
1122#endif
1123 return descriptor;
1124}
1125
1126bool cbm_mkdir_p(const char *path, int mode) {
1127 return cbm_mkdir_p_ex(path, mode, 0U);

Callers 1

cbm_mkdir_p_exFunction · 0.85

Calls 3

cbm_read_trusted_linkFunction · 0.85
cbm_walk_target_trustedFunction · 0.85
closeFunction · 0.50

Tested by

no test coverage detected