主要是冷气太足感冒了,加上少吃药抗药性差,全天昏迷,学傻了学傻了
cat t_chdir.c
#include <stdio.h>
#include <unistd.h>
#include <error.h>
#include <errno.h>
#include <sys/stat.h>int main(int argc,char *argv[])
{// ./t_chdir dir if(argc!=2){error(1,errno,"Usage:%s dir",argv[0]);}//打印当前工作目录char buf[128];printf("%s\n",getcwd(buf,128));//改变当前工作目录if(chdir(argv[1])==-1){error(1,errno,"chdir %s ",argv[1]);}printf("%s\n",getcwd(buf,128));return 0;
}
cat t_getcwd.c
#include <stdio.h>
#include <unistd.h>
#include <error.h>
#include <errno.h>int main(int argc,char *argv[])
{// ./t_getcwd//char buf[128];//char *cwd=getcwd(buf,128);char* cwd=getcwd(NULL,0);//如果传入的 buf为 NULL,且size为0//,则 getcwd 会调用 malloc 申请合适大小的内存空间,//填入当前工作目录的绝对路径//,然后返回alloc申请的空间的地址。if(!cwd){error(1,errno,"getcwd");}printf("%s\n",cwd);return 0;
}
cat t_mkdir.c
#include <stdio.h>
#include <unistd.h>
#include <error.h>
#include <errno.h>
#include <sys/stat.h>int main(int argc,char *argv[])
{// ./t_mkfir dir modeif(argc!=3){error(1,errno,"Usage:%s dir mode",argv[0]);}mode_t mode;sscanf(argv[2],"%o",&mode);if(mkdir(argv[1],mode)==-1){error(1,errno,"mkdir %s ",argv[1]);}return 0;
}
cat t_readdir.c
#include <func.h>int main(int argc,char *argv[])
{// ./t_readdir dir if(argc!=2){error(1,0,"Usage:%s dir mode",argv[0]);}//打开目录流DIR * dirp=opendir(argv[1]);if(dirp==NULL){error(1,errno,"opendir :%s ",argv[1]);}//依次读取每一个目录流errno=0;struct dirent *p;while((p=readdir(dirp))!=NULL){//打印目录项printf("d_ino=%ld ,d_off=%ld ,d_reclen=%hu ,d_type=%u ,d_name=%s\n",p->d_ino,p->d_off,p->d_reclen,p->d_type,p->d_name );}//p==NULLif(errno){error(0,errno,"readdir");}//关闭目录流closedir(dirp);return 0;
}
cat t_rmdir.c
#include <stdio.h>
#include <unistd.h>
#include <error.h>
#include <errno.h>
#include <sys/stat.h>int main(int argc,char *argv[])
{// ./t_rmfir dirif(argc!=2){error(1,errno,"Usage:%s dir mode",argv[0]);}if(rmdir(argv[1])==-1){error(1,errno,"rmdir %s ",argv[1]);}return 0;
}