|
发表于 2004-5-24 21:41:12
|
显示全部楼层
re
我那完整的找不到了,给你片段救救急,这个星期六若实在找不到,我就写个完整的,这是当年模仿shell的部分C程序,写得不好!如没有判断文件是否存在等等。
1 修改文件权限
[php]
#include <sys/types.h>
#include <sys/stat.h>
int main(int argc,char *argv[])
{
if(argc<2)
{
printf("请指定文件名\n");
exit(255);
}
else
{
chmod(argv[1],S_IRUSR|S_IWUSR|S_IRGRP|S_IROTH);
}
return 0;
}
[/php]
2 切换目录
[php]
#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>
#include <unistd.h>
int main(int argc,char *argv[])
{
int fd;
fd = opendir(argv[1]);
if(fd<0)
{
printf("切换目录失败\n");
exit(255);
}
else
{
fchdir(fd);
}
}
[/php] |
|