X-Git-Url: http://erislabs.net/gitweb/?a=blobdiff_plain;f=lib%2Fopen.c;h=f612b802d2185505b2aa19cc72290ab790190cba;hb=ca1938db6aed3e620314e9dfc451d7fe4d4ebb91;hp=08ecaff44b49efb636931828e54b6b89861445d8;hpb=dd66a62cc2d76ab463e1167824ea4ca5fd4ef2ae;p=gnulib.git diff --git a/lib/open.c b/lib/open.c index 08ecaff44..f612b802d 100644 --- a/lib/open.c +++ b/lib/open.c @@ -1,5 +1,5 @@ /* Open a descriptor to a file. - Copyright (C) 2007-2009 Free Software Foundation, Inc. + Copyright (C) 2007-2010 Free Software Foundation, Inc. This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by @@ -57,7 +57,7 @@ open (const char *filename, int flags, ...) va_start (arg, flags); /* We have to use PROMOTED_MODE_T instead of mode_t, otherwise GCC 4 - creates crashing code when 'mode_t' is smaller than 'int'. */ + creates crashing code when 'mode_t' is smaller than 'int'. */ mode = va_arg (arg, PROMOTED_MODE_T); va_end (arg); @@ -94,10 +94,10 @@ open (const char *filename, int flags, ...) { size_t len = strlen (filename); if (len > 0 && filename[len - 1] == '/') - { - errno = EISDIR; - return -1; - } + { + errno = EISDIR; + return -1; + } } #endif @@ -111,7 +111,7 @@ open (const char *filename, int flags, ...) override fstat() in fchdir.c to hide the fact that we have a dummy. */ if (REPLACE_OPEN_DIRECTORY && fd < 0 && errno == EACCES - && (mode & O_ACCMODE) == O_RDONLY) + && (flags & O_ACCMODE) == O_RDONLY) { struct stat statbuf; if (stat (filename, &statbuf) == 0 && S_ISDIR (statbuf.st_mode)) @@ -141,18 +141,19 @@ open (const char *filename, int flags, ...) with ENOTDIR. */ if (fd >= 0) { + /* We know len is positive, since open did not fail with ENOENT. */ size_t len = strlen (filename); - if (len > 0 && filename[len - 1] == '/') - { - struct stat statbuf; - - if (fstat (fd, &statbuf) >= 0 && !S_ISDIR (statbuf.st_mode)) - { - close (fd); - errno = ENOTDIR; - return -1; - } - } + if (filename[len - 1] == '/') + { + struct stat statbuf; + + if (fstat (fd, &statbuf) >= 0 && !S_ISDIR (statbuf.st_mode)) + { + close (fd); + errno = ENOTDIR; + return -1; + } + } } #endif