* rename.c (smart_rename): Fix test of whether file exists.

This commit is contained in:
Ian Lance Taylor 1999-05-06 11:03:33 +00:00
parent a8a9050d4a
commit 82716b788e
2 changed files with 8 additions and 4 deletions

View file

@ -1,3 +1,7 @@
1999-05-06 Ian Lance Taylor <ian@zembu.com>
* rename.c (smart_rename): Fix test of whether file exists.
1999-05-06 Nick Clifton <nickc@cygnus.com> 1999-05-06 Nick Clifton <nickc@cygnus.com>
* objdump.c (disassemble_data): Set display_endian based on target * objdump.c (disassemble_data): Set display_endian based on target

View file

@ -139,17 +139,17 @@ smart_rename (from, to, preserve_dates)
const char *to; const char *to;
int preserve_dates; int preserve_dates;
{ {
int exists; boolean exists;
struct stat s; struct stat s;
int ret = 0; int ret = 0;
exists = lstat (to, &s); exists = lstat (to, &s) == 0;
#if defined (_WIN32) && !defined (__CYGWIN32__) #if defined (_WIN32) && !defined (__CYGWIN32__)
/* Win32, unlike unix, will not erase `to' in `rename(from, to)' but /* Win32, unlike unix, will not erase `to' in `rename(from, to)' but
fail instead. Also, chown is not present. */ fail instead. Also, chown is not present. */
if (exists == 0) if (exists)
remove (to); remove (to);
ret = rename (from, to); ret = rename (from, to);
@ -163,7 +163,7 @@ smart_rename (from, to, preserve_dates)
#else #else
/* Use rename only if TO is not a symbolic link and has /* Use rename only if TO is not a symbolic link and has
only one hard link. */ only one hard link. */
if (exists < 0 || (!S_ISLNK (s.st_mode) && s.st_nlink == 1)) if (! exists || (!S_ISLNK (s.st_mode) && s.st_nlink == 1))
{ {
ret = rename (from, to); ret = rename (from, to);
if (ret == 0) if (ret == 0)