int get_cmd_path(const char cmd[], size_t path_len, char path[]) { if(starts_with(cmd, "!!")) { cmd += 2; } if(contains_slash(cmd)) { copy_str(path, path_len, cmd); return 0; } else { return find_cmd_in_path(cmd, path_len, path); } }
/* Checks whether executable exists at absolute path orin directories listed in * $PATH when path isn't absolute. Checks for various executable extensions on * Windows. Returns boolean value describing result of the check. */ static var_t executable_builtin(const call_info_t *call_info) { int exists; char *str_val; str_val = var_to_string(call_info->argv[0]); if(is_path_absolute(str_val)) { exists = executable_exists(str_val); } else { exists = (find_cmd_in_path(str_val, 0UL, NULL) == 0); } free(str_val); return exists ? var_true() : var_false(); }
/* Checks whether executable exists at absolute path orin directories listed in * $PATH when path isn't absolute. Checks for various executable extensions on * Windows. Returns boolean value describing result of the check. */ static var_t executable_builtin(const call_info_t *call_info) { int exists; char *str_val; str_val = var_to_string(call_info->argv[0]); if(strpbrk(str_val, PATH_SEPARATORS) != NULL) { exists = executable_exists(str_val); } else { exists = (find_cmd_in_path(str_val, 0UL, NULL) == 0); } free(str_val); return var_from_bool(exists); }