changeset 662:0c94af18f55e

Two more generic functions were moved to th-libs, so factor out the deprecated ones from here and convert to the changed APIs.
author Matti Hamalainen <ccr@tnsp.org>
date Fri, 12 Feb 2016 03:02:12 +0200
parents eb3692d85ac2
children 0b81e5fdc7b5
files main.c
diffstat 1 files changed, 7 insertions(+), 80 deletions(-) [+]
line wrap: on
line diff
--- a/main.c	Fri Feb 12 01:40:04 2016 +0200
+++ b/main.c	Fri Feb 12 03:02:12 2016 +0200
@@ -6,6 +6,7 @@
 #include "th_args.h"
 #include "th_config.h"
 #include "th_network.h"
+#include "th_file.h"
 #include "util.h"
 #include "ui.h"
 #include <unistd.h>
@@ -1935,80 +1936,6 @@
 }
 
 
-BOOL nn_stat_path(const char *path, BOOL *isDirectory, BOOL *isWritable, BOOL *isReadable)
-{
-#ifdef TH_PLAT_WINDOWS
-    DWORD attr = GetFileAttributes(path);
-
-    *isDirectory = (attr & FILE_ATTRIBUTE_DIRECTORY) != 0;
-    *isWritable = (attr & FILE_ATTRIBUTE_READONLY) == 0;
-    *isReadable = TRUE;
-#else
-    uid_t id = geteuid();
-    struct stat sb;
-    if (stat(path, &sb) < 0)
-        return FALSE;
-
-    *isDirectory = (S_ISDIR(sb.st_mode));
-    *isWritable = (id == sb.st_uid && (sb.st_mode & S_IWUSR));
-    *isReadable = (id == sb.st_uid && (sb.st_mode & S_IRUSR));
-#endif
-
-//    THERR("'%s': dir=%d, wr=%d, rd=%d\n", path, *isDirectory, *isWritable, *isReadable);
-    return TRUE;
-}
-
-
-BOOL nn_mkdir_rec(const char *cpath)
-{
-    char save, *path = th_strdup(cpath);
-    size_t start = 0, end;
-    BOOL res = FALSE, exists, isDir, isWritable, isReadable;
-
-    THMSG(0, "Creating directory %s\n", cpath);
-    do
-    {
-        for (save = 0, end = start; path[end] != 0; end++)
-        if (path[end] == SET_DIR_SEPARATOR)
-        {
-            save = path[end];
-            path[end] = 0;
-            break;
-        }
-        
-
-        if (path[start] != 0)
-        {
-            exists = nn_stat_path(path, &isDir, &isWritable, &isReadable);
-            if (exists && !isDir)
-                goto error;
-
-            if (!exists)
-            {
-#ifdef TH_PLAT_WINDOWS
-            if (!CreateDirectory(path, NULL))
-                goto error;
-#else
-            if (mkdir(path, 0x1c9) < 0)
-                goto error;
-#endif
-            }
-        }
-
-        path[end] = save;
-        start = end + 1;
-    } while (save != 0);
-
-    res = TRUE;
-
-error:
-    th_free(path);
-    return res;
-}
-
-
-
-
 int main(int argc, char *argv[])
 {
     char *tmpStr;
@@ -2152,20 +2079,20 @@
 
     if (optLogEnable)
     {
-        BOOL isDir, isWritable, isReadable;
-        if (nn_stat_path(optLogPath, &isDir, &isWritable, &isReadable))
+        int flags;
+        if (th_stat_path(optLogPath, &flags))
         {
-            if (!isDir)
+            if ((flags & TH_IS_DIR) == 0)
             {
                 THERR("The log file path '%s' is not a directory.\n",
                     optLogPath);
                 goto err_exit;
             }
             else
-            if (!isWritable)
+            if ((flags & TH_IS_WRITABLE) == 0)
             {
 #ifdef TH_PLAT_WINDOWS
-                if (!nn_mkdir_rec(optLogPath))
+                if (!th_mkdir_path(optLogPath, 0))
                 {
                     THERR("Could not create log file directory '%s'.\n",
                         optLogPath);
@@ -2179,7 +2106,7 @@
             }
         }
         else
-        if (!nn_mkdir_rec(optLogPath))
+        if (!th_mkdir_path(optLogPath, 0))
         {
             THERR("Could not create log file directory '%s'.\n",
                 optLogPath);