X-Git-Url: https://git.gag.com/?a=blobdiff_plain;f=lib%2Fopen.c;fp=lib%2Fopen.c;h=27801b916cdc1bd4c15732bd34a9f971c7be4313;hb=dc84183747ce1703eb99685b5dbde1f65a143c06;hp=f612b802d2185505b2aa19cc72290ab790190cba;hpb=a2016c1de6e4884f6c8ed5cc498f3bf821c25ca4;p=debian%2Fgzip diff --git a/lib/open.c b/lib/open.c index f612b80..27801b9 100644 --- a/lib/open.c +++ b/lib/open.c @@ -1,5 +1,5 @@ /* Open a descriptor to a file. - Copyright (C) 2007-2010 Free Software Foundation, Inc. + Copyright (C) 2007-2012 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 @@ -16,13 +16,16 @@ /* Written by Bruno Haible , 2007. */ +/* If the user's config.h happens to include , let it include only + the system's here, so that orig_open doesn't recurse to + rpl_open. */ +#define __need_system_fcntl_h #include /* Get the original definition of open. It might be defined as a macro. */ -#define __need_system_fcntl_h #include -#undef __need_system_fcntl_h #include +#undef __need_system_fcntl_h static inline int orig_open (const char *filename, int flags, mode_t mode) @@ -31,7 +34,9 @@ orig_open (const char *filename, int flags, mode_t mode) } /* Specification. */ -#include +/* Write "fcntl.h" here, not , otherwise OSF/1 5.1 DTK cc eliminates + this include because of the preliminary #include above. */ +#include "fcntl.h" #include #include @@ -63,6 +68,15 @@ open (const char *filename, int flags, ...) va_end (arg); } +#if GNULIB_defined_O_NONBLOCK + /* The only known platform that lacks O_NONBLOCK is mingw, but it + also lacks named pipes and Unix sockets, which are the only two + file types that require non-blocking handling in open(). + Therefore, it is safe to ignore O_NONBLOCK here. It is handy + that mingw also lacks openat(), so that is also covered here. */ + flags &= ~O_NONBLOCK; +#endif + #if (defined _WIN32 || defined __WIN32__) && ! defined __CYGWIN__ if (strcmp (filename, "/dev/null") == 0) filename = "NUL"; @@ -111,7 +125,8 @@ 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 - && (flags & O_ACCMODE) == O_RDONLY) + && ((flags & O_ACCMODE) == O_RDONLY + || (O_SEARCH != O_RDONLY && (flags & O_ACCMODE) == O_SEARCH))) { struct stat statbuf; if (stat (filename, &statbuf) == 0 && S_ISDIR (statbuf.st_mode))