#include "directory.h"
#include "filename.h"
-#include <algorithms/shell_sort.h>
#include <application/windoze_helper.h>
#include <basis/astring.h>
#include <basis/contracts.h>
#include <stdio.h>
#include <stdlib.h>
#include <sys/stat.h>
-#ifdef __UNIX__
+
+#include "../algorithms/sorts.h"
+#if defined(__UNIX__) || defined(__GNU_WINDOWS__)
#include <dirent.h>
#include <fnmatch.h>
#include <string.h>
#include <unistd.h>
#endif
-#ifdef __WIN32__
+#ifdef _MSC_VER
#include <direct.h>
#endif
{
char abs_path[MAX_ABS_PATH + 1];
abs_path[0] = '\0';
-#ifdef __WIN32__
+#ifdef _MSC_VER
if (!_fullpath(abs_path, rel_path.s(), MAX_ABS_PATH)) return "";
return abs_path;
#else
astring directory::current()
{
astring to_return("."); // failure result.
-#ifdef __WIN32__
+#ifdef _MSC_VER
flexichar buffer[MAX_ABS_PATH + 1] = { '\0' };
GetCurrentDirectory(MAX_ABS_PATH, buffer);
to_return = from_unicode_temp(buffer);
_folders->reset();
astring cur_dir = ".";
astring par_dir = "..";
-#ifdef __WIN32__
+#ifdef _MSC_VER
// start reading the directory.
WIN32_FIND_DATA wfd;
astring real_path_spec = *_path + "/" + *_pattern;
}
} while (FindNextFile(search_handle, &wfd));
FindClose(search_handle);
-#endif
-#ifdef __UNIX__
+#else
DIR *dir = opendir(_path->s());
//hmmm: could check errno to determine what caused the problem.
if (!dir) return false;
if (add_it && !fnmatch(_pattern->s(), file, 0)) {
filename temp_name(*_path, file);
if (!temp_name.is_normal()) {
-#ifdef DEBUG_DIRECTORY
+//#ifdef DEBUG_DIRECTORY
LOG(astring("skipping abnormal file: ") + temp_name);
-#endif
+//#endif
entry = readdir(dir);
continue; // cannot be adding goofy named pipes etc; cannot manage those.
}
bool directory::make_directory(const astring &path)
{
-#ifdef __UNIX__
+#if defined(__UNIX__) || defined(__GNU_WINDOWS__)
int mk_ret = mkdir(path.s(), 0777);
-#endif
-#ifdef __WIN32__
+#else
int mk_ret = mkdir(path.s());
#endif
return !mk_ret;
bool directory::remove_directory(const astring &path)
{
-#ifdef __UNIX__
+#if defined(__UNIX__) || defined(__GNU_WINDOWS__)
int rm_ret = rmdir(path.s());
-#endif
-#ifdef __WIN32__
+#else
int rm_ret = rmdir(path.s());
#endif
return !rm_ret;
FUNCDEF("recursive_create");
filename dir(directory_name);
string_array pieces;
- dir.separate(pieces);
+ bool rooted;
+ dir.separate(rooted, pieces);
for (int i = 0; i < pieces.length(); i++) {
// check each location along the way.
string_array partial = pieces.subarray(0, i);
filename curr;
- curr.join(partial); // this is our current location.
+ curr.join(rooted, partial); // this is our current location.
// make sure, if we see a drive letter component, that we call it
// a proper directory name.
if (curr.raw()[curr.raw().end()] == ':')
}
} // namespace.
+