diff options
Diffstat (limited to 'src/fileio.c')
| -rw-r--r-- | src/fileio.c | 35 |
1 files changed, 7 insertions, 28 deletions
diff --git a/src/fileio.c b/src/fileio.c index 2ccad83f668..0225e0bf3a9 100644 --- a/src/fileio.c +++ b/src/fileio.c | |||
| @@ -26,18 +26,6 @@ along with GNU Emacs. If not, see <http://www.gnu.org/licenses/>. */ | |||
| 26 | #include <setjmp.h> | 26 | #include <setjmp.h> |
| 27 | #include <unistd.h> | 27 | #include <unistd.h> |
| 28 | 28 | ||
| 29 | #if !defined (S_ISLNK) && defined (S_IFLNK) | ||
| 30 | # define S_ISLNK(m) (((m) & S_IFMT) == S_IFLNK) | ||
| 31 | #endif | ||
| 32 | |||
| 33 | #if !defined (S_ISFIFO) && defined (S_IFIFO) | ||
| 34 | # define S_ISFIFO(m) (((m) & S_IFMT) == S_IFIFO) | ||
| 35 | #endif | ||
| 36 | |||
| 37 | #if !defined (S_ISREG) && defined (S_IFREG) | ||
| 38 | # define S_ISREG(m) (((m) & S_IFMT) == S_IFREG) | ||
| 39 | #endif | ||
| 40 | |||
| 41 | #ifdef HAVE_PWD_H | 29 | #ifdef HAVE_PWD_H |
| 42 | #include <pwd.h> | 30 | #include <pwd.h> |
| 43 | #endif | 31 | #endif |
| @@ -95,10 +83,6 @@ along with GNU Emacs. If not, see <http://www.gnu.org/licenses/>. */ | |||
| 95 | 83 | ||
| 96 | #include "commands.h" | 84 | #include "commands.h" |
| 97 | 85 | ||
| 98 | #ifndef S_ISLNK | ||
| 99 | # define lstat stat | ||
| 100 | #endif | ||
| 101 | |||
| 102 | #ifndef FILE_SYSTEM_CASE | 86 | #ifndef FILE_SYSTEM_CASE |
| 103 | #define FILE_SYSTEM_CASE(filename) (filename) | 87 | #define FILE_SYSTEM_CASE(filename) (filename) |
| 104 | #endif | 88 | #endif |
| @@ -1922,7 +1906,6 @@ on the system, we copy the SELinux context of FILE to NEWNAME. */) | |||
| 1922 | Fcons (file, Fcons (newname, Qnil))); | 1906 | Fcons (file, Fcons (newname, Qnil))); |
| 1923 | } | 1907 | } |
| 1924 | 1908 | ||
| 1925 | #if defined (S_ISREG) && defined (S_ISLNK) | ||
| 1926 | if (input_file_statable_p) | 1909 | if (input_file_statable_p) |
| 1927 | { | 1910 | { |
| 1928 | if (!(S_ISREG (st.st_mode)) && !(S_ISLNK (st.st_mode))) | 1911 | if (!(S_ISREG (st.st_mode)) && !(S_ISLNK (st.st_mode))) |
| @@ -1934,7 +1917,6 @@ on the system, we copy the SELinux context of FILE to NEWNAME. */) | |||
| 1934 | report_file_error ("Non-regular file", Fcons (file, Qnil)); | 1917 | report_file_error ("Non-regular file", Fcons (file, Qnil)); |
| 1935 | } | 1918 | } |
| 1936 | } | 1919 | } |
| 1937 | #endif /* S_ISREG && S_ISLNK */ | ||
| 1938 | 1920 | ||
| 1939 | #ifdef MSDOS | 1921 | #ifdef MSDOS |
| 1940 | /* System's default file type was set to binary by _fmode in emacs.c. */ | 1922 | /* System's default file type was set to binary by _fmode in emacs.c. */ |
| @@ -2408,7 +2390,7 @@ check_writable (const char *filename) | |||
| 2408 | struct stat st; | 2390 | struct stat st; |
| 2409 | if (stat (filename, &st) < 0) | 2391 | if (stat (filename, &st) < 0) |
| 2410 | return 0; | 2392 | return 0; |
| 2411 | return (st.st_mode & S_IWRITE || (st.st_mode & S_IFMT) == S_IFDIR); | 2393 | return (st.st_mode & S_IWRITE || S_ISDIR (st.st_mode)); |
| 2412 | #else /* not MSDOS */ | 2394 | #else /* not MSDOS */ |
| 2413 | #ifdef HAVE_EUIDACCESS | 2395 | #ifdef HAVE_EUIDACCESS |
| 2414 | return (euidaccess (filename, 2) >= 0); | 2396 | return (euidaccess (filename, 2) >= 0); |
| @@ -2500,7 +2482,7 @@ See also `file-exists-p' and `file-attributes'. */) | |||
| 2500 | return Qnil; | 2482 | return Qnil; |
| 2501 | #else /* not DOS_NT and not macintosh */ | 2483 | #else /* not DOS_NT and not macintosh */ |
| 2502 | flags = O_RDONLY; | 2484 | flags = O_RDONLY; |
| 2503 | #if defined (S_ISFIFO) && defined (O_NONBLOCK) | 2485 | #if defined (S_IFIFO) && defined (O_NONBLOCK) |
| 2504 | /* Opening a fifo without O_NONBLOCK can wait. | 2486 | /* Opening a fifo without O_NONBLOCK can wait. |
| 2505 | We don't want to wait. But we don't want to mess wth O_NONBLOCK | 2487 | We don't want to wait. But we don't want to mess wth O_NONBLOCK |
| 2506 | except in the case of a fifo, on a system which handles it. */ | 2488 | except in the case of a fifo, on a system which handles it. */ |
| @@ -2555,7 +2537,7 @@ DEFUN ("file-writable-p", Ffile_writable_p, Sfile_writable_p, 1, 1, 0, | |||
| 2555 | should check ACLs though, which do affect this. */ | 2537 | should check ACLs though, which do affect this. */ |
| 2556 | if (stat (SDATA (dir), &statbuf) < 0) | 2538 | if (stat (SDATA (dir), &statbuf) < 0) |
| 2557 | return Qnil; | 2539 | return Qnil; |
| 2558 | return (statbuf.st_mode & S_IFMT) == S_IFDIR ? Qt : Qnil; | 2540 | return S_ISDIR (statbuf.st_mode) ? Qt : Qnil; |
| 2559 | #else | 2541 | #else |
| 2560 | return (check_writable (!NILP (dir) ? SSDATA (dir) : "") | 2542 | return (check_writable (!NILP (dir) ? SSDATA (dir) : "") |
| 2561 | ? Qt : Qnil); | 2543 | ? Qt : Qnil); |
| @@ -2681,7 +2663,7 @@ See `file-symlink-p' to distinguish symlinks. */) | |||
| 2681 | 2663 | ||
| 2682 | if (stat (SSDATA (absname), &st) < 0) | 2664 | if (stat (SSDATA (absname), &st) < 0) |
| 2683 | return Qnil; | 2665 | return Qnil; |
| 2684 | return (st.st_mode & S_IFMT) == S_IFDIR ? Qt : Qnil; | 2666 | return S_ISDIR (st.st_mode) ? Qt : Qnil; |
| 2685 | } | 2667 | } |
| 2686 | 2668 | ||
| 2687 | DEFUN ("file-accessible-directory-p", Ffile_accessible_directory_p, Sfile_accessible_directory_p, 1, 1, 0, | 2669 | DEFUN ("file-accessible-directory-p", Ffile_accessible_directory_p, Sfile_accessible_directory_p, 1, 1, 0, |
| @@ -2744,12 +2726,12 @@ See `file-symlink-p' to distinguish symlinks. */) | |||
| 2744 | 2726 | ||
| 2745 | if (result < 0) | 2727 | if (result < 0) |
| 2746 | return Qnil; | 2728 | return Qnil; |
| 2747 | return (st.st_mode & S_IFMT) == S_IFREG ? Qt : Qnil; | 2729 | return S_ISREG (st.st_mode) ? Qt : Qnil; |
| 2748 | } | 2730 | } |
| 2749 | #else | 2731 | #else |
| 2750 | if (stat (SSDATA (absname), &st) < 0) | 2732 | if (stat (SSDATA (absname), &st) < 0) |
| 2751 | return Qnil; | 2733 | return Qnil; |
| 2752 | return (st.st_mode & S_IFMT) == S_IFREG ? Qt : Qnil; | 2734 | return S_ISREG (st.st_mode) ? Qt : Qnil; |
| 2753 | #endif | 2735 | #endif |
| 2754 | } | 2736 | } |
| 2755 | 2737 | ||
| @@ -3007,8 +2989,7 @@ Use the current time if TIME is nil. TIME is in the format of | |||
| 3007 | struct stat st; | 2989 | struct stat st; |
| 3008 | 2990 | ||
| 3009 | /* Setting times on a directory always fails. */ | 2991 | /* Setting times on a directory always fails. */ |
| 3010 | if (stat (SDATA (encoded_absname), &st) == 0 | 2992 | if (stat (SSDATA (encoded_absname), &st) == 0 && S_ISDIR (st.st_mode)) |
| 3011 | && (st.st_mode & S_IFMT) == S_IFDIR) | ||
| 3012 | return Qnil; | 2993 | return Qnil; |
| 3013 | #endif | 2994 | #endif |
| 3014 | report_file_error ("Setting file times", Fcons (absname, Qnil)); | 2995 | report_file_error ("Setting file times", Fcons (absname, Qnil)); |
| @@ -3267,7 +3248,6 @@ variable `last-coding-system-used' to the coding system actually used. */) | |||
| 3267 | goto notfound; | 3248 | goto notfound; |
| 3268 | } | 3249 | } |
| 3269 | 3250 | ||
| 3270 | #ifdef S_IFREG | ||
| 3271 | /* This code will need to be changed in order to work on named | 3251 | /* This code will need to be changed in order to work on named |
| 3272 | pipes, and it's probably just not worth it. So we should at | 3252 | pipes, and it's probably just not worth it. So we should at |
| 3273 | least signal an error. */ | 3253 | least signal an error. */ |
| @@ -3282,7 +3262,6 @@ variable `last-coding-system-used' to the coding system actually used. */) | |||
| 3282 | xsignal2 (Qfile_error, | 3262 | xsignal2 (Qfile_error, |
| 3283 | build_string ("not a regular file"), orig_filename); | 3263 | build_string ("not a regular file"), orig_filename); |
| 3284 | } | 3264 | } |
| 3285 | #endif | ||
| 3286 | 3265 | ||
| 3287 | if (fd < 0) | 3266 | if (fd < 0) |
| 3288 | if ((fd = emacs_open (SSDATA (filename), O_RDONLY, 0)) < 0) | 3267 | if ((fd = emacs_open (SSDATA (filename), O_RDONLY, 0)) < 0) |