* 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.
This commit is contained in:
Corinna Vinschen 2002-01-14 20:39:59 +00:00
parent 55409319de
commit 7eddac1bc5
8 changed files with 33 additions and 21 deletions

View File

@ -1,3 +1,15 @@
2002-01-14 Corinna Vinschen <corinna@vinschen.de>
* 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 <cgf@redhat.com> 2002-01-13 Christopher Faylor <cgf@redhat.com>
* dcrt0.cc (multiple_cygwin_problem): Clarify logic and make * dcrt0.cc (multiple_cygwin_problem): Clarify logic and make

View File

@ -260,7 +260,7 @@ rmdir (const char *dir)
/* RemoveDirectory on a samba drive doesn't return an error if the /* RemoveDirectory on a samba drive doesn't return an error if the
directory can't be removed because it's not empty. Checking for directory can't be removed because it's not empty. Checking for
existence afterwards keeps us informed about success. */ existence afterwards keeps us informed about success. */
if (GetFileAttributes (real_dir) != (DWORD) -1) if (GetFileAttributes (real_dir) != INVALID_FILE_ATTRIBUTES)
set_errno (ENOTEMPTY); set_errno (ENOTEMPTY);
else else
res = 0; res = 0;

View File

@ -1,6 +1,6 @@
/* fhandler.cc. See console.cc for fhandler_console functions. /* 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. This file is part of Cygwin.
@ -386,7 +386,7 @@ fhandler_base::open (path_conv *, int flags, mode_t mode)
if (get_query_open () && if (get_query_open () &&
isremote () && isremote () &&
creation_distribution == OPEN_EXISTING && creation_distribution == OPEN_EXISTING &&
GetFileAttributes (get_win32_name ()) == (DWORD) -1) GetFileAttributes (get_win32_name ()) == INVALID_FILE_ATTRIBUTES)
{ {
set_errno (ENOENT); set_errno (ENOENT);
goto done; goto done;

View File

@ -1,6 +1,6 @@
/* fhandler_disk_file.cc /* 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. 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 which returns a valid handle when trying to open a file in a nonexistent
directory. */ directory. */
if (real_path->has_buggy_open () if (real_path->has_buggy_open ()
&& GetFileAttributes (win32_path_name) == (DWORD) -1) && GetFileAttributes (win32_path_name) == INVALID_FILE_ATTRIBUTES)
{ {
debug_printf ("Buggy open detected."); debug_printf ("Buggy open detected.");
close (); close ();
@ -804,7 +804,7 @@ fhandler_cygdrive::readdir (DIR *dir)
set_errno (ENMFILE); set_errno (ENMFILE);
return NULL; return NULL;
} }
if (GetFileAttributes (pdrive) == (DWORD) -1) if (GetFileAttributes (pdrive) == INVALID_FILE_ATTRIBUTES)
{ {
pdrive += DRVSZ; pdrive += DRVSZ;
return readdir (dir); return readdir (dir);

View File

@ -1,6 +1,6 @@
/* path.cc: path support. /* 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. This file is part of Cygwin.
@ -400,7 +400,7 @@ path_conv::check (const char *src, unsigned opt,
int loop = 0; int loop = 0;
path_flags = 0; path_flags = 0;
known_suffix = NULL; known_suffix = NULL;
fileattr = (DWORD) -1; fileattr = INVALID_FILE_ATTRIBUTES;
case_clash = false; case_clash = false;
devn = unit = 0; devn = unit = 0;
root_dir[0] = '\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 /* If symlink.check found an existing non-symlink file, then
it sets the appropriate flag. It also sets any suffix found it sets the appropriate flag. It also sets any suffix found
into `ext_here'. */ into `ext_here'. */
if (!sym.is_symlink && sym.fileattr != (DWORD) -1) if (!sym.is_symlink && sym.fileattr != INVALID_FILE_ATTRIBUTES)
{ {
error = sym.error; error = sym.error;
if (component == 0) if (component == 0)
@ -2397,7 +2397,7 @@ cygdrive_getmntent ()
__small_sprintf (native_path, "%c:\\", drive); __small_sprintf (native_path, "%c:\\", drive);
if (GetDriveType (native_path) == DRIVE_REMOVABLE || if (GetDriveType (native_path) == DRIVE_REMOVABLE ||
GetFileAttributes (native_path) == (DWORD) -1) GetFileAttributes (native_path) == INVALID_FILE_ATTRIBUTES)
{ {
available_drives &= ~mask; available_drives &= ~mask;
continue; continue;
@ -2609,7 +2609,7 @@ symlink (const char *topath, const char *frompath)
} }
backslashify (topath, w32topath, 0); backslashify (topath, w32topath, 0);
} }
if (!cp || GetFileAttributes (w32topath) == (DWORD)-1) if (!cp || GetFileAttributes (w32topath) == INVALID_FILE_ATTRIBUTES)
{ {
win32_topath.check (topath, PC_SYM_NOFOLLOW); win32_topath.check (topath, PC_SYM_NOFOLLOW);
if (!cp || win32_topath.error != ENOENT) if (!cp || win32_topath.error != ENOENT)
@ -2911,7 +2911,7 @@ symlink_info::check (char *path, const suffix_info *suffixes, unsigned opt)
{ {
error = 0; error = 0;
fileattr = GetFileAttributes (suffix.path); fileattr = GetFileAttributes (suffix.path);
if (fileattr == (DWORD) -1) if (fileattr == INVALID_FILE_ATTRIBUTES)
{ {
/* The GetFileAttributes call can fail for reasons that don't /* The GetFileAttributes call can fail for reasons that don't
matter, so we just return 0. For example, getting the 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) if (!suffix.lnk_match () || !ext_tacked_on)
goto file_not_symlink; goto file_not_symlink;
fileattr = (DWORD) -1; fileattr = INVALID_FILE_ATTRIBUTES;
continue; /* in case we're going to tack *another* .lnk on this filename. */ continue; /* in case we're going to tack *another* .lnk on this filename. */
case 2: case 2:
res = check_sysfile (suffix.path, fileattr, h, contents, &error, &pflags); 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.issymlink ())
{ {
if (pathbuf.fileattr != (DWORD) -1) if (pathbuf.fileattr != INVALID_FILE_ATTRIBUTES)
set_errno (EINVAL); set_errno (EINVAL);
return -1; return -1;
} }

View File

@ -1,6 +1,6 @@
/* path.h: path data structures /* 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. This file is part of Cygwin.
@ -86,7 +86,7 @@ class path_conv
int issymlink () const {return path_flags & PATH_SYMLINK;} int issymlink () const {return path_flags & PATH_SYMLINK;}
int issocket () const {return path_flags & PATH_SOCKET;} int issocket () const {return path_flags & PATH_SOCKET;}
int iscygexec () const {return path_flags & PATH_CYGWIN_EXEC;} 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);} bool has_attribute (DWORD x) const {return exists () && (fileattr & x);}
int isdir () const {return has_attribute (FILE_ATTRIBUTE_DIRECTORY);} int isdir () const {return has_attribute (FILE_ATTRIBUTE_DIRECTORY);}
executable_states exec_state () executable_states exec_state ()
@ -124,7 +124,7 @@ class path_conv
check (src, opt | PC_NULLEMPTY, suffixes); 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; } inline char *get_win32 () { return path; }
operator char *() {return path; } operator char *() {return path; }

View File

@ -205,7 +205,8 @@ _unlink (const char *ourname)
syscall_printf ("CreateFile/CloseHandle succeeded"); syscall_printf ("CreateFile/CloseHandle succeeded");
/* Everything is fine if the file has disappeared or if we know that the /* Everything is fine if the file has disappeared or if we know that the
FILE_FLAG_DELETE_ON_CLOSE will eventually work. */ 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 goto ok; /* The file is either gone already or will eventually be
deleted by the OS. */ deleted by the OS. */
} }

View File

@ -1,6 +1,6 @@
/* times.cc /* 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. This file is part of Cygwin.
@ -475,8 +475,7 @@ utimes (const char *path, struct timeval *tvp)
if (h == INVALID_HANDLE_VALUE) if (h == INVALID_HANDLE_VALUE)
{ {
if ((res = GetFileAttributes (win32.get_win32 ())) != -1 && if (win32.isdir ())
(res & FILE_ATTRIBUTE_DIRECTORY))
{ {
/* What we can do with directories more? */ /* What we can do with directories more? */
res = 0; res = 0;