kolibrios-gitea/programs/system/shell/cmd/cmd_mkdir.c
turbocat 1a5f178264 SHELL 0.8.3:
- Added the ability to create  parent directories if needed( "mkdir" command)

git-svn-id: svn://kolibrios.org@9173 a494cfbc-eb01-0410-851d-a64ba20cac60
2021-09-02 21:20:12 +00:00

44 lines
886 B
C

extern int (*mkdir)(char*);
int cmd_mkdir(char dir[]) {
unsigned dir_len = strlen(dir);
if(!dir_len){
printf(CMD_MKDIR_USAGE);
return TRUE;
}
char *temp = malloc(dir_len+3);
char *dir_path = strdup(dir);
ksys_bdfe_t *bdfe = malloc(sizeof(ksys_bdfe_t));
if(!dir_path || !temp || !bdfe){
return FALSE;
}
if(dir[0]=='/' || dir[0]=='\\'){
temp[0]='\0';
}else{
strcpy(temp,".");
}
char *pch = strtok(dir_path,"\\/");
while (pch != NULL){
strcat(temp, "/");
strcat(temp, pch);
if(_ksys_file_get_info(temp, bdfe)){
if(mkdir(temp)){
printf("\033[0;31;40m FAIL %s\n", temp);
}else {
printf("\033[0;32;40m OK %s\n", temp);
}
}else{
printf("\033[0;33;40m EXIST %s\n", temp);
}
pch = strtok(NULL, "\\/");
}
printf("\033[0m");
free(bdfe);
free(dir_path);
free(temp);
return TRUE;
}