comparison th_file.c @ 480:2aa2052cb17d

Fix th_stat_path() for *NIX.
author Matti Hamalainen <ccr@tnsp.org>
date Fri, 21 Dec 2018 14:19:59 +0200
parents b1e80180818a
children e4ce60239d16
comparison
equal deleted inserted replaced
479:77ad030e82c9 480:2aa2052cb17d
93 93
94 data->flags = (fdata.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY) ? TH_IS_DIR : 0; 94 data->flags = (fdata.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY) ? TH_IS_DIR : 0;
95 data->flags |= (fdata.dwFileAttributes & FILE_ATTRIBUTE_READONLY) ? 0 : TH_IS_WRITABLE; 95 data->flags |= (fdata.dwFileAttributes & FILE_ATTRIBUTE_READONLY) ? 0 : TH_IS_WRITABLE;
96 data->flags |= TH_IS_READABLE; 96 data->flags |= TH_IS_READABLE;
97 #else 97 #else
98 uid_t id = geteuid(); 98 uid_t uid = geteuid();
99 gid_t gid = getegid();
99 struct stat sb; 100 struct stat sb;
100 if (stat(path, &sb) < 0) 101 if (stat(path, &sb) < 0)
101 return FALSE; 102 return FALSE;
102 103
103 data->size = sb.st_size; 104 data->size = sb.st_size;
104 data->ctime = sb.st_ctime; 105 data->ctime = sb.st_ctime;
105 data->atime = sb.st_atime; 106 data->atime = sb.st_atime;
106 data->mtime = sb.st_mtime; 107 data->mtime = sb.st_mtime;
107 108
108 data->flags = S_ISDIR(sb.st_mode) ? TH_IS_DIR : 0; 109 data->flags = S_ISDIR(sb.st_mode) ? TH_IS_DIR : 0;
109 data->flags |= (id == sb.st_uid && (sb.st_mode & S_IWUSR)) ? TH_IS_WRITABLE : 0; 110
110 data->flags |= (id == sb.st_uid && (sb.st_mode & S_IRUSR)) ? TH_IS_READABLE : 0; 111 if ((uid == sb.st_uid && (sb.st_mode & S_IWUSR)) ||
112 (gid == sb.st_gid && (sb.st_mode & S_IWGRP)) ||
113 (sb.st_mode & S_IWOTH))
114 data->flags |= TH_IS_WRITABLE;
115
116 if ((uid == sb.st_uid && (sb.st_mode & S_IRUSR)) ||
117 (gid == sb.st_gid && (sb.st_mode & S_IRGRP)) ||
118 (sb.st_mode & S_IROTH))
119 data->flags |= TH_IS_READABLE;
111 #endif 120 #endif
112 121
113 return TRUE; 122 return TRUE;
114 } 123 }
115 124