Mirror of the gdb-patches mailing list
 help / color / mirror / Atom feed
From: Joel Brobecker <brobecker@ACT-Europe.FR>
To: Eli Zaretskii <eliz@is.elta.co.il>
Cc: gdb-patches@sources.redhat.com
Subject: Re: [RFA] Should openp open directories?
Date: Mon, 22 Apr 2002 04:00:00 -0000	[thread overview]
Message-ID: <20020422130016.D21070@act-europe.fr> (raw)
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

[-- Attachment #1: Type: text/plain, Size: 372 bytes --]

> 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  <brobecker@gnat.com>

        * 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

[-- Attachment #2: source.c.diff --]
[-- Type: text/plain, Size: 2012 bytes --]

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 ----
  }
  \f
  
+ /* 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:

  reply	other threads:[~2002-04-22 11:00 UTC|newest]

Thread overview: 7+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2002-04-18  3:25 Joel Brobecker
2002-04-18  8:17 ` Eli Zaretskii
2002-04-19  2:18   ` Joel Brobecker
2002-04-19  2:54     ` Eli Zaretskii
2002-04-22  4:00       ` Joel Brobecker [this message]
2002-04-22 11:33         ` Eli Zaretskii
2002-04-23  4:09           ` Joel Brobecker

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20020422130016.D21070@act-europe.fr \
    --to=brobecker@act-europe.fr \
    --cc=eliz@is.elta.co.il \
    --cc=gdb-patches@sources.redhat.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox