資源簡介
LINUX下實(shí)現(xiàn)一個(gè)簡單的SHELL
代碼片段和文件信息
//#include
#include
#include
#include
#include
#include
#include
#include
#include
#define?BUFFERSIZE?80
char?buffer[BUFFERSIZE+1];
//extern?char?*get_current_dir_name(void);
//extern?char?*getenv(const?char?*name);
//extern?pid_t?waitpid(pid_t?pidint?*statusint?options);
int?is_fileexist(char?*comm)
{
? char?*path*p;
int?i;
i=0;
path=getenv(“PATH“);
p=path;
while(*p!=‘\0‘)
{
if(*p!=‘:‘)
buffer[i++]=*p;
else
{
buffer[i++]=‘/‘;
buffer[i]=‘\0‘;
strcat(buffercomm);
if(access(bufferF_OK)==0)
return?0;
else
i=0;
}
p++;
}
return?-1;
}
int?main()
{
char?*path;
??????//??int?BUFFERSIZE=20;
?// char?buffer[20];
評(píng)論
共有 條評(píng)論