openp: Report a proper error message when attempting to open a directory or special file
Commit Message
I have attached this patch also to bug #17911, but sending it here
also since it may be the more relevant place.
Cheers,
Nicolai
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
@@ -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)