Mercurial > hg > xemacs-beta
comparison src/fileio.c @ 227:0e522484dd2a r20-5b12
Import from CVS: tag r20-5b12
author | cvs |
---|---|
date | Mon, 13 Aug 2007 10:12:37 +0200 |
parents | 12579d965149 |
children | 85a06df23a9a |
comparison
equal
deleted
inserted
replaced
226:eea38c7ad7b4 | 227:0e522484dd2a |
---|---|
381 if (EQ (operation, Vinhibit_file_name_operation)) | 381 if (EQ (operation, Vinhibit_file_name_operation)) |
382 inhibited_handlers = Vinhibit_file_name_handlers; | 382 inhibited_handlers = Vinhibit_file_name_handlers; |
383 else | 383 else |
384 inhibited_handlers = Qnil; | 384 inhibited_handlers = Qnil; |
385 | 385 |
386 for (chain = Vfile_name_handler_alist; CONSP (chain); | 386 EXTERNAL_LIST_LOOP (chain, Vfile_name_handler_alist) |
387 chain = XCDR (chain)) | |
388 { | 387 { |
389 Lisp_Object elt = XCAR (chain); | 388 Lisp_Object elt = XCAR (chain); |
390 if (CONSP (elt)) | 389 if (CONSP (elt)) |
391 { | 390 { |
392 Lisp_Object string; | 391 Lisp_Object string = XCAR (elt); |
393 string = XCAR (elt); | |
394 if (STRINGP (string) | 392 if (STRINGP (string) |
395 && (fast_lisp_string_match (string, filename) >= 0)) | 393 && (fast_lisp_string_match (string, filename) >= 0)) |
396 { | 394 { |
397 Lisp_Object handler = XCDR (elt); | 395 Lisp_Object handler = XCDR (elt); |
398 if (NILP (Fmemq (handler, inhibited_handlers))) | 396 if (NILP (Fmemq (handler, inhibited_handlers))) |
1253 | 1251 |
1254 return make_string (target, o - target); | 1252 return make_string (target, o - target); |
1255 } | 1253 } |
1256 | 1254 |
1257 #if 0 /* FSFmacs */ | 1255 #if 0 /* FSFmacs */ |
1258 another older version of expand-file-name; | 1256 /* another older version of expand-file-name; */ |
1259 #endif | 1257 #endif |
1260 | 1258 |
1261 DEFUN ("file-truename", Ffile_truename, 1, 2, 0, /* | 1259 DEFUN ("file-truename", Ffile_truename, 1, 2, 0, /* |
1262 Return the canonical name of the given FILE. | 1260 Return the canonical name of the given FILE. |
1263 Second arg DEFAULT is directory to start with if FILE is relative | 1261 Second arg DEFAULT is directory to start with if FILE is relative |
1726 else if (stat ((CONST char *) XSTRING_DATA (newname), &out_st) < 0) | 1724 else if (stat ((CONST char *) XSTRING_DATA (newname), &out_st) < 0) |
1727 out_st.st_mode = 0; | 1725 out_st.st_mode = 0; |
1728 | 1726 |
1729 ifd = interruptible_open ((char *) XSTRING_DATA (filename), O_RDONLY, 0); | 1727 ifd = interruptible_open ((char *) XSTRING_DATA (filename), O_RDONLY, 0); |
1730 if (ifd < 0) | 1728 if (ifd < 0) |
1731 report_file_error ("Opening input file", Fcons (filename, Qnil)); | 1729 report_file_error ("Opening input file", list1 (filename)); |
1732 | 1730 |
1733 record_unwind_protect (close_file_unwind, make_int (ifd)); | 1731 record_unwind_protect (close_file_unwind, make_int (ifd)); |
1734 | 1732 |
1735 /* We can only copy regular files and symbolic links. Other files are not | 1733 /* We can only copy regular files and symbolic links. Other files are not |
1736 copyable by us. */ | 1734 copyable by us. */ |
1740 if (out_st.st_mode != 0 | 1738 if (out_st.st_mode != 0 |
1741 && st.st_dev == out_st.st_dev && st.st_ino == out_st.st_ino) | 1739 && st.st_dev == out_st.st_dev && st.st_ino == out_st.st_ino) |
1742 { | 1740 { |
1743 errno = 0; | 1741 errno = 0; |
1744 report_file_error ("Input and output files are the same", | 1742 report_file_error ("Input and output files are the same", |
1745 Fcons (filename, Fcons (newname, Qnil))); | 1743 list2 (filename, newname)); |
1746 } | 1744 } |
1747 #endif | 1745 #endif |
1748 | 1746 |
1749 #if defined (S_ISREG) && defined (S_ISLNK) | 1747 #if defined (S_ISREG) && defined (S_ISLNK) |
1750 if (input_file_statable_p) | 1748 if (input_file_statable_p) |
1758 { | 1756 { |
1759 #if defined (EISDIR) | 1757 #if defined (EISDIR) |
1760 /* Get a better looking error message. */ | 1758 /* Get a better looking error message. */ |
1761 errno = EISDIR; | 1759 errno = EISDIR; |
1762 #endif /* EISDIR */ | 1760 #endif /* EISDIR */ |
1763 report_file_error ("Non-regular file", Fcons (filename, Qnil)); | 1761 report_file_error ("Non-regular file", list1 (filename)); |
1764 } | 1762 } |
1765 } | 1763 } |
1766 #endif /* S_ISREG && S_ISLNK */ | 1764 #endif /* S_ISREG && S_ISLNK */ |
1767 | 1765 |
1768 #ifdef MSDOS | 1766 #ifdef MSDOS |
1785 report_file_error ("I/O error", list1 (newname)); | 1783 report_file_error ("I/O error", list1 (newname)); |
1786 } | 1784 } |
1787 | 1785 |
1788 /* Closing the output clobbers the file times on some systems. */ | 1786 /* Closing the output clobbers the file times on some systems. */ |
1789 if (close (ofd) < 0) | 1787 if (close (ofd) < 0) |
1790 report_file_error ("I/O error", Fcons (newname, Qnil)); | 1788 report_file_error ("I/O error", list1 (newname)); |
1791 | 1789 |
1792 if (input_file_statable_p) | 1790 if (input_file_statable_p) |
1793 { | 1791 { |
1794 if (!NILP (keep_time)) | 1792 if (!NILP (keep_time)) |
1795 { | 1793 { |
1796 EMACS_TIME atime, mtime; | 1794 EMACS_TIME atime, mtime; |
1797 EMACS_SET_SECS_USECS (atime, st.st_atime, 0); | 1795 EMACS_SET_SECS_USECS (atime, st.st_atime, 0); |
1798 EMACS_SET_SECS_USECS (mtime, st.st_mtime, 0); | 1796 EMACS_SET_SECS_USECS (mtime, st.st_mtime, 0); |
1799 if (set_file_times ((char *) XSTRING_DATA (newname), atime, | 1797 if (set_file_times ((char *) XSTRING_DATA (newname), atime, |
1800 mtime)) | 1798 mtime)) |
1801 report_file_error ("I/O error", Fcons (newname, Qnil)); | 1799 report_file_error ("I/O error", list1 (newname)); |
1802 } | 1800 } |
1803 #ifndef MSDOS | 1801 #ifndef MSDOS |
1804 chmod ((CONST char *) XSTRING_DATA (newname), | 1802 chmod ((CONST char *) XSTRING_DATA (newname), |
1805 st.st_mode & 07777); | 1803 st.st_mode & 07777); |
1806 #else /* MSDOS */ | 1804 #else /* MSDOS */ |
2601 UNGCPRO; | 2599 UNGCPRO; |
2602 if (!NILP (handler)) | 2600 if (!NILP (handler)) |
2603 return call3 (handler, Qset_file_modes, abspath, mode); | 2601 return call3 (handler, Qset_file_modes, abspath, mode); |
2604 | 2602 |
2605 if (chmod ((char *) XSTRING_DATA (abspath), XINT (mode)) < 0) | 2603 if (chmod ((char *) XSTRING_DATA (abspath), XINT (mode)) < 0) |
2606 report_file_error ("Doing chmod", Fcons (abspath, Qnil)); | 2604 report_file_error ("Doing chmod", list1 (abspath)); |
2607 | 2605 |
2608 return Qnil; | 2606 return Qnil; |
2609 } | 2607 } |
2610 | 2608 |
2611 DEFUN ("set-default-file-modes", Fset_default_file_modes, 1, 1, 0, /* | 2609 DEFUN ("set-default-file-modes", Fset_default_file_modes, 1, 1, 0, /* |
2851 ) | 2849 ) |
2852 { | 2850 { |
2853 if (fd >= 0) close (fd); | 2851 if (fd >= 0) close (fd); |
2854 badopen: | 2852 badopen: |
2855 if (NILP (visit)) | 2853 if (NILP (visit)) |
2856 report_file_error ("Opening input file", | 2854 report_file_error ("Opening input file", list1 (filename)); |
2857 Fcons (filename, Qnil)); | |
2858 st.st_mtime = -1; | 2855 st.st_mtime = -1; |
2859 goto notfound; | 2856 goto notfound; |
2860 } | 2857 } |
2861 | 2858 |
2862 #ifdef S_IFREG | 2859 #ifdef S_IFREG |
3100 if (curpos == 0) | 3097 if (curpos == 0) |
3101 break; | 3098 break; |
3102 /* How much can we scan in the next step? */ | 3099 /* How much can we scan in the next step? */ |
3103 trial = min (curpos, sizeof buffer); | 3100 trial = min (curpos, sizeof buffer); |
3104 if (lseek (fd, curpos - trial, 0) < 0) | 3101 if (lseek (fd, curpos - trial, 0) < 0) |
3105 report_file_error ("Setting file position", | 3102 report_file_error ("Setting file position", list1 (filename)); |
3106 Fcons (filename, Qnil)); | |
3107 | 3103 |
3108 total_read = 0; | 3104 total_read = 0; |
3109 while (total_read < trial) | 3105 while (total_read < trial) |
3110 { | 3106 { |
3111 nread = read_allowing_quit (fd, buffer + total_read, | 3107 nread = read_allowing_quit (fd, buffer + total_read, |
3112 trial - total_read); | 3108 trial - total_read); |
3113 if (nread <= 0) | 3109 if (nread <= 0) |
3114 error ("IO error reading %s: %s", | 3110 report_file_error ("IO error reading file", list1 (filename)); |
3115 XSTRING_DATA (filename), strerror (errno)); | |
3116 total_read += nread; | 3111 total_read += nread; |
3117 } | 3112 } |
3118 /* Scan this bufferful from the end, comparing with | 3113 /* Scan this bufferful from the end, comparing with |
3119 the Emacs buffer. */ | 3114 the Emacs buffer. */ |
3120 bufpos = total_read; | 3115 bufpos = total_read; |
3204 } | 3199 } |
3205 #endif /* FSFMACS_SPEEDY_INSERT */ | 3200 #endif /* FSFMACS_SPEEDY_INSERT */ |
3206 | 3201 |
3207 if (!not_regular) | 3202 if (!not_regular) |
3208 { | 3203 { |
3209 Lisp_Object temp; | |
3210 | |
3211 total = XINT (end) - XINT (beg); | 3204 total = XINT (end) - XINT (beg); |
3212 | 3205 |
3213 /* Make sure point-max won't overflow after this insertion. */ | 3206 /* Make sure point-max won't overflow after this insertion. */ |
3214 XSETINT (temp, total); | 3207 if (total != XINT (make_int (total))) |
3215 if (total != XINT (temp)) | |
3216 error ("Maximum buffer size exceeded"); | 3208 error ("Maximum buffer size exceeded"); |
3217 } | 3209 } |
3218 else | 3210 else |
3219 /* For a special file, all we can do is guess. */ | 3211 /* For a special file, all we can do is guess. */ |
3220 total = READ_BUF_SIZE; | 3212 total = READ_BUF_SIZE; |
3227 || !NILP (replace) | 3219 || !NILP (replace) |
3228 #endif /* !FSFMACS_SPEEDY_INSERT */ | 3220 #endif /* !FSFMACS_SPEEDY_INSERT */ |
3229 ) | 3221 ) |
3230 { | 3222 { |
3231 if (lseek (fd, XINT (beg), 0) < 0) | 3223 if (lseek (fd, XINT (beg), 0) < 0) |
3232 report_file_error ("Setting file position", | 3224 report_file_error ("Setting file position", list1 (filename)); |
3233 Fcons (filename, Qnil)); | |
3234 } | 3225 } |
3235 | 3226 |
3236 { | 3227 { |
3237 Bufpos cur_point = BUF_PT (buf); | 3228 Bufpos cur_point = BUF_PT (buf); |
3238 struct gcpro ngcpro1; | 3229 struct gcpro ngcpro1; |
3429 inserted = XINT (insval); | 3420 inserted = XINT (insval); |
3430 } | 3421 } |
3431 | 3422 |
3432 if (inserted > 0) | 3423 if (inserted > 0) |
3433 { | 3424 { |
3434 Lisp_Object p = Vafter_insert_file_functions; | 3425 Lisp_Object p; |
3435 struct gcpro ngcpro1; | 3426 struct gcpro ngcpro1; |
3436 | 3427 |
3437 NGCPRO1 (p); | 3428 NGCPRO1 (p); |
3438 while (!NILP (p)) | 3429 EXTERNAL_LIST_LOOP (p, Vafter_insert_file_functions) |
3439 { | 3430 { |
3440 Lisp_Object insval = | 3431 Lisp_Object insval = |
3441 call1 (Fcar (p), make_int (inserted)); | 3432 call1 (XCAR (p), make_int (inserted)); |
3442 if (!NILP (insval)) | 3433 if (!NILP (insval)) |
3443 { | 3434 { |
3444 CHECK_NATNUM (insval); | 3435 CHECK_NATNUM (insval); |
3445 inserted = XINT (insval); | 3436 inserted = XINT (insval); |
3446 } | 3437 } |
3447 QUIT; | 3438 QUIT; |
3448 p = Fcdr (p); | |
3449 } | 3439 } |
3450 NUNGCPRO; | 3440 NUNGCPRO; |
3451 } | 3441 } |
3452 | 3442 |
3453 UNGCPRO; | 3443 UNGCPRO; |
3623 #ifdef CLASH_DETECTION | 3613 #ifdef CLASH_DETECTION |
3624 save_errno = errno; | 3614 save_errno = errno; |
3625 if (!auto_saving) unlock_file (lockname); | 3615 if (!auto_saving) unlock_file (lockname); |
3626 errno = save_errno; | 3616 errno = save_errno; |
3627 #endif /* CLASH_DETECTION */ | 3617 #endif /* CLASH_DETECTION */ |
3628 report_file_error ("Opening output file", | 3618 report_file_error ("Opening output file", list1 (filename)); |
3629 Fcons (filename, Qnil)); | |
3630 } | 3619 } |
3631 | 3620 |
3632 { | 3621 { |
3633 Lisp_Object desc_locative = Fcons (make_int (desc), Qnil); | 3622 Lisp_Object desc_locative = Fcons (make_int (desc), Qnil); |
3634 Lisp_Object instream = Qnil, outstream = Qnil; | 3623 Lisp_Object instream = Qnil, outstream = Qnil; |