Rev 8827 | Details | Compare with Previous | Last modification | View Log | RSS feed
Rev | Author | Line No. | Line |
---|---|---|---|
9173 | turbocat | 1 | extern int (*mkdir)(char*); |
1665 | Nasarus | 2 | |
8827 | rgimad | 3 | int cmd_mkdir(char dir[]) { |
9173 | turbocat | 4 | unsigned dir_len = strlen(dir); |
5 | if(!dir_len){ |
||
8827 | rgimad | 6 | printf(CMD_MKDIR_USAGE); |
7 | return TRUE; |
||
1665 | Nasarus | 8 | } |
9 | |||
9173 | turbocat | 10 | char *temp = malloc(dir_len+3); |
11 | char *dir_path = strdup(dir); |
||
12 | ksys_bdfe_t *bdfe = malloc(sizeof(ksys_bdfe_t)); |
||
13 | if(!dir_path || !temp || !bdfe){ |
||
8827 | rgimad | 14 | return FALSE; |
1665 | Nasarus | 15 | } |
9173 | turbocat | 16 | |
17 | if(dir[0]=='/' || dir[0]=='\\'){ |
||
18 | temp[0]='\0'; |
||
19 | }else{ |
||
20 | strcpy(temp,"."); |
||
21 | } |
||
1665 | Nasarus | 22 | |
9173 | turbocat | 23 | char *pch = strtok(dir_path,"\\/"); |
24 | |||
25 | while (pch != NULL){ |
||
26 | strcat(temp, "/"); |
||
27 | strcat(temp, pch); |
||
28 | if(_ksys_file_get_info(temp, bdfe)){ |
||
29 | if(mkdir(temp)){ |
||
30 | printf("\033[0;31;40m FAIL %s\n", temp); |
||
31 | }else { |
||
32 | printf("\033[0;32;40m OK %s\n", temp); |
||
33 | } |
||
34 | }else{ |
||
35 | printf("\033[0;33;40m EXIST %s\n", temp); |
||
36 | } |
||
37 | pch = strtok(NULL, "\\/"); |
||
1665 | Nasarus | 38 | } |
9173 | turbocat | 39 | printf("\033[0m"); |
40 | free(bdfe); |
||
41 | free(dir_path); |
||
42 | free(temp); |
||
43 | return TRUE; |
||
44 | } |