mkdir
rmdir
权限位
#include <stdio.h>
#include <stdlib.h>
#include <sys/stat.h>
int main(int argc, char argv[])
{
char * buf = "./a";
int isCreat = mkdir(buf, 0777);
if (!isCreat)
{
printf("creat path %s\n", buf);
}
else
{
printf("Error creat %s\n", buf);
}
exit(EXIT_SUCCESS);
}
第二版
/*
Linux API:mkdir
实现输入文件名字,创建文件
*/
#include <stdio.h>
#include <stdlib.h>
#include <sys/stat.h>
#include <unistd.h>
#define MODE (S_IRWXU | S_IWGRP | S_IWOTH)
int main(int argc, char *argv[])
{
char path[10] = {};
scanf("%s", path);
int isCreat = mkdir(path, MODE);
if (isCreat < 0)
{
perror("Error mkdir");
exit(EXIT_FAILURE);
}
puts("mkdir success:");
system("ls -al");
int temp = 0;
temp = rmdir(path);
if (temp < 0)
{
perror("rmdir Error");
exit(EXIT_FAILURE);
}
puts("rmdir success:");
system("ls -al");
//free(path); // 数组不需要free
exit(EXIT_SUCCESS);
}
makefile
cshell:code.o
gcc -o cshell code.o
code.o:code.c
gcc -c code.c
.PHONY: clean
clean:
rm -f *.o
rm -f cshell