ReactOS Fundraising Campaign 2012
 
€ 4,410 / € 30,000

Information | Donate

Home | Info | Community | Development | myReactOS | Contact Us

  1. Home
  2. Community
  3. Development
  4. myReactOS
  5. Fundraiser 2012

  1. Main Page
  2. Alphabetical List
  3. Data Structures
  4. Directories
  5. File List
  6. Data Fields
  7. Globals
  8. Related Pages

ReactOS Development > Doxygen

rmkdir.c
Go to the documentation of this file.
00001 #include <stdio.h>
00002 #include <string.h>
00003 #include <stdlib.h>
00004 #include <sys/stat.h>
00005 #include <unistd.h>
00006 #include <ctype.h>
00007 
00008 #define DOS_PATH_CHAR   '\\'
00009 #define UNIX_PATH_CHAR  '/'
00010 
00011 #if defined (__DJGPP__) || defined (__WIN32__)
00012 #define DOS_PATHS
00013 #define PATH_CHAR       '\\'
00014 #define PATH_CHAR_STR   "\\"
00015 #else
00016 #define UNIX_PATHS
00017 #define PATH_CHAR       '/'
00018 #define PATH_CHAR_STR   "/"
00019 #endif
00020 
00021 void ConvertPathCharacters(char *Path)
00022 {
00023     int     i;
00024 
00025     i = 0;
00026     while (Path[i] != 0)
00027     {
00028         if (Path[i] == DOS_PATH_CHAR || Path[i] == UNIX_PATH_CHAR)
00029         {
00030             Path[i] = PATH_CHAR;
00031         }
00032 
00033         i++;
00034     }
00035 }
00036 
00037 int MakeDirectory(char *Directory)
00038 {
00039     char    CurrentDirectory[1024];
00040 
00041     getcwd(CurrentDirectory, 1024);
00042 
00043     if (chdir(Directory) == 0)
00044     {
00045         chdir(CurrentDirectory);
00046         return 0;
00047     }
00048 
00049 #if defined (UNIX_PATHS) || defined (__DJGPP__)
00050     if (mkdir(Directory, 0755) != 0)
00051     {
00052         perror("Failed to create directory");
00053         return 1;
00054     }
00055 #else
00056     if (mkdir(Directory) != 0)
00057     {
00058         perror("Failed to create directory");
00059         return 1;
00060     }
00061 #endif
00062 
00063     if (chdir(Directory) != 0)
00064     {
00065         perror("Failed to change directory");
00066         return 1;
00067     }
00068 
00069     chdir(CurrentDirectory);
00070 
00071     return 0;
00072 }
00073 
00074 int main(int argc, char* argv[])
00075 {
00076     if (argc != 2)
00077     {
00078         fprintf(stderr, "Wrong number of arguments\n");
00079         exit(1);
00080     }
00081 
00082     ConvertPathCharacters(argv[1]);
00083 
00084     return MakeDirectory(argv[1]);
00085 }

Generated on Sat May 26 2012 04:18:07 for ReactOS by doxygen 1.7.6.1

ReactOS is a registered trademark or a trademark of ReactOS Foundation in the United States and other countries.