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

Function find_in_path

src/cli/cli.c:1130–1158  ·  view source on GitHub ↗

Search for an executable named `name` in the PATH environment variable. * Returns the full path in `out` (max out_sz) if found, else empty string. */

Source from the content-addressed store, hash-verified

1128/* Search for an executable named `name` in the PATH environment variable.
1129 * Returns the full path in `out` (max out_sz) if found, else empty string. */
1130static bool find_in_path(const char *name, char *out, size_t out_sz) {
1131 char path_copy[CLI_BUF_4K];
1132 if (!cbm_safe_getenv("PATH", path_copy, sizeof(path_copy), NULL)) {
1133 return false;
1134 }
1135 char *saveptr;
1136 char *dir = strtok_r(path_copy, PATH_DELIM, &saveptr);
1137 while (dir) {
1138 snprintf(out, out_sz, "%s/%s", dir, name);
1139 if (is_executable(out)) {
1140 return true;
1141 }
1142#ifdef _WIN32
1143 /* On Windows executables carry an extension (PATHEXT). A CLI like
1144 * opencode is often installed as a .cmd / .ps1 / .exe shim (e.g. via
1145 * mise or npm), so the bare-name probe above misses it (#221). Try the
1146 * common executable extensions before moving to the next PATH entry. */
1147 static const char *const win_exts[] = {".exe", ".cmd", ".bat", ".ps1", NULL};
1148 for (int i = 0; win_exts[i]; i++) {
1149 snprintf(out, out_sz, "%s/%s%s", dir, name, win_exts[i]);
1150 if (is_executable(out)) {
1151 return true;
1152 }
1153 }
1154#endif
1155 dir = strtok_r(NULL, PATH_DELIM, &saveptr);
1156 }
1157 return false;
1158}
1159
1160const char *cbm_find_cli(const char *name, const char *home_dir) {
1161 static CBM_TLS char buf[CLI_BUF_512];

Callers 2

cbm_find_cliFunction · 0.85
cbm_agent_cli_existsFunction · 0.85

Calls 2

cbm_safe_getenvFunction · 0.85
is_executableFunction · 0.85

Tested by

no test coverage detected