f_string_t fixed_arguments[arguments.used + 2];
const f_string_t last_slash = strrchr(program ? program : arguments.array[0].string, f_path_separator_s[0]);
- const f_array_length_t name_size = last_slash ? strnlen(last_slash, f_path_length_max) : strnlen(program ? program : arguments.array[0].string, f_path_length_max);
+ const f_array_length_t name_size = last_slash ? strnlen(last_slash + 1, f_path_length_max) : strnlen(program ? program : arguments.array[0].string, f_path_length_max);
char program_name[name_size + 1];
program_name[name_size] = 0;
- private_fll_execute_path_arguments_fixate(last_slash ? last_slash : program ? program : arguments.array[0].string, arguments, !program, name_size, program_name, fixed_arguments);
+ private_fll_execute_path_arguments_fixate(program ? program : arguments.array[0].string, arguments, last_slash, !program, name_size, program_name, fixed_arguments);
- const int code = option & fl_execute_parameter_option_path ? execv(program, fixed_arguments) : execvp(program, fixed_arguments);
+ const int code = option & fl_execute_parameter_option_path ? execv(program ? program : arguments.array[0].string, fixed_arguments) : execvp(program ? program : arguments.array[0].string, fixed_arguments);
// generally this does not return, but in some cases (such as with scripts) this does return so handle the results.
if (result) {
f_string_t fixed_arguments[arguments.used + 2];
const f_string_t last_slash = strrchr(program ? program : arguments.array[0].string, f_path_separator_s[0]);
- const f_array_length_t name_size = last_slash ? strnlen(last_slash, f_path_length_max) : strnlen(program ? program : arguments.array[0].string, f_path_length_max);
+ const f_array_length_t size_name = last_slash ? strnlen(last_slash + 1, f_path_length_max) : strnlen(program ? program : arguments.array[0].string, f_path_length_max);
- char program_name[name_size + 1];
-
- program_name[name_size] = 0;
+ char program_name[size_name + 1];
- private_fll_execute_path_arguments_fixate(last_slash ? last_slash : program ? program : arguments.array[0].string, arguments, !program, name_size, program_name, fixed_arguments);
+ private_fll_execute_path_arguments_fixate(program ? program : arguments.array[0].string, arguments, last_slash, !program, size_name, program_name, fixed_arguments);
// when the environment is to be cleared, a full path must be used.
if (parameter && !(parameter->option & fl_execute_parameter_option_path) && parameter->environment) {
f_string_dynamic_t path = f_string_dynamic_t_initialize;
f_string_dynamics_t paths = f_string_dynamics_t_initialize;
+ f_string_dynamic_t *found = 0;
- f_status_t status = f_environment_get(f_path_environment_s, &path);
+ f_status_t status = F_none;
- if (F_status_is_error(status)) {
+ if (last_slash) {
+ status = f_file_exists(program ? program : arguments.array[0].string);
- // Do not consider PATH is not available (or valid?) to be an error.
- if (F_status_set_fine(status) == F_valid_not || F_status_set_fine(status) == F_failure) {
- status = F_none;
+ if (status != F_true) {
+ f_macro_string_dynamics_t_delete_simple(paths);
+
+ return F_status_set_error(F_file_found_not);
}
+
+ path.string = program ? program : arguments.array[0].string;
+ path.used = strnlen(program ? program : arguments.array[0].string, f_path_length_max);
+ found = &path;
}
else {
- status = fl_environment_path_explode_dynamic(path, &paths);
- }
+ status = f_environment_get(f_path_environment_s, &path);
- f_macro_string_dynamic_t_delete_simple(path);
-
- if (F_status_is_error(status)) {
- f_macro_string_dynamics_t_delete_simple(paths);
- return status;
- }
+ if (F_status_is_error(status)) {
- f_string_dynamic_t *found = 0;
+ // Do not consider PATH is not available (or valid?) to be an error.
+ if (F_status_set_fine(status) == F_valid_not || F_status_set_fine(status) == F_failure) {
+ status = F_none;
+ }
+ }
+ else {
+ status = fl_environment_path_explode_dynamic(path, &paths);
+ }
- for (f_array_length_t i = 0; i < paths.used; i++) {
+ f_macro_string_dynamic_t_delete_simple(path);
- status = f_string_append(program_name, name_size, &paths.array[i]);
+ if (F_status_is_error(status)) {
+ f_macro_string_dynamics_t_delete_simple(paths);
- if (F_status_is_error_not(status)) {
- status = f_string_dynamic_terminate(&paths.array[i]);
+ return status;
}
- if (F_status_is_error_not(status)) {
- status = f_file_exists(paths.array[i].string);
+ for (f_array_length_t i = 0; i < paths.used; ++i) {
- if (status == F_true) {
- found = &paths.array[i];
- break;
+ status = f_string_append(program_name, size_name, &paths.array[i]);
+
+ if (F_status_is_error_not(status)) {
+ status = f_string_dynamic_terminate_after(&paths.array[i]);
}
- if (F_status_is_error(status)) {
- status = F_status_set_fine(status);
+ if (F_status_is_error_not(status)) {
+ status = f_file_exists(paths.array[i].string);
- // don't consider bad/non-accessible paths an error, just ignore them.
- if (status == F_name) {
- continue;
- }
- else if (status == F_directory) {
- continue;
+ if (status == F_true) {
+ found = &paths.array[i];
+
+ break;
}
- else if (status == F_access_denied) {
- continue;
+
+ if (F_status_is_error(status)) {
+ status = F_status_set_fine(status);
+
+ // don't consider bad/non-accessible paths an error, just ignore them.
+ if (status == F_name) {
+ continue;
+ }
+ else if (status == F_directory) {
+ continue;
+ }
+ else if (status == F_access_denied) {
+ continue;
+ }
}
}
- }
- if (F_status_is_error(status)) {
- f_macro_string_dynamics_t_delete_simple(paths);
+ if (F_status_is_error(status)) {
+ f_macro_string_dynamics_t_delete_simple(paths);
- return status;
- }
- } // for
+ return status;
+ }
+ } // for
- if (!found) {
- f_macro_string_dynamics_t_delete_simple(paths);
+ if (!found) {
+ f_macro_string_dynamics_t_delete_simple(paths);
- return F_status_set_error(F_file_found_not);
+ return F_status_set_error(F_file_found_not);
+ }
}
- char program_path[found->used];
+ char program_path[found->used + 1];
+ program_path[found->used] = 0;
memcpy(&program_path, found->string, found->used);
}
if (parameter && parameter->data) {
- return private_fll_execute_fork_data(program, fixed_arguments, parameter, as, result);
+ return private_fll_execute_fork_data(program ? program : arguments.array[0].string, fixed_arguments, parameter, as, result);
}
- return private_fll_execute_fork(program, fixed_arguments, parameter, as, result);
+ return private_fll_execute_fork(program ? program : arguments.array[0].string, fixed_arguments, parameter, as, result);
}
#endif // _di_fll_execute_program_
#endif // !defined(_di_fll_execute_program_)
#if !defined(_di_fll_execute_program_)
- void private_fll_execute_path_arguments_fixate(const f_string_t program_path, const f_string_statics_t arguments, const bool fixated_is, const f_array_length_t name_size, char program_name[], f_string_t fixed_arguments[]) {
+ void private_fll_execute_path_arguments_fixate(const f_string_t program_path, const f_string_statics_t arguments, const f_string_t last_slash, const bool fixated_is, const f_array_length_t name_size, char program_name[], f_string_t fixed_arguments[]) {
- memcpy(program_name, program_path, name_size);
- program_name[name_size] = 0;
+ memset(program_name, 0, name_size + 1);
+ memset(fixed_arguments, 0, sizeof(f_string_t) * (arguments.used + 2));
+ memcpy(program_name, last_slash ? last_slash + 1 : program_path, name_size);
if (name_size) {
fixed_arguments[0] = program_name;
}
- else {
- fixed_arguments[0] = 0;
- }
-
- f_array_length_t i = 0;
if (fixated_is) {
- for (i = 1; i < arguments.used; ++i) {
+ for (f_array_length_t i = 1; i < arguments.used; ++i) {
fixed_arguments[i] = arguments.array[i].string;
} // for
}
else {
- for (; i < arguments.used; ++i) {
+ for (f_array_length_t i = 0; i < arguments.used; ++i) {
fixed_arguments[i + 1] = arguments.array[i].string;
} // for
-
- i++;
}
-
- // insert the required end of array designator.
- fixed_arguments[i] = 0;
}
#endif // !defined(_di_fll_execute_program_)