comparison th_file.c @ 735:31bc1ed07cf5

Renaming BOOL->bool and TRUE/FALSE to true/false, and using stdbool.h if available.
author Matti Hamalainen <ccr@tnsp.org>
date Wed, 07 Dec 2022 12:14:39 +0200
parents 29e44a58bc73
children 32dab9b6058a
comparison
equal deleted inserted replaced
734:2ae1045f6c18 735:31bc1ed07cf5
99 return (value / ((1000 / 100) * 1000 * 1000)) - 11644473600ULL;; 99 return (value / ((1000 / 100) * 1000 * 1000)) - 11644473600ULL;;
100 } 100 }
101 #endif 101 #endif
102 102
103 103
104 BOOL th_stat_path(const char *path, th_stat_data *data) 104 bool th_stat_path(const char *path, th_stat_data *data)
105 { 105 {
106 #if defined(TH_PLAT_WINDOWS) 106 #if defined(TH_PLAT_WINDOWS)
107 WIN32_FILE_ATTRIBUTE_DATA fdata; 107 WIN32_FILE_ATTRIBUTE_DATA fdata;
108 if (!GetFileAttributesExA(path, GetFileExInfoStandard, &fdata)) 108 if (!GetFileAttributesExA(path, GetFileExInfoStandard, &fdata))
109 return FALSE; 109 return false;
110 110
111 data->size = (((uint64_t) fdata.nFileSizeHigh) << 32ULL) | ((uint64_t) fdata.nFileSizeLow); 111 data->size = (((uint64_t) fdata.nFileSizeHigh) << 32ULL) | ((uint64_t) fdata.nFileSizeLow);
112 data->ctime = th_convert_windows_time(fdata.ftCreationTime); 112 data->ctime = th_convert_windows_time(fdata.ftCreationTime);
113 data->atime = th_convert_windows_time(fdata.ftLastAccessTime); 113 data->atime = th_convert_windows_time(fdata.ftLastAccessTime);
114 data->mtime = th_convert_windows_time(fdata.ftLastWriteTime); 114 data->mtime = th_convert_windows_time(fdata.ftLastWriteTime);
123 gid_t gid = getegid(); 123 gid_t gid = getegid();
124 #endif 124 #endif
125 125
126 struct stat sb; 126 struct stat sb;
127 if (stat(path, &sb) < 0) 127 if (stat(path, &sb) < 0)
128 return FALSE; 128 return false;
129 129
130 data->size = sb.st_size; 130 data->size = sb.st_size;
131 data->ctime = sb.st_ctime; 131 data->ctime = sb.st_ctime;
132 data->atime = sb.st_atime; 132 data->atime = sb.st_atime;
133 data->mtime = sb.st_mtime; 133 data->mtime = sb.st_mtime;
148 data->flags |= TH_IS_READABLE | TH_IS_WRITABLE; 148 data->flags |= TH_IS_READABLE | TH_IS_WRITABLE;
149 #endif 149 #endif
150 150
151 #endif 151 #endif
152 152
153 return TRUE; 153 return true;
154 } 154 }
155 155
156 156
157 BOOL th_mkdir_path(const char *cpath, const int mode) 157 bool th_mkdir_path(const char *cpath, const int mode)
158 { 158 {
159 char save, *path = th_strdup(cpath); 159 char save, *path = th_strdup(cpath);
160 size_t start = 0, end; 160 size_t start = 0, end;
161 BOOL res = FALSE; 161 bool res = false;
162 162
163 #if defined(TH_PLAT_WINDOWS) 163 #if defined(TH_PLAT_WINDOWS)
164 (void) mode; 164 (void) mode;
165 #endif 165 #endif
166 166
178 178
179 // If the element is there, create it 179 // If the element is there, create it
180 if (path[start] != 0) 180 if (path[start] != 0)
181 { 181 {
182 th_stat_data sdata; 182 th_stat_data sdata;
183 BOOL exists = th_stat_path(path, &sdata); 183 bool exists = th_stat_path(path, &sdata);
184 if (exists && (sdata.flags & TH_IS_DIR) == 0) 184 if (exists && (sdata.flags & TH_IS_DIR) == 0)
185 goto error; 185 goto error;
186 186
187 if (!exists) 187 if (!exists)
188 { 188 {
199 // Restore separator character and jump to next element 199 // Restore separator character and jump to next element
200 path[end] = save; 200 path[end] = save;
201 start = end + 1; 201 start = end + 1;
202 } while (save != 0); 202 } while (save != 0);
203 203
204 res = TRUE; 204 res = true;
205 205
206 error: 206 error:
207 th_free(path); 207 th_free(path);
208 return res; 208 return res;
209 } 209 }