Cygwin: change virtual_ftype_t to not rely on negative values

So far negative values were denoting files, positive values
denoting directories.  We should prefer a less error prone
method.  Redefine virtual_ftype_t to contain only positive
values and replace checks for negativ or positive values with
inline functions virt_ftype_isfile() and virt_ftype_isdir().

Drop outdcated comments referring to numerical virtual_ftype_t
values.

Signed-off-by: Corinna Vinschen <corinna@vinschen.de>
This commit is contained in:
Corinna Vinschen
2019-07-22 18:40:33 +02:00
parent e118a605e2
commit dec444bee3
9 changed files with 31 additions and 36 deletions

View File

@ -306,13 +306,8 @@ multi_wcstombs (char *dst, size_t len, const wchar_t *src, size_t nwc)
return sum;
}
/* Returns 0 if path doesn't exist, >0 if path is a directory,
* <0 if path is a file.
*
* We open the last key but one and then enum it's sub-keys and values to see if the
* final component is there. This gets round the problem of not having security access
* to the final key in the path.
*/
/* Returns 0 if path doesn't exist, otherwise a virtual_ftype_t value
specifying the exact file type. */
virtual_ftype_t
fhandler_registry::exists ()
{
@ -502,7 +497,7 @@ fhandler_registry::fstat (struct stat *buf)
const char *path = get_name () + proc_len + prefix_len + 2;
hKey =
open_key (path, STANDARD_RIGHTS_READ | KEY_QUERY_VALUE, wow64,
(file_type < virt_none) ? true : false);
virt_ftype_isfile (file_type) ? true : false);
if (hKey == HKEY_PERFORMANCE_DATA)
/* RegQueryInfoKey () always returns write time 0,
@ -519,7 +514,7 @@ fhandler_registry::fstat (struct stat *buf)
to_timestruc_t ((PLARGE_INTEGER) &ftLastWriteTime, &buf->st_mtim);
buf->st_ctim = buf->st_birthtim = buf->st_mtim;
time_as_timestruc_t (&buf->st_atim);
if (file_type > virt_none)
if (virt_ftype_isdir (file_type))
buf->st_nlink = subkey_count + 2;
else
{