release candidate
[asdcplib.git] / src / KM_fileio.cpp
index b2b0465661e54bcab9b0b9d02755078e59e48c22..b9257abda88d7d9c87bd929cbce7a9bd806c47c7 100644 (file)
@@ -57,6 +57,7 @@ struct iovec {
 # if defined(__linux__)
 #   include <sys/statfs.h>
 # else
+#  include <sys/param.h>
 #  include <sys/mount.h>
 # endif
 
@@ -212,7 +213,7 @@ Kumu::FileSize(const std::string& pathname)
 
 //
 static PathCompList_t&
-s_PathMakeCanonical(PathCompList_t& CList, char separator, bool is_absolute)
+s_PathMakeCanonical(PathCompList_t& CList, bool is_absolute)
 {
   PathCompList_t::iterator ci, ri; // component and removal iterators
 
@@ -246,7 +247,7 @@ Kumu::PathMakeCanonical(const std::string& Path, char separator)
 {
   PathCompList_t CList;
   bool is_absolute = PathIsAbsolute(Path, separator);
-  s_PathMakeCanonical(PathToComponents(Path, CList, separator), separator, is_absolute);
+  s_PathMakeCanonical(PathToComponents(Path, CList, separator), is_absolute);
 
   if ( is_absolute )
     return ComponentsToAbsolutePath(CList, separator);
@@ -349,10 +350,10 @@ Kumu::PathMakeAbsolute(const std::string& Path, char separator)
     }
 
   PathCompList_t CList;
-  CList.push_back(cwd_buf);
+  PathToComponents(cwd_buf, CList);
   CList.push_back(Path);
 
-  return ComponentsToAbsolutePath(s_PathMakeCanonical(CList, separator, true), separator);
+  return ComponentsToAbsolutePath(s_PathMakeCanonical(CList, true), separator);
 }
 
 //
@@ -428,6 +429,28 @@ Kumu::PathSetExtension(const std::string& Path, const std::string& Extension) //
   return Basename + "." + Extension;
 }
 
+//
+std::string
+Kumu::PathJoin(const std::string& Path1, const std::string& Path2, char separator)
+{
+  return Path1 + separator + Path2;
+}
+
+//
+std::string
+Kumu::PathJoin(const std::string& Path1, const std::string& Path2, const std::string& Path3, char separator)
+{
+  return Path1 + separator + Path2 + separator + Path3;
+}
+
+//
+std::string
+Kumu::PathJoin(const std::string& Path1, const std::string& Path2,
+              const std::string& Path3, const std::string& Path4, char separator)
+{
+  return Path1 + separator + Path2 + separator + Path3 + separator + Path4;
+}
+
 //
 Kumu::PathList_t&
 Kumu::FindInPaths(const IPathMatch& Pattern, const Kumu::PathList_t& SearchPaths,
@@ -1189,6 +1212,9 @@ Kumu::WriteBufferIntoFile(const Kumu::ByteString& Buffer, const std::string& Fil
 //
 #ifdef KM_WIN32
 
+//
+Kumu::DirScanner::DirScanner(void) : m_Handle(-1) {}
+
 //
 //
 Result_t
@@ -1274,6 +1300,9 @@ Kumu::DirScanner::GetNext(char* filename)
 
 // POSIX directory scanner
 
+//
+Kumu::DirScanner::DirScanner(void) : m_Handle(NULL) {}
+
 //
 Result_t
 Kumu::DirScanner::Open(const char* filename)
@@ -1371,7 +1400,6 @@ Result_t
 Kumu::CreateDirectoriesInPath(const std::string& Path)
 {
   bool abs = PathIsAbsolute(Path);
-  assert(abs);
   PathCompList_t PathComps, TmpPathComps;
 
   PathToComponents(Path, PathComps);
@@ -1427,7 +1455,9 @@ Kumu::DeleteFile(const std::string& filename)
 Result_t
 h__DeletePath(const std::string& pathname)
 {
-  fprintf(stderr, "h__DeletePath %s\n", pathname.c_str());
+  if ( pathname.empty() )
+    return RESULT_NULL_STR;
+
   Result_t result = RESULT_OK;
 
   if ( ! PathIsDirectory(pathname) )
@@ -1498,17 +1528,17 @@ Kumu::DeletePath(const std::string& pathname)
 
 Result_t
 Kumu::FreeSpaceForPath(const std::string& path, Kumu::fsize_t& free_space, Kumu::fsize_t& total_space)
-{\r
+{
 #ifdef KM_WIN32
-       ULARGE_INTEGER lTotalNumberOfBytes;\r
+       ULARGE_INTEGER lTotalNumberOfBytes;
        ULARGE_INTEGER lTotalNumberOfFreeBytes;
 
        BOOL fResult = ::GetDiskFreeSpaceEx(path.c_str(), NULL, &lTotalNumberOfBytes, &lTotalNumberOfFreeBytes);
-       if (fResult) {\r
+       if (fResult) {
       free_space = static_cast<Kumu::fsize_t>(lTotalNumberOfFreeBytes.QuadPart);
       total_space = static_cast<Kumu::fsize_t>(lTotalNumberOfBytes.QuadPart);
       return RESULT_OK;
-       }\r
+       }
        HRESULT LastError = ::GetLastError();
 
        DefaultLogSink().Error("FreeSpaceForPath GetDiskFreeSpaceEx %s: %lu\n", path.c_str(), ::GetLastError());