/** * @file test_exec.c * @brief exec テスト * @author Nomura Kei * @copyright 2008 Nomura Kei */ #include <stdio.h> #include <stdlib.h> #include <errno.h> #include <sys/types.h> #include <sys/wait.h> #include <filetype.h> #include <test_lock.h> /** * 指定されたパスを実行します。 * * @param pathname パス * @return true/false (実行成功/実行失敗) */ bool can_exec(const char* pathname) { // パス存在有無確認 (しない場合 NG) bool is_error = !is_exists(pathname); if (is_error) { errno = ENOENT; return false; } // 実行 int ret = system(pathname); if (ret == -1) { // 実行エラー return false; } bool is_success = (WIFEXITED(ret) && (WEXITSTATUS(ret) == 0)); return is_success; }