checking in the recent efforts at optimizing clam
[feisty_meow.git] / nucleus / library / filesystem / directory.cpp
index 052c10bf994486a7148dc1fdc9ec5dad5671d5bb..4f6dfc2227d1376ffdf9d565a984467a4d40df13 100644 (file)
@@ -15,7 +15,6 @@
 #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__
-  #include <direct.h>
-#endif
+//#ifdef _MSC_VER
+//  #include <direct.h>
+//#endif
 
 /*
 #ifdef __WIN32__
@@ -101,26 +102,26 @@ astring directory::absolute_path(const astring &rel_path)
 {
   char abs_path[MAX_ABS_PATH + 1];
   abs_path[0] = '\0';
-#ifdef __WIN32__
-  if (!_fullpath(abs_path, rel_path.s(), MAX_ABS_PATH)) return "";
-  return abs_path;
-#else
+//#ifdef _MSC_VER
+//  if (!_fullpath(abs_path, rel_path.s(), MAX_ABS_PATH)) return "";
+//  return abs_path;
+//#else
   if (!realpath(rel_path.s(), abs_path)) return "";
   return abs_path;
-#endif
+//#endif
 }
 
 astring directory::current()
 {
   astring to_return(".");  // failure result.
-#ifdef __WIN32__
-  flexichar buffer[MAX_ABS_PATH + 1] = { '\0' };
-  GetCurrentDirectory(MAX_ABS_PATH, buffer);
-  to_return = from_unicode_temp(buffer);
-#else
+//#ifdef _MSC_VER
+//  flexichar buffer[MAX_ABS_PATH + 1] = { '\0' };
+//  GetCurrentDirectory(MAX_ABS_PATH, buffer);
+//  to_return = from_unicode_temp(buffer);
+//#else
   char buffer[MAX_ABS_PATH + 1] = { '\0' };
   if (realpath(".", buffer)) to_return = buffer;
-#endif
+//#endif
   return to_return;
 }
 
@@ -151,7 +152,8 @@ bool directory::rescan()
   _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;
@@ -194,8 +196,8 @@ bool directory::rescan()
        }
   } 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;
@@ -224,7 +226,7 @@ bool directory::rescan()
     entry = readdir(dir);
   }
   closedir(dir);
-#endif
+//#endif
   shell_sort(_files->access(), _files->length());
   shell_sort(_folders->access(), _folders->length());
 
@@ -234,10 +236,9 @@ bool directory::rescan()
 
 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;
@@ -245,10 +246,9 @@ bool directory::make_directory(const astring &path)
 
 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;
@@ -283,3 +283,4 @@ bool directory::recursive_create(const astring &directory_name)
 }
 
 } // namespace.
+