comparison th_file.c @ 457:85fa3d333556

Actually, revert the boolean changes .. meh.
author Matti Hamalainen <ccr@tnsp.org>
date Tue, 02 Jan 2018 23:09:29 +0200
parents 347bfd3e017e
children 77d1af382e08
comparison
equal deleted inserted replaced
456:1bf886fa9db5 457:85fa3d333556
67 return th_get_data_dir(); 67 return th_get_data_dir();
68 #endif 68 #endif
69 } 69 }
70 70
71 71
72 bool th_stat_path(const char *path, int *flags) 72 BOOL th_stat_path(const char *path, int *flags)
73 { 73 {
74 *flags = 0; 74 *flags = 0;
75 75
76 #ifdef TH_PLAT_WINDOWS 76 #ifdef TH_PLAT_WINDOWS
77 DWORD attr = GetFileAttributes(path); 77 DWORD attr = GetFileAttributes(path);
81 *flags |= TH_IS_READABLE; 81 *flags |= TH_IS_READABLE;
82 #else 82 #else
83 uid_t id = geteuid(); 83 uid_t id = geteuid();
84 struct stat sb; 84 struct stat sb;
85 if (stat(path, &sb) < 0) 85 if (stat(path, &sb) < 0)
86 return false; 86 return FALSE;
87 87
88 *flags |= S_ISDIR(sb.st_mode) ? TH_IS_DIR : 0; 88 *flags |= S_ISDIR(sb.st_mode) ? TH_IS_DIR : 0;
89 *flags |= (id == sb.st_uid && (sb.st_mode & S_IWUSR)) ? TH_IS_WRITABLE : 0; 89 *flags |= (id == sb.st_uid && (sb.st_mode & S_IWUSR)) ? TH_IS_WRITABLE : 0;
90 *flags |= (id == sb.st_uid && (sb.st_mode & S_IRUSR)) ? TH_IS_READABLE : 0; 90 *flags |= (id == sb.st_uid && (sb.st_mode & S_IRUSR)) ? TH_IS_READABLE : 0;
91 #endif 91 #endif
92 92
93 return true; 93 return TRUE;
94 } 94 }
95 95
96 96
97 bool th_mkdir_path(const char *cpath, int mode) 97 BOOL th_mkdir_path(const char *cpath, int mode)
98 { 98 {
99 char save, *path = th_strdup(cpath); 99 char save, *path = th_strdup(cpath);
100 size_t start = 0, end; 100 size_t start = 0, end;
101 bool res = false; 101 BOOL res = FALSE;
102 102
103 // If mode is 0, default to something sensible 103 // If mode is 0, default to something sensible
104 if (mode == 0) 104 if (mode == 0)
105 mode = 0711; 105 mode = 0711;
106 106
118 118
119 // If the element is there, create it 119 // If the element is there, create it
120 if (path[start] != 0) 120 if (path[start] != 0)
121 { 121 {
122 int flags; 122 int flags;
123 bool exists = th_stat_path(path, &flags); 123 BOOL exists = th_stat_path(path, &flags);
124 if (exists && (flags & TH_IS_DIR) == 0) 124 if (exists && (flags & TH_IS_DIR) == 0)
125 goto error; 125 goto error;
126 126
127 if (!exists) 127 if (!exists)
128 { 128 {
139 // Restore separator character and jump to next element 139 // Restore separator character and jump to next element
140 path[end] = save; 140 path[end] = save;
141 start = end + 1; 141 start = end + 1;
142 } while (save != 0); 142 } while (save != 0);
143 143
144 res = true; 144 res = TRUE;
145 145
146 error: 146 error:
147 th_free(path); 147 th_free(path);
148 return res; 148 return res;
149 } 149 }