如果文件夹abc123在当前目录已经存在,再次使用mkdir函数在该目录创建,则返回-1。
#include <stdio.h>
#include <sys/stat.h>
#include <sys/types.h>
#include <time.h>
#include <stdlib.h>
#include <string.h>
#include <unistd.h>
int main()
{
char dirname[]="abc123";
int ret1 = -1;
int ret2 = -1;
ret1 = mkdir(dirname,0777);
sleep(5);
ret2 = mkdir(dirname,0777);
printf("\n ret1[%d] ret2[%d] \n",ret1,ret2);
return 0;
}
-bash-3.2$
-bash-3.2$ gcc csdn2017-4-24.c
-bash-3.2$
-bash-3.2$ ./a.out
ret1[0] ret2[-1]
-bash-3.2$
drwxr-xr-x 2 zhouzhenhe zhouzhenhe 4096 04-24 13:34 abc123
-rwxr-xr-x 1 zhouzhenhe zhouzhenhe 7071 04-24 13:34 a.out
-rwxr--r-- 1 zhouzhenhe zhouzhenhe 393 04-24 11:35 csdn2017-4-24.c
-rwxr--r-- 1 zhouzhenhe zhouzhenhe 1480 03-24 15:40 test.c