This is the mail archive of the
gdb-patches@sourceware.org
mailing list for the GDB project.
openp: Report a proper error message when attempting to open a directory or special file
- From: Nicolai HÃhnle-Montoro <nhaehnle at gmail dot com>
- To: gdb-patches at sourceware dot org
- Date: Thu, 12 Feb 2015 12:04:44 +0100
- Subject: openp: Report a proper error message when attempting to open a directory or special file
- Authentication-results: sourceware.org; auth=none
I have attached this patch also to bug #17911, but sending it here
also since it may be the more relevant place.
Cheers,
Nicolai
--
Lerne, wie die Welt wirklich ist,
aber vergiss niemals, wie sie sein sollte.
commit 5238e6871515e591feb93cbc90df2b64b4ab67c9
Author: Nicolai HÃhnle <haehnle@or.uni-bonn.de>
Date: Sat Jan 31 15:21:14 2015 +0100
openp: Report a proper error message when attempting to open a directory or special file
diff --git a/gdb/source.c b/gdb/source.c
index 14b1f71..20e2531 100644
--- a/gdb/source.c
+++ b/gdb/source.c
@@ -679,7 +679,9 @@ source_info (char *ignore, int from_tty)
}
-/* Return True if the file NAME exists and is a regular file. */
+/* Return True if the file NAME exists and is a regular file.
+
+ Ensures that errno is set to an appropriate value. */
static int
is_regular_file (const char *name)
{
@@ -694,7 +696,18 @@ is_regular_file (const char *name)
if (status != 0)
return (errno != ENOENT);
- return S_ISREG (st.st_mode);
+ if (S_ISDIR (st.st_mode))
+ {
+ errno = EISDIR;
+ return 0;
+ }
+ else if (!S_ISREG (st.st_mode))
+ {
+ errno = ENOEXEC;
+ return 0;
+ }
+ else
+ return 1;
}
/* Open a file named STRING, searching path PATH (dir names sep by some char)