Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00011 #include <fvar.hpp>
00012 #include <adstring.hpp>
00013
00014 #include <stdlib.h>
00015 #if !defined(_MSC_VER)
00016 #include <dirent.h>
00017 #include <sys/stat.h>
00018 #endif
00019 #if defined(__BORLANDC__)
00020 # include <dir.h>
00021 #endif
00022 #if defined(_WIN32)
00023 # include <windows.h>
00024 #else
00025 # include <unistd.h>
00026 #endif
00027
00028 #if !defined(_MSC_VER)
00029 #include <iostream>
00030 using namespace std;
00031 #include <memory.h>
00032 #include <fcntl.h>
00033 #include <sys/stat.h>
00034 #include <sys/types.h>
00035 #include <unistd.h>
00036 #endif
00037
00038 #include <cassert>
00039
00044 int ad_chdir(const char * s)
00045 {
00046 #if defined(_WIN32)
00047 return SetCurrentDirectory(s);
00048 #else
00049 return chdir(s);
00050 #endif
00051 }
00052
00057 void ad_getcd(const adstring& _s)
00058 {
00059 adstring& s=(adstring&) (_s);
00060 #if defined(_WIN32)
00061 char tmp[301];
00062 tmp[0]='\0';
00063 GetCurrentDirectory(300,tmp);
00064 s=tmp;
00065 #else
00066 char tmp[301];
00067 tmp[0]='\0';
00068 #ifdef __GNUC__
00069 char* ret = getcwd(tmp,300);
00070 assert(ret != 0);
00071 #else
00072 getcwd(tmp,300);
00073 #endif
00074 s=adstring(tmp);
00075 #endif
00076 }
00077
00083 int ad_mkdir(const char* s)
00084 {
00085 #if defined(_WIN32)
00086 return CreateDirectory(s, NULL) != 0;
00087 #else
00088 return mkdir(s,S_IREAD | S_IWRITE) == 0;
00089 #endif
00090 }
00096 int make_sub_directory(const char* s)
00097 {
00098 adstring currdir;
00099 adstring currdir1;
00100 ad_getcd(currdir);
00101 #if defined(_WIN32)
00102 int ierr = SetCurrentDirectory(s);
00103 if (!ierr)
00104 #else
00105 DIR* dirp = opendir(s);
00106 if (!dirp)
00107 #endif
00108 {
00109 ad_getcd(currdir);
00110 return ad_mkdir(s);
00111 }
00112 else
00113 {
00114 ad_getcd(currdir1);
00115 ad_chdir(currdir);
00116 ad_getcd(currdir1);
00117 }
00118 #if defined(_WIN32)
00119 return ierr != 0;
00120 #else
00121 return closedir(dirp) != -1;
00122 #endif
00123 }