1 #include <stdio.h> 2 #include <string.h> 3 #include <stdlib.h> 4 #include <sys/stat.h> 5 #include <unistd.h> 6 #include <ctype.h> 7 8 #define DOS_PATH_CHAR '\\' 9 #define UNIX_PATH_CHAR '/' 10 11 #if defined (__DJGPP__) || defined (__WIN32__) 12 #define DOS_PATHS 13 #define PATH_CHAR '\\' 14 #define PATH_CHAR_STR "\\" 15 #else 16 #define UNIX_PATHS 17 #define PATH_CHAR '/' 18 #define PATH_CHAR_STR "/" 19 #endif 20 21 void ConvertPathCharacters(char *Path) 22 { 23 int i; 24 25 i = 0; 26 while (Path[i] != 0) 27 { 28 if (Path[i] == DOS_PATH_CHAR || Path[i] == UNIX_PATH_CHAR) 29 { 30 Path[i] = PATH_CHAR; 31 } 32 33 i++; 34 } 35 } 36 37 int MakeDirectory(char *Directory) 38 { 39 char CurrentDirectory[1024]; 40 41 getcwd(CurrentDirectory, 1024); 42 43 if (chdir(Directory) == 0) 44 { 45 chdir(CurrentDirectory); 46 return 0; 47 } 48 49 #if defined (UNIX_PATHS) || defined (__DJGPP__) 50 if (mkdir(Directory, 0755) != 0) 51 { 52 perror("Failed to create directory"); 53 return 1; 54 } 55 #else 56 if (mkdir(Directory) != 0) 57 { 58 perror("Failed to create directory"); 59 return 1; 60 } 61 #endif 62 63 if (chdir(Directory) != 0) 64 { 65 perror("Failed to change directory"); 66 return 1; 67 } 68 69 chdir(CurrentDirectory); 70 71 return 0; 72 } 73 74 int main(int argc, char* argv[]) 75 { 76 if (argc != 2) 77 { 78 fprintf(stderr, "Wrong number of arguments\n"); 79 exit(1); 80 } 81 82 ConvertPathCharacters(argv[1]); 83 84 return MakeDirectory(argv[1]); 85 } 86