From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 25426 invoked by alias); 22 Apr 2002 11:00:26 -0000 Mailing-List: contact gdb-patches-help@sources.redhat.com; run by ezmlm Precedence: bulk List-Subscribe: List-Archive: List-Post: List-Help: , Sender: gdb-patches-owner@sources.redhat.com Received: (qmail 25317 invoked from network); 22 Apr 2002 11:00:20 -0000 Received: from unknown (HELO dublin.ACT-Europe.FR) (212.157.227.154) by sources.redhat.com with SMTP; 22 Apr 2002 11:00:20 -0000 Received: from berlin.ACT-Europe.FR (berlin.int.act-europe.fr [10.10.0.169]) by dublin.ACT-Europe.FR (Postfix) with ESMTP id F0E4C229E38; Mon, 22 Apr 2002 13:00:18 +0200 (MET DST) Received: by berlin.ACT-Europe.FR (Postfix, from userid 507) id 397A295B; Mon, 22 Apr 2002 13:00:17 +0200 (CEST) Date: Mon, 22 Apr 2002 04:00:00 -0000 From: Joel Brobecker To: Eli Zaretskii Cc: gdb-patches@sources.redhat.com Subject: Re: [RFA] Should openp open directories? Message-ID: <20020422130016.D21070@act-europe.fr> References: <20020418122535.B11802@act-europe.fr> <20020419111807.A7903@act-europe.fr> <6097-Fri19Apr2002124608+0300-eliz@is.elta.co.il> Mime-Version: 1.0 Content-Type: multipart/mixed; boundary="xgyAXRrhYN0wYx8y" Content-Disposition: inline User-Agent: Mutt/1.2.5i In-Reply-To: <6097-Fri19Apr2002124608+0300-eliz@is.elta.co.il>; from eliz@is.elta.co.il on Fri, Apr 19, 2002 at 12:46:08PM +0300 X-SW-Source: 2002-04/txt/msg00784.txt.bz2 --xgyAXRrhYN0wYx8y Content-Type: text/plain; charset=us-ascii Content-Disposition: inline Content-length: 372 > This is okay with me (non-existing files will fail the open call > anyhow). Sorry for the delay. Here is a new patch, based on our discussion: 2002-04-18 Joel Brobecker * source.c (is_regular_file): New function. (openp): Check wether file to open is a regular file to avoid opening directories. Ok to commit? -- Joel --xgyAXRrhYN0wYx8y Content-Type: text/plain; charset=us-ascii Content-Disposition: attachment; filename="source.c.diff" Content-length: 2012 Index: source.c =================================================================== RCS file: /cvs/src/src/gdb/source.c,v retrieving revision 1.27 diff -c -3 -p -r1.27 source.c *** source.c 12 Apr 2002 19:46:29 -0000 1.27 --- source.c 22 Apr 2002 10:59:28 -0000 *************** source_info (char *ignore, int from_tty) *** 503,508 **** --- 503,525 ---- } + /* Return True if the file NAME exists and is a regular file */ + static int + is_regular_file (const char *name) + { + struct stat st; + const int status = stat (name, &st); + + /* Stat should never fail except when the file does not exist. + If stat fails, analyze the source of error and return True + unless the file does not exist, to avoid returning false results + on obscure systems where stat does not work as expected. + */ + if (status != 0) + return (errno != ENOENT); + + return S_ISREG (st.st_mode); + } /* Open a file named STRING, searching path PATH (dir names sep by some char) using mode MODE and protection bits PROT in the calls to open. *************** openp (const char *path, int try_cwd_fir *** 543,549 **** mode |= O_BINARY; #endif ! if (try_cwd_first || IS_ABSOLUTE_PATH (string)) { int i; filename = alloca (strlen (string) + 1); --- 560,566 ---- mode |= O_BINARY; #endif ! if ((try_cwd_first || IS_ABSOLUTE_PATH (string)) && is_regular_file (string)) { int i; filename = alloca (strlen (string) + 1); *************** openp (const char *path, int try_cwd_fir *** 601,609 **** strcat (filename + len, SLASH_STRING); strcat (filename, string); ! fd = open (filename, mode); ! if (fd >= 0) ! break; } done: --- 618,629 ---- strcat (filename + len, SLASH_STRING); strcat (filename, string); ! if (is_regular_file (filename)) ! { ! fd = open (filename, mode); ! if (fd >= 0) ! break; ! } } done: --xgyAXRrhYN0wYx8y--