comparison src/fileio.c @ 225:12579d965149 r20-4b11

Import from CVS: tag r20-4b11
author cvs
date Mon, 13 Aug 2007 10:11:40 +0200
parents 2c611d1463a6
children 0e522484dd2a
comparison
equal deleted inserted replaced
224:4663b37daab6 225:12579d965149
768 && ! (XSTRING_LENGTH (default_) >= 3 768 && ! (XSTRING_LENGTH (default_) >= 3
769 #ifdef DOS_NT 769 #ifdef DOS_NT
770 /* Detect MSDOS file names with drive specifiers. */ 770 /* Detect MSDOS file names with drive specifiers. */
771 && (IS_DRIVE (XSTRING_BYTE (default_, 0)) 771 && (IS_DRIVE (XSTRING_BYTE (default_, 0))
772 && (IS_DEVICE_SEP (XSTRING_BYTE (default_, 1)) 772 && (IS_DEVICE_SEP (XSTRING_BYTE (default_, 1))
773 && IS_DIRECTORY_SEP (XSTRING_BYTE (default_, 2))))) 773 && IS_DIRECTORY_SEP (XSTRING_BYTE (default_, 2))))
774 #ifdef WINDOWSNT 774 #ifdef WINDOWSNT
775 /* Detect Windows file names in UNC format. */ 775 /* Detect Windows file names in UNC format. */
776 && ! (XSTRING_LENGTH (default_) >= 2 776 && ! (XSTRING_LENGTH (default_) >= 2
777 && IS_DIRECTORY_SEP (XSTRING_BYTE (default_, 0)) 777 && IS_DIRECTORY_SEP (XSTRING_BYTE (default_, 0))
778 && IS_DIRECTORY_SEP (XSTRING_BYTE (default_, 1))) 778 && IS_DIRECTORY_SEP (XSTRING_BYTE (default_, 1)))
779 #endif 779 #endif
780 #else /* not DOS_NT */ 780 #else /* not DOS_NT */
781 /* Detect Unix absolute file names (/... alone is not absolute on 781 /* Detect Unix absolute file names (/... alone is not absolute on
782 DOS or Windows). */ 782 DOS or Windows). */
783 && (IS_DIRECTORY_SEP (XSTRING_BYTE (default_, 0)) 783 && (IS_DIRECTORY_SEP (XSTRING_BYTE (default_, 0))
784 || IS_DEVICE_SEP (XSTRING_BYTE (default_, 1)))) 784 || IS_DEVICE_SEP (XSTRING_BYTE (default_, 1)))
785 #endif /* not DOS_NT */ 785 #endif /* not DOS_NT */
786 ) 786 ))
787 { 787 {
788 struct gcpro gcpro1; 788 struct gcpro gcpro1;
789 789
790 GCPRO1 (default_); /* may be current_buffer->directory */ 790 GCPRO1 (default_); /* may be current_buffer->directory */
791 default_ = Fexpand_file_name (default_, Qnil); 791 default_ = Fexpand_file_name (default_, Qnil);
1114 drive = newdir[0]; 1114 drive = newdir[0];
1115 newdir += 2; 1115 newdir += 2;
1116 } 1116 }
1117 1117
1118 /* Keep only a prefix from newdir if nm starts with slash 1118 /* Keep only a prefix from newdir if nm starts with slash
1119 (//server/share for UNC, nothing otherwise). */ 1119 (/ /server/share for UNC, nothing otherwise). */
1120 if (IS_DIRECTORY_SEP (nm[0]) && collapse_newdir) 1120 if (IS_DIRECTORY_SEP (nm[0]) && collapse_newdir)
1121 { 1121 {
1122 #ifdef WINDOWSNT 1122 #ifdef WINDOWSNT
1123 if (IS_DIRECTORY_SEP (newdir[0]) && IS_DIRECTORY_SEP (newdir[1])) 1123 if (IS_DIRECTORY_SEP (newdir[0]) && IS_DIRECTORY_SEP (newdir[1]))
1124 { 1124 {
1724 barf_or_query_if_file_exists (newname, "copy to it", 1724 barf_or_query_if_file_exists (newname, "copy to it",
1725 INTP (ok_if_already_exists), &out_st); 1725 INTP (ok_if_already_exists), &out_st);
1726 else if (stat ((CONST char *) XSTRING_DATA (newname), &out_st) < 0) 1726 else if (stat ((CONST char *) XSTRING_DATA (newname), &out_st) < 0)
1727 out_st.st_mode = 0; 1727 out_st.st_mode = 0;
1728 1728
1729 ifd = open ((char *) XSTRING_DATA (filename), O_RDONLY, 0); 1729 ifd = interruptible_open ((char *) XSTRING_DATA (filename), O_RDONLY, 0);
1730 if (ifd < 0) 1730 if (ifd < 0)
1731 report_file_error ("Opening input file", Fcons (filename, Qnil)); 1731 report_file_error ("Opening input file", Fcons (filename, Qnil));
1732 1732
1733 record_unwind_protect (close_file_unwind, make_int (ifd)); 1733 record_unwind_protect (close_file_unwind, make_int (ifd));
1734 1734
2307 Return t if file FILENAME exists and you can read it. 2307 Return t if file FILENAME exists and you can read it.
2308 See also `file-exists-p' and `file-attributes'. 2308 See also `file-exists-p' and `file-attributes'.
2309 */ 2309 */
2310 (filename)) 2310 (filename))
2311 { 2311 {
2312 /* This function can GC. GC checked 1997.04.10. */ 2312 /* This function can GC */
2313 Lisp_Object abspath; 2313 Lisp_Object abspath = Qnil;
2314 Lisp_Object handler; 2314 Lisp_Object handler;
2315 int desc; 2315 int desc;
2316 struct gcpro gcpro1; 2316 struct gcpro gcpro1;
2317 GCPRO1 (abspath);
2317 2318
2318 CHECK_STRING (filename); 2319 CHECK_STRING (filename);
2319 abspath = Fexpand_file_name (filename, Qnil); 2320 abspath = Fexpand_file_name (filename, Qnil);
2320 2321
2321 /* If the file name has special constructs in it, 2322 /* If the file name has special constructs in it,
2322 call the corresponding file handler. */ 2323 call the corresponding file handler. */
2323 GCPRO1 (abspath);
2324 handler = Ffind_file_name_handler (abspath, Qfile_readable_p); 2324 handler = Ffind_file_name_handler (abspath, Qfile_readable_p);
2325 UNGCPRO;
2326 if (!NILP (handler)) 2325 if (!NILP (handler))
2327 return call2 (handler, Qfile_readable_p, abspath); 2326 RETURN_UNGCPRO (call2 (handler, Qfile_readable_p, abspath));
2328 2327
2329 #ifdef DOS_NT 2328 #ifdef DOS_NT
2330 /* Under MS-DOS and Windows, open does not work for directories. */ 2329 /* Under MS-DOS and Windows, open does not work for directories. */
2331 if (access (XSTRING_DATA (abspath), 0) == 0) 2330 if (access (XSTRING_DATA (abspath), 0) == 0)
2332 return Qt; 2331 return Qt;
2333 return Qnil; 2332 return Qnil;
2334 #else /* not DOS_NT */ 2333 #else /* not DOS_NT */
2335 desc = open ((char *) XSTRING_DATA (abspath), O_RDONLY, 0); 2334 desc = interruptible_open ((char *) XSTRING_DATA (abspath), O_RDONLY, 0);
2335 UNGCPRO;
2336 if (desc < 0) 2336 if (desc < 0)
2337 return Qnil; 2337 return Qnil;
2338 close (desc); 2338 close (desc);
2339 return Qt; 2339 return Qt;
2340 #endif /* not DOS_NT */ 2340 #endif /* not DOS_NT */
2838 if ( (!NILP (beg) || !NILP (end)) && !NILP (visit) ) 2838 if ( (!NILP (beg) || !NILP (end)) && !NILP (visit) )
2839 error ("Attempt to visit less than an entire file"); 2839 error ("Attempt to visit less than an entire file");
2840 2840
2841 fd = -1; 2841 fd = -1;
2842 2842
2843 if (
2843 #ifndef APOLLO 2844 #ifndef APOLLO
2844 if (stat ((char *) XSTRING_DATA (filename), &st) < 0) 2845 (stat ((char *) XSTRING_DATA (filename), &st) < 0)
2845 #else /* APOLLO */ 2846 #else /* APOLLO */
2846 if ((fd = open ((char *) XSTRING_DATA (filename), O_RDONLY, 0)) < 0 2847 /* Don't even bother with interruptible_open. APOLLO sucks. */
2847 || fstat (fd, &st) < 0) 2848 ((fd = open ((char *) XSTRING_DATA (filename), O_RDONLY, 0)) < 0
2849 || fstat (fd, &st) < 0)
2848 #endif /* APOLLO */ 2850 #endif /* APOLLO */
2851 )
2849 { 2852 {
2850 if (fd >= 0) close (fd); 2853 if (fd >= 0) close (fd);
2851 badopen: 2854 badopen:
2852 if (NILP (visit)) 2855 if (NILP (visit))
2853 report_file_error ("Opening input file", 2856 report_file_error ("Opening input file",
2883 beg = Qzero; 2886 beg = Qzero;
2884 2887
2885 if (!NILP (end)) 2888 if (!NILP (end))
2886 CHECK_INT (end); 2889 CHECK_INT (end);
2887 2890
2888 /* Here, we should call some form of interruptable_open, so the user
2889 can quit gracefully when opening named pipes. interruptable_open
2890 should be just like sys_open in sysdep.c, only it would call QUIT
2891 if interrupted by EINTR. */
2892 if (fd < 0) 2891 if (fd < 0)
2893 if ((fd = open ((char *) XSTRING_DATA (filename), O_RDONLY, 0)) < 0) 2892 {
2894 goto badopen; 2893 if ((fd = interruptible_open ((char *) XSTRING_DATA (filename),
2894 O_RDONLY, 0)) < 0)
2895 goto badopen;
2896 }
2895 2897
2896 /* Replacement should preserve point as it preserves markers. */ 2898 /* Replacement should preserve point as it preserves markers. */
2897 if (!NILP (replace)) 2899 if (!NILP (replace))
2898 record_unwind_protect (restore_point_unwind, Fpoint_marker (Qnil, Qnil)); 2900 record_unwind_protect (restore_point_unwind, Fpoint_marker (Qnil, Qnil));
2899 2901