Mercurial > hg > xemacs-beta
comparison src/fileio.c @ 44:8d2a9b52c682 r19-15prefinal
Import from CVS: tag r19-15prefinal
author | cvs |
---|---|
date | Mon, 13 Aug 2007 08:55:10 +0200 |
parents | 7e54bd776075 |
children | 6a22abad6937 |
comparison
equal
deleted
inserted
replaced
43:23cafc5d2038 | 44:8d2a9b52c682 |
---|---|
337 but we still do run any other handlers. This lets handlers | 337 but we still do run any other handlers. This lets handlers |
338 use the standard functions without calling themselves recursively. | 338 use the standard functions without calling themselves recursively. |
339 */ | 339 */ |
340 (filename, operation)) | 340 (filename, operation)) |
341 { | 341 { |
342 /* This function does not GC */ | |
342 /* This function must not munge the match data. */ | 343 /* This function must not munge the match data. */ |
343 Lisp_Object chain, inhibited_handlers; | 344 Lisp_Object chain, inhibited_handlers; |
344 | 345 |
345 CHECK_STRING (filename); | 346 CHECK_STRING (filename); |
346 | 347 |
371 } | 372 } |
372 | 373 |
373 static Lisp_Object | 374 static Lisp_Object |
374 call2_check_string (Lisp_Object fn, Lisp_Object arg0, Lisp_Object arg1) | 375 call2_check_string (Lisp_Object fn, Lisp_Object arg0, Lisp_Object arg1) |
375 { | 376 { |
376 /* This function can GC */ | 377 /* This function can call lisp */ |
377 Lisp_Object result = call2 (fn, arg0, arg1); | 378 Lisp_Object result = call2 (fn, arg0, arg1); |
378 CHECK_STRING (result); | 379 CHECK_STRING (result); |
379 return (result); | 380 return (result); |
380 } | 381 } |
381 | 382 |
382 static Lisp_Object | 383 static Lisp_Object |
383 call2_check_string_or_nil (Lisp_Object fn, Lisp_Object arg0, Lisp_Object arg1) | 384 call2_check_string_or_nil (Lisp_Object fn, Lisp_Object arg0, Lisp_Object arg1) |
384 { | 385 { |
385 /* This function can GC */ | 386 /* This function can call lisp */ |
386 Lisp_Object result = call2 (fn, arg0, arg1); | 387 Lisp_Object result = call2 (fn, arg0, arg1); |
387 if (!NILP (result)) | 388 if (!NILP (result)) |
388 CHECK_STRING (result); | 389 CHECK_STRING (result); |
389 return (result); | 390 return (result); |
390 } | 391 } |
391 | 392 |
392 static Lisp_Object | 393 static Lisp_Object |
393 call3_check_string (Lisp_Object fn, Lisp_Object arg0, | 394 call3_check_string (Lisp_Object fn, Lisp_Object arg0, |
394 Lisp_Object arg1, Lisp_Object arg2) | 395 Lisp_Object arg1, Lisp_Object arg2) |
395 { | 396 { |
396 /* This function can GC */ | 397 /* This function can call lisp */ |
397 Lisp_Object result = call3 (fn, arg0, arg1, arg2); | 398 Lisp_Object result = call3 (fn, arg0, arg1, arg2); |
398 CHECK_STRING (result); | 399 CHECK_STRING (result); |
399 return (result); | 400 return (result); |
400 } | 401 } |
401 | 402 |
407 Given a Unix syntax file name, returns a string ending in slash; | 408 Given a Unix syntax file name, returns a string ending in slash; |
408 on VMS, perhaps instead a string ending in `:', `]' or `>'. | 409 on VMS, perhaps instead a string ending in `:', `]' or `>'. |
409 */ | 410 */ |
410 (file)) | 411 (file)) |
411 { | 412 { |
412 /* This function can GC */ | 413 /* This function can call lisp */ |
413 Bufbyte *beg; | 414 Bufbyte *beg; |
414 Bufbyte *p; | 415 Bufbyte *p; |
415 Lisp_Object handler; | 416 Lisp_Object handler; |
416 | 417 |
417 CHECK_STRING (file); | 418 CHECK_STRING (file); |
475 this is everything after the last slash, | 476 this is everything after the last slash, |
476 or the entire name if it contains no slash. | 477 or the entire name if it contains no slash. |
477 */ | 478 */ |
478 (file)) | 479 (file)) |
479 { | 480 { |
480 /* This function can GC */ | 481 /* This function can call lisp */ |
481 Bufbyte *beg, *p, *end; | 482 Bufbyte *beg, *p, *end; |
482 Lisp_Object handler; | 483 Lisp_Object handler; |
483 | 484 |
484 CHECK_STRING (file); | 485 CHECK_STRING (file); |
485 | 486 |
511 The `call-process' and `start-process' functions use this function to | 512 The `call-process' and `start-process' functions use this function to |
512 get a current directory to run processes in. | 513 get a current directory to run processes in. |
513 */ | 514 */ |
514 (filename)) | 515 (filename)) |
515 { | 516 { |
516 /* This function can GC */ | 517 /* This function can call lisp */ |
517 Lisp_Object handler; | 518 Lisp_Object handler; |
518 | 519 |
519 /* If the file name has special constructs in it, | 520 /* If the file name has special constructs in it, |
520 call the corresponding file handler. */ | 521 call the corresponding file handler. */ |
521 handler = Ffind_file_name_handler (filename, Qunhandled_file_name_directory); | 522 handler = Ffind_file_name_handler (filename, Qunhandled_file_name_directory); |
611 For a Unix-syntax file name, just appends a slash. | 612 For a Unix-syntax file name, just appends a slash. |
612 On VMS, converts \"[X]FOO.DIR\" to \"[X.FOO]\", etc. | 613 On VMS, converts \"[X]FOO.DIR\" to \"[X.FOO]\", etc. |
613 */ | 614 */ |
614 (file)) | 615 (file)) |
615 { | 616 { |
616 /* This function can GC */ | 617 /* This function can call lisp */ |
617 char *buf; | 618 char *buf; |
618 Lisp_Object handler; | 619 Lisp_Object handler; |
619 | 620 |
620 CHECK_STRING (file); | 621 CHECK_STRING (file); |
621 | 622 |
797 On VMS, given a VMS-syntax directory name such as \"[X.Y]\", | 798 On VMS, given a VMS-syntax directory name such as \"[X.Y]\", |
798 it returns a file name such as \"[X]Y.DIR.1\". | 799 it returns a file name such as \"[X]Y.DIR.1\". |
799 */ | 800 */ |
800 (directory)) | 801 (directory)) |
801 { | 802 { |
802 /* This function can GC */ | 803 /* This function can call lisp */ |
803 char *buf; | 804 char *buf; |
804 Lisp_Object handler; | 805 Lisp_Object handler; |
805 | 806 |
806 CHECK_STRING (directory); | 807 CHECK_STRING (directory); |
807 | 808 |
865 An initial `~USER/' expands to USER's home directory. | 866 An initial `~USER/' expands to USER's home directory. |
866 See also the function `substitute-in-file-name'. | 867 See also the function `substitute-in-file-name'. |
867 */ | 868 */ |
868 (name, defalt)) | 869 (name, defalt)) |
869 { | 870 { |
870 /* This function can GC */ | 871 /* This function can call lisp */ |
871 Bufbyte *nm; | 872 Bufbyte *nm; |
872 | 873 |
873 Bufbyte *newdir, *p, *o; | 874 Bufbyte *newdir, *p, *o; |
874 int tlen; | 875 int tlen; |
875 Bufbyte *target; | 876 Bufbyte *target; |
1395 No component of the resulting pathname will be a symbolic link, as | 1396 No component of the resulting pathname will be a symbolic link, as |
1396 in the realpath() function. | 1397 in the realpath() function. |
1397 */ | 1398 */ |
1398 (filename, defalt)) | 1399 (filename, defalt)) |
1399 { | 1400 { |
1400 /* This function can GC */ | 1401 /* This function can call lisp */ |
1401 struct gcpro gcpro1; | 1402 struct gcpro gcpro1; |
1402 Lisp_Object expanded_name; | 1403 Lisp_Object expanded_name; |
1403 Lisp_Object handler; | 1404 Lisp_Object handler; |
1404 | 1405 |
1405 CHECK_STRING (filename); | 1406 CHECK_STRING (filename); |
1522 On VMS, `$' substitution is not done; this function does little and only | 1523 On VMS, `$' substitution is not done; this function does little and only |
1523 duplicates what `expand-file-name' does. | 1524 duplicates what `expand-file-name' does. |
1524 */ | 1525 */ |
1525 (string)) | 1526 (string)) |
1526 { | 1527 { |
1528 /* This function can call lisp */ | |
1527 Bufbyte *nm; | 1529 Bufbyte *nm; |
1528 | 1530 |
1529 Bufbyte *s, *p, *o, *x, *endp; | 1531 Bufbyte *s, *p, *o, *x, *endp; |
1530 Bufbyte *target = 0; | 1532 Bufbyte *target = 0; |
1531 int total = 0; | 1533 int total = 0; |
1732 /* (directory-file-name (expand-file-name FOO)) */ | 1734 /* (directory-file-name (expand-file-name FOO)) */ |
1733 | 1735 |
1734 Lisp_Object | 1736 Lisp_Object |
1735 expand_and_dir_to_file (Lisp_Object filename, Lisp_Object defdir) | 1737 expand_and_dir_to_file (Lisp_Object filename, Lisp_Object defdir) |
1736 { | 1738 { |
1737 /* This function can GC */ | 1739 /* This function can call lisp */ |
1738 Lisp_Object abspath; | 1740 Lisp_Object abspath; |
1739 struct gcpro gcpro1; | 1741 struct gcpro gcpro1; |
1740 | 1742 |
1741 GCPRO1 (filename); | |
1742 abspath = Fexpand_file_name (filename, defdir); | 1743 abspath = Fexpand_file_name (filename, defdir); |
1744 GCPRO1 (abspath); | |
1743 #ifdef VMS | 1745 #ifdef VMS |
1744 { | 1746 { |
1745 Bufbyte c = | 1747 Bufbyte c = |
1746 XSTRING_BYTE (abspath, XSTRING_LENGTH (abspath) - 1); | 1748 XSTRING_BYTE (abspath, XSTRING_LENGTH (abspath) - 1); |
1747 if (c == ':' || c == ']' || c == '>') | 1749 if (c == ':' || c == ']' || c == '>') |
1770 | 1772 |
1771 static void | 1773 static void |
1772 barf_or_query_if_file_exists (Lisp_Object absname, CONST char *querystring, | 1774 barf_or_query_if_file_exists (Lisp_Object absname, CONST char *querystring, |
1773 int interactive, struct stat *statptr) | 1775 int interactive, struct stat *statptr) |
1774 { | 1776 { |
1777 /* This function can call lisp */ | |
1775 struct stat statbuf; | 1778 struct stat statbuf; |
1776 | 1779 |
1777 /* stat is a good way to tell whether the file exists, | 1780 /* stat is a good way to tell whether the file exists, |
1778 regardless of what access permissions it has. */ | 1781 regardless of what access permissions it has. */ |
1779 if (stat ((char *) XSTRING_DATA (absname), &statbuf) >= 0) | 1782 if (stat ((char *) XSTRING_DATA (absname), &statbuf) >= 0) |
1780 { | 1783 { |
1781 Lisp_Object tem; | 1784 Lisp_Object tem; |
1782 struct gcpro gcpro1; | 1785 |
1783 | |
1784 GCPRO1 (absname); | |
1785 if (interactive) | 1786 if (interactive) |
1786 tem = call1 | 1787 { |
1787 (Qyes_or_no_p, | 1788 Lisp_Object prompt; |
1788 (emacs_doprnt_string_c | 1789 struct gcpro gcpro1; |
1790 | |
1791 prompt = emacs_doprnt_string_c | |
1789 ((CONST Bufbyte *) GETTEXT ("File %s already exists; %s anyway? "), | 1792 ((CONST Bufbyte *) GETTEXT ("File %s already exists; %s anyway? "), |
1790 Qnil, -1, XSTRING_DATA (absname), | 1793 Qnil, -1, XSTRING_DATA (absname), |
1791 GETTEXT (querystring)))); | 1794 GETTEXT (querystring)); |
1795 | |
1796 GCPRO1 (prompt); | |
1797 tem = call1 (Qyes_or_no_p, prompt); | |
1798 UNGCPRO; | |
1799 } | |
1792 else | 1800 else |
1793 tem = Qnil; | 1801 tem = Qnil; |
1794 UNGCPRO; | 1802 |
1795 if (NILP (tem)) | 1803 if (NILP (tem)) |
1796 Fsignal (Qfile_already_exists, | 1804 Fsignal (Qfile_already_exists, |
1797 list2 (build_translated_string ("File already exists"), | 1805 list2 (build_translated_string ("File already exists"), |
1798 absname)); | 1806 absname)); |
1799 if (statptr) | 1807 if (statptr) |
1818 last-modified time as the old one. (This works on only some systems.) | 1826 last-modified time as the old one. (This works on only some systems.) |
1819 A prefix arg makes KEEP-TIME non-nil. | 1827 A prefix arg makes KEEP-TIME non-nil. |
1820 */ | 1828 */ |
1821 (filename, newname, ok_if_already_exists, keep_time)) | 1829 (filename, newname, ok_if_already_exists, keep_time)) |
1822 { | 1830 { |
1823 /* This function can GC */ | 1831 /* This function can call lisp */ |
1824 int ifd, ofd, n; | 1832 int ifd, ofd, n; |
1825 char buf[16 * 1024]; | 1833 char buf[16 * 1024]; |
1826 struct stat st, out_st; | 1834 struct stat st, out_st; |
1827 Lisp_Object handler; | 1835 Lisp_Object handler; |
1828 int speccount = specpdl_depth (); | 1836 int speccount = specpdl_depth (); |
1984 DEFUN ("make-directory-internal", Fmake_directory_internal, 1, 1, 0, /* | 1992 DEFUN ("make-directory-internal", Fmake_directory_internal, 1, 1, 0, /* |
1985 Create a directory. One argument, a file name string. | 1993 Create a directory. One argument, a file name string. |
1986 */ | 1994 */ |
1987 (dirname)) | 1995 (dirname)) |
1988 { | 1996 { |
1989 /* This function can GC */ | 1997 /* This function can call lisp */ |
1990 char dir [MAXPATHLEN]; | 1998 char dir [MAXPATHLEN]; |
1991 Lisp_Object handler; | 1999 Lisp_Object handler; |
1992 struct gcpro gcpro1; | 2000 struct gcpro gcpro1; |
1993 | 2001 |
1994 CHECK_STRING (dirname); | 2002 CHECK_STRING (dirname); |
2028 DEFUN ("delete-directory", Fdelete_directory, 1, 1, "FDelete directory: ", /* | 2036 DEFUN ("delete-directory", Fdelete_directory, 1, 1, "FDelete directory: ", /* |
2029 Delete a directory. One argument, a file name or directory name string. | 2037 Delete a directory. One argument, a file name or directory name string. |
2030 */ | 2038 */ |
2031 (dirname)) | 2039 (dirname)) |
2032 { | 2040 { |
2033 /* This function can GC */ | 2041 /* This function can call lisp */ |
2034 Lisp_Object handler; | 2042 Lisp_Object handler; |
2035 struct gcpro gcpro1; | 2043 struct gcpro gcpro1; |
2036 | 2044 |
2037 CHECK_STRING (dirname); | 2045 CHECK_STRING (dirname); |
2038 | 2046 |
2055 Delete specified file. One argument, a file name string. | 2063 Delete specified file. One argument, a file name string. |
2056 If file has multiple names, it continues to exist with the other names. | 2064 If file has multiple names, it continues to exist with the other names. |
2057 */ | 2065 */ |
2058 (filename)) | 2066 (filename)) |
2059 { | 2067 { |
2060 /* This function can GC */ | 2068 /* This function can call lisp */ |
2061 Lisp_Object handler; | 2069 Lisp_Object handler; |
2062 struct gcpro gcpro1; | 2070 struct gcpro gcpro1; |
2063 | 2071 |
2064 CHECK_STRING (filename); | 2072 CHECK_STRING (filename); |
2065 filename = Fexpand_file_name (filename, Qnil); | 2073 filename = Fexpand_file_name (filename, Qnil); |
2084 /* Delete file FILENAME, returning 1 if successful and 0 if failed. */ | 2092 /* Delete file FILENAME, returning 1 if successful and 0 if failed. */ |
2085 | 2093 |
2086 int | 2094 int |
2087 internal_delete_file (Lisp_Object filename) | 2095 internal_delete_file (Lisp_Object filename) |
2088 { | 2096 { |
2097 /* This function can call lisp */ | |
2089 return NILP (condition_case_1 (Qt, Fdelete_file, filename, | 2098 return NILP (condition_case_1 (Qt, Fdelete_file, filename, |
2090 internal_delete_file_1, Qnil)); | 2099 internal_delete_file_1, Qnil)); |
2091 } | 2100 } |
2092 | 2101 |
2093 DEFUN ("rename-file", Frename_file, 2, 3, | 2102 DEFUN ("rename-file", Frename_file, 2, 3, |
2099 A number as third arg means request confirmation if NEWNAME already exists. | 2108 A number as third arg means request confirmation if NEWNAME already exists. |
2100 This is what happens in interactive use with M-x. | 2109 This is what happens in interactive use with M-x. |
2101 */ | 2110 */ |
2102 (filename, newname, ok_if_already_exists)) | 2111 (filename, newname, ok_if_already_exists)) |
2103 { | 2112 { |
2104 /* This function can GC */ | 2113 /* This function can call lisp */ |
2105 Lisp_Object handler; | 2114 Lisp_Object handler; |
2106 struct gcpro gcpro1, gcpro2; | 2115 struct gcpro gcpro1, gcpro2; |
2107 | 2116 |
2108 GCPRO2 (filename, newname); | 2117 GCPRO2 (filename, newname); |
2109 CHECK_STRING (filename); | 2118 CHECK_STRING (filename); |
2192 A number as third arg means request confirmation if NEWNAME already exists. | 2201 A number as third arg means request confirmation if NEWNAME already exists. |
2193 This is what happens in interactive use with M-x. | 2202 This is what happens in interactive use with M-x. |
2194 */ | 2203 */ |
2195 (filename, newname, ok_if_already_exists)) | 2204 (filename, newname, ok_if_already_exists)) |
2196 { | 2205 { |
2197 /* This function can GC */ | 2206 /* This function can call lisp */ |
2198 Lisp_Object handler; | 2207 Lisp_Object handler; |
2199 struct gcpro gcpro1, gcpro2; | 2208 struct gcpro gcpro1, gcpro2; |
2200 | 2209 |
2201 GCPRO2 (filename, newname); | 2210 GCPRO2 (filename, newname); |
2202 CHECK_STRING (filename); | 2211 CHECK_STRING (filename); |
2249 A number as third arg means request confirmation if LINKNAME already exists. | 2258 A number as third arg means request confirmation if LINKNAME already exists. |
2250 This happens for interactive use with M-x. | 2259 This happens for interactive use with M-x. |
2251 */ | 2260 */ |
2252 (filename, linkname, ok_if_already_exists)) | 2261 (filename, linkname, ok_if_already_exists)) |
2253 { | 2262 { |
2254 /* This function can GC */ | 2263 /* This function can call lisp */ |
2255 Lisp_Object handler; | 2264 Lisp_Object handler; |
2256 struct gcpro gcpro1, gcpro2; | 2265 struct gcpro gcpro1, gcpro2; |
2257 | 2266 |
2258 GCPRO2 (filename, linkname); | 2267 GCPRO2 (filename, linkname); |
2259 CHECK_STRING (filename); | 2268 CHECK_STRING (filename); |
2357 Return t if file FILENAME specifies an absolute path name. | 2366 Return t if file FILENAME specifies an absolute path name. |
2358 On Unix, this is a name starting with a `/' or a `~'. | 2367 On Unix, this is a name starting with a `/' or a `~'. |
2359 */ | 2368 */ |
2360 (filename)) | 2369 (filename)) |
2361 { | 2370 { |
2371 /* This function does not GC */ | |
2362 Bufbyte *ptr; | 2372 Bufbyte *ptr; |
2363 | 2373 |
2364 CHECK_STRING (filename); | 2374 CHECK_STRING (filename); |
2365 ptr = XSTRING_DATA (filename); | 2375 ptr = XSTRING_DATA (filename); |
2366 if (IS_DIRECTORY_SEP (*ptr) || *ptr == '~' | 2376 if (IS_DIRECTORY_SEP (*ptr) || *ptr == '~' |
2436 Return t if file FILENAME exists. (This does not mean you can read it.) | 2446 Return t if file FILENAME exists. (This does not mean you can read it.) |
2437 See also `file-readable-p' and `file-attributes'. | 2447 See also `file-readable-p' and `file-attributes'. |
2438 */ | 2448 */ |
2439 (filename)) | 2449 (filename)) |
2440 { | 2450 { |
2441 /* This function can GC */ | 2451 /* This function can call lisp */ |
2442 Lisp_Object abspath; | 2452 Lisp_Object abspath; |
2443 Lisp_Object handler; | 2453 Lisp_Object handler; |
2444 struct stat statbuf; | 2454 struct stat statbuf; |
2445 struct gcpro gcpro1; | 2455 struct gcpro gcpro1; |
2446 | 2456 |
2447 GCPRO1 (filename); | |
2448 CHECK_STRING (filename); | 2457 CHECK_STRING (filename); |
2449 abspath = Fexpand_file_name (filename, Qnil); | 2458 abspath = Fexpand_file_name (filename, Qnil); |
2450 UNGCPRO; | |
2451 | 2459 |
2452 /* If the file name has special constructs in it, | 2460 /* If the file name has special constructs in it, |
2453 call the corresponding file handler. */ | 2461 call the corresponding file handler. */ |
2454 GCPRO1 (abspath); | 2462 GCPRO1 (abspath); |
2455 handler = Ffind_file_name_handler (abspath, Qfile_exists_p); | 2463 handler = Ffind_file_name_handler (abspath, Qfile_exists_p); |
2467 Return t if FILENAME can be executed by you. | 2475 Return t if FILENAME can be executed by you. |
2468 For a directory, this means you can access files in that directory. | 2476 For a directory, this means you can access files in that directory. |
2469 */ | 2477 */ |
2470 (filename)) | 2478 (filename)) |
2471 { | 2479 { |
2472 /* This function can GC */ | 2480 /* This function can call lisp */ |
2473 Lisp_Object abspath; | 2481 Lisp_Object abspath; |
2474 Lisp_Object handler; | 2482 Lisp_Object handler; |
2475 struct gcpro gcpro1; | 2483 struct gcpro gcpro1; |
2476 | 2484 |
2477 GCPRO1 (filename); | 2485 GCPRO1 (filename); |
2495 Return t if file FILENAME exists and you can read it. | 2503 Return t if file FILENAME exists and you can read it. |
2496 See also `file-exists-p' and `file-attributes'. | 2504 See also `file-exists-p' and `file-attributes'. |
2497 */ | 2505 */ |
2498 (filename)) | 2506 (filename)) |
2499 { | 2507 { |
2500 /* This function can GC */ | 2508 /* This function can call lisp */ |
2501 Lisp_Object abspath; | 2509 Lisp_Object abspath; |
2502 Lisp_Object handler; | 2510 Lisp_Object handler; |
2503 int desc; | 2511 int desc; |
2504 struct gcpro gcpro1; | 2512 struct gcpro gcpro1; |
2505 | 2513 |
2506 GCPRO1 (filename); | |
2507 CHECK_STRING (filename); | 2514 CHECK_STRING (filename); |
2508 abspath = Fexpand_file_name (filename, Qnil); | 2515 abspath = Fexpand_file_name (filename, Qnil); |
2509 UNGCPRO; | |
2510 | 2516 |
2511 /* If the file name has special constructs in it, | 2517 /* If the file name has special constructs in it, |
2512 call the corresponding file handler. */ | 2518 call the corresponding file handler. */ |
2513 GCPRO1 (abspath); | 2519 GCPRO1 (abspath); |
2514 handler = Ffind_file_name_handler (abspath, Qfile_readable_p); | 2520 handler = Ffind_file_name_handler (abspath, Qfile_readable_p); |
2528 DEFUN ("file-writable-p", Ffile_writable_p, 1, 1, 0, /* | 2534 DEFUN ("file-writable-p", Ffile_writable_p, 1, 1, 0, /* |
2529 Return t if file FILENAME can be written or created by you. | 2535 Return t if file FILENAME can be written or created by you. |
2530 */ | 2536 */ |
2531 (filename)) | 2537 (filename)) |
2532 { | 2538 { |
2533 /* This function can GC */ | 2539 /* This function can call lisp */ |
2534 Lisp_Object abspath, dir; | 2540 Lisp_Object abspath, dir; |
2535 Lisp_Object handler; | 2541 Lisp_Object handler; |
2536 struct stat statbuf; | 2542 struct stat statbuf; |
2537 struct gcpro gcpro1; | 2543 struct gcpro gcpro1; |
2538 | 2544 |
2539 GCPRO1 (filename); | |
2540 CHECK_STRING (filename); | 2545 CHECK_STRING (filename); |
2541 abspath = Fexpand_file_name (filename, Qnil); | 2546 abspath = Fexpand_file_name (filename, Qnil); |
2542 UNGCPRO; | |
2543 | 2547 |
2544 /* If the file name has special constructs in it, | 2548 /* If the file name has special constructs in it, |
2545 call the corresponding file handler. */ | 2549 call the corresponding file handler. */ |
2546 GCPRO1 (abspath); | 2550 GCPRO1 (abspath); |
2547 handler = Ffind_file_name_handler (abspath, Qfile_writable_p); | 2551 handler = Ffind_file_name_handler (abspath, Qfile_writable_p); |
2575 The value is the name of the file to which it is linked. | 2579 The value is the name of the file to which it is linked. |
2576 Otherwise returns nil. | 2580 Otherwise returns nil. |
2577 */ | 2581 */ |
2578 (filename)) | 2582 (filename)) |
2579 { | 2583 { |
2580 /* This function can GC */ | 2584 /* This function can call lisp */ |
2581 #ifdef S_IFLNK | 2585 #ifdef S_IFLNK |
2582 char *buf; | 2586 char *buf; |
2583 int bufsize; | 2587 int bufsize; |
2584 int valsize; | 2588 int valsize; |
2585 Lisp_Object val; | 2589 Lisp_Object val; |
2586 Lisp_Object handler; | 2590 Lisp_Object handler; |
2587 struct gcpro gcpro1; | 2591 struct gcpro gcpro1; |
2588 | 2592 |
2589 GCPRO1 (filename); | |
2590 CHECK_STRING (filename); | 2593 CHECK_STRING (filename); |
2591 filename = Fexpand_file_name (filename, Qnil); | 2594 filename = Fexpand_file_name (filename, Qnil); |
2592 UNGCPRO; | |
2593 | 2595 |
2594 /* If the file name has special constructs in it, | 2596 /* If the file name has special constructs in it, |
2595 call the corresponding file handler. */ | 2597 call the corresponding file handler. */ |
2598 GCPRO1 (filename); | |
2596 handler = Ffind_file_name_handler (filename, Qfile_symlink_p); | 2599 handler = Ffind_file_name_handler (filename, Qfile_symlink_p); |
2600 UNGCPRO; | |
2597 if (!NILP (handler)) | 2601 if (!NILP (handler)) |
2598 return call2 (handler, Qfile_symlink_p, filename); | 2602 return call2 (handler, Qfile_symlink_p, filename); |
2599 | 2603 |
2600 bufsize = 100; | 2604 bufsize = 100; |
2601 while (1) | 2605 while (1) |
2627 A directory name spec may be given instead; then the value is t | 2631 A directory name spec may be given instead; then the value is t |
2628 if the directory so specified exists and really is a directory. | 2632 if the directory so specified exists and really is a directory. |
2629 */ | 2633 */ |
2630 (filename)) | 2634 (filename)) |
2631 { | 2635 { |
2632 /* This function can GC */ | 2636 /* This function can call lisp */ |
2633 Lisp_Object abspath; | 2637 Lisp_Object abspath; |
2634 struct stat st; | 2638 struct stat st; |
2635 Lisp_Object handler; | 2639 Lisp_Object handler; |
2636 struct gcpro gcpro1; | 2640 struct gcpro gcpro1; |
2637 | 2641 |
2661 if the directory so specified exists and really is a readable and | 2665 if the directory so specified exists and really is a readable and |
2662 searchable directory. | 2666 searchable directory. |
2663 */ | 2667 */ |
2664 (filename)) | 2668 (filename)) |
2665 { | 2669 { |
2666 /* This function can GC */ | 2670 /* This function can call lisp */ |
2667 Lisp_Object handler; | 2671 Lisp_Object handler; |
2668 struct gcpro gcpro1; | |
2669 | 2672 |
2670 /* If the file name has special constructs in it, | 2673 /* If the file name has special constructs in it, |
2671 call the corresponding file handler. */ | 2674 call the corresponding file handler. */ |
2672 handler = Ffind_file_name_handler (filename, Qfile_accessible_directory_p); | 2675 handler = Ffind_file_name_handler (filename, Qfile_accessible_directory_p); |
2673 if (!NILP (handler)) | 2676 if (!NILP (handler)) |
2674 return call2 (handler, Qfile_accessible_directory_p, | 2677 return call2 (handler, Qfile_accessible_directory_p, |
2675 filename); | 2678 filename); |
2676 | 2679 |
2677 /* #### dmoore - this gcpro on filename should be unneccesary since | |
2678 the caller should ahve already protected it. */ | |
2679 GCPRO1 (filename); | |
2680 if (NILP (Ffile_directory_p (filename))) | 2680 if (NILP (Ffile_directory_p (filename))) |
2681 { | |
2682 UNGCPRO; | |
2683 return (Qnil); | 2681 return (Qnil); |
2684 } | 2682 else |
2685 handler = Ffile_executable_p (filename); | 2683 return Ffile_executable_p (filename); |
2686 UNGCPRO; | |
2687 return (handler); | |
2688 } | 2684 } |
2689 | 2685 |
2690 DEFUN ("file-regular-p", Ffile_regular_p, 1, 1, 0, /* | 2686 DEFUN ("file-regular-p", Ffile_regular_p, 1, 1, 0, /* |
2691 "Return t if file FILENAME is the name of a regular file. | 2687 "Return t if file FILENAME is the name of a regular file. |
2692 This is the sort of file that holds an ordinary stream of data bytes. | 2688 This is the sort of file that holds an ordinary stream of data bytes. |
2693 */ | 2689 */ |
2694 (filename)) | 2690 (filename)) |
2695 { | 2691 { |
2692 /* This function can call lisp */ | |
2696 Lisp_Object abspath; | 2693 Lisp_Object abspath; |
2697 struct stat st; | 2694 struct stat st; |
2698 Lisp_Object handler; | 2695 Lisp_Object handler; |
2699 struct gcpro gcpro1; | 2696 struct gcpro gcpro1; |
2700 | 2697 |
2718 DEFUN ("file-modes", Ffile_modes, 1, 1, 0, /* | 2715 DEFUN ("file-modes", Ffile_modes, 1, 1, 0, /* |
2719 Return mode bits of FILE, as an integer. | 2716 Return mode bits of FILE, as an integer. |
2720 */ | 2717 */ |
2721 (filename)) | 2718 (filename)) |
2722 { | 2719 { |
2723 /* This function can GC */ | 2720 /* This function can call lisp */ |
2724 Lisp_Object abspath; | 2721 Lisp_Object abspath; |
2725 struct stat st; | 2722 struct stat st; |
2726 Lisp_Object handler; | 2723 Lisp_Object handler; |
2727 struct gcpro gcpro1; | 2724 struct gcpro gcpro1; |
2728 | 2725 |
2753 Set mode bits of FILE to MODE (an integer). | 2750 Set mode bits of FILE to MODE (an integer). |
2754 Only the 12 low bits of MODE are used. | 2751 Only the 12 low bits of MODE are used. |
2755 */ | 2752 */ |
2756 (filename, mode)) | 2753 (filename, mode)) |
2757 { | 2754 { |
2758 /* This function can GC */ | 2755 /* This function can call lisp */ |
2759 Lisp_Object abspath; | 2756 Lisp_Object abspath; |
2760 Lisp_Object handler; | 2757 Lisp_Object handler; |
2761 struct gcpro gcpro1; | 2758 struct gcpro gcpro1; |
2762 | 2759 |
2763 GCPRO1 (current_buffer->directory); | 2760 GCPRO1 (current_buffer->directory); |
2764 abspath = Fexpand_file_name (filename, current_buffer->directory); | 2761 abspath = Fexpand_file_name (filename, current_buffer->directory); |
2762 UNGCPRO; | |
2763 | |
2765 CHECK_INT (mode); | 2764 CHECK_INT (mode); |
2766 UNGCPRO; | |
2767 | 2765 |
2768 /* If the file name has special constructs in it, | 2766 /* If the file name has special constructs in it, |
2769 call the corresponding file handler. */ | 2767 call the corresponding file handler. */ |
2770 GCPRO1 (abspath); | 2768 GCPRO1 (abspath); |
2771 handler = Ffind_file_name_handler (abspath, Qset_file_modes); | 2769 handler = Ffind_file_name_handler (abspath, Qset_file_modes); |
2828 If FILE1 does not exist, the answer is nil; | 2826 If FILE1 does not exist, the answer is nil; |
2829 otherwise, if FILE2 does not exist, the answer is t. | 2827 otherwise, if FILE2 does not exist, the answer is t. |
2830 */ | 2828 */ |
2831 (file1, file2)) | 2829 (file1, file2)) |
2832 { | 2830 { |
2833 /* This function can GC */ | 2831 /* This function can call lisp */ |
2834 Lisp_Object abspath1, abspath2; | 2832 Lisp_Object abspath1, abspath2; |
2835 struct stat st; | 2833 struct stat st; |
2836 int mtime1; | 2834 int mtime1; |
2837 Lisp_Object handler; | 2835 Lisp_Object handler; |
2838 struct gcpro gcpro1, gcpro2, gcpro3; | 2836 struct gcpro gcpro1, gcpro2, gcpro3; |
2895 the whole thing because (1) it preserves some marker positions | 2893 the whole thing because (1) it preserves some marker positions |
2896 and (2) it puts less data in the undo list. | 2894 and (2) it puts less data in the undo list. |
2897 */ | 2895 */ |
2898 (filename, visit, beg, end, replace)) | 2896 (filename, visit, beg, end, replace)) |
2899 { | 2897 { |
2900 /* This function can GC */ | 2898 /* This function can call lisp */ |
2899 /* #### dmoore - this function hasn't been checked for gc recently */ | |
2901 struct stat st; | 2900 struct stat st; |
2902 int fd; | 2901 int fd; |
2903 int saverrno = 0; | 2902 int saverrno = 0; |
2904 Charcount inserted = 0; | 2903 Charcount inserted = 0; |
2905 int speccount; | 2904 int speccount; |
3345 Kludgy feature: if START is a string, then that string is written | 3344 Kludgy feature: if START is a string, then that string is written |
3346 to the file, instead of any buffer contents, and END is ignored. | 3345 to the file, instead of any buffer contents, and END is ignored. |
3347 */ | 3346 */ |
3348 (start, end, filename, append, visit, lockname)) | 3347 (start, end, filename, append, visit, lockname)) |
3349 { | 3348 { |
3350 /* This function can GC */ | 3349 /* This function can call lisp */ |
3351 int desc; | 3350 int desc; |
3352 int failure; | 3351 int failure; |
3353 int save_errno = 0; | 3352 int save_errno = 0; |
3354 struct stat st; | 3353 struct stat st; |
3355 Lisp_Object fn; | 3354 Lisp_Object fn; |
3972 Return t if last mod time of BUF's visited file matches what BUF records. | 3971 Return t if last mod time of BUF's visited file matches what BUF records. |
3973 This means that the file has not been changed since it was visited or saved. | 3972 This means that the file has not been changed since it was visited or saved. |
3974 */ | 3973 */ |
3975 (buf)) | 3974 (buf)) |
3976 { | 3975 { |
3977 /* This function can GC */ | 3976 /* This function can call lisp */ |
3978 struct buffer *b; | 3977 struct buffer *b; |
3979 struct stat st; | 3978 struct stat st; |
3980 Lisp_Object handler; | 3979 Lisp_Object handler; |
3981 | 3980 |
3982 CHECK_BUFFER (buf); | 3981 CHECK_BUFFER (buf); |
4038 (instead of that of the visited file), in the form of a list | 4037 (instead of that of the visited file), in the form of a list |
4039 (HIGH . LOW) or (HIGH LOW). | 4038 (HIGH . LOW) or (HIGH LOW). |
4040 */ | 4039 */ |
4041 (time_list)) | 4040 (time_list)) |
4042 { | 4041 { |
4043 /* This function can GC */ | 4042 /* This function can call lisp */ |
4044 if (!NILP (time_list)) | 4043 if (!NILP (time_list)) |
4045 { | 4044 { |
4046 time_t the_time; | 4045 time_t the_time; |
4047 lisp_to_time (time_list, &the_time); | 4046 lisp_to_time (time_list, &the_time); |
4048 current_buffer->modtime = (int) the_time; | 4047 current_buffer->modtime = (int) the_time; |
4077 current time. In either case, if the optional arg TIME is supplied, | 4076 current time. In either case, if the optional arg TIME is supplied, |
4078 it will be used if it is either an integer or a cons of two integers. | 4077 it will be used if it is either an integer or a cons of two integers. |
4079 */ | 4078 */ |
4080 (buf, in_time)) | 4079 (buf, in_time)) |
4081 { | 4080 { |
4082 /* This function can GC */ | 4081 /* This function can call lisp */ |
4083 unsigned long time_to_use = 0; | 4082 unsigned long time_to_use = 0; |
4084 int set_time_to_use = 0; | 4083 int set_time_to_use = 0; |
4085 struct stat st; | 4084 struct stat st; |
4086 | 4085 |
4087 CHECK_BUFFER (buf); | 4086 CHECK_BUFFER (buf); |
4151 | 4150 |
4152 | 4151 |
4153 static Lisp_Object | 4152 static Lisp_Object |
4154 auto_save_error (Lisp_Object condition_object, Lisp_Object ignored) | 4153 auto_save_error (Lisp_Object condition_object, Lisp_Object ignored) |
4155 { | 4154 { |
4156 /* This function can GC */ | 4155 /* This function can call lisp */ |
4157 if (gc_in_progress) | 4156 if (gc_in_progress) |
4158 return Qnil; | 4157 return Qnil; |
4159 /* Don't try printing an error message after everything is gone! */ | 4158 /* Don't try printing an error message after everything is gone! */ |
4160 if (preparing_for_armageddon) | 4159 if (preparing_for_armageddon) |
4161 return Qnil; | 4160 return Qnil; |
4171 } | 4170 } |
4172 | 4171 |
4173 static Lisp_Object | 4172 static Lisp_Object |
4174 auto_save_1 (Lisp_Object ignored) | 4173 auto_save_1 (Lisp_Object ignored) |
4175 { | 4174 { |
4176 /* This function can GC */ | 4175 /* This function can call lisp */ |
4176 /* #### I think caller is protecting current_buffer? */ | |
4177 struct stat st; | 4177 struct stat st; |
4178 Lisp_Object fn = current_buffer->filename; | 4178 Lisp_Object fn = current_buffer->filename; |
4179 Lisp_Object a = current_buffer->auto_save_file_name; | 4179 Lisp_Object a = current_buffer->auto_save_file_name; |
4180 | 4180 |
4181 if (!STRINGP (a)) | 4181 if (!STRINGP (a)) |
4194 | 4194 |
4195 return | 4195 return |
4196 Fwrite_region_internal (Qnil, Qnil, a, Qnil, Qlambda, Qnil); | 4196 Fwrite_region_internal (Qnil, Qnil, a, Qnil, Qlambda, Qnil); |
4197 } | 4197 } |
4198 | 4198 |
4199 static Lisp_Object | |
4200 auto_save_expand_name_error (Lisp_Object condition_object, Lisp_Object ignored) | |
4201 { | |
4202 /* #### this function should spew an error message about not being | |
4203 able to open the .saves file. */ | |
4204 return Qnil; | |
4205 } | |
4206 | |
4207 static Lisp_Object | |
4208 auto_save_expand_name (Lisp_Object name) | |
4209 { | |
4210 struct gcpro gcpro1; | |
4211 | |
4212 /* note that caller did NOT gc protect name, so we do it. */ | |
4213 /* #### dmoore - this might not be neccessary, if condition_case_1 | |
4214 protects it. but I don't think it does. */ | |
4215 GCPRO1 (name); | |
4216 RETURN_UNGCPRO (Fexpand_file_name (name, Qnil)); | |
4217 } | |
4218 | |
4199 | 4219 |
4200 static Lisp_Object | 4220 static Lisp_Object |
4201 do_auto_save_unwind (Lisp_Object fd) | 4221 do_auto_save_unwind (Lisp_Object fd) |
4202 { | 4222 { |
4203 close (XINT (fd)); | 4223 close (XINT (fd)); |
4231 Non-nil first argument means do not print any message if successful. | 4251 Non-nil first argument means do not print any message if successful. |
4232 Non-nil second argument means save only current buffer. | 4252 Non-nil second argument means save only current buffer. |
4233 */ | 4253 */ |
4234 (no_message, current_only)) | 4254 (no_message, current_only)) |
4235 { | 4255 { |
4236 /* This function can GC */ | 4256 /* This function can call lisp */ |
4237 struct buffer *b; | 4257 struct buffer *b; |
4238 Lisp_Object tail, buf; | 4258 Lisp_Object tail, buf; |
4239 int auto_saved = 0; | 4259 int auto_saved = 0; |
4240 int do_handled_files; | 4260 int do_handled_files; |
4241 Lisp_Object oquit = Qnil; | 4261 Lisp_Object oquit = Qnil; |
4260 no_message = Qt; | 4280 no_message = Qt; |
4261 | 4281 |
4262 run_hook (Qauto_save_hook); | 4282 run_hook (Qauto_save_hook); |
4263 | 4283 |
4264 if (GC_STRINGP (Vauto_save_list_file_name)) | 4284 if (GC_STRINGP (Vauto_save_list_file_name)) |
4265 listfile = Fexpand_file_name (Vauto_save_list_file_name, Qnil); | 4285 listfile = condition_case_1 (Qt, |
4286 auto_save_expand_name, | |
4287 Vauto_save_list_file_name, | |
4288 auto_save_expand_name_error, Qnil); | |
4266 | 4289 |
4267 /* Make sure auto_saving is reset. */ | 4290 /* Make sure auto_saving is reset. */ |
4268 record_unwind_protect (do_auto_save_unwind_2, make_int (auto_saving)); | 4291 record_unwind_protect (do_auto_save_unwind_2, make_int (auto_saving)); |
4269 | 4292 |
4270 auto_saving = 1; | 4293 auto_saving = 1; |