X-Git-Url: http://erislabs.net/gitweb/?a=blobdiff_plain;f=lib%2Ffopen.c;h=33412fbcea1f314097535830d942f218b1e5d059;hb=e901c96e0151d00195c60e9efb1a7668c4b5e3bd;hp=72610bd9b4414b5c4e49cac72640b55f87d2b375;hpb=fc75b897899e64bed6a931c93b967e698da2d213;p=gnulib.git diff --git a/lib/fopen.c b/lib/fopen.c index 72610bd9b..33412fbce 100644 --- a/lib/fopen.c +++ b/lib/fopen.c @@ -1,5 +1,5 @@ /* Open a stream to a file. - Copyright (C) 2007-2009 Free Software Foundation, Inc. + Copyright (C) 2007-2011 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,10 +16,13 @@ /* 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_fopen doesn't recurse to + rpl_fopen. */ +#define __need_FILE #include /* Get the original definition of fopen. It might be defined as a macro. */ -#define __need_FILE #include #undef __need_FILE @@ -68,35 +71,35 @@ rpl_fopen (const char *filename, const char *mode) size_t len = strlen (filename); if (len > 0 && filename[len - 1] == '/') { - int fd; - struct stat statbuf; - FILE *fp; - - if (mode[0] == 'w' || mode[0] == 'a') - { - errno = EISDIR; - return NULL; - } - - fd = open (filename, O_RDONLY); - if (fd < 0) - return NULL; - - if (fstat (fd, &statbuf) >= 0 && !S_ISDIR (statbuf.st_mode)) - { - close (fd); - errno = ENOTDIR; - return NULL; - } - - fp = fdopen (fd, mode); - if (fp == NULL) - { - int saved_errno = errno; - close (fd); - errno = saved_errno; - } - return fp; + int fd; + struct stat statbuf; + FILE *fp; + + if (mode[0] == 'w' || mode[0] == 'a') + { + errno = EISDIR; + return NULL; + } + + fd = open (filename, O_RDONLY); + if (fd < 0) + return NULL; + + if (fstat (fd, &statbuf) >= 0 && !S_ISDIR (statbuf.st_mode)) + { + close (fd); + errno = ENOTDIR; + return NULL; + } + + fp = fdopen (fd, mode); + if (fp == NULL) + { + int saved_errno = errno; + close (fd); + errno = saved_errno; + } + return fp; } } # endif