我正在尝试做简单的 shell 作为对自己的练习。我正在编写一个函数,它应该在 PATH 中找到一个可执行文件,并返回一个指向字符串的指针,该字符串包含可执行文件的完整路径。这是我到目前为止所拥有的;
/*bunch of includes here*/
/*
* Find executable in path, return NULL
* if can't find.
*/
char *find_executable(char *command)
{
const char *PATH = getenv("PATH");
DIR *dp;
/* get each pathname, and try to find executable in there. */
}
int main(int argc,char *argv[])
{ /* nothing intersting here ...*/
}
我想知道我应该如何分隔路径的每个部分,并在 for 循环中处理这些部分。