21 # include <vcl_msvc_warnings.h> 24 #if defined(_WIN32) && !defined(__CYGWIN__) 34 constexpr
int BIG = 65536;
36 if (getcwd(buf,BIG-1))
39 return "Error returned by getcwd";
49 #if defined(_WIN32) && !defined(__CYGWIN__) 50 return -1 != mkdir(name);
52 return -1 != mkdir(name, 0755);
59 return stat(fn, &fs) == 0
60 && (fs.st_mode & S_IFMT) == S_IFDIR;
65 if(stat(filename, &fs)!=0)
66 return std::time_t(0);
70 #if defined(_WIN32) && !defined(__CYGWIN__) 71 bool vul_file::is_drive(
char const* fn)
75 && std::isalpha(fn[0])
86 #if defined(_WIN32) && !defined(__CYGWIN__) 87 if (
is_directory(filename) || is_drive(filename))
return true;
103 if (stat(fn, &fs) == 0)
112 std::string name(fn);
114 #if defined(_WIN32) && !defined(__CYGWIN__) 115 std::string::size_type last_non_slash_index = name.find_last_not_of(
"\\/");
117 std::string::size_type last_non_slash_index = name.find_last_not_of(
'/');
119 if (last_non_slash_index != std::string::npos)
120 last_non_slash_index++;
121 name = name.substr(0, last_non_slash_index);
122 return stat(name.c_str(), &fs) == 0;
127 std::string
self(fn);
129 #if defined(_WIN32) && !defined(__CYGWIN__) 130 std::string::size_type slash_index =
self.find_last_of(
"\\/");
132 std::string::size_type slash_index =
self.rfind(
'/');
134 if (slash_index == std::string::npos)
138 return self.substr(0, slash_index);
143 std::string
self(fn);
145 std::string::size_type dot_index =
self.rfind(
'.');
146 if (dot_index != std::string::npos)
147 return self.substr(dot_index, std::string::npos);
149 return std::string();
154 std::string
self(fn);
156 #if defined(_WIN32) && !defined(__CYGWIN__) 157 std::string::size_type slash_index =
self.find_last_of(
"\\/");
159 std::string::size_type slash_index =
self.rfind(
'/');
161 if (slash_index != std::string::npos)
162 self.erase(0, slash_index+1);
169 std::string
self(fn);
171 std::string::size_type dot_index =
self.rfind(
'.');
172 if (dot_index != std::string::npos)
173 self.erase(dot_index, std::string::npos);
181 std::string
self(fn);
183 #if defined(_WIN32) && !defined(__CYGWIN__) 184 std::string::size_type slash_index =
self.find_last_of(
"\\/");
186 std::string::size_type slash_index =
self.rfind(
'/');
189 if (slash_index != std::string::npos)
190 self.erase(0, slash_index+1);
194 int start = (int)(
self.
size() - std::strlen(suffix));
196 if (std::string(
self.begin()+start,
self.end()) == suffix)
197 self.erase(start, std::string::npos);
203 #if defined(_WIN32) && !defined(__CYGWIN__) 205 static unsigned replace(
char from,
char to, std::string &s)
208 for (
unsigned i=0; i<s.size(); ++i)
224 #if defined(_WIN32) && !defined(__CYGWIN__) 225 std::string command = file_glob;
226 replace(
'/',
'\\', command);
227 command =
"del /Q " + command;
229 std::string command =
"/bin/rm -f " + file_glob;
231 return std::system(command.c_str())==0;
237 if (!vul_filename || (std::strlen(vul_filename) == 0))
240 #if defined(_WIN32) && !defined(__CYGWIN__) 242 return std::string(vul_filename);
245 if (vul_filename[0] !=
'~')
246 return std::string(vul_filename);
251 std::string fn(vul_filename);
253 std::string::size_type first_slash = fn.find(
'/');
254 if (first_slash != std::string::npos) {
255 dir = fn.substr(1, first_slash-1);
256 fn = fn.substr(first_slash, std::string::npos);
259 dir = fn.substr(1, std::string::npos);
268 if (dir.size() == 0) {
270 char const * home_directory = getenv(
"HOME");
271 if (!home_directory) home_directory =
"";
272 return std::string(home_directory) + fn;
278 return std::string(vul_filename);
286 #if defined(_WIN32) && VXL_USE_WIN_WCHAR_T 292 constexpr
int BIG = 65536;
306 return -1 != _wmkdir(name);
312 return _wstat(fn, &fs) == 0
313 && (fs.st_mode & S_IFMT) == S_IFDIR;
316 bool vul_file::is_drive(
wchar_t const* fn)
329 if (
is_directory(filename) || is_drive(filename))
return true;
338 return _wstat(fn, &fs) == 0;
343 std::wstring
self(fn);
345 std::wstring::size_type slash_index =
self.find_last_of(L
"\\/");
346 if (slash_index == std::wstring::npos)
349 return self.substr(0, slash_index);
354 std::wstring
self(fn);
356 std::wstring::size_type dot_index =
self.rfind(L
'.');
357 if (dot_index != std::wstring::npos)
358 return self.substr(dot_index, std::wstring::npos);
360 return std::wstring();
365 std::wstring
self(fn);
367 std::wstring::size_type slash_index =
self.find_last_of(L
"\\/");
368 if (slash_index != std::wstring::npos)
369 self.erase(0, slash_index+1);
376 std::wstring
self(fn);
378 std::wstring::size_type dot_index =
self.rfind(L
'.');
379 if (dot_index != std::wstring::npos)
380 self.erase(dot_index, std::wstring::npos);
388 std::wstring
self(fn);
390 std::wstring::size_type slash_index =
self.find_last_of(L
"\\/");
392 if (slash_index != std::wstring::npos)
393 self.erase(0, slash_index+1);
397 int start = (int)
self.
size() - (int)wcslen(suffix);
399 if (std::wstring(
self.begin()+start,
self.end()) == suffix)
400 self.erase(start, std::wstring::npos);
Reads information about a user from the password file.
static std::string extension(char const *filename)
Return extension (including the '.
static std::string basename(char const *filename, char const *suffix=nullptr)
Return basename.
Reads information about a user from the password file.
static bool delete_file_glob(std::string const &file_glob)
Delete 1 or more files using the Local OS preferred globbing.
static bool make_directory_path(char const *filename)
Make a writable directory, including any necessary parents.
A collection of miscellaneous filesystem-type utilities.
static std::string strip_directory(char const *filename)
Strips away directory of the filename.
static bool change_directory(char const *dirname)
change current working directory.
static std::string expand_tilde(char const *filename)
Expand any leading ~ escapes in filename.
static unsigned long size(char const *filename)
Return size of vul_file.
static bool is_directory(char const *filename)
Return true iff filename is a directory.
static std::string get_cwd()
Return current working directory.
static std::string strip_extension(char const *filename)
Strips away extension of the filename.
static bool make_directory(char const *filename)
Make a writable directory.
static std::time_t time_modified(char const *filename)
static bool exists(char const *filename)
Return true iff filename exists. It may be any sort of file.
std::string home_directory
static std::string dirname(char const *filename)
Return dirname.