1 /* File IO for GNU Emacs.
2 Copyright (C) 1985, 1986, 1987, 1988, 1992, 1993 Free Software Foundation, Inc.
4 This file is part of GNU Emacs.
6 GNU Emacs is free software; you can redistribute it and/or modify
7 it under the terms of the GNU General Public License as published by
8 the Free Software Foundation; either version 2, or (at your option)
11 GNU Emacs is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 GNU General Public License for more details.
16 You should have received a copy of the GNU General Public License
17 along with GNU Emacs; see the file COPYING. If not, write to
18 the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA. */
22 #include <sys/types.h>
44 extern char *sys_errlist
[];
48 #define err_str(a) ((a) < sys_nerr ? sys_errlist[a] : "unknown error")
63 #include "intervals.h"
87 #define min(a, b) ((a) < (b) ? (a) : (b))
88 #define max(a, b) ((a) > (b) ? (a) : (b))
90 /* Nonzero during writing of auto-save files */
93 /* Set by auto_save_1 to mode of original file so Fwrite_region will create
94 a new file with the same mode as the original */
95 int auto_save_mode_bits
;
97 /* Alist of elements (REGEXP . HANDLER) for file names
98 whose I/O is done with a special handler. */
99 Lisp_Object Vfile_name_handler_alist
;
101 /* Nonzero means, when reading a filename in the minibuffer,
102 start out by inserting the default directory into the minibuffer. */
103 int insert_default_directory
;
105 /* On VMS, nonzero means write new files with record format stmlf.
106 Zero means use var format. */
109 Lisp_Object Qfile_error
, Qfile_already_exists
;
111 Lisp_Object Qfile_name_history
;
113 report_file_error (string
, data
)
117 Lisp_Object errstring
;
119 if (errno
>= 0 && errno
< sys_nerr
)
120 errstring
= build_string (sys_errlist
[errno
]);
122 errstring
= build_string ("undocumented error code");
124 /* System error messages are capitalized. Downcase the initial
125 unless it is followed by a slash. */
126 if (XSTRING (errstring
)->data
[1] != '/')
127 XSTRING (errstring
)->data
[0] = DOWNCASE (XSTRING (errstring
)->data
[0]);
130 Fsignal (Qfile_error
,
131 Fcons (build_string (string
), Fcons (errstring
, data
)));
134 close_file_unwind (fd
)
137 close (XFASTINT (fd
));
140 Lisp_Object Qexpand_file_name
;
141 Lisp_Object Qdirectory_file_name
;
142 Lisp_Object Qfile_name_directory
;
143 Lisp_Object Qfile_name_nondirectory
;
144 Lisp_Object Qunhandled_file_name_directory
;
145 Lisp_Object Qfile_name_as_directory
;
146 Lisp_Object Qcopy_file
;
147 Lisp_Object Qmake_directory
;
148 Lisp_Object Qdelete_directory
;
149 Lisp_Object Qdelete_file
;
150 Lisp_Object Qrename_file
;
151 Lisp_Object Qadd_name_to_file
;
152 Lisp_Object Qmake_symbolic_link
;
153 Lisp_Object Qfile_exists_p
;
154 Lisp_Object Qfile_executable_p
;
155 Lisp_Object Qfile_readable_p
;
156 Lisp_Object Qfile_symlink_p
;
157 Lisp_Object Qfile_writable_p
;
158 Lisp_Object Qfile_directory_p
;
159 Lisp_Object Qfile_accessible_directory_p
;
160 Lisp_Object Qfile_modes
;
161 Lisp_Object Qset_file_modes
;
162 Lisp_Object Qfile_newer_than_file_p
;
163 Lisp_Object Qinsert_file_contents
;
164 Lisp_Object Qwrite_region
;
165 Lisp_Object Qverify_visited_file_modtime
;
167 DEFUN ("find-file-name-handler", Ffind_file_name_handler
, Sfind_file_name_handler
, 1, 1, 0,
168 "Return FILENAME's handler function, if its syntax is handled specially.\n\
169 Otherwise, return nil.\n\
170 A file name is handled if one of the regular expressions in\n\
171 `file-name-handler-alist' matches it.")
173 Lisp_Object filename
;
175 /* This function must not munge the match data. */
178 for (chain
= Vfile_name_handler_alist
; XTYPE (chain
) == Lisp_Cons
;
179 chain
= XCONS (chain
)->cdr
)
182 elt
= XCONS (chain
)->car
;
183 if (XTYPE (elt
) == Lisp_Cons
)
186 string
= XCONS (elt
)->car
;
187 if (XTYPE (string
) == Lisp_String
188 && fast_string_match (string
, filename
) >= 0)
189 return XCONS (elt
)->cdr
;
197 DEFUN ("file-name-directory", Ffile_name_directory
, Sfile_name_directory
,
199 "Return the directory component in file name NAME.\n\
200 Return nil if NAME does not include a directory.\n\
201 Otherwise return a directory spec.\n\
202 Given a Unix syntax file name, returns a string ending in slash;\n\
203 on VMS, perhaps instead a string ending in `:', `]' or `>'.")
207 register unsigned char *beg
;
208 register unsigned char *p
;
211 CHECK_STRING (file
, 0);
213 /* If the file name has special constructs in it,
214 call the corresponding file handler. */
215 handler
= Ffind_file_name_handler (file
);
217 return call2 (handler
, Qfile_name_directory
, file
);
219 beg
= XSTRING (file
)->data
;
220 p
= beg
+ XSTRING (file
)->size
;
222 while (p
!= beg
&& p
[-1] != '/'
224 && p
[-1] != ':' && p
[-1] != ']' && p
[-1] != '>'
230 return make_string (beg
, p
- beg
);
233 DEFUN ("file-name-nondirectory", Ffile_name_nondirectory
, Sfile_name_nondirectory
,
235 "Return file name NAME sans its directory.\n\
236 For example, in a Unix-syntax file name,\n\
237 this is everything after the last slash,\n\
238 or the entire name if it contains no slash.")
242 register unsigned char *beg
, *p
, *end
;
245 CHECK_STRING (file
, 0);
247 /* If the file name has special constructs in it,
248 call the corresponding file handler. */
249 handler
= Ffind_file_name_handler (file
);
251 return call2 (handler
, Qfile_name_nondirectory
, file
);
253 beg
= XSTRING (file
)->data
;
254 end
= p
= beg
+ XSTRING (file
)->size
;
256 while (p
!= beg
&& p
[-1] != '/'
258 && p
[-1] != ':' && p
[-1] != ']' && p
[-1] != '>'
262 return make_string (p
, end
- p
);
265 DEFUN ("unhandled-file-name-directory", Funhandled_file_name_directory
, Sunhandled_file_name_directory
, 1, 1, 0,
266 "Return a directly usable directory name somehow associated with FILENAME.\n\
267 A `directly usable' directory name is one that may be used without the\n\
268 intervention of any file handler.\n\
269 If FILENAME is a directly usable file itself, return\n\
270 (file-name-directory FILENAME).\n\
271 The `call-process' and `start-process' functions use this function to\n\
272 get a current directory to run processes in.")
274 Lisp_Object filename
;
278 /* If the file name has special constructs in it,
279 call the corresponding file handler. */
280 handler
= Ffind_file_name_handler (filename
);
282 return call2 (handler
, Qunhandled_file_name_directory
, filename
);
284 return Ffile_name_directory (filename
);
289 file_name_as_directory (out
, in
)
292 int size
= strlen (in
) - 1;
297 /* Is it already a directory string? */
298 if (in
[size
] == ':' || in
[size
] == ']' || in
[size
] == '>')
300 /* Is it a VMS directory file name? If so, hack VMS syntax. */
301 else if (! index (in
, '/')
302 && ((size
> 3 && ! strcmp (&in
[size
- 3], ".DIR"))
303 || (size
> 3 && ! strcmp (&in
[size
- 3], ".dir"))
304 || (size
> 5 && (! strncmp (&in
[size
- 5], ".DIR", 4)
305 || ! strncmp (&in
[size
- 5], ".dir", 4))
306 && (in
[size
- 1] == '.' || in
[size
- 1] == ';')
307 && in
[size
] == '1')))
309 register char *p
, *dot
;
313 dir:x.dir --> dir:[x]
314 dir:[x]y.dir --> dir:[x.y] */
316 while (p
!= in
&& *p
!= ':' && *p
!= '>' && *p
!= ']') p
--;
319 strncpy (out
, in
, p
- in
);
338 dot
= index (p
, '.');
341 /* blindly remove any extension */
342 size
= strlen (out
) + (dot
- p
);
343 strncat (out
, p
, dot
- p
);
354 /* For Unix syntax, Append a slash if necessary */
355 if (out
[size
] != '/')
361 DEFUN ("file-name-as-directory", Ffile_name_as_directory
,
362 Sfile_name_as_directory
, 1, 1, 0,
363 "Return a string representing file FILENAME interpreted as a directory.\n\
364 This operation exists because a directory is also a file, but its name as\n\
365 a directory is different from its name as a file.\n\
366 The result can be used as the value of `default-directory'\n\
367 or passed as second argument to `expand-file-name'.\n\
368 For a Unix-syntax file name, just appends a slash.\n\
369 On VMS, converts \"[X]FOO.DIR\" to \"[X.FOO]\", etc.")
376 CHECK_STRING (file
, 0);
380 /* If the file name has special constructs in it,
381 call the corresponding file handler. */
382 handler
= Ffind_file_name_handler (file
);
384 return call2 (handler
, Qfile_name_as_directory
, file
);
386 buf
= (char *) alloca (XSTRING (file
)->size
+ 10);
387 return build_string (file_name_as_directory (buf
, XSTRING (file
)->data
));
391 * Convert from directory name to filename.
393 * xyzzy:[mukesh.emacs] => xyzzy:[mukesh]emacs.dir.1
394 * xyzzy:[mukesh] => xyzzy:[000000]mukesh.dir.1
395 * On UNIX, it's simple: just make sure there is a terminating /
397 * Value is nonzero if the string output is different from the input.
400 directory_file_name (src
, dst
)
408 struct FAB fab
= cc$rms_fab
;
409 struct NAM nam
= cc$rms_nam
;
410 char esa
[NAM$C_MAXRSS
];
415 if (! index (src
, '/')
416 && (src
[slen
- 1] == ']'
417 || src
[slen
- 1] == ':'
418 || src
[slen
- 1] == '>'))
420 /* VMS style - convert [x.y.z] to [x.y]z, [x] to [000000]x */
422 fab
.fab$b_fns
= slen
;
423 fab
.fab$l_nam
= &nam
;
424 fab
.fab$l_fop
= FAB$M_NAM
;
427 nam
.nam$b_ess
= sizeof esa
;
428 nam
.nam$b_nop
|= NAM$M_SYNCHK
;
430 /* We call SYS$PARSE to handle such things as [--] for us. */
431 if (SYS$
PARSE(&fab
, 0, 0) == RMS$_NORMAL
)
433 slen
= nam
.nam$b_esl
;
434 if (esa
[slen
- 1] == ';' && esa
[slen
- 2] == '.')
439 if (src
[slen
- 1] != ']' && src
[slen
- 1] != '>')
441 /* what about when we have logical_name:???? */
442 if (src
[slen
- 1] == ':')
443 { /* Xlate logical name and see what we get */
444 ptr
= strcpy (dst
, src
); /* upper case for getenv */
447 if ('a' <= *ptr
&& *ptr
<= 'z')
451 dst
[slen
- 1] = 0; /* remove colon */
452 if (!(src
= egetenv (dst
)))
454 /* should we jump to the beginning of this procedure?
455 Good points: allows us to use logical names that xlate
457 Bad points: can be a problem if we just translated to a device
459 For now, I'll punt and always expect VMS names, and hope for
462 if (src
[slen
- 1] != ']' && src
[slen
- 1] != '>')
463 { /* no recursion here! */
469 { /* not a directory spec */
474 bracket
= src
[slen
- 1];
476 /* If bracket is ']' or '>', bracket - 2 is the corresponding
478 ptr
= index (src
, bracket
- 2);
480 { /* no opening bracket */
484 if (!(rptr
= rindex (src
, '.')))
487 strncpy (dst
, src
, slen
);
491 dst
[slen
++] = bracket
;
496 /* If we have the top-level of a rooted directory (i.e. xx:[000000]),
497 then translate the device and recurse. */
498 if (dst
[slen
- 1] == ':'
499 && dst
[slen
- 2] != ':' /* skip decnet nodes */
500 && strcmp(src
+ slen
, "[000000]") == 0)
502 dst
[slen
- 1] = '\0';
503 if ((ptr
= egetenv (dst
))
504 && (rlen
= strlen (ptr
) - 1) > 0
505 && (ptr
[rlen
] == ']' || ptr
[rlen
] == '>')
506 && ptr
[rlen
- 1] == '.')
508 char * buf
= (char *) alloca (strlen (ptr
) + 1);
512 return directory_file_name (buf
, dst
);
517 strcat (dst
, "[000000]");
521 rlen
= strlen (rptr
) - 1;
522 strncat (dst
, rptr
, rlen
);
523 dst
[slen
+ rlen
] = '\0';
524 strcat (dst
, ".DIR.1");
528 /* Process as Unix format: just remove any final slash.
529 But leave "/" unchanged; do not change it to "". */
531 if (slen
> 1 && dst
[slen
- 1] == '/')
536 DEFUN ("directory-file-name", Fdirectory_file_name
, Sdirectory_file_name
,
538 "Returns the file name of the directory named DIR.\n\
539 This is the name of the file that holds the data for the directory DIR.\n\
540 This operation exists because a directory is also a file, but its name as\n\
541 a directory is different from its name as a file.\n\
542 In Unix-syntax, this function just removes the final slash.\n\
543 On VMS, given a VMS-syntax directory name such as \"[X.Y]\",\n\
544 it returns a file name such as \"[X]Y.DIR.1\".")
546 Lisp_Object directory
;
551 CHECK_STRING (directory
, 0);
553 if (NILP (directory
))
556 /* If the file name has special constructs in it,
557 call the corresponding file handler. */
558 handler
= Ffind_file_name_handler (directory
);
560 return call2 (handler
, Qdirectory_file_name
, directory
);
563 /* 20 extra chars is insufficient for VMS, since we might perform a
564 logical name translation. an equivalence string can be up to 255
565 chars long, so grab that much extra space... - sss */
566 buf
= (char *) alloca (XSTRING (directory
)->size
+ 20 + 255);
568 buf
= (char *) alloca (XSTRING (directory
)->size
+ 20);
570 directory_file_name (XSTRING (directory
)->data
, buf
);
571 return build_string (buf
);
574 DEFUN ("make-temp-name", Fmake_temp_name
, Smake_temp_name
, 1, 1, 0,
575 "Generate temporary file name (string) starting with PREFIX (a string).\n\
576 The Emacs process number forms part of the result,\n\
577 so there is no danger of generating a name being used by another process.")
582 val
= concat2 (prefix
, build_string ("XXXXXX"));
583 mktemp (XSTRING (val
)->data
);
587 DEFUN ("expand-file-name", Fexpand_file_name
, Sexpand_file_name
, 1, 2, 0,
588 "Convert FILENAME to absolute, and canonicalize it.\n\
589 Second arg DEFAULT is directory to start with if FILENAME is relative\n\
590 (does not start with slash); if DEFAULT is nil or missing,\n\
591 the current buffer's value of default-directory is used.\n\
592 Path components that are `.' are removed, and \n\
593 path components followed by `..' are removed, along with the `..' itself;\n\
594 note that these simplifications are done without checking the resulting\n\
595 paths in the file system.\n\
596 An initial `~/' expands to your home directory.\n\
597 An initial `~USER/' expands to USER's home directory.\n\
598 See also the function `substitute-in-file-name'.")
600 Lisp_Object name
, defalt
;
604 register unsigned char *newdir
, *p
, *o
;
606 unsigned char *target
;
609 unsigned char * colon
= 0;
610 unsigned char * close
= 0;
611 unsigned char * slash
= 0;
612 unsigned char * brack
= 0;
613 int lbrack
= 0, rbrack
= 0;
618 CHECK_STRING (name
, 0);
620 /* If the file name has special constructs in it,
621 call the corresponding file handler. */
622 handler
= Ffind_file_name_handler (name
);
624 return call3 (handler
, Qexpand_file_name
, name
, defalt
);
626 /* Use the buffer's default-directory if DEFALT is omitted. */
628 defalt
= current_buffer
->directory
;
629 CHECK_STRING (defalt
, 1);
631 /* Make sure DEFALT is properly expanded.
632 It would be better to do this down below where we actually use
633 defalt. Unfortunately, calling Fexpand_file_name recursively
634 could invoke GC, and the strings might be relocated. This would
635 be annoying because we have pointers into strings lying around
636 that would need adjusting, and people would add new pointers to
637 the code and forget to adjust them, resulting in intermittent bugs.
638 Putting this call here avoids all that crud.
640 The EQ test avoids infinite recursion. */
641 if (! NILP (defalt
) && !EQ (defalt
, name
)
642 /* This saves time in a common case. */
643 && XSTRING (defalt
)->data
[0] != '/')
648 defalt
= Fexpand_file_name (defalt
, Qnil
);
653 /* Filenames on VMS are always upper case. */
654 name
= Fupcase (name
);
657 nm
= XSTRING (name
)->data
;
659 /* If nm is absolute, flush ...// and detect /./ and /../.
660 If no /./ or /../ we can return right away. */
668 /* If it turns out that the filename we want to return is just a
669 suffix of FILENAME, we don't need to go through and edit
670 things; we just need to construct a new string using data
671 starting at the middle of FILENAME. If we set lose to a
672 non-zero value, that means we've discovered that we can't do
679 /* Since we know the path is absolute, we can assume that each
680 element starts with a "/". */
682 /* "//" anywhere isn't necessarily hairy; we just start afresh
683 with the second slash. */
684 if (p
[0] == '/' && p
[1] == '/'
686 /* // at start of filename is meaningful on Apollo system */
692 /* "~" is hairy as the start of any path element. */
693 if (p
[0] == '/' && p
[1] == '~')
694 nm
= p
+ 1, lose
= 1;
696 /* "." and ".." are hairy. */
701 || (p
[2] == '.' && (p
[3] == '/'
708 /* if dev:[dir]/, move nm to / */
709 if (!slash
&& p
> nm
&& (brack
|| colon
)) {
710 nm
= (brack
? brack
+ 1 : colon
+ 1);
719 /* VMS pre V4.4,convert '-'s in filenames. */
720 if (lbrack
== rbrack
)
722 if (dots
< 2) /* this is to allow negative version numbers */
727 if (lbrack
> rbrack
&&
728 ((p
[-1] == '.' || p
[-1] == '[' || p
[-1] == '<') &&
729 (p
[1] == '.' || p
[1] == ']' || p
[1] == '>')))
735 /* count open brackets, reset close bracket pointer */
736 if (p
[0] == '[' || p
[0] == '<')
738 /* count close brackets, set close bracket pointer */
739 if (p
[0] == ']' || p
[0] == '>')
741 /* detect ][ or >< */
742 if ((p
[0] == ']' || p
[0] == '>') && (p
[1] == '[' || p
[1] == '<'))
744 if ((p
[0] == ':' || p
[0] == ']' || p
[0] == '>') && p
[1] == '~')
745 nm
= p
+ 1, lose
= 1;
746 if (p
[0] == ':' && (colon
|| slash
))
747 /* if dev1:[dir]dev2:, move nm to dev2: */
753 /* if /pathname/dev:, move nm to dev: */
756 /* if node::dev:, move colon following dev */
757 else if (colon
&& colon
[-1] == ':')
759 /* if dev1:dev2:, move nm to dev2: */
760 else if (colon
&& colon
[-1] != ':')
765 if (p
[0] == ':' && !colon
)
771 if (lbrack
== rbrack
)
774 else if (p
[0] == '.')
783 return build_string (sys_translate_unix (nm
));
785 if (nm
== XSTRING (name
)->data
)
787 return build_string (nm
);
791 /* Now determine directory to start with and put it in newdir */
795 if (nm
[0] == '~') /* prefix ~ */
801 || nm
[1] == 0) /* ~ by itself */
803 if (!(newdir
= (unsigned char *) egetenv ("HOME")))
804 newdir
= (unsigned char *) "";
807 nm
++; /* Don't leave the slash in nm. */
810 else /* ~user/filename */
812 for (p
= nm
; *p
&& (*p
!= '/'
817 o
= (unsigned char *) alloca (p
- nm
+ 1);
818 bcopy ((char *) nm
, o
, p
- nm
);
821 pw
= (struct passwd
*) getpwnam (o
+ 1);
824 newdir
= (unsigned char *) pw
-> pw_dir
;
826 nm
= p
+ 1; /* skip the terminator */
832 /* If we don't find a user of that name, leave the name
833 unchanged; don't move nm forward to p. */
843 newdir
= XSTRING (defalt
)->data
;
848 /* Get rid of any slash at the end of newdir. */
849 int length
= strlen (newdir
);
850 /* Adding `length > 1 &&' makes ~ expand into / when homedir
851 is the root dir. People disagree about whether that is right.
852 Anyway, we can't take the risk of this change now. */
853 if (newdir
[length
- 1] == '/')
855 unsigned char *temp
= (unsigned char *) alloca (length
);
856 bcopy (newdir
, temp
, length
- 1);
857 temp
[length
- 1] = 0;
865 /* Now concatenate the directory and name to new space in the stack frame */
866 tlen
+= strlen (nm
) + 1;
867 target
= (unsigned char *) alloca (tlen
);
873 if (nm
[0] == 0 || nm
[0] == '/')
874 strcpy (target
, newdir
);
877 file_name_as_directory (target
, newdir
);
882 if (index (target
, '/'))
883 strcpy (target
, sys_translate_unix (target
));
886 /* Now canonicalize by removing /. and /foo/.. if they appear. */
894 if (*p
!= ']' && *p
!= '>' && *p
!= '-')
900 else if ((p
[0] == ']' || p
[0] == '>') && p
[0] == p
[1] + 2)
901 /* brackets are offset from each other by 2 */
904 if (*p
!= '.' && *p
!= '-' && o
[-1] != '.')
905 /* convert [foo][bar] to [bar] */
906 while (o
[-1] != '[' && o
[-1] != '<')
908 else if (*p
== '-' && *o
!= '.')
911 else if (p
[0] == '-' && o
[-1] == '.' &&
912 (p
[1] == '.' || p
[1] == ']' || p
[1] == '>'))
913 /* flush .foo.- ; leave - if stopped by '[' or '<' */
917 while (o
[-1] != '.' && o
[-1] != '[' && o
[-1] != '<');
918 if (p
[1] == '.') /* foo.-.bar ==> bar*/
920 else if (o
[-1] == '.') /* '.foo.-]' ==> ']' */
922 /* else [foo.-] ==> [-] */
928 o
[-1] != '[' && o
[-1] != '<' && o
[-1] != '.' &&
929 p
[1] != ']' && p
[1] != '>' && p
[1] != '.')
939 else if (!strncmp (p
, "//", 2)
941 /* // at start of filename is meaningful in Apollo system */
954 /* If "/." is the entire filename, keep the "/". Otherwise,
955 just delete the whole "/.". */
956 if (o
== target
&& p
[2] == '\0')
960 else if (!strncmp (p
, "/..", 3)
961 /* `/../' is the "superroot" on certain file systems. */
963 && (p
[3] == '/' || p
[3] == 0))
965 while (o
!= target
&& *--o
!= '/')
968 if (o
== target
+ 1 && o
[-1] == '/' && o
[0] == '/')
972 if (o
== target
&& *o
== '/')
983 return make_string (target
, o
- target
);
986 /* Changed this DEFUN to a DEAFUN, so as not to confuse `make-docfile'.
987 DEAFUN ("expand-file-name", Fexpand_file_name, Sexpand_file_name, 1, 2, 0,
988 "Convert FILENAME to absolute, and canonicalize it.\n\
989 Second arg DEFAULT is directory to start with if FILENAME is relative\n\
990 (does not start with slash); if DEFAULT is nil or missing,\n\
991 the current buffer's value of default-directory is used.\n\
992 Filenames containing `.' or `..' as components are simplified;\n\
993 initial `~/' expands to your home directory.\n\
994 See also the function `substitute-in-file-name'.")
996 Lisp_Object name, defalt;
1000 register unsigned char *newdir, *p, *o;
1002 unsigned char *target;
1006 unsigned char * colon = 0;
1007 unsigned char * close = 0;
1008 unsigned char * slash = 0;
1009 unsigned char * brack = 0;
1010 int lbrack = 0, rbrack = 0;
1014 CHECK_STRING (name
, 0);
1017 /* Filenames on VMS are always upper case. */
1018 name
= Fupcase (name
);
1021 nm
= XSTRING (name
)->data
;
1023 /* If nm is absolute, flush ...// and detect /./ and /../.
1024 If no /./ or /../ we can return right away. */
1036 if (p
[0] == '/' && p
[1] == '/'
1038 /* // at start of filename is meaningful on Apollo system */
1043 if (p
[0] == '/' && p
[1] == '~')
1044 nm
= p
+ 1, lose
= 1;
1045 if (p
[0] == '/' && p
[1] == '.'
1046 && (p
[2] == '/' || p
[2] == 0
1047 || (p
[2] == '.' && (p
[3] == '/' || p
[3] == 0))))
1053 /* if dev:[dir]/, move nm to / */
1054 if (!slash
&& p
> nm
&& (brack
|| colon
)) {
1055 nm
= (brack
? brack
+ 1 : colon
+ 1);
1056 lbrack
= rbrack
= 0;
1064 /* VMS pre V4.4,convert '-'s in filenames. */
1065 if (lbrack
== rbrack
)
1067 if (dots
< 2) /* this is to allow negative version numbers */
1072 if (lbrack
> rbrack
&&
1073 ((p
[-1] == '.' || p
[-1] == '[' || p
[-1] == '<') &&
1074 (p
[1] == '.' || p
[1] == ']' || p
[1] == '>')))
1080 /* count open brackets, reset close bracket pointer */
1081 if (p
[0] == '[' || p
[0] == '<')
1082 lbrack
++, brack
= 0;
1083 /* count close brackets, set close bracket pointer */
1084 if (p
[0] == ']' || p
[0] == '>')
1085 rbrack
++, brack
= p
;
1086 /* detect ][ or >< */
1087 if ((p
[0] == ']' || p
[0] == '>') && (p
[1] == '[' || p
[1] == '<'))
1089 if ((p
[0] == ':' || p
[0] == ']' || p
[0] == '>') && p
[1] == '~')
1090 nm
= p
+ 1, lose
= 1;
1091 if (p
[0] == ':' && (colon
|| slash
))
1092 /* if dev1:[dir]dev2:, move nm to dev2: */
1098 /* if /pathname/dev:, move nm to dev: */
1101 /* if node::dev:, move colon following dev */
1102 else if (colon
&& colon
[-1] == ':')
1104 /* if dev1:dev2:, move nm to dev2: */
1105 else if (colon
&& colon
[-1] != ':')
1110 if (p
[0] == ':' && !colon
)
1116 if (lbrack
== rbrack
)
1119 else if (p
[0] == '.')
1127 if (index (nm
, '/'))
1128 return build_string (sys_translate_unix (nm
));
1130 if (nm
== XSTRING (name
)->data
)
1132 return build_string (nm
);
1136 /* Now determine directory to start with and put it in NEWDIR */
1140 if (nm
[0] == '~') /* prefix ~ */
1145 || nm
[1] == 0)/* ~/filename */
1147 if (!(newdir
= (unsigned char *) egetenv ("HOME")))
1148 newdir
= (unsigned char *) "";
1151 nm
++; /* Don't leave the slash in nm. */
1154 else /* ~user/filename */
1156 /* Get past ~ to user */
1157 unsigned char *user
= nm
+ 1;
1158 /* Find end of name. */
1159 unsigned char *ptr
= (unsigned char *) index (user
, '/');
1160 int len
= ptr
? ptr
- user
: strlen (user
);
1162 unsigned char *ptr1
= index (user
, ':');
1163 if (ptr1
!= 0 && ptr1
- user
< len
)
1166 /* Copy the user name into temp storage. */
1167 o
= (unsigned char *) alloca (len
+ 1);
1168 bcopy ((char *) user
, o
, len
);
1171 /* Look up the user name. */
1172 pw
= (struct passwd
*) getpwnam (o
+ 1);
1174 error ("\"%s\" isn't a registered user", o
+ 1);
1176 newdir
= (unsigned char *) pw
->pw_dir
;
1178 /* Discard the user name from NM. */
1185 #endif /* not VMS */
1189 defalt
= current_buffer
->directory
;
1190 CHECK_STRING (defalt
, 1);
1191 newdir
= XSTRING (defalt
)->data
;
1194 /* Now concatenate the directory and name to new space in the stack frame */
1196 tlen
= (newdir
? strlen (newdir
) + 1 : 0) + strlen (nm
) + 1;
1197 target
= (unsigned char *) alloca (tlen
);
1203 if (nm
[0] == 0 || nm
[0] == '/')
1204 strcpy (target
, newdir
);
1207 file_name_as_directory (target
, newdir
);
1210 strcat (target
, nm
);
1212 if (index (target
, '/'))
1213 strcpy (target
, sys_translate_unix (target
));
1216 /* Now canonicalize by removing /. and /foo/.. if they appear */
1224 if (*p
!= ']' && *p
!= '>' && *p
!= '-')
1230 else if ((p
[0] == ']' || p
[0] == '>') && p
[0] == p
[1] + 2)
1231 /* brackets are offset from each other by 2 */
1234 if (*p
!= '.' && *p
!= '-' && o
[-1] != '.')
1235 /* convert [foo][bar] to [bar] */
1236 while (o
[-1] != '[' && o
[-1] != '<')
1238 else if (*p
== '-' && *o
!= '.')
1241 else if (p
[0] == '-' && o
[-1] == '.' &&
1242 (p
[1] == '.' || p
[1] == ']' || p
[1] == '>'))
1243 /* flush .foo.- ; leave - if stopped by '[' or '<' */
1247 while (o
[-1] != '.' && o
[-1] != '[' && o
[-1] != '<');
1248 if (p
[1] == '.') /* foo.-.bar ==> bar*/
1250 else if (o
[-1] == '.') /* '.foo.-]' ==> ']' */
1252 /* else [foo.-] ==> [-] */
1258 o
[-1] != '[' && o
[-1] != '<' && o
[-1] != '.' &&
1259 p
[1] != ']' && p
[1] != '>' && p
[1] != '.')
1269 else if (!strncmp (p
, "//", 2)
1271 /* // at start of filename is meaningful in Apollo system */
1279 else if (p
[0] == '/' && p
[1] == '.' &&
1280 (p
[2] == '/' || p
[2] == 0))
1282 else if (!strncmp (p
, "/..", 3)
1283 /* `/../' is the "superroot" on certain file systems. */
1285 && (p
[3] == '/' || p
[3] == 0))
1287 while (o
!= target
&& *--o
!= '/')
1290 if (o
== target
+ 1 && o
[-1] == '/' && o
[0] == '/')
1294 if (o
== target
&& *o
== '/')
1302 #endif /* not VMS */
1305 return make_string (target
, o
- target
);
1309 DEFUN ("substitute-in-file-name", Fsubstitute_in_file_name
,
1310 Ssubstitute_in_file_name
, 1, 1, 0,
1311 "Substitute environment variables referred to in FILENAME.\n\
1312 `$FOO' where FOO is an environment variable name means to substitute\n\
1313 the value of that variable. The variable name should be terminated\n\
1314 with a character not a letter, digit or underscore; otherwise, enclose\n\
1315 the entire variable name in braces.\n\
1316 If `/~' appears, all of FILENAME through that `/' is discarded.\n\n\
1317 On VMS, `$' substitution is not done; this function does little and only\n\
1318 duplicates what `expand-file-name' does.")
1324 register unsigned char *s
, *p
, *o
, *x
, *endp
;
1325 unsigned char *target
;
1327 int substituted
= 0;
1330 CHECK_STRING (string
, 0);
1332 nm
= XSTRING (string
)->data
;
1333 endp
= nm
+ XSTRING (string
)->size
;
1335 /* If /~ or // appears, discard everything through first slash. */
1337 for (p
= nm
; p
!= endp
; p
++)
1341 /* // at start of file name is meaningful in Apollo system */
1342 (p
[0] == '/' && p
- 1 != nm
)
1343 #else /* not APOLLO */
1345 #endif /* not APOLLO */
1349 (p
[-1] == ':' || p
[-1] == ']' || p
[-1] == '>' ||
1362 return build_string (nm
);
1365 /* See if any variables are substituted into the string
1366 and find the total length of their values in `total' */
1368 for (p
= nm
; p
!= endp
;)
1378 /* "$$" means a single "$" */
1387 while (p
!= endp
&& *p
!= '}') p
++;
1388 if (*p
!= '}') goto missingclose
;
1394 while (p
!= endp
&& (isalnum (*p
) || *p
== '_')) p
++;
1398 /* Copy out the variable name */
1399 target
= (unsigned char *) alloca (s
- o
+ 1);
1400 strncpy (target
, o
, s
- o
);
1403 /* Get variable value */
1404 o
= (unsigned char *) egetenv (target
);
1405 /* The presence of this code makes vax 5.0 crash, for reasons yet unknown */
1408 if (!o
&& !strcmp (target
, "USER"))
1409 o
= egetenv ("LOGNAME");
1412 if (!o
) goto badvar
;
1413 total
+= strlen (o
);
1420 /* If substitution required, recopy the string and do it */
1421 /* Make space in stack frame for the new copy */
1422 xnm
= (unsigned char *) alloca (XSTRING (string
)->size
+ total
+ 1);
1425 /* Copy the rest of the name through, replacing $ constructs with values */
1442 while (p
!= endp
&& *p
!= '}') p
++;
1443 if (*p
!= '}') goto missingclose
;
1449 while (p
!= endp
&& (isalnum (*p
) || *p
== '_')) p
++;
1453 /* Copy out the variable name */
1454 target
= (unsigned char *) alloca (s
- o
+ 1);
1455 strncpy (target
, o
, s
- o
);
1458 /* Get variable value */
1459 o
= (unsigned char *) egetenv (target
);
1460 /* The presence of this code makes vax 5.0 crash, for reasons yet unknown */
1463 if (!o
&& !strcmp (target
, "USER"))
1464 o
= egetenv ("LOGNAME");
1476 /* If /~ or // appears, discard everything through first slash. */
1478 for (p
= xnm
; p
!= x
; p
++)
1481 /* // at start of file name is meaningful in Apollo system */
1482 (p
[0] == '/' && p
- 1 != xnm
)
1483 #else /* not APOLLO */
1485 #endif /* not APOLLO */
1487 && p
!= nm
&& p
[-1] == '/')
1490 return make_string (xnm
, x
- xnm
);
1493 error ("Bad format environment-variable substitution");
1495 error ("Missing \"}\" in environment-variable substitution");
1497 error ("Substituting nonexistent environment variable \"%s\"", target
);
1500 #endif /* not VMS */
1503 /* A slightly faster and more convenient way to get
1504 (directory-file-name (expand-file-name FOO)). The return value may
1505 have had its last character zapped with a '\0' character, meaning
1506 that it is acceptable to system calls, but not to other lisp
1507 functions. Callers should make sure that the return value doesn't
1511 expand_and_dir_to_file (filename
, defdir
)
1512 Lisp_Object filename
, defdir
;
1514 register Lisp_Object abspath
;
1516 abspath
= Fexpand_file_name (filename
, defdir
);
1519 register int c
= XSTRING (abspath
)->data
[XSTRING (abspath
)->size
- 1];
1520 if (c
== ':' || c
== ']' || c
== '>')
1521 abspath
= Fdirectory_file_name (abspath
);
1524 /* Remove final slash, if any (unless path is root).
1525 stat behaves differently depending! */
1526 if (XSTRING (abspath
)->size
> 1
1527 && XSTRING (abspath
)->data
[XSTRING (abspath
)->size
- 1] == '/')
1529 if (EQ (abspath
, filename
))
1530 abspath
= Fcopy_sequence (abspath
);
1531 XSTRING (abspath
)->data
[XSTRING (abspath
)->size
- 1] = 0;
1537 barf_or_query_if_file_exists (absname
, querystring
, interactive
)
1538 Lisp_Object absname
;
1539 unsigned char *querystring
;
1542 register Lisp_Object tem
;
1543 struct gcpro gcpro1
;
1545 if (access (XSTRING (absname
)->data
, 4) >= 0)
1548 Fsignal (Qfile_already_exists
,
1549 Fcons (build_string ("File already exists"),
1550 Fcons (absname
, Qnil
)));
1552 tem
= do_yes_or_no_p (format1 ("File %s already exists; %s anyway? ",
1553 XSTRING (absname
)->data
, querystring
));
1556 Fsignal (Qfile_already_exists
,
1557 Fcons (build_string ("File already exists"),
1558 Fcons (absname
, Qnil
)));
1563 DEFUN ("copy-file", Fcopy_file
, Scopy_file
, 2, 4,
1564 "fCopy file: \nFCopy %s to file: \np\nP",
1565 "Copy FILE to NEWNAME. Both args must be strings.\n\
1566 Signals a `file-already-exists' error if file NEWNAME already exists,\n\
1567 unless a third argument OK-IF-ALREADY-EXISTS is supplied and non-nil.\n\
1568 A number as third arg means request confirmation if NEWNAME already exists.\n\
1569 This is what happens in interactive use with M-x.\n\
1570 Fourth arg KEEP-TIME non-nil means give the new file the same\n\
1571 last-modified time as the old one. (This works on only some systems.)\n\
1572 A prefix arg makes KEEP-TIME non-nil.")
1573 (filename
, newname
, ok_if_already_exists
, keep_date
)
1574 Lisp_Object filename
, newname
, ok_if_already_exists
, keep_date
;
1577 char buf
[16 * 1024];
1579 Lisp_Object handler
;
1580 struct gcpro gcpro1
, gcpro2
;
1581 int count
= specpdl_ptr
- specpdl
;
1583 GCPRO2 (filename
, newname
);
1584 CHECK_STRING (filename
, 0);
1585 CHECK_STRING (newname
, 1);
1586 filename
= Fexpand_file_name (filename
, Qnil
);
1587 newname
= Fexpand_file_name (newname
, Qnil
);
1589 /* If the input file name has special constructs in it,
1590 call the corresponding file handler. */
1591 handler
= Ffind_file_name_handler (filename
);
1592 if (!NILP (handler
))
1593 return call3 (handler
, Qcopy_file
, filename
, newname
);
1594 /* Likewise for output file name. */
1595 handler
= Ffind_file_name_handler (newname
);
1596 if (!NILP (handler
))
1597 return call3 (handler
, Qcopy_file
, filename
, newname
);
1599 if (NILP (ok_if_already_exists
)
1600 || XTYPE (ok_if_already_exists
) == Lisp_Int
)
1601 barf_or_query_if_file_exists (newname
, "copy to it",
1602 XTYPE (ok_if_already_exists
) == Lisp_Int
);
1604 ifd
= open (XSTRING (filename
)->data
, 0);
1606 report_file_error ("Opening input file", Fcons (filename
, Qnil
));
1608 record_unwind_protect (close_file_unwind
, make_number (ifd
));
1611 /* Create the copy file with the same record format as the input file */
1612 ofd
= sys_creat (XSTRING (newname
)->data
, 0666, ifd
);
1614 ofd
= creat (XSTRING (newname
)->data
, 0666);
1617 report_file_error ("Opening output file", Fcons (newname
, Qnil
));
1619 record_unwind_protect (close_file_unwind
, make_number (ofd
));
1623 while ((n
= read (ifd
, buf
, sizeof buf
)) > 0)
1624 if (write (ofd
, buf
, n
) != n
)
1625 report_file_error ("I/O error", Fcons (newname
, Qnil
));
1628 if (fstat (ifd
, &st
) >= 0)
1630 if (!NILP (keep_date
))
1632 EMACS_TIME atime
, mtime
;
1633 EMACS_SET_SECS_USECS (atime
, st
.st_atime
, 0);
1634 EMACS_SET_SECS_USECS (mtime
, st
.st_mtime
, 0);
1635 EMACS_SET_UTIMES (XSTRING (newname
)->data
, atime
, mtime
);
1638 if (!egetenv ("USE_DOMAIN_ACLS"))
1640 chmod (XSTRING (newname
)->data
, st
.st_mode
& 07777);
1643 /* Discard the unwind protects. */
1644 specpdl_ptr
= specpdl
+ count
;
1647 if (close (ofd
) < 0)
1648 report_file_error ("I/O error", Fcons (newname
, Qnil
));
1654 DEFUN ("make-directory-internal", Fmake_directory_internal
,
1655 Smake_directory_internal
, 1, 1, 0,
1656 "Create a directory. One argument, a file name string.")
1658 Lisp_Object dirname
;
1661 Lisp_Object handler
;
1663 CHECK_STRING (dirname
, 0);
1664 dirname
= Fexpand_file_name (dirname
, Qnil
);
1666 handler
= Ffind_file_name_handler (dirname
);
1667 if (!NILP (handler
))
1668 return call3 (handler
, Qmake_directory
, dirname
, Qnil
);
1670 dir
= XSTRING (dirname
)->data
;
1672 if (mkdir (dir
, 0777) != 0)
1673 report_file_error ("Creating directory", Flist (1, &dirname
));
1678 DEFUN ("delete-directory", Fdelete_directory
, Sdelete_directory
, 1, 1, "FDelete directory: ",
1679 "Delete a directory. One argument, a file name string.")
1681 Lisp_Object dirname
;
1684 Lisp_Object handler
;
1686 CHECK_STRING (dirname
, 0);
1687 dirname
= Fexpand_file_name (dirname
, Qnil
);
1688 dir
= XSTRING (dirname
)->data
;
1690 handler
= Ffind_file_name_handler (dirname
);
1691 if (!NILP (handler
))
1692 return call2 (handler
, Qdelete_directory
, dirname
);
1694 if (rmdir (dir
) != 0)
1695 report_file_error ("Removing directory", Flist (1, &dirname
));
1700 DEFUN ("delete-file", Fdelete_file
, Sdelete_file
, 1, 1, "fDelete file: ",
1701 "Delete specified file. One argument, a file name string.\n\
1702 If file has multiple names, it continues to exist with the other names.")
1704 Lisp_Object filename
;
1706 Lisp_Object handler
;
1707 CHECK_STRING (filename
, 0);
1708 filename
= Fexpand_file_name (filename
, Qnil
);
1710 handler
= Ffind_file_name_handler (filename
);
1711 if (!NILP (handler
))
1712 return call2 (handler
, Qdelete_file
, filename
);
1714 if (0 > unlink (XSTRING (filename
)->data
))
1715 report_file_error ("Removing old name", Flist (1, &filename
));
1719 DEFUN ("rename-file", Frename_file
, Srename_file
, 2, 3,
1720 "fRename file: \nFRename %s to file: \np",
1721 "Rename FILE as NEWNAME. Both args strings.\n\
1722 If file has names other than FILE, it continues to have those names.\n\
1723 Signals a `file-already-exists' error if a file NEWNAME already exists\n\
1724 unless optional third argument OK-IF-ALREADY-EXISTS is non-nil.\n\
1725 A number as third arg means request confirmation if NEWNAME already exists.\n\
1726 This is what happens in interactive use with M-x.")
1727 (filename
, newname
, ok_if_already_exists
)
1728 Lisp_Object filename
, newname
, ok_if_already_exists
;
1731 Lisp_Object args
[2];
1733 Lisp_Object handler
;
1734 struct gcpro gcpro1
, gcpro2
;
1736 GCPRO2 (filename
, newname
);
1737 CHECK_STRING (filename
, 0);
1738 CHECK_STRING (newname
, 1);
1739 filename
= Fexpand_file_name (filename
, Qnil
);
1740 newname
= Fexpand_file_name (newname
, Qnil
);
1742 /* If the file name has special constructs in it,
1743 call the corresponding file handler. */
1744 handler
= Ffind_file_name_handler (filename
);
1745 if (!NILP (handler
))
1746 return call3 (handler
, Qrename_file
, filename
, newname
);
1748 if (NILP (ok_if_already_exists
)
1749 || XTYPE (ok_if_already_exists
) == Lisp_Int
)
1750 barf_or_query_if_file_exists (newname
, "rename to it",
1751 XTYPE (ok_if_already_exists
) == Lisp_Int
);
1753 if (0 > rename (XSTRING (filename
)->data
, XSTRING (newname
)->data
))
1755 if (0 > link (XSTRING (filename
)->data
, XSTRING (newname
)->data
)
1756 || 0 > unlink (XSTRING (filename
)->data
))
1761 Fcopy_file (filename
, newname
, ok_if_already_exists
, Qt
);
1762 Fdelete_file (filename
);
1769 report_file_error ("Renaming", Flist (2, args
));
1772 report_file_error ("Renaming", Flist (2, &filename
));
1779 DEFUN ("add-name-to-file", Fadd_name_to_file
, Sadd_name_to_file
, 2, 3,
1780 "fAdd name to file: \nFName to add to %s: \np",
1781 "Give FILE additional name NEWNAME. Both args strings.\n\
1782 Signals a `file-already-exists' error if a file NEWNAME already exists\n\
1783 unless optional third argument OK-IF-ALREADY-EXISTS is non-nil.\n\
1784 A number as third arg means request confirmation if NEWNAME already exists.\n\
1785 This is what happens in interactive use with M-x.")
1786 (filename
, newname
, ok_if_already_exists
)
1787 Lisp_Object filename
, newname
, ok_if_already_exists
;
1790 Lisp_Object args
[2];
1792 Lisp_Object handler
;
1793 struct gcpro gcpro1
, gcpro2
;
1795 GCPRO2 (filename
, newname
);
1796 CHECK_STRING (filename
, 0);
1797 CHECK_STRING (newname
, 1);
1798 filename
= Fexpand_file_name (filename
, Qnil
);
1799 newname
= Fexpand_file_name (newname
, Qnil
);
1801 /* If the file name has special constructs in it,
1802 call the corresponding file handler. */
1803 handler
= Ffind_file_name_handler (filename
);
1804 if (!NILP (handler
))
1805 return call3 (handler
, Qadd_name_to_file
, filename
, newname
);
1807 if (NILP (ok_if_already_exists
)
1808 || XTYPE (ok_if_already_exists
) == Lisp_Int
)
1809 barf_or_query_if_file_exists (newname
, "make it a new name",
1810 XTYPE (ok_if_already_exists
) == Lisp_Int
);
1811 unlink (XSTRING (newname
)->data
);
1812 if (0 > link (XSTRING (filename
)->data
, XSTRING (newname
)->data
))
1817 report_file_error ("Adding new name", Flist (2, args
));
1819 report_file_error ("Adding new name", Flist (2, &filename
));
1828 DEFUN ("make-symbolic-link", Fmake_symbolic_link
, Smake_symbolic_link
, 2, 3,
1829 "FMake symbolic link to file: \nFMake symbolic link to file %s: \np",
1830 "Make a symbolic link to FILENAME, named LINKNAME. Both args strings.\n\
1831 Signals a `file-already-exists' error if a file NEWNAME already exists\n\
1832 unless optional third argument OK-IF-ALREADY-EXISTS is non-nil.\n\
1833 A number as third arg means request confirmation if NEWNAME already exists.\n\
1834 This happens for interactive use with M-x.")
1835 (filename
, linkname
, ok_if_already_exists
)
1836 Lisp_Object filename
, linkname
, ok_if_already_exists
;
1839 Lisp_Object args
[2];
1841 Lisp_Object handler
;
1842 struct gcpro gcpro1
, gcpro2
;
1844 GCPRO2 (filename
, linkname
);
1845 CHECK_STRING (filename
, 0);
1846 CHECK_STRING (linkname
, 1);
1847 #if 0 /* This made it impossible to make a link to a relative name. */
1848 filename
= Fexpand_file_name (filename
, Qnil
);
1850 linkname
= Fexpand_file_name (linkname
, Qnil
);
1852 /* If the file name has special constructs in it,
1853 call the corresponding file handler. */
1854 handler
= Ffind_file_name_handler (filename
);
1855 if (!NILP (handler
))
1856 return call3 (handler
, Qmake_symbolic_link
, filename
, linkname
);
1858 if (NILP (ok_if_already_exists
)
1859 || XTYPE (ok_if_already_exists
) == Lisp_Int
)
1860 barf_or_query_if_file_exists (linkname
, "make it a link",
1861 XTYPE (ok_if_already_exists
) == Lisp_Int
);
1862 if (0 > symlink (XSTRING (filename
)->data
, XSTRING (linkname
)->data
))
1864 /* If we didn't complain already, silently delete existing file. */
1865 if (errno
== EEXIST
)
1867 unlink (XSTRING (linkname
)->data
);
1868 if (0 <= symlink (XSTRING (filename
)->data
, XSTRING (linkname
)->data
))
1875 report_file_error ("Making symbolic link", Flist (2, args
));
1877 report_file_error ("Making symbolic link", Flist (2, &filename
));
1883 #endif /* S_IFLNK */
1887 DEFUN ("define-logical-name", Fdefine_logical_name
, Sdefine_logical_name
,
1888 2, 2, "sDefine logical name: \nsDefine logical name %s as: ",
1889 "Define the job-wide logical name NAME to have the value STRING.\n\
1890 If STRING is nil or a null string, the logical name NAME is deleted.")
1892 Lisp_Object varname
;
1895 CHECK_STRING (varname
, 0);
1897 delete_logical_name (XSTRING (varname
)->data
);
1900 CHECK_STRING (string
, 1);
1902 if (XSTRING (string
)->size
== 0)
1903 delete_logical_name (XSTRING (varname
)->data
);
1905 define_logical_name (XSTRING (varname
)->data
, XSTRING (string
)->data
);
1914 DEFUN ("sysnetunam", Fsysnetunam
, Ssysnetunam
, 2, 2, 0,
1915 "Open a network connection to PATH using LOGIN as the login string.")
1917 Lisp_Object path
, login
;
1921 CHECK_STRING (path
, 0);
1922 CHECK_STRING (login
, 0);
1924 netresult
= netunam (XSTRING (path
)->data
, XSTRING (login
)->data
);
1926 if (netresult
== -1)
1931 #endif /* HPUX_NET */
1933 DEFUN ("file-name-absolute-p", Ffile_name_absolute_p
, Sfile_name_absolute_p
,
1935 "Return t if file FILENAME specifies an absolute path name.\n\
1936 On Unix, this is a name starting with a `/' or a `~'.")
1938 Lisp_Object filename
;
1942 CHECK_STRING (filename
, 0);
1943 ptr
= XSTRING (filename
)->data
;
1944 if (*ptr
== '/' || *ptr
== '~'
1946 /* ??? This criterion is probably wrong for '<'. */
1947 || index (ptr
, ':') || index (ptr
, '<')
1948 || (*ptr
== '[' && (ptr
[1] != '-' || (ptr
[2] != '.' && ptr
[2] != ']'))
1957 DEFUN ("file-exists-p", Ffile_exists_p
, Sfile_exists_p
, 1, 1, 0,
1958 "Return t if file FILENAME exists. (This does not mean you can read it.)\n\
1959 See also `file-readable-p' and `file-attributes'.")
1961 Lisp_Object filename
;
1963 Lisp_Object abspath
;
1964 Lisp_Object handler
;
1966 CHECK_STRING (filename
, 0);
1967 abspath
= Fexpand_file_name (filename
, Qnil
);
1969 /* If the file name has special constructs in it,
1970 call the corresponding file handler. */
1971 handler
= Ffind_file_name_handler (abspath
);
1972 if (!NILP (handler
))
1973 return call2 (handler
, Qfile_exists_p
, abspath
);
1975 return (access (XSTRING (abspath
)->data
, 0) >= 0) ? Qt
: Qnil
;
1978 DEFUN ("file-executable-p", Ffile_executable_p
, Sfile_executable_p
, 1, 1, 0,
1979 "Return t if FILENAME can be executed by you.\n\
1980 For a directory, this means you can access files in that directory.")
1982 Lisp_Object filename
;
1985 Lisp_Object abspath
;
1986 Lisp_Object handler
;
1988 CHECK_STRING (filename
, 0);
1989 abspath
= Fexpand_file_name (filename
, Qnil
);
1991 /* If the file name has special constructs in it,
1992 call the corresponding file handler. */
1993 handler
= Ffind_file_name_handler (abspath
);
1994 if (!NILP (handler
))
1995 return call2 (handler
, Qfile_executable_p
, abspath
);
1997 return (access (XSTRING (abspath
)->data
, 1) >= 0) ? Qt
: Qnil
;
2000 DEFUN ("file-readable-p", Ffile_readable_p
, Sfile_readable_p
, 1, 1, 0,
2001 "Return t if file FILENAME exists and you can read it.\n\
2002 See also `file-exists-p' and `file-attributes'.")
2004 Lisp_Object filename
;
2006 Lisp_Object abspath
;
2007 Lisp_Object handler
;
2009 CHECK_STRING (filename
, 0);
2010 abspath
= Fexpand_file_name (filename
, Qnil
);
2012 /* If the file name has special constructs in it,
2013 call the corresponding file handler. */
2014 handler
= Ffind_file_name_handler (abspath
);
2015 if (!NILP (handler
))
2016 return call2 (handler
, Qfile_readable_p
, abspath
);
2018 return (access (XSTRING (abspath
)->data
, 4) >= 0) ? Qt
: Qnil
;
2021 DEFUN ("file-symlink-p", Ffile_symlink_p
, Sfile_symlink_p
, 1, 1, 0,
2022 "If file FILENAME is the name of a symbolic link\n\
2023 returns the name of the file to which it is linked.\n\
2024 Otherwise returns NIL.")
2026 Lisp_Object filename
;
2033 Lisp_Object handler
;
2035 CHECK_STRING (filename
, 0);
2036 filename
= Fexpand_file_name (filename
, Qnil
);
2038 /* If the file name has special constructs in it,
2039 call the corresponding file handler. */
2040 handler
= Ffind_file_name_handler (filename
);
2041 if (!NILP (handler
))
2042 return call2 (handler
, Qfile_symlink_p
, filename
);
2047 buf
= (char *) xmalloc (bufsize
);
2048 bzero (buf
, bufsize
);
2049 valsize
= readlink (XSTRING (filename
)->data
, buf
, bufsize
);
2050 if (valsize
< bufsize
) break;
2051 /* Buffer was not long enough */
2060 val
= make_string (buf
, valsize
);
2063 #else /* not S_IFLNK */
2065 #endif /* not S_IFLNK */
2068 /* Having this before file-symlink-p mysteriously caused it to be forgotten
2070 DEFUN ("file-writable-p", Ffile_writable_p
, Sfile_writable_p
, 1, 1, 0,
2071 "Return t if file FILENAME can be written or created by you.")
2073 Lisp_Object filename
;
2075 Lisp_Object abspath
, dir
;
2076 Lisp_Object handler
;
2078 CHECK_STRING (filename
, 0);
2079 abspath
= Fexpand_file_name (filename
, Qnil
);
2081 /* If the file name has special constructs in it,
2082 call the corresponding file handler. */
2083 handler
= Ffind_file_name_handler (abspath
);
2084 if (!NILP (handler
))
2085 return call2 (handler
, Qfile_writable_p
, abspath
);
2087 if (access (XSTRING (abspath
)->data
, 0) >= 0)
2088 return (access (XSTRING (abspath
)->data
, 2) >= 0) ? Qt
: Qnil
;
2089 dir
= Ffile_name_directory (abspath
);
2092 dir
= Fdirectory_file_name (dir
);
2094 return (access (!NILP (dir
) ? (char *) XSTRING (dir
)->data
: "", 2) >= 0
2098 DEFUN ("file-directory-p", Ffile_directory_p
, Sfile_directory_p
, 1, 1, 0,
2099 "Return t if file FILENAME is the name of a directory as a file.\n\
2100 A directory name spec may be given instead; then the value is t\n\
2101 if the directory so specified exists and really is a directory.")
2103 Lisp_Object filename
;
2105 register Lisp_Object abspath
;
2107 Lisp_Object handler
;
2109 abspath
= expand_and_dir_to_file (filename
, current_buffer
->directory
);
2111 /* If the file name has special constructs in it,
2112 call the corresponding file handler. */
2113 handler
= Ffind_file_name_handler (abspath
);
2114 if (!NILP (handler
))
2115 return call2 (handler
, Qfile_directory_p
, abspath
);
2117 if (stat (XSTRING (abspath
)->data
, &st
) < 0)
2119 return (st
.st_mode
& S_IFMT
) == S_IFDIR
? Qt
: Qnil
;
2122 DEFUN ("file-accessible-directory-p", Ffile_accessible_directory_p
, Sfile_accessible_directory_p
, 1, 1, 0,
2123 "Return t if file FILENAME is the name of a directory as a file,\n\
2124 and files in that directory can be opened by you. In order to use a\n\
2125 directory as a buffer's current directory, this predicate must return true.\n\
2126 A directory name spec may be given instead; then the value is t\n\
2127 if the directory so specified exists and really is a readable and\n\
2128 searchable directory.")
2130 Lisp_Object filename
;
2132 Lisp_Object handler
;
2134 /* If the file name has special constructs in it,
2135 call the corresponding file handler. */
2136 handler
= Ffind_file_name_handler (filename
);
2137 if (!NILP (handler
))
2138 return call2 (handler
, Qfile_accessible_directory_p
, filename
);
2140 if (NILP (Ffile_directory_p (filename
))
2141 || NILP (Ffile_executable_p (filename
)))
2147 DEFUN ("file-modes", Ffile_modes
, Sfile_modes
, 1, 1, 0,
2148 "Return mode bits of FILE, as an integer.")
2150 Lisp_Object filename
;
2152 Lisp_Object abspath
;
2154 Lisp_Object handler
;
2156 abspath
= expand_and_dir_to_file (filename
, current_buffer
->directory
);
2158 /* If the file name has special constructs in it,
2159 call the corresponding file handler. */
2160 handler
= Ffind_file_name_handler (abspath
);
2161 if (!NILP (handler
))
2162 return call2 (handler
, Qfile_modes
, abspath
);
2164 if (stat (XSTRING (abspath
)->data
, &st
) < 0)
2166 return make_number (st
.st_mode
& 07777);
2169 DEFUN ("set-file-modes", Fset_file_modes
, Sset_file_modes
, 2, 2, 0,
2170 "Set mode bits of FILE to MODE (an integer).\n\
2171 Only the 12 low bits of MODE are used.")
2173 Lisp_Object filename
, mode
;
2175 Lisp_Object abspath
;
2176 Lisp_Object handler
;
2178 abspath
= Fexpand_file_name (filename
, current_buffer
->directory
);
2179 CHECK_NUMBER (mode
, 1);
2181 /* If the file name has special constructs in it,
2182 call the corresponding file handler. */
2183 handler
= Ffind_file_name_handler (abspath
);
2184 if (!NILP (handler
))
2185 return call3 (handler
, Qset_file_modes
, abspath
, mode
);
2188 if (chmod (XSTRING (abspath
)->data
, XINT (mode
)) < 0)
2189 report_file_error ("Doing chmod", Fcons (abspath
, Qnil
));
2191 if (!egetenv ("USE_DOMAIN_ACLS"))
2194 struct timeval tvp
[2];
2196 /* chmod on apollo also change the file's modtime; need to save the
2197 modtime and then restore it. */
2198 if (stat (XSTRING (abspath
)->data
, &st
) < 0)
2200 report_file_error ("Doing chmod", Fcons (abspath
, Qnil
));
2204 if (chmod (XSTRING (abspath
)->data
, XINT (mode
)) < 0)
2205 report_file_error ("Doing chmod", Fcons (abspath
, Qnil
));
2207 /* reset the old accessed and modified times. */
2208 tvp
[0].tv_sec
= st
.st_atime
+ 1; /* +1 due to an Apollo roundoff bug */
2210 tvp
[1].tv_sec
= st
.st_mtime
+ 1; /* +1 due to an Apollo roundoff bug */
2213 if (utimes (XSTRING (abspath
)->data
, tvp
) < 0)
2214 report_file_error ("Doing utimes", Fcons (abspath
, Qnil
));
2221 DEFUN ("set-default-file-modes", Fset_default_file_modes
, Sset_default_file_modes
, 1, 1, 0,
2222 "Set the file permission bits for newly created files.\n\
2223 The argument MODE should be an integer; only the low 9 bits are used.\n\
2224 This setting is inherited by subprocesses.")
2228 CHECK_NUMBER (mode
, 0);
2230 umask ((~ XINT (mode
)) & 0777);
2235 DEFUN ("default-file-modes", Fdefault_file_modes
, Sdefault_file_modes
, 0, 0, 0,
2236 "Return the default file protection for created files.\n\
2237 The value is an integer.")
2243 realmask
= umask (0);
2246 XSET (value
, Lisp_Int
, (~ realmask
) & 0777);
2252 DEFUN ("unix-sync", Funix_sync
, Sunix_sync
, 0, 0, "",
2253 "Tell Unix to finish all pending disk updates.")
2262 DEFUN ("file-newer-than-file-p", Ffile_newer_than_file_p
, Sfile_newer_than_file_p
, 2, 2, 0,
2263 "Return t if file FILE1 is newer than file FILE2.\n\
2264 If FILE1 does not exist, the answer is nil;\n\
2265 otherwise, if FILE2 does not exist, the answer is t.")
2267 Lisp_Object file1
, file2
;
2269 Lisp_Object abspath1
, abspath2
;
2272 Lisp_Object handler
;
2273 struct gcpro gcpro1
, gcpro2
;
2275 CHECK_STRING (file1
, 0);
2276 CHECK_STRING (file2
, 0);
2279 GCPRO2 (abspath1
, file2
);
2280 abspath1
= expand_and_dir_to_file (file1
, current_buffer
->directory
);
2281 abspath2
= expand_and_dir_to_file (file2
, current_buffer
->directory
);
2284 /* If the file name has special constructs in it,
2285 call the corresponding file handler. */
2286 handler
= Ffind_file_name_handler (abspath1
);
2287 if (!NILP (handler
))
2288 return call3 (handler
, Qfile_newer_than_file_p
, abspath1
, abspath2
);
2290 if (stat (XSTRING (abspath1
)->data
, &st
) < 0)
2293 mtime1
= st
.st_mtime
;
2295 if (stat (XSTRING (abspath2
)->data
, &st
) < 0)
2298 return (mtime1
> st
.st_mtime
) ? Qt
: Qnil
;
2301 DEFUN ("insert-file-contents", Finsert_file_contents
, Sinsert_file_contents
,
2303 "Insert contents of file FILENAME after point.\n\
2304 Returns list of absolute pathname and length of data inserted.\n\
2305 If second argument VISIT is non-nil, the buffer's visited filename\n\
2306 and last save file modtime are set, and it is marked unmodified.\n\
2307 If visiting and the file does not exist, visiting is completed\n\
2308 before the error is signaled.")
2310 Lisp_Object filename
, visit
;
2314 register int inserted
= 0;
2315 register int how_much
;
2316 int count
= specpdl_ptr
- specpdl
;
2317 struct gcpro gcpro1
;
2318 Lisp_Object handler
, val
;
2323 if (!NILP (current_buffer
->read_only
))
2324 Fbarf_if_buffer_read_only();
2326 CHECK_STRING (filename
, 0);
2327 filename
= Fexpand_file_name (filename
, Qnil
);
2329 /* If the file name has special constructs in it,
2330 call the corresponding file handler. */
2331 handler
= Ffind_file_name_handler (filename
);
2332 if (!NILP (handler
))
2334 val
= call3 (handler
, Qinsert_file_contents
, filename
, visit
);
2342 if (stat (XSTRING (filename
)->data
, &st
) < 0
2343 || (fd
= open (XSTRING (filename
)->data
, 0)) < 0)
2345 if ((fd
= open (XSTRING (filename
)->data
, 0)) < 0
2346 || fstat (fd
, &st
) < 0)
2347 #endif /* not APOLLO */
2349 if (fd
>= 0) close (fd
);
2351 report_file_error ("Opening input file", Fcons (filename
, Qnil
));
2357 record_unwind_protect (close_file_unwind
, make_number (fd
));
2360 /* This code will need to be changed in order to work on named
2361 pipes, and it's probably just not worth it. So we should at
2362 least signal an error. */
2363 if ((st
.st_mode
& S_IFMT
) == S_IFSOCK
)
2364 Fsignal (Qfile_error
,
2365 Fcons (build_string ("reading from named pipe"),
2366 Fcons (filename
, Qnil
)));
2369 /* Supposedly happens on VMS. */
2371 error ("File size is negative");
2374 register Lisp_Object temp
;
2376 /* Make sure point-max won't overflow after this insertion. */
2377 XSET (temp
, Lisp_Int
, st
.st_size
+ Z
);
2378 if (st
.st_size
+ Z
!= XINT (temp
))
2379 error ("maximum buffer size exceeded");
2383 prepare_to_modify_buffer (point
, point
);
2386 if (GAP_SIZE
< st
.st_size
)
2387 make_gap (st
.st_size
- GAP_SIZE
);
2391 int try = min (st
.st_size
- inserted
, 64 << 10);
2394 /* Allow quitting out of the actual I/O. */
2397 this = read (fd
, &FETCH_CHAR (point
+ inserted
- 1) + 1, try);
2415 record_insert (point
, inserted
);
2417 /* Only defined if Emacs is compiled with USE_TEXT_PROPERTIES */
2418 offset_intervals (current_buffer
, point
, inserted
);
2424 /* Discard the unwind protect */
2425 specpdl_ptr
= specpdl
+ count
;
2428 error ("IO error reading %s: %s",
2429 XSTRING (filename
)->data
, err_str (errno
));
2436 current_buffer
->undo_list
= Qnil
;
2438 stat (XSTRING (filename
)->data
, &st
);
2440 current_buffer
->modtime
= st
.st_mtime
;
2441 current_buffer
->save_modified
= MODIFF
;
2442 current_buffer
->auto_save_modified
= MODIFF
;
2443 XFASTINT (current_buffer
->save_length
) = Z
- BEG
;
2444 #ifdef CLASH_DETECTION
2447 if (!NILP (current_buffer
->filename
))
2448 unlock_file (current_buffer
->filename
);
2449 unlock_file (filename
);
2451 #endif /* CLASH_DETECTION */
2452 current_buffer
->filename
= filename
;
2453 /* If visiting nonexistent file, return nil. */
2454 if (current_buffer
->modtime
== -1)
2455 report_file_error ("Opening input file", Fcons (filename
, Qnil
));
2458 signal_after_change (point
, 0, inserted
);
2461 RETURN_UNGCPRO (val
);
2462 RETURN_UNGCPRO (Fcons (filename
,
2463 Fcons (make_number (inserted
),
2467 DEFUN ("write-region", Fwrite_region
, Swrite_region
, 3, 5,
2468 "r\nFWrite region to file: ",
2469 "Write current region into specified file.\n\
2470 When called from a program, takes three arguments:\n\
2471 START, END and FILENAME. START and END are buffer positions.\n\
2472 Optional fourth argument APPEND if non-nil means\n\
2473 append to existing file contents (if any).\n\
2474 Optional fifth argument VISIT if t means\n\
2475 set the last-save-file-modtime of buffer to this file's modtime\n\
2476 and mark buffer not modified.\n\
2477 If VISIT is a string, it is a second file name;\n\
2478 the output goes to FILENAME, but the buffer is marked as visiting VISIT.\n\
2479 VISIT is also the file name to lock and unlock for clash detection.\n\
2480 If VISIT is neither t nor nil nor a string,\n\
2481 that means do not print the \"Wrote file\" message.\n\
2482 Kludgy feature: if START is a string, then that string is written\n\
2483 to the file, instead of any buffer contents, and END is ignored.")
2484 (start
, end
, filename
, append
, visit
)
2485 Lisp_Object start
, end
, filename
, append
, visit
;
2493 int count
= specpdl_ptr
- specpdl
;
2495 unsigned char *fname
= 0; /* If non-0, original filename (must rename) */
2497 Lisp_Object handler
;
2498 Lisp_Object visit_file
;
2499 struct gcpro gcpro1
, gcpro2
, gcpro3
, gcpro4
;
2501 /* Special kludge to simplify auto-saving */
2504 XFASTINT (start
) = BEG
;
2507 else if (XTYPE (start
) != Lisp_String
)
2508 validate_region (&start
, &end
);
2510 filename
= Fexpand_file_name (filename
, Qnil
);
2511 if (XTYPE (visit
) == Lisp_String
)
2512 visit_file
= Fexpand_file_name (visit
, Qnil
);
2514 visit_file
= filename
;
2516 GCPRO4 (start
, filename
, visit
, visit_file
);
2518 /* If the file name has special constructs in it,
2519 call the corresponding file handler. */
2520 handler
= Ffind_file_name_handler (filename
);
2522 if (!NILP (handler
))
2524 Lisp_Object args
[7];
2527 args
[1] = Qwrite_region
;
2533 val
= Ffuncall (7, args
);
2535 /* Do this before reporting IO error
2536 to avoid a "file has changed on disk" warning on
2537 next attempt to save. */
2538 if (EQ (visit
, Qt
) || XTYPE (visit
) == Lisp_String
)
2540 current_buffer
->modtime
= 0;
2541 current_buffer
->save_modified
= MODIFF
;
2542 XFASTINT (current_buffer
->save_length
) = Z
- BEG
;
2543 current_buffer
->filename
= visit_file
;
2549 #ifdef CLASH_DETECTION
2551 lock_file (visit_file
);
2552 #endif /* CLASH_DETECTION */
2554 fn
= XSTRING (filename
)->data
;
2557 desc
= open (fn
, O_WRONLY
);
2561 if (auto_saving
) /* Overwrite any previous version of autosave file */
2563 vms_truncate (fn
); /* if fn exists, truncate to zero length */
2564 desc
= open (fn
, O_RDWR
);
2566 desc
= creat_copy_attrs (XTYPE (current_buffer
->filename
) == Lisp_String
2567 ? XSTRING (current_buffer
->filename
)->data
: 0,
2570 else /* Write to temporary name and rename if no errors */
2572 Lisp_Object temp_name
;
2573 temp_name
= Ffile_name_directory (filename
);
2575 if (!NILP (temp_name
))
2577 temp_name
= Fmake_temp_name (concat2 (temp_name
,
2578 build_string ("$$SAVE$$")));
2579 fname
= XSTRING (filename
)->data
;
2580 fn
= XSTRING (temp_name
)->data
;
2581 desc
= creat_copy_attrs (fname
, fn
);
2584 /* If we can't open the temporary file, try creating a new
2585 version of the original file. VMS "creat" creates a
2586 new version rather than truncating an existing file. */
2589 desc
= creat (fn
, 0666);
2590 #if 0 /* This can clobber an existing file and fail to replace it,
2591 if the user runs out of space. */
2594 /* We can't make a new version;
2595 try to truncate and rewrite existing version if any. */
2597 desc
= open (fn
, O_RDWR
);
2603 desc
= creat (fn
, 0666);
2606 desc
= creat (fn
, auto_saving
? auto_save_mode_bits
: 0666);
2607 #endif /* not VMS */
2613 #ifdef CLASH_DETECTION
2615 if (!auto_saving
) unlock_file (visit_file
);
2617 #endif /* CLASH_DETECTION */
2618 report_file_error ("Opening output file", Fcons (filename
, Qnil
));
2621 record_unwind_protect (close_file_unwind
, make_number (desc
));
2624 if (lseek (desc
, 0, 2) < 0)
2626 #ifdef CLASH_DETECTION
2627 if (!auto_saving
) unlock_file (visit_file
);
2628 #endif /* CLASH_DETECTION */
2629 report_file_error ("Lseek error", Fcons (filename
, Qnil
));
2634 * Kludge Warning: The VMS C RTL likes to insert carriage returns
2635 * if we do writes that don't end with a carriage return. Furthermore
2636 * it cannot handle writes of more then 16K. The modified
2637 * version of "sys_write" in SYSDEP.C (see comment there) copes with
2638 * this EXCEPT for the last record (iff it doesn't end with a carriage
2639 * return). This implies that if your buffer doesn't end with a carriage
2640 * return, you get one free... tough. However it also means that if
2641 * we make two calls to sys_write (a la the following code) you can
2642 * get one at the gap as well. The easiest way to fix this (honest)
2643 * is to move the gap to the next newline (or the end of the buffer).
2648 if (GPT
> BEG
&& GPT_ADDR
[-1] != '\n')
2649 move_gap (find_next_newline (GPT
, 1));
2655 if (XTYPE (start
) == Lisp_String
)
2657 failure
= 0 > e_write (desc
, XSTRING (start
)->data
,
2658 XSTRING (start
)->size
);
2661 else if (XINT (start
) != XINT (end
))
2663 if (XINT (start
) < GPT
)
2665 register int end1
= XINT (end
);
2667 failure
= 0 > e_write (desc
, &FETCH_CHAR (tem
),
2668 min (GPT
, end1
) - tem
);
2672 if (XINT (end
) > GPT
&& !failure
)
2675 tem
= max (tem
, GPT
);
2676 failure
= 0 > e_write (desc
, &FETCH_CHAR (tem
), XINT (end
) - tem
);
2684 /* Note fsync appears to change the modtime on BSD4.2 (both vax and sun).
2685 Disk full in NFS may be reported here. */
2686 if (fsync (desc
) < 0)
2687 failure
= 1, save_errno
= errno
;
2690 /* Spurious "file has changed on disk" warnings have been
2691 observed on Suns as well.
2692 It seems that `close' can change the modtime, under nfs.
2694 (This has supposedly been fixed in Sunos 4,
2695 but who knows about all the other machines with NFS?) */
2698 /* On VMS and APOLLO, must do the stat after the close
2699 since closing changes the modtime. */
2702 /* Recall that #if defined does not work on VMS. */
2709 /* NFS can report a write failure now. */
2710 if (close (desc
) < 0)
2711 failure
= 1, save_errno
= errno
;
2714 /* If we wrote to a temporary name and had no errors, rename to real name. */
2718 failure
= (rename (fn
, fname
) != 0), save_errno
= errno
;
2726 /* Discard the unwind protect */
2727 specpdl_ptr
= specpdl
+ count
;
2729 #ifdef CLASH_DETECTION
2731 unlock_file (visit_file
);
2732 #endif /* CLASH_DETECTION */
2734 /* Do this before reporting IO error
2735 to avoid a "file has changed on disk" warning on
2736 next attempt to save. */
2737 if (EQ (visit
, Qt
) || XTYPE (visit
) == Lisp_String
)
2738 current_buffer
->modtime
= st
.st_mtime
;
2741 error ("IO error writing %s: %s", fn
, err_str (save_errno
));
2743 if (EQ (visit
, Qt
) || XTYPE (visit
) == Lisp_String
)
2745 current_buffer
->save_modified
= MODIFF
;
2746 XFASTINT (current_buffer
->save_length
) = Z
- BEG
;
2747 current_buffer
->filename
= visit_file
;
2749 else if (!NILP (visit
))
2753 message ("Wrote %s", XSTRING (visit_file
)->data
);
2759 e_write (desc
, addr
, len
)
2761 register char *addr
;
2764 char buf
[16 * 1024];
2765 register char *p
, *end
;
2767 if (!EQ (current_buffer
->selective_display
, Qt
))
2768 return write (desc
, addr
, len
) - len
;
2772 end
= p
+ sizeof buf
;
2777 if (write (desc
, buf
, sizeof buf
) != sizeof buf
)
2786 if (write (desc
, buf
, p
- buf
) != p
- buf
)
2792 DEFUN ("verify-visited-file-modtime", Fverify_visited_file_modtime
,
2793 Sverify_visited_file_modtime
, 1, 1, 0,
2794 "Return t if last mod time of BUF's visited file matches what BUF records.\n\
2795 This means that the file has not been changed since it was visited or saved.")
2801 Lisp_Object handler
;
2803 CHECK_BUFFER (buf
, 0);
2806 if (XTYPE (b
->filename
) != Lisp_String
) return Qt
;
2807 if (b
->modtime
== 0) return Qt
;
2809 /* If the file name has special constructs in it,
2810 call the corresponding file handler. */
2811 handler
= Ffind_file_name_handler (b
->filename
);
2812 if (!NILP (handler
))
2813 return call2 (handler
, Qverify_visited_file_modtime
, buf
);
2815 if (stat (XSTRING (b
->filename
)->data
, &st
) < 0)
2817 /* If the file doesn't exist now and didn't exist before,
2818 we say that it isn't modified, provided the error is a tame one. */
2819 if (errno
== ENOENT
|| errno
== EACCES
|| errno
== ENOTDIR
)
2824 if (st
.st_mtime
== b
->modtime
2825 /* If both are positive, accept them if they are off by one second. */
2826 || (st
.st_mtime
> 0 && b
->modtime
> 0
2827 && (st
.st_mtime
== b
->modtime
+ 1
2828 || st
.st_mtime
== b
->modtime
- 1)))
2833 DEFUN ("clear-visited-file-modtime", Fclear_visited_file_modtime
,
2834 Sclear_visited_file_modtime
, 0, 0, 0,
2835 "Clear out records of last mod time of visited file.\n\
2836 Next attempt to save will certainly not complain of a discrepancy.")
2839 current_buffer
->modtime
= 0;
2843 DEFUN ("visited-file-modtime", Fvisited_file_modtime
,
2844 Svisited_file_modtime
, 0, 0, 0,
2845 "Return the current buffer's recorded visited file modification time.\n\
2846 The value is a list of the form (HIGH . LOW), like the time values\n\
2847 that `file-attributes' returns.")
2850 return long_to_cons (current_buffer
->modtime
);
2853 DEFUN ("set-visited-file-modtime", Fset_visited_file_modtime
,
2854 Sset_visited_file_modtime
, 0, 1, 0,
2855 "Update buffer's recorded modification time from the visited file's time.\n\
2856 Useful if the buffer was not read from the file normally\n\
2857 or if the file itself has been changed for some known benign reason.\n\
2858 An argument specifies the modification time value to use\n\
2859 \(instead of that of the visited file), in the form of a list\n\
2860 \(HIGH . LOW) or (HIGH LOW).")
2862 Lisp_Object time_list
;
2864 if (!NILP (time_list
))
2865 current_buffer
->modtime
= cons_to_long (time_list
);
2868 register Lisp_Object filename
;
2870 Lisp_Object handler
;
2872 filename
= Fexpand_file_name (current_buffer
->filename
, Qnil
);
2874 /* If the file name has special constructs in it,
2875 call the corresponding file handler. */
2876 handler
= Ffind_file_name_handler (filename
);
2877 if (!NILP (handler
))
2878 return call3 (handler
, Qfile_name_directory
, filename
, Qnil
);
2879 else if (stat (XSTRING (filename
)->data
, &st
) >= 0)
2880 current_buffer
->modtime
= st
.st_mtime
;
2889 unsigned char *name
= XSTRING (current_buffer
->name
)->data
;
2892 message ("Autosaving...error for %s", name
);
2893 Fsleep_for (make_number (1), Qnil
);
2894 message ("Autosaving...error!for %s", name
);
2895 Fsleep_for (make_number (1), Qnil
);
2896 message ("Autosaving...error for %s", name
);
2897 Fsleep_for (make_number (1), Qnil
);
2907 /* Get visited file's mode to become the auto save file's mode. */
2908 if (stat (XSTRING (current_buffer
->filename
)->data
, &st
) >= 0)
2909 /* But make sure we can overwrite it later! */
2910 auto_save_mode_bits
= st
.st_mode
| 0600;
2912 auto_save_mode_bits
= 0666;
2915 Fwrite_region (Qnil
, Qnil
,
2916 current_buffer
->auto_save_file_name
,
2920 DEFUN ("do-auto-save", Fdo_auto_save
, Sdo_auto_save
, 0, 2, "",
2921 "Auto-save all buffers that need it.\n\
2922 This is all buffers that have auto-saving enabled\n\
2923 and are changed since last auto-saved.\n\
2924 Auto-saving writes the buffer into a file\n\
2925 so that your editing is not lost if the system crashes.\n\
2926 This file is not the file you visited; that changes only when you save.\n\n\
2927 Non-nil first argument means do not print any message if successful.\n\
2928 Non-nil second argument means save only current buffer.")
2929 (no_message
, current_only
)
2930 Lisp_Object no_message
, current_only
;
2932 struct buffer
*old
= current_buffer
, *b
;
2933 Lisp_Object tail
, buf
;
2935 char *omessage
= echo_area_glyphs
;
2936 extern int minibuf_level
;
2937 int do_handled_files
;
2939 /* No GCPRO needed, because (when it matters) all Lisp_Object variables
2940 point to non-strings reached from Vbuffer_alist. */
2946 /* Vrun_hooks is nil before emacs is dumped, and inc-vers.el will
2947 eventually call do-auto-save, so don't err here in that case. */
2948 if (!NILP (Vrun_hooks
))
2949 call1 (Vrun_hooks
, intern ("auto-save-hook"));
2951 /* First, save all files which don't have handlers. If Emacs is
2952 crashing, the handlers may tweak what is causing Emacs to crash
2953 in the first place, and it would be a shame if Emacs failed to
2954 autosave perfectly ordinary files because it couldn't handle some
2956 for (do_handled_files
= 0; do_handled_files
< 2; do_handled_files
++)
2957 for (tail
= Vbuffer_alist
; XGCTYPE (tail
) == Lisp_Cons
;
2958 tail
= XCONS (tail
)->cdr
)
2960 buf
= XCONS (XCONS (tail
)->car
)->cdr
;
2963 if (!NILP (current_only
)
2964 && b
!= current_buffer
)
2967 /* Check for auto save enabled
2968 and file changed since last auto save
2969 and file changed since last real save. */
2970 if (XTYPE (b
->auto_save_file_name
) == Lisp_String
2971 && b
->save_modified
< BUF_MODIFF (b
)
2972 && b
->auto_save_modified
< BUF_MODIFF (b
)
2973 && (do_handled_files
2974 || NILP (Ffind_file_name_handler (b
->auto_save_file_name
))))
2976 if ((XFASTINT (b
->save_length
) * 10
2977 > (BUF_Z (b
) - BUF_BEG (b
)) * 13)
2978 /* A short file is likely to change a large fraction;
2979 spare the user annoying messages. */
2980 && XFASTINT (b
->save_length
) > 5000
2981 /* These messages are frequent and annoying for `*mail*'. */
2982 && !EQ (b
->filename
, Qnil
)
2983 && NILP (no_message
))
2985 /* It has shrunk too much; turn off auto-saving here. */
2986 message ("Buffer %s has shrunk a lot; auto save turned off there",
2987 XSTRING (b
->name
)->data
);
2988 /* User can reenable saving with M-x auto-save. */
2989 b
->auto_save_file_name
= Qnil
;
2990 /* Prevent warning from repeating if user does so. */
2991 XFASTINT (b
->save_length
) = 0;
2992 Fsleep_for (make_number (1), Qnil
);
2995 set_buffer_internal (b
);
2996 if (!auto_saved
&& NILP (no_message
))
2997 message1 ("Auto-saving...");
2998 internal_condition_case (auto_save_1
, Qt
, auto_save_error
);
3000 b
->auto_save_modified
= BUF_MODIFF (b
);
3001 XFASTINT (current_buffer
->save_length
) = Z
- BEG
;
3002 set_buffer_internal (old
);
3006 /* Prevent another auto save till enough input events come in. */
3007 record_auto_save ();
3009 if (auto_saved
&& NILP (no_message
))
3010 message1 (omessage
? omessage
: "Auto-saving...done");
3016 DEFUN ("set-buffer-auto-saved", Fset_buffer_auto_saved
,
3017 Sset_buffer_auto_saved
, 0, 0, 0,
3018 "Mark current buffer as auto-saved with its current text.\n\
3019 No auto-save file will be written until the buffer changes again.")
3022 current_buffer
->auto_save_modified
= MODIFF
;
3023 XFASTINT (current_buffer
->save_length
) = Z
- BEG
;
3027 DEFUN ("recent-auto-save-p", Frecent_auto_save_p
, Srecent_auto_save_p
,
3029 "Return t if buffer has been auto-saved since last read in or saved.")
3032 return (current_buffer
->save_modified
< current_buffer
->auto_save_modified
) ? Qt
: Qnil
;
3035 /* Reading and completing file names */
3036 extern Lisp_Object
Ffile_name_completion (), Ffile_name_all_completions ();
3038 DEFUN ("read-file-name-internal", Fread_file_name_internal
, Sread_file_name_internal
,
3040 "Internal subroutine for read-file-name. Do not call this.")
3041 (string
, dir
, action
)
3042 Lisp_Object string
, dir
, action
;
3043 /* action is nil for complete, t for return list of completions,
3044 lambda for verify final value */
3046 Lisp_Object name
, specdir
, realdir
, val
, orig_string
;
3048 struct gcpro gcpro1
, gcpro2
, gcpro3
, gcpro4
;
3055 /* No need to protect ACTION--we only compare it with t and nil. */
3056 GCPRO4 (string
, realdir
, name
, specdir
);
3058 if (XSTRING (string
)->size
== 0)
3060 if (EQ (action
, Qlambda
))
3068 orig_string
= string
;
3069 string
= Fsubstitute_in_file_name (string
);
3070 changed
= NILP (Fstring_equal (string
, orig_string
));
3071 name
= Ffile_name_nondirectory (string
);
3072 val
= Ffile_name_directory (string
);
3074 realdir
= Fexpand_file_name (val
, realdir
);
3079 specdir
= Ffile_name_directory (string
);
3080 val
= Ffile_name_completion (name
, realdir
);
3082 if (XTYPE (val
) != Lisp_String
)
3089 if (!NILP (specdir
))
3090 val
= concat2 (specdir
, val
);
3093 register unsigned char *old
, *new;
3097 osize
= XSTRING (val
)->size
;
3098 /* Quote "$" as "$$" to get it past substitute-in-file-name */
3099 for (n
= osize
, count
= 0, old
= XSTRING (val
)->data
; n
> 0; n
--)
3100 if (*old
++ == '$') count
++;
3103 old
= XSTRING (val
)->data
;
3104 val
= Fmake_string (make_number (osize
+ count
), make_number (0));
3105 new = XSTRING (val
)->data
;
3106 for (n
= osize
; n
> 0; n
--)
3117 #endif /* Not VMS */
3122 if (EQ (action
, Qt
))
3123 return Ffile_name_all_completions (name
, realdir
);
3124 /* Only other case actually used is ACTION = lambda */
3126 /* Supposedly this helps commands such as `cd' that read directory names,
3127 but can someone explain how it helps them? -- RMS */
3128 if (XSTRING (name
)->size
== 0)
3131 return Ffile_exists_p (string
);
3134 DEFUN ("read-file-name", Fread_file_name
, Sread_file_name
, 1, 5, 0,
3135 "Read file name, prompting with PROMPT and completing in directory DIR.\n\
3136 Value is not expanded---you must call `expand-file-name' yourself.\n\
3137 Default name to DEFAULT if user enters a null string.\n\
3138 (If DEFAULT is omitted, the visited file name is used.)\n\
3139 Fourth arg MUSTMATCH non-nil means require existing file's name.\n\
3140 Non-nil and non-t means also require confirmation after completion.\n\
3141 Fifth arg INITIAL specifies text to start with.\n\
3142 DIR defaults to current buffer's directory default.")
3143 (prompt
, dir
, defalt
, mustmatch
, initial
)
3144 Lisp_Object prompt
, dir
, defalt
, mustmatch
, initial
;
3146 Lisp_Object val
, insdef
, insdef1
, tem
;
3147 struct gcpro gcpro1
, gcpro2
;
3148 register char *homedir
;
3152 dir
= current_buffer
->directory
;
3154 defalt
= current_buffer
->filename
;
3156 /* If dir starts with user's homedir, change that to ~. */
3157 homedir
= (char *) egetenv ("HOME");
3159 && XTYPE (dir
) == Lisp_String
3160 && !strncmp (homedir
, XSTRING (dir
)->data
, strlen (homedir
))
3161 && XSTRING (dir
)->data
[strlen (homedir
)] == '/')
3163 dir
= make_string (XSTRING (dir
)->data
+ strlen (homedir
) - 1,
3164 XSTRING (dir
)->size
- strlen (homedir
) + 1);
3165 XSTRING (dir
)->data
[0] = '~';
3168 if (insert_default_directory
)
3172 if (!NILP (initial
))
3174 Lisp_Object args
[2], pos
;
3178 insdef
= Fconcat (2, args
);
3179 pos
= make_number (XSTRING (dir
)->size
);
3180 insdef1
= Fcons (insdef
, pos
);
3184 insdef
= Qnil
, insdef1
= Qnil
;
3187 count
= specpdl_ptr
- specpdl
;
3188 specbind (intern ("completion-ignore-case"), Qt
);
3191 GCPRO2 (insdef
, defalt
);
3192 val
= Fcompleting_read (prompt
, intern ("read-file-name-internal"),
3193 dir
, mustmatch
, insdef1
,
3194 Qfile_name_history
);
3197 unbind_to (count
, Qnil
);
3202 error ("No file name specified");
3203 tem
= Fstring_equal (val
, insdef
);
3204 if (!NILP (tem
) && !NILP (defalt
))
3206 return Fsubstitute_in_file_name (val
);
3209 #if 0 /* Old version */
3210 DEFUN ("read-file-name", Fread_file_name
, Sread_file_name
, 1, 5, 0,
3211 "Read file name, prompting with PROMPT and completing in directory DIR.\n\
3212 Value is not expanded---you must call `expand-file-name' yourself.\n\
3213 Default name to DEFAULT if user enters a null string.\n\
3214 (If DEFAULT is omitted, the visited file name is used.)\n\
3215 Fourth arg MUSTMATCH non-nil means require existing file's name.\n\
3216 Non-nil and non-t means also require confirmation after completion.\n\
3217 Fifth arg INITIAL specifies text to start with.\n\
3218 DIR defaults to current buffer's directory default.")
3219 (prompt
, dir
, defalt
, mustmatch
, initial
)
3220 Lisp_Object prompt
, dir
, defalt
, mustmatch
, initial
;
3222 Lisp_Object val
, insdef
, tem
;
3223 struct gcpro gcpro1
, gcpro2
;
3224 register char *homedir
;
3228 dir
= current_buffer
->directory
;
3230 defalt
= current_buffer
->filename
;
3232 /* If dir starts with user's homedir, change that to ~. */
3233 homedir
= (char *) egetenv ("HOME");
3235 && XTYPE (dir
) == Lisp_String
3236 && !strncmp (homedir
, XSTRING (dir
)->data
, strlen (homedir
))
3237 && XSTRING (dir
)->data
[strlen (homedir
)] == '/')
3239 dir
= make_string (XSTRING (dir
)->data
+ strlen (homedir
) - 1,
3240 XSTRING (dir
)->size
- strlen (homedir
) + 1);
3241 XSTRING (dir
)->data
[0] = '~';
3244 if (!NILP (initial
))
3246 else if (insert_default_directory
)
3249 insdef
= build_string ("");
3252 count
= specpdl_ptr
- specpdl
;
3253 specbind (intern ("completion-ignore-case"), Qt
);
3256 GCPRO2 (insdef
, defalt
);
3257 val
= Fcompleting_read (prompt
, intern ("read-file-name-internal"),
3259 insert_default_directory
? insdef
: Qnil
,
3260 Qfile_name_history
);
3263 unbind_to (count
, Qnil
);
3268 error ("No file name specified");
3269 tem
= Fstring_equal (val
, insdef
);
3270 if (!NILP (tem
) && !NILP (defalt
))
3272 return Fsubstitute_in_file_name (val
);
3274 #endif /* Old version */
3278 Qexpand_file_name
= intern ("expand-file-name");
3279 Qdirectory_file_name
= intern ("directory-file-name");
3280 Qfile_name_directory
= intern ("file-name-directory");
3281 Qfile_name_nondirectory
= intern ("file-name-nondirectory");
3282 Qunhandled_file_name_directory
= intern ("unhandled-file-name-directory");
3283 Qfile_name_as_directory
= intern ("file-name-as-directory");
3284 Qcopy_file
= intern ("copy-file");
3285 Qmake_directory
= intern ("make-directory");
3286 Qdelete_directory
= intern ("delete-directory");
3287 Qdelete_file
= intern ("delete-file");
3288 Qrename_file
= intern ("rename-file");
3289 Qadd_name_to_file
= intern ("add-name-to-file");
3290 Qmake_symbolic_link
= intern ("make-symbolic-link");
3291 Qfile_exists_p
= intern ("file-exists-p");
3292 Qfile_executable_p
= intern ("file-executable-p");
3293 Qfile_readable_p
= intern ("file-readable-p");
3294 Qfile_symlink_p
= intern ("file-symlink-p");
3295 Qfile_writable_p
= intern ("file-writable-p");
3296 Qfile_directory_p
= intern ("file-directory-p");
3297 Qfile_accessible_directory_p
= intern ("file-accessible-directory-p");
3298 Qfile_modes
= intern ("file-modes");
3299 Qset_file_modes
= intern ("set-file-modes");
3300 Qfile_newer_than_file_p
= intern ("file-newer-than-file-p");
3301 Qinsert_file_contents
= intern ("insert-file-contents");
3302 Qwrite_region
= intern ("write-region");
3303 Qverify_visited_file_modtime
= intern ("verify-visited-file-modtime");
3305 staticpro (&Qexpand_file_name
);
3306 staticpro (&Qdirectory_file_name
);
3307 staticpro (&Qfile_name_directory
);
3308 staticpro (&Qfile_name_nondirectory
);
3309 staticpro (&Qunhandled_file_name_directory
);
3310 staticpro (&Qfile_name_as_directory
);
3311 staticpro (&Qcopy_file
);
3312 staticpro (&Qmake_directory
);
3313 staticpro (&Qdelete_directory
);
3314 staticpro (&Qdelete_file
);
3315 staticpro (&Qrename_file
);
3316 staticpro (&Qadd_name_to_file
);
3317 staticpro (&Qmake_symbolic_link
);
3318 staticpro (&Qfile_exists_p
);
3319 staticpro (&Qfile_executable_p
);
3320 staticpro (&Qfile_readable_p
);
3321 staticpro (&Qfile_symlink_p
);
3322 staticpro (&Qfile_writable_p
);
3323 staticpro (&Qfile_directory_p
);
3324 staticpro (&Qfile_accessible_directory_p
);
3325 staticpro (&Qfile_modes
);
3326 staticpro (&Qset_file_modes
);
3327 staticpro (&Qfile_newer_than_file_p
);
3328 staticpro (&Qinsert_file_contents
);
3329 staticpro (&Qwrite_region
);
3330 staticpro (&Qverify_visited_file_modtime
);
3332 Qfile_name_history
= intern ("file-name-history");
3333 Fset (Qfile_name_history
, Qnil
);
3334 staticpro (&Qfile_name_history
);
3336 Qfile_error
= intern ("file-error");
3337 staticpro (&Qfile_error
);
3338 Qfile_already_exists
= intern("file-already-exists");
3339 staticpro (&Qfile_already_exists
);
3341 Fput (Qfile_error
, Qerror_conditions
,
3342 Fcons (Qfile_error
, Fcons (Qerror
, Qnil
)));
3343 Fput (Qfile_error
, Qerror_message
,
3344 build_string ("File error"));
3346 Fput (Qfile_already_exists
, Qerror_conditions
,
3347 Fcons (Qfile_already_exists
,
3348 Fcons (Qfile_error
, Fcons (Qerror
, Qnil
))));
3349 Fput (Qfile_already_exists
, Qerror_message
,
3350 build_string ("File already exists"));
3352 DEFVAR_BOOL ("insert-default-directory", &insert_default_directory
,
3353 "*Non-nil means when reading a filename start with default dir in minibuffer.");
3354 insert_default_directory
= 1;
3356 DEFVAR_BOOL ("vms-stmlf-recfm", &vms_stmlf_recfm
,
3357 "*Non-nil means write new files with record format `stmlf'.\n\
3358 nil means use format `var'. This variable is meaningful only on VMS.");
3359 vms_stmlf_recfm
= 0;
3361 DEFVAR_LISP ("file-name-handler-alist", &Vfile_name_handler_alist
,
3362 "*Alist of elements (REGEXP . HANDLER) for file names handled specially.\n\
3363 If a file name matches REGEXP, then all I/O on that file is done by calling\n\
3366 The first argument given to HANDLER is the name of the I/O primitive\n\
3367 to be handled; the remaining arguments are the arguments that were\n\
3368 passed to that primitive. For example, if you do\n\
3369 (file-exists-p FILENAME)\n\
3370 and FILENAME is handled by HANDLER, then HANDLER is called like this:\n\
3371 (funcall HANDLER 'file-exists-p FILENAME)\n\
3372 The function `find-file-name-handler' checks this list for a handler\n\
3373 for its argument.");
3374 Vfile_name_handler_alist
= Qnil
;
3376 defsubr (&Sfind_file_name_handler
);
3377 defsubr (&Sfile_name_directory
);
3378 defsubr (&Sfile_name_nondirectory
);
3379 defsubr (&Sunhandled_file_name_directory
);
3380 defsubr (&Sfile_name_as_directory
);
3381 defsubr (&Sdirectory_file_name
);
3382 defsubr (&Smake_temp_name
);
3383 defsubr (&Sexpand_file_name
);
3384 defsubr (&Ssubstitute_in_file_name
);
3385 defsubr (&Scopy_file
);
3386 defsubr (&Smake_directory_internal
);
3387 defsubr (&Sdelete_directory
);
3388 defsubr (&Sdelete_file
);
3389 defsubr (&Srename_file
);
3390 defsubr (&Sadd_name_to_file
);
3392 defsubr (&Smake_symbolic_link
);
3393 #endif /* S_IFLNK */
3395 defsubr (&Sdefine_logical_name
);
3398 defsubr (&Ssysnetunam
);
3399 #endif /* HPUX_NET */
3400 defsubr (&Sfile_name_absolute_p
);
3401 defsubr (&Sfile_exists_p
);
3402 defsubr (&Sfile_executable_p
);
3403 defsubr (&Sfile_readable_p
);
3404 defsubr (&Sfile_writable_p
);
3405 defsubr (&Sfile_symlink_p
);
3406 defsubr (&Sfile_directory_p
);
3407 defsubr (&Sfile_accessible_directory_p
);
3408 defsubr (&Sfile_modes
);
3409 defsubr (&Sset_file_modes
);
3410 defsubr (&Sset_default_file_modes
);
3411 defsubr (&Sdefault_file_modes
);
3412 defsubr (&Sfile_newer_than_file_p
);
3413 defsubr (&Sinsert_file_contents
);
3414 defsubr (&Swrite_region
);
3415 defsubr (&Sverify_visited_file_modtime
);
3416 defsubr (&Sclear_visited_file_modtime
);
3417 defsubr (&Svisited_file_modtime
);
3418 defsubr (&Sset_visited_file_modtime
);
3419 defsubr (&Sdo_auto_save
);
3420 defsubr (&Sset_buffer_auto_saved
);
3421 defsubr (&Srecent_auto_save_p
);
3423 defsubr (&Sread_file_name_internal
);
3424 defsubr (&Sread_file_name
);
3427 defsubr (&Sunix_sync
);