diff options
| author | Richard M. Stallman | 1995-07-22 16:13:31 +0000 |
|---|---|---|
| committer | Richard M. Stallman | 1995-07-22 16:13:31 +0000 |
| commit | 3be3c08ef8142ada51a065831d3350bf39a786e8 (patch) | |
| tree | 3da63dc82438fc597dc40b17c989077fa3176c77 /src | |
| parent | cbc55f55696b257a75007fefbfc57bec7dc67ab8 (diff) | |
| download | emacs-3be3c08ef8142ada51a065831d3350bf39a786e8.tar.gz emacs-3be3c08ef8142ada51a065831d3350bf39a786e8.zip | |
(do_auto_save_unwind): Set auto_saving to 0.
(Fdo_auto_save): Don't clear auto_saving here. Set it to 1
only when we make the unwind-protect.
(Ffile_modes) [DOS_NT]: Use check_executable.
(check_executable): DOS_NT code moved here from Ffile_modes.
(check_writable): New code for MSDOS.
(Fexpand_file_name): Initial ~ means name is absolute.
Diffstat (limited to 'src')
| -rw-r--r-- | src/fileio.c | 81 |
1 files changed, 53 insertions, 28 deletions
diff --git a/src/fileio.c b/src/fileio.c index 19706a19873..3465f8cbe03 100644 --- a/src/fileio.c +++ b/src/fileio.c | |||
| @@ -835,6 +835,32 @@ See also the function `substitute-in-file-name'.") | |||
| 835 | } | 835 | } |
| 836 | #endif /* DOS_NT */ | 836 | #endif /* DOS_NT */ |
| 837 | 837 | ||
| 838 | /* Handle // and /~ in middle of file name | ||
| 839 | by discarding everything through the first / of that sequence. */ | ||
| 840 | p = nm; | ||
| 841 | while (*p) | ||
| 842 | { | ||
| 843 | /* Since we know the path is absolute, we can assume that each | ||
| 844 | element starts with a "/". */ | ||
| 845 | |||
| 846 | /* "//" anywhere isn't necessarily hairy; we just start afresh | ||
| 847 | with the second slash. */ | ||
| 848 | if (IS_DIRECTORY_SEP (p[0]) && IS_DIRECTORY_SEP (p[1]) | ||
| 849 | #if defined (APOLLO) || defined (WINDOWSNT) | ||
| 850 | /* // at start of filename is meaningful on Apollo | ||
| 851 | and WindowsNT systems */ | ||
| 852 | && nm != p | ||
| 853 | #endif /* APOLLO || WINDOWSNT */ | ||
| 854 | ) | ||
| 855 | nm = p + 1; | ||
| 856 | |||
| 857 | /* "~" is hairy as the start of any path element. */ | ||
| 858 | if (IS_DIRECTORY_SEP (p[0]) && p[1] == '~') | ||
| 859 | nm = p + 1; | ||
| 860 | |||
| 861 | p++; | ||
| 862 | } | ||
| 863 | |||
| 838 | /* If nm is absolute, flush ...// and detect /./ and /../. | 864 | /* If nm is absolute, flush ...// and detect /./ and /../. |
| 839 | If no /./ or /../ we can return right away. */ | 865 | If no /./ or /../ we can return right away. */ |
| 840 | if ( | 866 | if ( |
| @@ -858,21 +884,6 @@ See also the function `substitute-in-file-name'.") | |||
| 858 | /* Since we know the path is absolute, we can assume that each | 884 | /* Since we know the path is absolute, we can assume that each |
| 859 | element starts with a "/". */ | 885 | element starts with a "/". */ |
| 860 | 886 | ||
| 861 | /* "//" anywhere isn't necessarily hairy; we just start afresh | ||
| 862 | with the second slash. */ | ||
| 863 | if (IS_DIRECTORY_SEP (p[0]) && IS_DIRECTORY_SEP (p[1]) | ||
| 864 | #if defined (APOLLO) || defined (WINDOWSNT) | ||
| 865 | /* // at start of filename is meaningful on Apollo | ||
| 866 | and WindowsNT systems */ | ||
| 867 | && nm != p | ||
| 868 | #endif /* APOLLO || WINDOWSNT */ | ||
| 869 | ) | ||
| 870 | nm = p + 1; | ||
| 871 | |||
| 872 | /* "~" is hairy as the start of any path element. */ | ||
| 873 | if (IS_DIRECTORY_SEP (p[0]) && p[1] == '~') | ||
| 874 | nm = p + 1, lose = 1; | ||
| 875 | |||
| 876 | /* "." and ".." are hairy. */ | 887 | /* "." and ".." are hairy. */ |
| 877 | if (IS_DIRECTORY_SEP (p[0]) | 888 | if (IS_DIRECTORY_SEP (p[0]) |
| 878 | && p[1] == '.' | 889 | && p[1] == '.' |
| @@ -2284,6 +2295,18 @@ static int | |||
| 2284 | check_executable (filename) | 2295 | check_executable (filename) |
| 2285 | char *filename; | 2296 | char *filename; |
| 2286 | { | 2297 | { |
| 2298 | #ifdef DOS_NT | ||
| 2299 | int len = strlen (filename); | ||
| 2300 | char *suffix; | ||
| 2301 | struct stat st; | ||
| 2302 | if (stat (filename, &st) < 0) | ||
| 2303 | return 0; | ||
| 2304 | return (S_ISREG (st.st_mode) | ||
| 2305 | && len >= 5 | ||
| 2306 | && (stricmp ((suffix = filename + len-4), ".com") == 0 | ||
| 2307 | || stricmp (suffix, ".exe") == 0 | ||
| 2308 | || stricmp (suffix, ".bat") == 0)); | ||
| 2309 | #else /* not DOS_NT */ | ||
| 2287 | #ifdef HAVE_EACCESS | 2310 | #ifdef HAVE_EACCESS |
| 2288 | return (eaccess (filename, 1) >= 0); | 2311 | return (eaccess (filename, 1) >= 0); |
| 2289 | #else | 2312 | #else |
| @@ -2292,6 +2315,7 @@ check_executable (filename) | |||
| 2292 | But Unix doesn't give us a right way to do it. */ | 2315 | But Unix doesn't give us a right way to do it. */ |
| 2293 | return (access (filename, 1) >= 0); | 2316 | return (access (filename, 1) >= 0); |
| 2294 | #endif | 2317 | #endif |
| 2318 | #endif /* not DOS_NT */ | ||
| 2295 | } | 2319 | } |
| 2296 | 2320 | ||
| 2297 | /* Return nonzero if file FILENAME exists and can be written. */ | 2321 | /* Return nonzero if file FILENAME exists and can be written. */ |
| @@ -2300,6 +2324,12 @@ static int | |||
| 2300 | check_writable (filename) | 2324 | check_writable (filename) |
| 2301 | char *filename; | 2325 | char *filename; |
| 2302 | { | 2326 | { |
| 2327 | #ifdef MSDOS | ||
| 2328 | struct stat st; | ||
| 2329 | if (stat (filename, &st) < 0) | ||
| 2330 | return 0; | ||
| 2331 | return (st.st_mode & S_IWRITE || (st.st_mode & S_IFMT) == S_IFDIR); | ||
| 2332 | #else /* not MSDOS */ | ||
| 2303 | #ifdef HAVE_EACCESS | 2333 | #ifdef HAVE_EACCESS |
| 2304 | return (eaccess (filename, 2) >= 0); | 2334 | return (eaccess (filename, 2) >= 0); |
| 2305 | #else | 2335 | #else |
| @@ -2310,6 +2340,7 @@ check_writable (filename) | |||
| 2310 | but would lose for directories. */ | 2340 | but would lose for directories. */ |
| 2311 | return (access (filename, 2) >= 0); | 2341 | return (access (filename, 2) >= 0); |
| 2312 | #endif | 2342 | #endif |
| 2343 | #endif /* not MSDOS */ | ||
| 2313 | } | 2344 | } |
| 2314 | 2345 | ||
| 2315 | DEFUN ("file-exists-p", Ffile_exists_p, Sfile_exists_p, 1, 1, 0, | 2346 | DEFUN ("file-exists-p", Ffile_exists_p, Sfile_exists_p, 1, 1, 0, |
| @@ -2565,16 +2596,8 @@ DEFUN ("file-modes", Ffile_modes, Sfile_modes, 1, 1, 0, | |||
| 2565 | if (stat (XSTRING (abspath)->data, &st) < 0) | 2596 | if (stat (XSTRING (abspath)->data, &st) < 0) |
| 2566 | return Qnil; | 2597 | return Qnil; |
| 2567 | #ifdef DOS_NT | 2598 | #ifdef DOS_NT |
| 2568 | { | 2599 | if (check_executable (XSTRING (abspath)->data)) |
| 2569 | int len; | 2600 | st.st_mode |= S_IEXEC; |
| 2570 | char *suffix; | ||
| 2571 | if (S_ISREG (st.st_mode) | ||
| 2572 | && (len = XSTRING (abspath)->size) >= 5 | ||
| 2573 | && (stricmp ((suffix = XSTRING (abspath)->data + len-4), ".com") == 0 | ||
| 2574 | || stricmp (suffix, ".exe") == 0 | ||
| 2575 | || stricmp (suffix, ".bat") == 0)) | ||
| 2576 | st.st_mode |= S_IEXEC; | ||
| 2577 | } | ||
| 2578 | #endif /* DOS_NT */ | 2601 | #endif /* DOS_NT */ |
| 2579 | 2602 | ||
| 2580 | return make_number (st.st_mode & 07777); | 2603 | return make_number (st.st_mode & 07777); |
| @@ -3733,6 +3756,7 @@ static Lisp_Object | |||
| 3733 | do_auto_save_unwind (desc) /* used as unwind-protect function */ | 3756 | do_auto_save_unwind (desc) /* used as unwind-protect function */ |
| 3734 | Lisp_Object desc; | 3757 | Lisp_Object desc; |
| 3735 | { | 3758 | { |
| 3759 | auto_saving = 0; | ||
| 3736 | close (XINT (desc)); | 3760 | close (XINT (desc)); |
| 3737 | return Qnil; | 3761 | return Qnil; |
| 3738 | } | 3762 | } |
| @@ -3770,7 +3794,6 @@ Non-nil second argument means save only current buffer.") | |||
| 3770 | /* No GCPRO needed, because (when it matters) all Lisp_Object variables | 3794 | /* No GCPRO needed, because (when it matters) all Lisp_Object variables |
| 3771 | point to non-strings reached from Vbuffer_alist. */ | 3795 | point to non-strings reached from Vbuffer_alist. */ |
| 3772 | 3796 | ||
| 3773 | auto_saving = 1; | ||
| 3774 | if (minibuf_level) | 3797 | if (minibuf_level) |
| 3775 | no_message = Qt; | 3798 | no_message = Qt; |
| 3776 | 3799 | ||
| @@ -3792,10 +3815,13 @@ Non-nil second argument means save only current buffer.") | |||
| 3792 | else | 3815 | else |
| 3793 | listdesc = -1; | 3816 | listdesc = -1; |
| 3794 | 3817 | ||
| 3795 | /* Arrange to close that file whether or not we get an error. */ | 3818 | /* Arrange to close that file whether or not we get an error. |
| 3819 | Also reset auto_saving to 0. */ | ||
| 3796 | if (listdesc >= 0) | 3820 | if (listdesc >= 0) |
| 3797 | record_unwind_protect (do_auto_save_unwind, make_number (listdesc)); | 3821 | record_unwind_protect (do_auto_save_unwind, make_number (listdesc)); |
| 3798 | 3822 | ||
| 3823 | auto_saving = 1; | ||
| 3824 | |||
| 3799 | /* First, save all files which don't have handlers. If Emacs is | 3825 | /* First, save all files which don't have handlers. If Emacs is |
| 3800 | crashing, the handlers may tweak what is causing Emacs to crash | 3826 | crashing, the handlers may tweak what is causing Emacs to crash |
| 3801 | in the first place, and it would be a shame if Emacs failed to | 3827 | in the first place, and it would be a shame if Emacs failed to |
| @@ -3903,7 +3929,6 @@ Non-nil second argument means save only current buffer.") | |||
| 3903 | 3929 | ||
| 3904 | Vquit_flag = oquit; | 3930 | Vquit_flag = oquit; |
| 3905 | 3931 | ||
| 3906 | auto_saving = 0; | ||
| 3907 | unbind_to (count, Qnil); | 3932 | unbind_to (count, Qnil); |
| 3908 | return Qnil; | 3933 | return Qnil; |
| 3909 | } | 3934 | } |