include sys stat include sys types include unistd include stdio includ

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
#include <sys/stat.h>
#include <sys/types.h>
#include <unistd.h>
#include <stdio.h>
#include <stdlib.h>
#define DIRNAME "dcache-test-dir"
int main(void) {
int i = 0;
char dir[1024];
getcwd(dir, sizeof(dir));
while (1) {
if (mkdir(DIRNAME, S_IRWXU) < 0) {
perror("Can't mkdir");
break;
}
if (chdir(DIRNAME) < 0) {
perror("Can't chdir");
break;
}
i++;
}
printf("Created/entered into %d directories!\n", i);
/* Cleanup */
chdir(dir);
system("rm -rf " DIRNAME);
return 1;
}