Mercurial > hg > th-libs
changeset 480:2aa2052cb17d
Fix th_stat_path() for *NIX.
author | Matti Hamalainen <ccr@tnsp.org> |
---|---|
date | Fri, 21 Dec 2018 14:19:59 +0200 |
parents | 77ad030e82c9 |
children | e4ce60239d16 |
files | th_file.c |
diffstat | 1 files changed, 12 insertions(+), 3 deletions(-) [+] |
line wrap: on
line diff
--- a/th_file.c Tue Nov 27 07:48:58 2018 +0200 +++ b/th_file.c Fri Dec 21 14:19:59 2018 +0200 @@ -95,7 +95,8 @@ data->flags |= (fdata.dwFileAttributes & FILE_ATTRIBUTE_READONLY) ? 0 : TH_IS_WRITABLE; data->flags |= TH_IS_READABLE; #else - uid_t id = geteuid(); + uid_t uid = geteuid(); + gid_t gid = getegid(); struct stat sb; if (stat(path, &sb) < 0) return FALSE; @@ -106,8 +107,16 @@ data->mtime = sb.st_mtime; data->flags = S_ISDIR(sb.st_mode) ? TH_IS_DIR : 0; - data->flags |= (id == sb.st_uid && (sb.st_mode & S_IWUSR)) ? TH_IS_WRITABLE : 0; - data->flags |= (id == sb.st_uid && (sb.st_mode & S_IRUSR)) ? TH_IS_READABLE : 0; + + if ((uid == sb.st_uid && (sb.st_mode & S_IWUSR)) || + (gid == sb.st_gid && (sb.st_mode & S_IWGRP)) || + (sb.st_mode & S_IWOTH)) + data->flags |= TH_IS_WRITABLE; + + if ((uid == sb.st_uid && (sb.st_mode & S_IRUSR)) || + (gid == sb.st_gid && (sb.st_mode & S_IRGRP)) || + (sb.st_mode & S_IROTH)) + data->flags |= TH_IS_READABLE; #endif return TRUE;