From 7eddac1bc503f29cd81bba336ad7e45a20ee0bef Mon Sep 17 00:00:00 2001 From: Corinna Vinschen Date: Mon, 14 Jan 2002 20:39:59 +0000 Subject: [PATCH] * dir.cc: Use INVALID_FILE_ATTRIBUTES instead of "(DWORD) -1" for file attributes throughout. * fhandler.cc: Ditto. * fhandler_disk_file.cc: Ditto. * path.cc: Ditto. * path.h: Ditto. * syscalls.cc: Ditto. * times.cc (utimes): Use path_conv::isdir() instead of explicit GetFileAttributes() call. --- winsup/cygwin/ChangeLog | 12 ++++++++++++ winsup/cygwin/dir.cc | 2 +- winsup/cygwin/fhandler.cc | 4 ++-- winsup/cygwin/fhandler_disk_file.cc | 6 +++--- winsup/cygwin/path.cc | 16 ++++++++-------- winsup/cygwin/path.h | 6 +++--- winsup/cygwin/syscalls.cc | 3 ++- winsup/cygwin/times.cc | 5 ++--- 8 files changed, 33 insertions(+), 21 deletions(-) diff --git a/winsup/cygwin/ChangeLog b/winsup/cygwin/ChangeLog index 9db8955cd..f64fbb92e 100644 --- a/winsup/cygwin/ChangeLog +++ b/winsup/cygwin/ChangeLog @@ -1,3 +1,15 @@ +2002-01-14 Corinna Vinschen + + * dir.cc: Use INVALID_FILE_ATTRIBUTES instead of "(DWORD) -1" + for file attributes throughout. + * fhandler.cc: Ditto. + * fhandler_disk_file.cc: Ditto. + * path.cc: Ditto. + * path.h: Ditto. + * syscalls.cc: Ditto. + * times.cc (utimes): Use path_conv::isdir() instead of explicit + GetFileAttributes() call. + 2002-01-13 Christopher Faylor * dcrt0.cc (multiple_cygwin_problem): Clarify logic and make diff --git a/winsup/cygwin/dir.cc b/winsup/cygwin/dir.cc index 086645a8a..1134c45e0 100644 --- a/winsup/cygwin/dir.cc +++ b/winsup/cygwin/dir.cc @@ -260,7 +260,7 @@ rmdir (const char *dir) /* RemoveDirectory on a samba drive doesn't return an error if the directory can't be removed because it's not empty. Checking for existence afterwards keeps us informed about success. */ - if (GetFileAttributes (real_dir) != (DWORD) -1) + if (GetFileAttributes (real_dir) != INVALID_FILE_ATTRIBUTES) set_errno (ENOTEMPTY); else res = 0; diff --git a/winsup/cygwin/fhandler.cc b/winsup/cygwin/fhandler.cc index 21f4fb39c..a36ef0b13 100644 --- a/winsup/cygwin/fhandler.cc +++ b/winsup/cygwin/fhandler.cc @@ -1,6 +1,6 @@ /* fhandler.cc. See console.cc for fhandler_console functions. - Copyright 1996, 1997, 1998, 1999, 2000, 2001 Red Hat, Inc. + Copyright 1996, 1997, 1998, 1999, 2000, 2001, 2002 Red Hat, Inc. This file is part of Cygwin. @@ -386,7 +386,7 @@ fhandler_base::open (path_conv *, int flags, mode_t mode) if (get_query_open () && isremote () && creation_distribution == OPEN_EXISTING && - GetFileAttributes (get_win32_name ()) == (DWORD) -1) + GetFileAttributes (get_win32_name ()) == INVALID_FILE_ATTRIBUTES) { set_errno (ENOENT); goto done; diff --git a/winsup/cygwin/fhandler_disk_file.cc b/winsup/cygwin/fhandler_disk_file.cc index 1ce4893d2..18887844e 100644 --- a/winsup/cygwin/fhandler_disk_file.cc +++ b/winsup/cygwin/fhandler_disk_file.cc @@ -1,6 +1,6 @@ /* fhandler_disk_file.cc - Copyright 1996, 1997, 1998, 1999, 2000, 2001 Red Hat, Inc. + Copyright 1996, 1997, 1998, 1999, 2000, 2001, 2002 Red Hat, Inc. This file is part of Cygwin. @@ -382,7 +382,7 @@ fhandler_disk_file::open (path_conv *real_path, int flags, mode_t mode) which returns a valid handle when trying to open a file in a nonexistent directory. */ if (real_path->has_buggy_open () - && GetFileAttributes (win32_path_name) == (DWORD) -1) + && GetFileAttributes (win32_path_name) == INVALID_FILE_ATTRIBUTES) { debug_printf ("Buggy open detected."); close (); @@ -804,7 +804,7 @@ fhandler_cygdrive::readdir (DIR *dir) set_errno (ENMFILE); return NULL; } - if (GetFileAttributes (pdrive) == (DWORD) -1) + if (GetFileAttributes (pdrive) == INVALID_FILE_ATTRIBUTES) { pdrive += DRVSZ; return readdir (dir); diff --git a/winsup/cygwin/path.cc b/winsup/cygwin/path.cc index aa0ec5454..6b8a71e49 100644 --- a/winsup/cygwin/path.cc +++ b/winsup/cygwin/path.cc @@ -1,6 +1,6 @@ /* path.cc: path support. - Copyright 1996, 1997, 1998, 1999, 2000, 2001 Red Hat, Inc. + Copyright 1996, 1997, 1998, 1999, 2000, 2001, 2002 Red Hat, Inc. This file is part of Cygwin. @@ -400,7 +400,7 @@ path_conv::check (const char *src, unsigned opt, int loop = 0; path_flags = 0; known_suffix = NULL; - fileattr = (DWORD) -1; + fileattr = INVALID_FILE_ATTRIBUTES; case_clash = false; devn = unit = 0; root_dir[0] = '\0'; @@ -551,7 +551,7 @@ path_conv::check (const char *src, unsigned opt, /* If symlink.check found an existing non-symlink file, then it sets the appropriate flag. It also sets any suffix found into `ext_here'. */ - if (!sym.is_symlink && sym.fileattr != (DWORD) -1) + if (!sym.is_symlink && sym.fileattr != INVALID_FILE_ATTRIBUTES) { error = sym.error; if (component == 0) @@ -2397,7 +2397,7 @@ cygdrive_getmntent () __small_sprintf (native_path, "%c:\\", drive); if (GetDriveType (native_path) == DRIVE_REMOVABLE || - GetFileAttributes (native_path) == (DWORD) -1) + GetFileAttributes (native_path) == INVALID_FILE_ATTRIBUTES) { available_drives &= ~mask; continue; @@ -2609,7 +2609,7 @@ symlink (const char *topath, const char *frompath) } backslashify (topath, w32topath, 0); } - if (!cp || GetFileAttributes (w32topath) == (DWORD)-1) + if (!cp || GetFileAttributes (w32topath) == INVALID_FILE_ATTRIBUTES) { win32_topath.check (topath, PC_SYM_NOFOLLOW); if (!cp || win32_topath.error != ENOENT) @@ -2911,7 +2911,7 @@ symlink_info::check (char *path, const suffix_info *suffixes, unsigned opt) { error = 0; fileattr = GetFileAttributes (suffix.path); - if (fileattr == (DWORD) -1) + if (fileattr == INVALID_FILE_ATTRIBUTES) { /* The GetFileAttributes call can fail for reasons that don't matter, so we just return 0. For example, getting the @@ -2978,7 +2978,7 @@ symlink_info::check (char *path, const suffix_info *suffixes, unsigned opt) if (!suffix.lnk_match () || !ext_tacked_on) goto file_not_symlink; - fileattr = (DWORD) -1; + fileattr = INVALID_FILE_ATTRIBUTES; continue; /* in case we're going to tack *another* .lnk on this filename. */ case 2: res = check_sysfile (suffix.path, fileattr, h, contents, &error, &pflags); @@ -3072,7 +3072,7 @@ readlink (const char *path, char *buf, int buflen) if (!pathbuf.issymlink ()) { - if (pathbuf.fileattr != (DWORD) -1) + if (pathbuf.fileattr != INVALID_FILE_ATTRIBUTES) set_errno (EINVAL); return -1; } diff --git a/winsup/cygwin/path.h b/winsup/cygwin/path.h index 766c2a261..ea3a6545a 100644 --- a/winsup/cygwin/path.h +++ b/winsup/cygwin/path.h @@ -1,6 +1,6 @@ /* path.h: path data structures - Copyright 1996, 1997, 1998, 2000 Red Hat, Inc. + Copyright 1996, 1997, 1998, 2000, 2001, 2002 Red Hat, Inc. This file is part of Cygwin. @@ -86,7 +86,7 @@ class path_conv int issymlink () const {return path_flags & PATH_SYMLINK;} int issocket () const {return path_flags & PATH_SOCKET;} int iscygexec () const {return path_flags & PATH_CYGWIN_EXEC;} - bool exists () const {return fileattr != (DWORD) -1;} + bool exists () const {return fileattr != INVALID_FILE_ATTRIBUTES;} bool has_attribute (DWORD x) const {return exists () && (fileattr & x);} int isdir () const {return has_attribute (FILE_ATTRIBUTE_DIRECTORY);} executable_states exec_state () @@ -124,7 +124,7 @@ class path_conv check (src, opt | PC_NULLEMPTY, suffixes); } - path_conv (): path_flags (0), known_suffix (NULL), error (0), devn (0), unit (0), fileattr (0xffffffff) {path[0] = '\0';} + path_conv (): path_flags (0), known_suffix (NULL), error (0), devn (0), unit (0), fileattr (INVALID_FILE_ATTRIBUTES) {path[0] = '\0';} inline char *get_win32 () { return path; } operator char *() {return path; } diff --git a/winsup/cygwin/syscalls.cc b/winsup/cygwin/syscalls.cc index a7bb3ac00..c7693ae81 100644 --- a/winsup/cygwin/syscalls.cc +++ b/winsup/cygwin/syscalls.cc @@ -205,7 +205,8 @@ _unlink (const char *ourname) syscall_printf ("CreateFile/CloseHandle succeeded"); /* Everything is fine if the file has disappeared or if we know that the FILE_FLAG_DELETE_ON_CLOSE will eventually work. */ - if (GetFileAttributes (win32_name) == (DWORD) -1 || delete_on_close_ok) + if (GetFileAttributes (win32_name) == INVALID_FILE_ATTRIBUTES + || delete_on_close_ok) goto ok; /* The file is either gone already or will eventually be deleted by the OS. */ } diff --git a/winsup/cygwin/times.cc b/winsup/cygwin/times.cc index e5635ddff..1993c5884 100644 --- a/winsup/cygwin/times.cc +++ b/winsup/cygwin/times.cc @@ -1,6 +1,6 @@ /* times.cc - Copyright 1996, 1997, 1998, 1999, 2000, 2001 Red Hat, Inc. + Copyright 1996, 1997, 1998, 1999, 2000, 2001, 2002 Red Hat, Inc. This file is part of Cygwin. @@ -475,8 +475,7 @@ utimes (const char *path, struct timeval *tvp) if (h == INVALID_HANDLE_VALUE) { - if ((res = GetFileAttributes (win32.get_win32 ())) != -1 && - (res & FILE_ATTRIBUTE_DIRECTORY)) + if (win32.isdir ()) { /* What we can do with directories more? */ res = 0;