Mercurial > hg > xemacs-beta
annotate src/fileio.c @ 4742:4cf435fcebbc
Make #'letf not error if handed a #'values form.
lisp/ChangeLog addition:
2009-11-14 Aidan Kehoe <kehoea@parhasard.net>
* cl-macs.el (letf):
Check whether arguments to #'values are bound, and make them
unbound after evaluating BODY; document the limitations of this
macro.
tests/ChangeLog addition:
2009-11-14 Aidan Kehoe <kehoea@parhasard.net>
* automated/lisp-tests.el:
Don't call Known-Bug-Expect-Failure now that the particular letf
bug it tickled is fixed.
| author | Aidan Kehoe <kehoea@parhasard.net> |
|---|---|
| date | Sat, 14 Nov 2009 11:43:09 +0000 |
| parents | a5210e70ffbe |
| children | aa5ed11f473b |
| rev | line source |
|---|---|
| 428 | 1 /* File IO for XEmacs. |
| 2 Copyright (C) 1985-1988, 1992-1995 Free Software Foundation, Inc. | |
| 2367 | 3 Copyright (C) 1996, 2001, 2002, 2003, 2004 Ben Wing. |
| 428 | 4 |
| 5 This file is part of XEmacs. | |
| 6 | |
| 7 XEmacs is free software; you can redistribute it and/or modify it | |
| 8 under the terms of the GNU General Public License as published by the | |
| 9 Free Software Foundation; either version 2, or (at your option) any | |
| 10 later version. | |
| 11 | |
| 12 XEmacs is distributed in the hope that it will be useful, but WITHOUT | |
| 13 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or | |
| 14 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License | |
| 15 for more details. | |
| 16 | |
| 17 You should have received a copy of the GNU General Public License | |
| 18 along with XEmacs; see the file COPYING. If not, write to | |
| 19 the Free Software Foundation, Inc., 59 Temple Place - Suite 330, | |
| 20 Boston, MA 02111-1307, USA. */ | |
| 21 | |
| 22 /* Synched up with: Mule 2.0, FSF 19.30. */ | |
| 771 | 23 /* More syncing: FSF Emacs 19.34.6 by Marc Paquette <marcpa@cam.org> |
| 24 (Note: Sync messages from Marc Paquette may indicate | |
| 25 incomplete synching, so beware.) */ | |
| 2526 | 26 /* Some functions synched with FSF 21.0.103. */ |
| 771 | 27 /* Mule-ized completely except for the #if 0-code including decrypt-string |
| 28 and encrypt-string. --ben 7-2-00 */ | |
| 1333 | 29 /* #if 0-code Mule-ized, 2-22-03. --ben */ |
| 771 | 30 |
| 428 | 31 |
| 32 #include <config.h> | |
| 33 #include "lisp.h" | |
| 34 | |
| 35 #include "buffer.h" | |
| 800 | 36 #include "device.h" |
| 428 | 37 #include "events.h" |
| 800 | 38 #include "file-coding.h" |
| 428 | 39 #include "frame.h" |
| 40 #include "insdel.h" | |
| 41 #include "lstream.h" | |
| 2526 | 42 #include "profile.h" |
| 872 | 43 #include "process.h" |
| 428 | 44 #include "redisplay.h" |
| 45 #include "sysdep.h" | |
| 872 | 46 #include "window-impl.h" |
| 771 | 47 |
| 428 | 48 #include "sysfile.h" |
| 49 #include "sysproc.h" | |
| 50 #include "syspwd.h" | |
| 51 #include "systime.h" | |
| 52 #include "sysdir.h" | |
| 53 | |
| 54 #ifdef HPUX | |
| 55 #include <netio.h> | |
| 56 #ifdef HPUX_PRE_8_0 | |
| 57 #include <errnet.h> | |
| 58 #endif /* HPUX_PRE_8_0 */ | |
| 59 #endif /* HPUX */ | |
| 60 | |
| 1315 | 61 #ifdef WIN32_ANY |
| 657 | 62 #define WIN32_FILENAMES |
| 771 | 63 #include "syswindows.h" |
| 428 | 64 #define IS_DRIVE(x) isalpha (x) |
| 65 /* Need to lower-case the drive letter, or else expanded | |
| 66 filenames will sometimes compare inequal, because | |
| 67 `expand-file-name' doesn't always down-case the drive letter. */ | |
| 68 #define DRIVE_LETTER(x) tolower (x) | |
| 657 | 69 #endif /* WIN32_NATIVE || CYGWIN */ |
| 428 | 70 |
| 71 int lisp_to_time (Lisp_Object, time_t *); | |
| 72 Lisp_Object time_to_lisp (time_t); | |
| 73 | |
| 74 /* Nonzero during writing of auto-save files */ | |
| 75 static int auto_saving; | |
| 76 | |
| 77 /* Set by auto_save_1 to mode of original file so Fwrite_region_internal | |
| 78 will create a new file with the same mode as the original */ | |
| 79 static int auto_save_mode_bits; | |
| 80 | |
| 81 /* Alist of elements (REGEXP . HANDLER) for file names | |
| 82 whose I/O is done with a special handler. */ | |
| 83 Lisp_Object Vfile_name_handler_alist; | |
| 84 | |
| 85 /* Format for auto-save files */ | |
| 86 Lisp_Object Vauto_save_file_format; | |
| 87 | |
| 88 /* Lisp functions for translating file formats */ | |
| 89 Lisp_Object Qformat_decode, Qformat_annotate_function; | |
| 90 | |
| 91 /* Functions to be called to process text properties in inserted file. */ | |
| 92 Lisp_Object Vafter_insert_file_functions; | |
| 93 | |
| 94 /* Functions to be called to create text property annotations for file. */ | |
| 95 Lisp_Object Vwrite_region_annotate_functions; | |
| 96 | |
| 97 /* During build_annotations, each time an annotation function is called, | |
| 98 this holds the annotations made by the previous functions. */ | |
| 99 Lisp_Object Vwrite_region_annotations_so_far; | |
| 100 | |
| 101 /* File name in which we write a list of all our auto save files. */ | |
| 102 Lisp_Object Vauto_save_list_file_name; | |
| 103 | |
| 444 | 104 /* Prefix used to construct Vauto_save_list_file_name. */ |
| 105 Lisp_Object Vauto_save_list_file_prefix; | |
| 106 | |
| 107 /* When non-nil, it prevents auto-save list file creation. */ | |
| 108 int inhibit_auto_save_session; | |
| 109 | |
| 428 | 110 int disable_auto_save_when_buffer_shrinks; |
| 111 | |
| 112 Lisp_Object Vdirectory_sep_char; | |
| 113 | |
|
4499
eb82259f265d
Port write-region-inhibit-sync, allowing avoidance of bad FS performance.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4465
diff
changeset
|
114 #ifdef HAVE_FSYNC |
|
eb82259f265d
Port write-region-inhibit-sync, allowing avoidance of bad FS performance.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4465
diff
changeset
|
115 /* Nonzero means skip the call to fsync in Fwrite-region. */ |
|
eb82259f265d
Port write-region-inhibit-sync, allowing avoidance of bad FS performance.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4465
diff
changeset
|
116 int write_region_inhibit_fsync; |
|
eb82259f265d
Port write-region-inhibit-sync, allowing avoidance of bad FS performance.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4465
diff
changeset
|
117 #endif |
|
eb82259f265d
Port write-region-inhibit-sync, allowing avoidance of bad FS performance.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4465
diff
changeset
|
118 |
| 428 | 119 /* These variables describe handlers that have "already" had a chance |
| 120 to handle the current operation. | |
| 121 | |
| 122 Vinhibit_file_name_handlers is a list of file name handlers. | |
| 123 Vinhibit_file_name_operation is the operation being handled. | |
| 124 If we try to handle that operation, we ignore those handlers. */ | |
| 125 | |
| 126 static Lisp_Object Vinhibit_file_name_handlers; | |
| 127 static Lisp_Object Vinhibit_file_name_operation; | |
| 128 | |
| 563 | 129 Lisp_Object Qfile_already_exists; |
| 4266 | 130 Lisp_Object Qexcl; |
| 428 | 131 |
| 132 Lisp_Object Qauto_save_hook; | |
| 133 Lisp_Object Qauto_save_error; | |
| 134 Lisp_Object Qauto_saving; | |
| 135 | |
| 136 Lisp_Object Qcar_less_than_car; | |
| 137 | |
| 138 Lisp_Object Qcompute_buffer_file_truename; | |
| 139 | |
| 2526 | 140 Lisp_Object QSin_expand_file_name; |
| 141 | |
| 428 | 142 EXFUN (Frunning_temacs_p, 0); |
| 143 | |
| 563 | 144 /* DATA can be anything acceptable to signal_error (). |
| 145 */ | |
| 146 | |
| 147 DOESNT_RETURN | |
| 148 report_file_type_error (Lisp_Object errtype, Lisp_Object oserrmess, | |
| 867 | 149 const CIbyte *string, Lisp_Object data) |
| 563 | 150 { |
| 151 struct gcpro gcpro1; | |
| 152 Lisp_Object errdata = build_error_data (NULL, data); | |
| 153 | |
| 154 GCPRO1 (errdata); | |
| 771 | 155 errdata = Fcons (build_msg_string (string), |
| 563 | 156 Fcons (oserrmess, errdata)); |
| 157 signal_error_1 (errtype, errdata); | |
| 801 | 158 /* UNGCPRO; not reached */ |
| 563 | 159 } |
| 160 | |
| 161 DOESNT_RETURN | |
| 162 report_error_with_errno (Lisp_Object errtype, | |
| 867 | 163 const CIbyte *string, Lisp_Object data) |
| 563 | 164 { |
| 165 report_file_type_error (errtype, lisp_strerror (errno), string, data); | |
| 166 } | |
| 167 | |
| 428 | 168 /* signal a file error when errno contains a meaningful value. */ |
| 169 | |
| 170 DOESNT_RETURN | |
| 867 | 171 report_file_error (const CIbyte *string, Lisp_Object data) |
| 428 | 172 { |
| 563 | 173 report_error_with_errno (Qfile_error, string, data); |
| 428 | 174 } |
| 175 | |
| 176 | |
| 177 /* Just like strerror(3), except return a lisp string instead of char *. | |
| 178 The string needs to be converted since it may be localized. | |
| 771 | 179 */ |
| 428 | 180 Lisp_Object |
| 181 lisp_strerror (int errnum) | |
| 182 { | |
| 771 | 183 Extbyte *ret = strerror (errnum); |
| 184 if (!ret) | |
| 185 { | |
| 867 | 186 Ibyte ffff[99]; |
| 771 | 187 qxesprintf (ffff, "Unknown error %d", errnum); |
| 188 return build_intstring (ffff); | |
| 189 } | |
| 190 return build_ext_string (ret, Qstrerror_encoding); | |
| 428 | 191 } |
| 192 | |
| 193 static Lisp_Object | |
| 194 close_file_unwind (Lisp_Object fd) | |
| 195 { | |
| 196 if (CONSP (fd)) | |
| 197 { | |
| 198 if (INTP (XCAR (fd))) | |
| 771 | 199 retry_close (XINT (XCAR (fd))); |
| 428 | 200 |
| 853 | 201 free_cons (fd); |
| 428 | 202 } |
| 203 else | |
| 771 | 204 retry_close (XINT (fd)); |
| 428 | 205 |
| 206 return Qnil; | |
| 207 } | |
| 208 | |
| 209 static Lisp_Object | |
| 210 delete_stream_unwind (Lisp_Object stream) | |
| 211 { | |
| 212 Lstream_delete (XLSTREAM (stream)); | |
| 213 return Qnil; | |
| 214 } | |
| 215 | |
| 216 /* Restore point, having saved it as a marker. */ | |
| 217 | |
| 218 static Lisp_Object | |
| 219 restore_point_unwind (Lisp_Object point_marker) | |
| 220 { | |
| 221 BUF_SET_PT (current_buffer, marker_position (point_marker)); | |
| 222 return Fset_marker (point_marker, Qnil, Qnil); | |
| 223 } | |
| 224 | |
| 225 | |
| 226 Lisp_Object Qexpand_file_name; | |
| 227 Lisp_Object Qfile_truename; | |
| 228 Lisp_Object Qsubstitute_in_file_name; | |
| 229 Lisp_Object Qdirectory_file_name; | |
| 230 Lisp_Object Qfile_name_directory; | |
| 231 Lisp_Object Qfile_name_nondirectory; | |
| 996 | 232 Lisp_Object Qfile_name_sans_extension; |
| 428 | 233 Lisp_Object Qunhandled_file_name_directory; |
| 234 Lisp_Object Qfile_name_as_directory; | |
| 235 Lisp_Object Qcopy_file; | |
| 236 Lisp_Object Qmake_directory_internal; | |
| 237 Lisp_Object Qdelete_directory; | |
| 238 Lisp_Object Qdelete_file; | |
| 239 Lisp_Object Qrename_file; | |
| 240 Lisp_Object Qadd_name_to_file; | |
| 241 Lisp_Object Qmake_symbolic_link; | |
| 844 | 242 Lisp_Object Qmake_temp_name; |
| 428 | 243 Lisp_Object Qfile_exists_p; |
| 244 Lisp_Object Qfile_executable_p; | |
| 245 Lisp_Object Qfile_readable_p; | |
| 246 Lisp_Object Qfile_symlink_p; | |
| 247 Lisp_Object Qfile_writable_p; | |
| 248 Lisp_Object Qfile_directory_p; | |
| 249 Lisp_Object Qfile_regular_p; | |
| 250 Lisp_Object Qfile_accessible_directory_p; | |
| 251 Lisp_Object Qfile_modes; | |
| 252 Lisp_Object Qset_file_modes; | |
| 253 Lisp_Object Qfile_newer_than_file_p; | |
| 254 Lisp_Object Qinsert_file_contents; | |
| 255 Lisp_Object Qwrite_region; | |
| 256 Lisp_Object Qverify_visited_file_modtime; | |
| 257 Lisp_Object Qset_visited_file_modtime; | |
| 258 | |
| 259 /* If FILENAME is handled specially on account of its syntax, | |
| 260 return its handler function. Otherwise, return nil. */ | |
| 261 | |
| 262 DEFUN ("find-file-name-handler", Ffind_file_name_handler, 1, 2, 0, /* | |
| 263 Return FILENAME's handler function for OPERATION, if it has one. | |
| 264 Otherwise, return nil. | |
| 265 A file name is handled if one of the regular expressions in | |
| 266 `file-name-handler-alist' matches it. | |
| 267 | |
| 268 If OPERATION equals `inhibit-file-name-operation', then we ignore | |
| 269 any handlers that are members of `inhibit-file-name-handlers', | |
| 270 but we still do run any other handlers. This lets handlers | |
| 271 use the standard functions without calling themselves recursively. | |
| 751 | 272 |
| 273 Otherwise, OPERATION is the name of a funcall'able function. | |
| 428 | 274 */ |
| 275 (filename, operation)) | |
| 276 { | |
| 277 /* This function does not GC */ | |
| 278 /* This function can be called during GC */ | |
| 279 /* This function must not munge the match data. */ | |
| 2367 | 280 Lisp_Object inhibited_handlers; |
| 428 | 281 |
| 282 CHECK_STRING (filename); | |
| 283 | |
| 284 if (EQ (operation, Vinhibit_file_name_operation)) | |
| 285 inhibited_handlers = Vinhibit_file_name_handlers; | |
| 286 else | |
| 287 inhibited_handlers = Qnil; | |
| 288 | |
| 2367 | 289 { |
| 290 EXTERNAL_LIST_LOOP_2 (elt, Vfile_name_handler_alist) | |
| 291 { | |
| 292 if (CONSP (elt)) | |
| 293 { | |
| 294 Lisp_Object string = XCAR (elt); | |
| 295 if (STRINGP (string) | |
| 296 && (fast_lisp_string_match (string, filename) >= 0)) | |
| 297 { | |
| 298 Lisp_Object handler = XCDR (elt); | |
| 299 if (NILP (Fmemq (handler, inhibited_handlers))) | |
| 300 return handler; | |
| 301 } | |
| 302 } | |
| 303 } | |
| 304 } | |
| 428 | 305 return Qnil; |
| 306 } | |
| 307 | |
| 308 static Lisp_Object | |
| 309 call2_check_string (Lisp_Object fn, Lisp_Object arg0, Lisp_Object arg1) | |
| 310 { | |
| 311 /* This function can call lisp */ | |
| 312 Lisp_Object result = call2 (fn, arg0, arg1); | |
| 313 CHECK_STRING (result); | |
| 314 return result; | |
| 315 } | |
| 316 | |
| 317 static Lisp_Object | |
| 318 call2_check_string_or_nil (Lisp_Object fn, Lisp_Object arg0, Lisp_Object arg1) | |
| 319 { | |
| 320 /* This function can call lisp */ | |
| 321 Lisp_Object result = call2 (fn, arg0, arg1); | |
| 322 if (!NILP (result)) | |
| 323 CHECK_STRING (result); | |
| 324 return result; | |
| 325 } | |
| 326 | |
| 327 static Lisp_Object | |
| 328 call3_check_string (Lisp_Object fn, Lisp_Object arg0, | |
| 329 Lisp_Object arg1, Lisp_Object arg2) | |
| 330 { | |
| 331 /* This function can call lisp */ | |
| 332 Lisp_Object result = call3 (fn, arg0, arg1, arg2); | |
| 333 CHECK_STRING (result); | |
| 334 return result; | |
| 335 } | |
| 336 | |
| 337 | |
| 2526 | 338 |
| 339 Ibyte * | |
| 340 find_end_of_directory_component (const Ibyte *path, Bytecount len) | |
| 341 { | |
| 342 const Ibyte *p = path + len; | |
| 343 | |
| 344 while (p != path && !IS_DIRECTORY_SEP (p[-1]) | |
| 345 #ifdef WIN32_FILENAMES | |
| 346 /* only recognise drive specifier at the beginning */ | |
| 347 && !(p[-1] == ':' | |
| 348 /* handle the "/:d:foo" and "/:foo" cases correctly */ | |
| 349 && ((p == path + 2 && !IS_DIRECTORY_SEP (*path)) | |
| 350 || (p == path + 4 && IS_DIRECTORY_SEP (*path)))) | |
| 351 #endif | |
| 352 ) p--; | |
| 353 | |
| 354 return (Ibyte *) p; | |
| 355 } | |
| 356 | |
| 428 | 357 DEFUN ("file-name-directory", Ffile_name_directory, 1, 1, 0, /* |
| 444 | 358 Return the directory component in file name FILENAME. |
| 359 Return nil if FILENAME does not include a directory. | |
| 428 | 360 Otherwise return a directory spec. |
| 361 Given a Unix syntax file name, returns a string ending in slash. | |
| 362 */ | |
| 444 | 363 (filename)) |
| 428 | 364 { |
| 442 | 365 /* This function can GC. GC checked 2000-07-28 ben */ |
| 771 | 366 /* This function synched with Emacs 21.0.103. */ |
| 867 | 367 Ibyte *beg; |
| 368 Ibyte *p; | |
| 428 | 369 Lisp_Object handler; |
| 370 | |
| 444 | 371 CHECK_STRING (filename); |
| 428 | 372 |
| 373 /* If the file name has special constructs in it, | |
| 374 call the corresponding file handler. */ | |
| 444 | 375 handler = Ffind_file_name_handler (filename, Qfile_name_directory); |
| 428 | 376 if (!NILP (handler)) |
| 444 | 377 return call2_check_string_or_nil (handler, Qfile_name_directory, filename); |
| 428 | 378 |
| 379 #ifdef FILE_SYSTEM_CASE | |
| 444 | 380 filename = FILE_SYSTEM_CASE (filename); |
| 428 | 381 #endif |
| 444 | 382 beg = XSTRING_DATA (filename); |
| 771 | 383 /* XEmacs: no need to alloca-copy here */ |
| 2526 | 384 p = find_end_of_directory_component (beg, XSTRING_LENGTH (filename)); |
| 428 | 385 |
| 386 if (p == beg) | |
| 387 return Qnil; | |
| 442 | 388 #ifdef WIN32_NATIVE |
| 428 | 389 /* Expansion of "c:" to drive and default directory. */ |
| 771 | 390 if (p[-1] == ':') |
| 428 | 391 { |
| 867 | 392 Ibyte *res; |
| 393 Ibyte *wd = mswindows_getdcwd (toupper (*beg) - 'A' + 1); | |
| 771 | 394 |
| 2367 | 395 res = alloca_ibytes ((wd ? qxestrlen (wd) : 0) + 10); /* go overboard */ |
| 1116 | 396 res[0] = '\0'; |
| 771 | 397 if (p == beg + 4 && IS_DIRECTORY_SEP (*beg) && beg[1] == ':') |
| 398 { | |
| 399 qxestrncpy (res, beg, 2); | |
| 400 beg += 2; | |
| 1116 | 401 res[2] = '\0'; |
| 771 | 402 } |
| 403 | |
| 404 if (wd) | |
| 428 | 405 { |
| 3648 | 406 int size; |
| 771 | 407 qxestrcat (res, wd); |
| 3648 | 408 size = qxestrlen (res); |
| 409 if (!IS_DIRECTORY_SEP (res[size - 1])) | |
| 410 { | |
| 411 res[size] = DIRECTORY_SEP; | |
| 412 res[size + 1] = '\0'; | |
| 413 } | |
| 428 | 414 beg = res; |
| 771 | 415 p = beg + qxestrlen (beg); |
| 428 | 416 } |
| 3648 | 417 else |
| 418 { | |
| 419 return Qnil; | |
| 420 } | |
| 771 | 421 if (wd) |
| 1726 | 422 xfree (wd, Ibyte *); |
| 428 | 423 } |
| 771 | 424 |
| 425 #if 0 /* No! This screws up efs, which calls file-name-directory on URL's | |
| 426 and expects the slashes to be left alone. This is here because of | |
| 427 an analogous call in FSF 21. */ | |
| 428 { | |
| 429 Bytecount len = p - beg; | |
| 867 | 430 Ibyte *newbeg = alloca_ibytes (len + 1); |
| 771 | 431 |
| 432 qxestrncpy (newbeg, beg, len); | |
| 433 newbeg[len] = '\0'; | |
| 434 newbeg = mswindows_canonicalize_filename (newbeg); | |
| 1726 | 435 return build_intstring (newbeg); |
| 771 | 436 } |
| 437 #endif | |
| 438 #endif /* not WIN32_NATIVE */ | |
| 428 | 439 return make_string (beg, p - beg); |
| 440 } | |
| 441 | |
| 442 DEFUN ("file-name-nondirectory", Ffile_name_nondirectory, 1, 1, 0, /* | |
| 444 | 443 Return file name FILENAME sans its directory. |
| 428 | 444 For example, in a Unix-syntax file name, |
| 445 this is everything after the last slash, | |
| 446 or the entire name if it contains no slash. | |
| 447 */ | |
| 444 | 448 (filename)) |
| 428 | 449 { |
| 442 | 450 /* This function can GC. GC checked 2000-07-28 ben */ |
| 771 | 451 /* This function synched with Emacs 21.0.103. */ |
| 867 | 452 Ibyte *beg, *p, *end; |
| 428 | 453 Lisp_Object handler; |
| 454 | |
| 444 | 455 CHECK_STRING (filename); |
| 428 | 456 |
| 457 /* If the file name has special constructs in it, | |
| 458 call the corresponding file handler. */ | |
| 444 | 459 handler = Ffind_file_name_handler (filename, Qfile_name_nondirectory); |
| 428 | 460 if (!NILP (handler)) |
| 444 | 461 return call2_check_string (handler, Qfile_name_nondirectory, filename); |
| 462 | |
| 463 beg = XSTRING_DATA (filename); | |
| 464 end = p = beg + XSTRING_LENGTH (filename); | |
| 428 | 465 |
| 771 | 466 while (p != beg && !IS_DIRECTORY_SEP (p[-1]) |
| 657 | 467 #ifdef WIN32_FILENAMES |
| 771 | 468 /* only recognise drive specifier at beginning */ |
| 469 && !(p[-1] == ':' | |
| 470 /* handle the "/:d:foo" case correctly */ | |
| 471 && (p == beg + 2 || (p == beg + 4 && IS_DIRECTORY_SEP (*beg)))) | |
| 428 | 472 #endif |
| 771 | 473 ) |
| 474 p--; | |
| 428 | 475 |
| 476 return make_string (p, end - p); | |
| 477 } | |
| 478 | |
| 479 DEFUN ("unhandled-file-name-directory", Funhandled_file_name_directory, 1, 1, 0, /* | |
| 480 Return a directly usable directory name somehow associated with FILENAME. | |
| 481 A `directly usable' directory name is one that may be used without the | |
| 482 intervention of any file handler. | |
| 483 If FILENAME is a directly usable file itself, return | |
| 484 \(file-name-directory FILENAME). | |
| 485 The `call-process' and `start-process' functions use this function to | |
| 486 get a current directory to run processes in. | |
| 487 */ | |
| 444 | 488 (filename)) |
| 428 | 489 { |
| 442 | 490 /* This function can GC. GC checked 2000-07-28 ben */ |
| 428 | 491 Lisp_Object handler; |
| 492 | |
| 493 /* If the file name has special constructs in it, | |
| 494 call the corresponding file handler. */ | |
| 495 handler = Ffind_file_name_handler (filename, Qunhandled_file_name_directory); | |
| 496 if (!NILP (handler)) | |
| 497 return call2 (handler, Qunhandled_file_name_directory, | |
| 498 filename); | |
| 499 | |
| 500 return Ffile_name_directory (filename); | |
| 501 } | |
| 502 | |
| 503 | |
| 867 | 504 static Ibyte * |
| 505 file_name_as_directory (Ibyte *out, Ibyte *in) | |
| 428 | 506 { |
| 442 | 507 /* This function cannot GC */ |
| 771 | 508 int size = qxestrlen (in); |
| 428 | 509 |
| 510 if (size == 0) | |
| 511 { | |
| 512 out[0] = '.'; | |
| 513 out[1] = DIRECTORY_SEP; | |
| 514 out[2] = '\0'; | |
| 515 } | |
| 516 else | |
| 517 { | |
| 771 | 518 qxestrcpy (out, in); |
| 428 | 519 /* Append a slash if necessary */ |
| 520 if (!IS_ANY_SEP (out[size-1])) | |
| 521 { | |
| 522 out[size] = DIRECTORY_SEP; | |
| 523 out[size + 1] = '\0'; | |
| 524 } | |
| 525 } | |
| 526 return out; | |
| 527 } | |
| 528 | |
| 529 DEFUN ("file-name-as-directory", Ffile_name_as_directory, 1, 1, 0, /* | |
| 530 Return a string representing file FILENAME interpreted as a directory. | |
| 531 This operation exists because a directory is also a file, but its name as | |
| 532 a directory is different from its name as a file. | |
| 533 The result can be used as the value of `default-directory' | |
| 534 or passed as second argument to `expand-file-name'. | |
| 535 For a Unix-syntax file name, just appends a slash, | |
| 536 except for (file-name-as-directory \"\") => \"./\". | |
| 537 */ | |
| 444 | 538 (filename)) |
| 428 | 539 { |
| 442 | 540 /* This function can GC. GC checked 2000-07-28 ben */ |
| 867 | 541 Ibyte *buf; |
| 428 | 542 Lisp_Object handler; |
| 543 | |
| 444 | 544 CHECK_STRING (filename); |
| 428 | 545 |
| 546 /* If the file name has special constructs in it, | |
| 547 call the corresponding file handler. */ | |
| 444 | 548 handler = Ffind_file_name_handler (filename, Qfile_name_as_directory); |
| 428 | 549 if (!NILP (handler)) |
| 444 | 550 return call2_check_string (handler, Qfile_name_as_directory, filename); |
| 551 | |
| 867 | 552 buf = alloca_ibytes (XSTRING_LENGTH (filename) + 10); |
| 2526 | 553 file_name_as_directory (buf, XSTRING_DATA (filename)); |
| 554 if (qxestrcmp (buf, XSTRING_DATA (filename))) | |
| 555 return build_intstring (buf); | |
| 556 else | |
| 557 return filename; | |
| 428 | 558 } |
| 559 | |
| 560 /* | |
| 561 * Convert from directory name to filename. | |
| 562 * On UNIX, it's simple: just make sure there isn't a terminating / | |
| 563 * | |
| 564 * Value is nonzero if the string output is different from the input. | |
| 565 */ | |
| 566 | |
| 567 static int | |
| 867 | 568 directory_file_name (const Ibyte *src, Ibyte *dst) |
| 428 | 569 { |
| 442 | 570 /* This function cannot GC */ |
| 771 | 571 long slen = qxestrlen (src); |
| 428 | 572 /* Process as Unix format: just remove any final slash. |
| 573 But leave "/" unchanged; do not change it to "". */ | |
| 771 | 574 qxestrcpy (dst, src); |
| 428 | 575 if (slen > 1 |
| 576 && IS_DIRECTORY_SEP (dst[slen - 1]) | |
| 657 | 577 #ifdef WIN32_FILENAMES |
| 428 | 578 && !IS_ANY_SEP (dst[slen - 2]) |
| 657 | 579 #endif /* WIN32_FILENAMES */ |
| 428 | 580 ) |
| 581 dst[slen - 1] = 0; | |
| 582 return 1; | |
| 583 } | |
| 584 | |
| 585 DEFUN ("directory-file-name", Fdirectory_file_name, 1, 1, 0, /* | |
| 444 | 586 Return the file name of the directory named DIRECTORY. |
| 587 This is the name of the file that holds the data for the directory. | |
| 428 | 588 This operation exists because a directory is also a file, but its name as |
| 589 a directory is different from its name as a file. | |
| 590 In Unix-syntax, this function just removes the final slash. | |
| 591 */ | |
| 592 (directory)) | |
| 593 { | |
| 442 | 594 /* This function can GC. GC checked 2000-07-28 ben */ |
| 867 | 595 Ibyte *buf; |
| 428 | 596 Lisp_Object handler; |
| 597 | |
| 598 CHECK_STRING (directory); | |
| 599 | |
| 600 #if 0 /* #### WTF? */ | |
| 601 if (NILP (directory)) | |
| 602 return Qnil; | |
| 603 #endif | |
| 604 | |
| 605 /* If the file name has special constructs in it, | |
| 606 call the corresponding file handler. */ | |
| 607 handler = Ffind_file_name_handler (directory, Qdirectory_file_name); | |
| 608 if (!NILP (handler)) | |
| 609 return call2_check_string (handler, Qdirectory_file_name, directory); | |
| 2367 | 610 buf = alloca_ibytes (XSTRING_LENGTH (directory) + 20); |
| 771 | 611 directory_file_name (XSTRING_DATA (directory), buf); |
| 612 return build_intstring (buf); | |
| 428 | 613 } |
| 614 | |
| 615 /* Fmake_temp_name used to be a simple wrapper around mktemp(), but it | |
| 616 proved too broken for our purposes (it supported only 26 or 62 | |
| 617 unique names under some implementations). For example, this | |
| 618 arbitrary limit broke generation of Gnus Incoming* files. | |
| 619 | |
| 620 This implementation is better than what one usually finds in libc. | |
| 621 --hniksic */ | |
| 622 | |
| 442 | 623 static unsigned int temp_name_rand; |
| 624 | |
| 428 | 625 DEFUN ("make-temp-name", Fmake_temp_name, 1, 1, 0, /* |
| 442 | 626 Generate a temporary file name starting with PREFIX. |
| 428 | 627 The Emacs process number forms part of the result, so there is no |
| 628 danger of generating a name being used by another process. | |
| 629 | |
| 630 In addition, this function makes an attempt to choose a name that | |
| 631 does not specify an existing file. To make this work, PREFIX should | |
| 4266 | 632 be an absolute file name. |
| 633 | |
| 634 This function is analagous to mktemp(3) under POSIX, and as with it, there | |
| 635 exists a race condition between the test for the existence of the new file | |
|
4383
1e04b9c8125b
Correct the make-temp-name docstring.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4324
diff
changeset
|
636 and its creation. See `make-temp-file' for a function which avoids this |
| 4266 | 637 race condition by specifying the appropriate flags to `write-region'. |
| 428 | 638 */ |
| 639 (prefix)) | |
| 640 { | |
| 442 | 641 static const char tbl[64] = |
| 642 { | |
| 428 | 643 'A','B','C','D','E','F','G','H', |
| 644 'I','J','K','L','M','N','O','P', | |
| 645 'Q','R','S','T','U','V','W','X', | |
| 646 'Y','Z','a','b','c','d','e','f', | |
| 647 'g','h','i','j','k','l','m','n', | |
| 648 'o','p','q','r','s','t','u','v', | |
| 649 'w','x','y','z','0','1','2','3', | |
| 442 | 650 '4','5','6','7','8','9','-','_' |
| 651 }; | |
| 428 | 652 |
| 653 Bytecount len; | |
| 867 | 654 Ibyte *p, *data; |
| 844 | 655 Lisp_Object handler; |
| 428 | 656 |
| 657 CHECK_STRING (prefix); | |
| 844 | 658 handler = Ffind_file_name_handler (prefix, Qmake_temp_name); |
| 659 if (!NILP (handler)) | |
| 660 return call2_check_string (handler, Qmake_temp_name, prefix); | |
| 428 | 661 |
| 662 /* I was tempted to apply Fexpand_file_name on PREFIX here, but it's | |
| 663 a bad idea because: | |
| 664 | |
| 665 1) It might change the prefix, so the resulting string might not | |
| 666 begin with PREFIX. This violates the principle of least | |
| 667 surprise. | |
| 668 | |
| 669 2) It breaks under many unforeseeable circumstances, such as with | |
| 670 the code that uses (make-temp-name "") instead of | |
| 671 (make-temp-name "./"). | |
| 672 | |
| 844 | 673 [[ 3) It might yield unexpected (to stat(2)) results in the presence |
| 674 of EFS and file name handlers.]] Now that we check for a handler, | |
| 675 that's less of a concern. --ben */ | |
| 428 | 676 |
| 677 len = XSTRING_LENGTH (prefix); | |
| 867 | 678 data = alloca_ibytes (len + 7); |
| 428 | 679 memcpy (data, XSTRING_DATA (prefix), len); |
| 680 p = data + len; | |
| 771 | 681 p[6] = '\0'; |
| 428 | 682 |
| 683 /* VAL is created by adding 6 characters to PREFIX. The first three | |
| 684 are the PID of this process, in base 64, and the second three are | |
| 442 | 685 a pseudo-random number seeded from process startup time. This |
| 686 ensures 262144 unique file names per PID per PREFIX per machine. */ | |
| 687 | |
| 688 { | |
| 771 | 689 unsigned int pid = (unsigned int) qxe_getpid (); |
| 442 | 690 *p++ = tbl[(pid >> 0) & 63]; |
| 691 *p++ = tbl[(pid >> 6) & 63]; | |
| 692 *p++ = tbl[(pid >> 12) & 63]; | |
| 693 } | |
| 428 | 694 |
| 695 /* Here we try to minimize useless stat'ing when this function is | |
| 696 invoked many times successively with the same PREFIX. We achieve | |
| 442 | 697 this by using a very pseudo-random number generator to generate |
| 698 file names unique to this process, with a very long cycle. */ | |
| 428 | 699 |
| 700 while (1) | |
| 701 { | |
| 702 struct stat ignored; | |
| 442 | 703 |
| 704 p[0] = tbl[(temp_name_rand >> 0) & 63]; | |
| 705 p[1] = tbl[(temp_name_rand >> 6) & 63]; | |
| 706 p[2] = tbl[(temp_name_rand >> 12) & 63]; | |
| 428 | 707 |
| 708 /* Poor man's congruential RN generator. Replace with ++count | |
| 709 for debugging. */ | |
| 442 | 710 temp_name_rand += 25229; |
| 711 temp_name_rand %= 225307; | |
| 428 | 712 |
| 713 QUIT; | |
| 714 | |
| 771 | 715 if (qxe_stat (data, &ignored) < 0) |
| 428 | 716 { |
| 717 /* We want to return only if errno is ENOENT. */ | |
| 718 if (errno == ENOENT) | |
| 771 | 719 return make_string (data, len + 6); |
| 428 | 720 |
| 721 /* The error here is dubious, but there is little else we | |
| 722 can do. The alternatives are to return nil, which is | |
| 723 as bad as (and in many cases worse than) throwing the | |
| 724 error, or to ignore the error, which will likely result | |
| 725 in inflooping. */ | |
| 726 report_file_error ("Cannot create temporary name for prefix", | |
| 563 | 727 prefix); |
| 428 | 728 return Qnil; /* not reached */ |
| 729 } | |
| 730 } | |
| 731 } | |
| 732 | |
| 733 | |
| 771 | 734 |
| 428 | 735 DEFUN ("expand-file-name", Fexpand_file_name, 1, 2, 0, /* |
| 736 Convert filename NAME to absolute, and canonicalize it. | |
| 737 Second arg DEFAULT-DIRECTORY is directory to start with if NAME is relative | |
| 738 (does not start with slash); if DEFAULT-DIRECTORY is nil or missing, | |
| 444 | 739 the current buffer's value of `default-directory' is used. |
| 428 | 740 File name components that are `.' are removed, and |
| 741 so are file name components followed by `..', along with the `..' itself; | |
| 742 note that these simplifications are done without checking the resulting | |
| 743 file names in the file system. | |
| 744 An initial `~/' expands to your home directory. | |
| 745 An initial `~USER/' expands to USER's home directory. | |
| 746 See also the function `substitute-in-file-name'. | |
| 747 */ | |
| 748 (name, default_directory)) | |
| 749 { | |
| 771 | 750 /* This function can GC. GC-checked 2000-11-18. |
| 751 This function synched with Emacs 21.0.103. */ | |
| 867 | 752 Ibyte *nm; |
| 753 | |
| 754 Ibyte *newdir, *p, *o; | |
| 428 | 755 int tlen; |
| 867 | 756 Ibyte *target; |
| 657 | 757 #ifdef WIN32_FILENAMES |
| 428 | 758 int drive = 0; |
| 759 int collapse_newdir = 1; | |
| 771 | 760 /* XEmacs note: This concerns the special '/:' syntax for preventing |
| 761 wildcards and such. We don't support this currently but I'm | |
| 762 keeping the code here in case we do. */ | |
| 763 int is_escaped = 0; | |
| 657 | 764 #endif |
| 765 #ifndef WIN32_NATIVE | |
| 428 | 766 struct passwd *pw; |
| 771 | 767 #endif |
| 428 | 768 int length; |
| 446 | 769 Lisp_Object handler = Qnil; |
| 770 struct gcpro gcpro1, gcpro2, gcpro3; | |
| 2526 | 771 PROFILE_DECLARE (); |
| 772 | |
| 773 PROFILE_RECORD_ENTERING_SECTION (QSin_expand_file_name); | |
| 442 | 774 |
| 775 /* both of these get set below */ | |
| 446 | 776 GCPRO3 (name, default_directory, handler); |
| 428 | 777 |
| 778 CHECK_STRING (name); | |
| 779 | |
| 780 /* If the file name has special constructs in it, | |
| 781 call the corresponding file handler. */ | |
| 782 handler = Ffind_file_name_handler (name, Qexpand_file_name); | |
| 783 if (!NILP (handler)) | |
| 2526 | 784 RETURN_UNGCPRO_EXIT_PROFILING (QSin_expand_file_name, |
| 785 call3_check_string | |
| 786 (handler, Qexpand_file_name, | |
| 787 name, default_directory)); | |
| 428 | 788 |
| 789 /* Use the buffer's default-directory if DEFAULT_DIRECTORY is omitted. */ | |
| 790 if (NILP (default_directory)) | |
| 791 default_directory = current_buffer->directory; | |
| 792 if (! STRINGP (default_directory)) | |
|
4733
a5210e70ffbe
No need to fatal () on startup if $PWD doesn't exist; chdir to "/" instead.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4499
diff
changeset
|
793 default_directory = build_string (DEFAULT_DIRECTORY_FALLBACK); |
| 428 | 794 |
| 795 if (!NILP (default_directory)) | |
| 796 { | |
| 797 handler = Ffind_file_name_handler (default_directory, Qexpand_file_name); | |
| 798 if (!NILP (handler)) | |
| 2526 | 799 RETURN_UNGCPRO_EXIT_PROFILING (QSin_expand_file_name, |
| 800 call3 (handler, Qexpand_file_name, | |
| 801 name, default_directory)); | |
| 428 | 802 } |
| 803 | |
| 804 o = XSTRING_DATA (default_directory); | |
| 805 | |
| 806 /* Make sure DEFAULT_DIRECTORY is properly expanded. | |
| 807 It would be better to do this down below where we actually use | |
| 808 default_directory. Unfortunately, calling Fexpand_file_name recursively | |
| 809 could invoke GC, and the strings might be relocated. This would | |
| 810 be annoying because we have pointers into strings lying around | |
| 811 that would need adjusting, and people would add new pointers to | |
| 812 the code and forget to adjust them, resulting in intermittent bugs. | |
| 813 Putting this call here avoids all that crud. | |
| 814 | |
| 815 The EQ test avoids infinite recursion. */ | |
| 816 if (! NILP (default_directory) && !EQ (default_directory, name) | |
| 817 /* Save time in some common cases - as long as default_directory | |
| 818 is not relative, it can be canonicalized with name below (if it | |
| 819 is needed at all) without requiring it to be expanded now. */ | |
| 657 | 820 #ifdef WIN32_FILENAMES |
| 442 | 821 /* Detect Windows file names with drive specifiers. */ |
| 428 | 822 && ! (IS_DRIVE (o[0]) && (IS_DEVICE_SEP (o[1]) && IS_DIRECTORY_SEP (o[2]))) |
| 823 /* Detect Windows file names in UNC format. */ | |
| 824 && ! (IS_DIRECTORY_SEP (o[0]) && IS_DIRECTORY_SEP (o[1])) | |
| 657 | 825 #endif /* not WIN32_FILENAMES */ |
| 826 #ifndef WIN32_NATIVE | |
| 428 | 827 /* Detect Unix absolute file names (/... alone is not absolute on |
| 442 | 828 Windows). */ |
| 428 | 829 && ! (IS_DIRECTORY_SEP (o[0])) |
| 442 | 830 #endif /* not WIN32_NATIVE */ |
| 428 | 831 ) |
| 442 | 832 |
| 833 default_directory = Fexpand_file_name (default_directory, Qnil); | |
| 428 | 834 |
| 835 #ifdef FILE_SYSTEM_CASE | |
| 836 name = FILE_SYSTEM_CASE (name); | |
| 837 #endif | |
| 838 | |
| 839 /* #### dmoore - this is ugly, clean this up. Looks like nm pointing | |
| 840 into name should be safe during all of this, though. */ | |
| 841 nm = XSTRING_DATA (name); | |
| 842 | |
| 657 | 843 #ifdef WIN32_FILENAMES |
| 428 | 844 /* We will force directory separators to be either all \ or /, so make |
| 845 a local copy to modify, even if there ends up being no change. */ | |
| 867 | 846 nm = qxestrcpy (alloca_ibytes (qxestrlen (nm) + 1), nm); |
| 771 | 847 |
| 848 /* Note if special escape prefix is present, but remove for now. */ | |
| 849 if (nm[0] == '/' && nm[1] == ':') | |
| 850 { | |
| 851 is_escaped = 1; | |
| 852 nm += 2; | |
| 853 } | |
| 428 | 854 |
| 855 /* Find and remove drive specifier if present; this makes nm absolute | |
| 856 even if the rest of the name appears to be relative. */ | |
| 857 { | |
| 867 | 858 Ibyte *colon = qxestrrchr (nm, ':'); |
| 428 | 859 |
| 860 if (colon) | |
| 657 | 861 { |
| 428 | 862 /* Only recognize colon as part of drive specifier if there is a |
| 863 single alphabetic character preceding the colon (and if the | |
| 864 character before the drive letter, if present, is a directory | |
| 865 separator); this is to support the remote system syntax used by | |
| 866 ange-ftp, and the "po:username" syntax for POP mailboxes. */ | |
| 867 look_again: | |
| 868 if (nm == colon) | |
| 869 nm++; | |
| 870 else if (IS_DRIVE (colon[-1]) | |
| 871 && (colon == nm + 1 || IS_DIRECTORY_SEP (colon[-2]))) | |
| 872 { | |
| 873 drive = colon[-1]; | |
| 874 nm = colon + 1; | |
| 875 } | |
| 876 else | |
| 877 { | |
| 878 while (--colon >= nm) | |
| 879 if (colon[0] == ':') | |
| 880 goto look_again; | |
| 881 } | |
| 657 | 882 } |
| 428 | 883 } |
| 884 | |
| 885 /* If we see "c://somedir", we want to strip the first slash after the | |
| 886 colon when stripping the drive letter. Otherwise, this expands to | |
| 887 "//somedir". */ | |
| 888 if (drive && IS_DIRECTORY_SEP (nm[0]) && IS_DIRECTORY_SEP (nm[1])) | |
| 889 nm++; | |
| 657 | 890 #endif /* WIN32_FILENAMES */ |
| 428 | 891 |
| 771 | 892 #ifdef WIN32_FILENAMES |
| 893 /* Discard any previous drive specifier if nm is now in UNC format. */ | |
| 894 if (IS_DIRECTORY_SEP (nm[0]) && IS_DIRECTORY_SEP (nm[1])) | |
| 895 { | |
| 896 drive = 0; | |
| 897 } | |
| 898 #endif | |
| 899 | |
| 428 | 900 /* If nm is absolute, look for /./ or /../ sequences; if none are |
| 901 found, we can probably return right away. We will avoid allocating | |
| 902 a new string if name is already fully expanded. */ | |
| 903 if ( | |
| 904 IS_DIRECTORY_SEP (nm[0]) | |
| 442 | 905 #ifdef WIN32_NATIVE |
| 771 | 906 && (drive || IS_DIRECTORY_SEP (nm[1])) && !is_escaped |
| 428 | 907 #endif |
| 908 ) | |
| 909 { | |
| 910 /* If it turns out that the filename we want to return is just a | |
| 911 suffix of FILENAME, we don't need to go through and edit | |
| 912 things; we just need to construct a new string using data | |
| 913 starting at the middle of FILENAME. If we set lose to a | |
| 914 non-zero value, that means we've discovered that we can't do | |
| 915 that cool trick. */ | |
| 916 int lose = 0; | |
| 917 | |
| 918 p = nm; | |
| 919 while (*p) | |
| 920 { | |
| 921 /* Since we know the name is absolute, we can assume that each | |
| 922 element starts with a "/". */ | |
| 923 | |
| 924 /* "." and ".." are hairy. */ | |
| 925 if (IS_DIRECTORY_SEP (p[0]) | |
| 926 && p[1] == '.' | |
| 927 && (IS_DIRECTORY_SEP (p[2]) | |
| 928 || p[2] == 0 | |
| 929 || (p[2] == '.' && (IS_DIRECTORY_SEP (p[3]) | |
| 930 || p[3] == 0)))) | |
| 931 lose = 1; | |
| 771 | 932 /* We want to replace multiple `/' in a row with a single |
| 933 slash. */ | |
| 934 else if (p > nm | |
| 935 && IS_DIRECTORY_SEP (p[0]) | |
| 936 && IS_DIRECTORY_SEP (p[1])) | |
| 937 lose = 1; | |
| 428 | 938 p++; |
| 939 } | |
| 940 if (!lose) | |
| 941 { | |
| 657 | 942 #ifdef WIN32_FILENAMES |
| 943 if (drive || IS_DIRECTORY_SEP (nm[1])) | |
| 428 | 944 { |
| 867 | 945 Ibyte *newnm; |
| 771 | 946 |
| 657 | 947 if (IS_DIRECTORY_SEP (nm[1])) |
| 948 { | |
| 771 | 949 newnm = mswindows_canonicalize_filename (nm); |
| 950 if (qxestrcmp (newnm, XSTRING_DATA (name)) != 0) | |
| 951 name = build_intstring (newnm); | |
| 657 | 952 } |
| 771 | 953 else |
| 657 | 954 { |
| 771 | 955 /* drive must be set, so this is okay */ |
| 956 newnm = mswindows_canonicalize_filename (nm - 2); | |
| 957 if (qxestrcmp (newnm, XSTRING_DATA (name)) != 0) | |
| 958 { | |
| 959 name = build_intstring (newnm); | |
| 960 XSTRING_DATA (name)[0] = DRIVE_LETTER (drive); | |
| 961 XSTRING_DATA (name)[1] = ':'; | |
| 962 } | |
| 657 | 963 } |
| 1726 | 964 xfree (newnm, Ibyte *); |
| 2526 | 965 RETURN_UNGCPRO_EXIT_PROFILING (QSin_expand_file_name, name); |
| 428 | 966 } |
| 771 | 967 #endif /* WIN32_FILENAMES */ |
| 657 | 968 #ifndef WIN32_NATIVE |
| 428 | 969 if (nm == XSTRING_DATA (name)) |
| 2526 | 970 RETURN_UNGCPRO_EXIT_PROFILING (QSin_expand_file_name, name); |
| 971 RETURN_UNGCPRO_EXIT_PROFILING (QSin_expand_file_name, | |
| 972 build_intstring (nm)); | |
| 442 | 973 #endif /* not WIN32_NATIVE */ |
| 428 | 974 } |
| 975 } | |
| 976 | |
| 977 /* At this point, nm might or might not be an absolute file name. We | |
| 978 need to expand ~ or ~user if present, otherwise prefix nm with | |
| 979 default_directory if nm is not absolute, and finally collapse /./ | |
| 980 and /foo/../ sequences. | |
| 981 | |
| 982 We set newdir to be the appropriate prefix if one is needed: | |
| 983 - the relevant user directory if nm starts with ~ or ~user | |
| 984 - the specified drive's working dir (DOS/NT only) if nm does not | |
| 985 start with / | |
| 986 - the value of default_directory. | |
| 987 | |
| 988 Note that these prefixes are not guaranteed to be absolute (except | |
| 989 for the working dir of a drive). Therefore, to ensure we always | |
| 990 return an absolute name, if the final prefix is not absolute we | |
| 991 append it to the current working directory. */ | |
| 992 | |
| 993 newdir = 0; | |
| 994 | |
| 995 if (nm[0] == '~') /* prefix ~ */ | |
| 996 { | |
| 997 if (IS_DIRECTORY_SEP (nm[1]) | |
| 998 || nm[1] == 0) /* ~ by itself */ | |
| 999 { | |
| 867 | 1000 Ibyte *homedir = get_home_directory (); |
| 771 | 1001 |
| 1002 if (!homedir) | |
| 867 | 1003 newdir = (Ibyte *) ""; |
| 428 | 1004 else |
| 771 | 1005 newdir = homedir; |
| 428 | 1006 |
| 1007 nm++; | |
| 657 | 1008 #ifdef WIN32_FILENAMES |
| 428 | 1009 collapse_newdir = 0; |
| 1010 #endif | |
| 1011 } | |
| 1012 else /* ~user/filename */ | |
| 1013 { | |
| 1014 for (p = nm; *p && (!IS_DIRECTORY_SEP (*p)); p++) | |
| 1015 DO_NOTHING; | |
| 2367 | 1016 o = alloca_ibytes (p - nm + 1); |
| 771 | 1017 memcpy (o, nm, p - nm); |
| 428 | 1018 o [p - nm] = 0; |
| 1019 | |
| 558 | 1020 /* #### While NT is single-user (for the moment) you still |
| 1021 can have multiple user profiles users defined, each with | |
| 1022 its HOME. So maybe possibly we should think about handling | |
| 1023 ~user. --ben */ | |
| 1024 #ifndef WIN32_NATIVE | |
| 442 | 1025 #ifdef CYGWIN |
| 771 | 1026 { |
| 867 | 1027 Ibyte *user; |
| 771 | 1028 |
| 1029 if ((user = user_login_name (NULL)) != NULL) | |
| 1030 { | |
| 1031 /* Does the user login name match the ~name? */ | |
| 1032 if (qxestrcmp (user, o + 1) == 0) | |
| 1033 { | |
| 1034 newdir = get_home_directory (); | |
| 1035 nm = p; | |
| 1036 } | |
| 1037 } | |
| 1038 } | |
| 1039 if (!newdir) | |
| 428 | 1040 { |
| 442 | 1041 #endif /* CYGWIN */ |
| 428 | 1042 /* Jamie reports that getpwnam() can get wedged by SIGIO/SIGALARM |
| 1043 occurring in it. (It can call select()). */ | |
| 1044 slow_down_interrupts (); | |
| 771 | 1045 pw = (struct passwd *) qxe_getpwnam (o + 1); |
| 428 | 1046 speed_up_interrupts (); |
| 1047 if (pw) | |
| 1048 { | |
| 867 | 1049 newdir = (Ibyte *) pw->pw_dir; |
| 428 | 1050 nm = p; |
| 771 | 1051 /* FSF: if WIN32_NATIVE, collapse_newdir = 0; |
| 1052 not possible here. */ | |
| 428 | 1053 } |
| 442 | 1054 #ifdef CYGWIN |
| 428 | 1055 } |
| 1056 #endif | |
| 442 | 1057 #endif /* not WIN32_NATIVE */ |
| 428 | 1058 |
| 1059 /* If we don't find a user of that name, leave the name | |
| 1060 unchanged; don't move nm forward to p. */ | |
| 1061 } | |
| 1062 } | |
| 1063 | |
| 657 | 1064 #ifdef WIN32_FILENAMES |
| 428 | 1065 /* On DOS and Windows, nm is absolute if a drive name was specified; |
| 1066 use the drive's current directory as the prefix if needed. */ | |
| 1067 if (!newdir && drive) | |
| 1068 { | |
| 657 | 1069 #ifdef WIN32_NATIVE |
| 428 | 1070 /* Get default directory if needed to make nm absolute. */ |
| 1071 if (!IS_DIRECTORY_SEP (nm[0])) | |
| 1072 { | |
| 867 | 1073 Ibyte *newcwd = mswindows_getdcwd (toupper (drive) - 'A' + 1); |
| 771 | 1074 if (newcwd) |
| 1075 { | |
| 867 | 1076 IBYTE_STRING_TO_ALLOCA (newcwd, newdir); |
| 1726 | 1077 xfree (newcwd, Ibyte *); |
| 771 | 1078 } |
| 1079 else | |
| 428 | 1080 newdir = NULL; |
| 1081 } | |
| 657 | 1082 #endif /* WIN32_NATIVE */ |
| 428 | 1083 if (!newdir) |
| 1084 { | |
| 1085 /* Either nm starts with /, or drive isn't mounted. */ | |
| 2367 | 1086 newdir = alloca_ibytes (4); |
| 428 | 1087 newdir[0] = DRIVE_LETTER (drive); |
| 1088 newdir[1] = ':'; | |
| 1089 newdir[2] = '/'; | |
| 1090 newdir[3] = 0; | |
| 1091 } | |
| 1092 } | |
| 657 | 1093 #endif /* WIN32_FILENAMES */ |
| 428 | 1094 |
| 1095 /* Finally, if no prefix has been specified and nm is not absolute, | |
| 1096 then it must be expanded relative to default_directory. */ | |
| 1097 | |
| 1098 if (1 | |
| 442 | 1099 #ifndef WIN32_NATIVE |
| 428 | 1100 /* /... alone is not absolute on DOS and Windows. */ |
| 1101 && !IS_DIRECTORY_SEP (nm[0]) | |
| 657 | 1102 #endif |
| 1103 #ifdef WIN32_FILENAMES | |
| 428 | 1104 && !(IS_DIRECTORY_SEP (nm[0]) && IS_DIRECTORY_SEP (nm[1])) |
| 1105 #endif | |
| 1106 && !newdir) | |
| 1107 { | |
| 1108 newdir = XSTRING_DATA (default_directory); | |
| 771 | 1109 #ifdef WIN32_FILENAMES |
| 1110 /* Note if special escape prefix is present, but remove for now. */ | |
| 1111 if (newdir[0] == '/' && newdir[1] == ':') | |
| 1112 { | |
| 1113 is_escaped = 1; | |
| 1114 newdir += 2; | |
| 1115 } | |
| 1116 #endif | |
| 428 | 1117 } |
| 1118 | |
| 657 | 1119 #ifdef WIN32_FILENAMES |
| 428 | 1120 if (newdir) |
| 1121 { | |
| 1122 /* First ensure newdir is an absolute name. */ | |
| 1123 if ( | |
| 442 | 1124 /* Detect Windows file names with drive specifiers. */ |
| 428 | 1125 ! (IS_DRIVE (newdir[0]) |
| 1126 && IS_DEVICE_SEP (newdir[1]) && IS_DIRECTORY_SEP (newdir[2])) | |
| 1127 /* Detect Windows file names in UNC format. */ | |
| 1128 && ! (IS_DIRECTORY_SEP (newdir[0]) && IS_DIRECTORY_SEP (newdir[1])) | |
| 771 | 1129 /* XEmacs: added these two lines: Detect drive spec by itself */ |
| 428 | 1130 && ! (IS_DEVICE_SEP (newdir[1]) && newdir[2] == 0) |
| 657 | 1131 /* Detect unix format. */ |
| 1132 #ifndef WIN32_NATIVE | |
| 1133 && ! (IS_DIRECTORY_SEP (newdir[0])) | |
| 1134 #endif | |
| 428 | 1135 ) |
| 1136 { | |
| 1137 /* Effectively, let newdir be (expand-file-name newdir cwd). | |
| 1138 Because of the admonition against calling expand-file-name | |
| 1139 when we have pointers into lisp strings, we accomplish this | |
| 1140 indirectly by prepending newdir to nm if necessary, and using | |
| 1141 cwd (or the wd of newdir's drive) as the new newdir. */ | |
| 1142 | |
| 1143 if (IS_DRIVE (newdir[0]) && newdir[1] == ':') | |
| 1144 { | |
| 1145 drive = newdir[0]; | |
| 1146 newdir += 2; | |
| 1147 } | |
| 1148 if (!IS_DIRECTORY_SEP (nm[0])) | |
| 1149 { | |
| 2367 | 1150 Ibyte *tmp = alloca_ibytes (qxestrlen (newdir) + |
| 1151 qxestrlen (nm) + 2); | |
| 771 | 1152 file_name_as_directory (tmp, newdir); |
| 1153 qxestrcat (tmp, nm); | |
| 428 | 1154 nm = tmp; |
| 1155 } | |
| 1156 if (drive) | |
| 1157 { | |
| 657 | 1158 #ifdef WIN32_NATIVE |
| 867 | 1159 Ibyte *newcwd = mswindows_getdcwd (toupper (drive) - 'A' + 1); |
| 771 | 1160 if (newcwd) |
| 1161 { | |
| 867 | 1162 IBYTE_STRING_TO_ALLOCA (newcwd, newdir); |
| 1726 | 1163 xfree (newcwd, Ibyte *); |
| 771 | 1164 } |
| 1165 else | |
| 657 | 1166 #endif |
| 867 | 1167 IBYTE_STRING_TO_ALLOCA ((Ibyte *) "/", newdir); |
| 428 | 1168 } |
| 1169 else | |
| 867 | 1170 IBYTE_STRING_TO_ALLOCA (get_initial_directory (0, 0), newdir); |
| 428 | 1171 } |
| 1172 | |
| 1173 /* Strip off drive name from prefix, if present. */ | |
| 1174 if (IS_DRIVE (newdir[0]) && newdir[1] == ':') | |
| 1175 { | |
| 1176 drive = newdir[0]; | |
| 1177 newdir += 2; | |
| 1178 } | |
| 1179 | |
| 1180 /* Keep only a prefix from newdir if nm starts with slash | |
| 771 | 1181 (//server/share for UNC, nothing otherwise). */ |
| 657 | 1182 if (IS_DIRECTORY_SEP (nm[0]) |
| 1183 #ifndef WIN32_NATIVE | |
| 1184 && IS_DIRECTORY_SEP (nm[1]) | |
| 1185 #endif | |
| 1186 && collapse_newdir) | |
| 428 | 1187 { |
| 1188 if (IS_DIRECTORY_SEP (newdir[0]) && IS_DIRECTORY_SEP (newdir[1])) | |
| 1189 { | |
| 2367 | 1190 /* !!#### Use ei API */ |
| 1191 newdir = qxestrcpy (alloca_ibytes (qxestrlen (newdir) + 1), | |
| 1192 newdir); | |
| 428 | 1193 p = newdir + 2; |
| 1194 while (*p && !IS_DIRECTORY_SEP (*p)) p++; | |
| 1195 p++; | |
| 1196 while (*p && !IS_DIRECTORY_SEP (*p)) p++; | |
| 1197 *p = 0; | |
| 1198 } | |
| 1199 else | |
| 867 | 1200 newdir = (Ibyte *) ""; |
| 428 | 1201 } |
| 1202 } | |
| 657 | 1203 #endif /* WIN32_FILENAMES */ |
| 428 | 1204 |
| 1205 if (newdir) | |
| 1206 { | |
| 1207 /* Get rid of any slash at the end of newdir, unless newdir is | |
| 771 | 1208 just / or // (an incomplete UNC name). */ |
| 1209 length = qxestrlen (newdir); | |
| 428 | 1210 if (length > 1 && IS_DIRECTORY_SEP (newdir[length - 1]) |
| 657 | 1211 #ifdef WIN32_FILENAMES |
| 428 | 1212 && !(length == 2 && IS_DIRECTORY_SEP (newdir[0])) |
| 1213 #endif | |
| 1214 ) | |
| 1215 { | |
| 2367 | 1216 Ibyte *temp = alloca_ibytes (length); |
| 428 | 1217 memcpy (temp, newdir, length - 1); |
| 1218 temp[length - 1] = 0; | |
| 1219 newdir = temp; | |
| 1220 } | |
| 1221 tlen = length + 1; | |
| 1222 } | |
| 1223 else | |
| 1224 tlen = 0; | |
| 1225 | |
| 1226 /* Now concatenate the directory and name to new space in the stack frame */ | |
| 771 | 1227 tlen += qxestrlen (nm) + 1; |
| 657 | 1228 #ifdef WIN32_FILENAMES |
| 771 | 1229 /* Reserve space for drive specifier and escape prefix, since either |
| 1230 or both may need to be inserted. (The Microsoft x86 compiler | |
| 428 | 1231 produces incorrect code if the following two lines are combined.) */ |
| 2367 | 1232 target = alloca_ibytes (tlen + 4); |
| 771 | 1233 target += 4; |
| 657 | 1234 #else /* not WIN32_FILENAMES */ |
| 2367 | 1235 target = alloca_ibytes (tlen); |
| 657 | 1236 #endif /* not WIN32_FILENAMES */ |
| 428 | 1237 *target = 0; |
| 1238 | |
| 1239 if (newdir) | |
| 1240 { | |
| 1241 if (nm[0] == 0 || IS_DIRECTORY_SEP (nm[0])) | |
| 771 | 1242 { |
| 1243 #ifdef WIN32_FILENAMES | |
| 1244 /* If newdir is effectively "C:/", then the drive letter will have | |
| 1245 been stripped and newdir will be "/". Concatenating with an | |
| 1246 absolute directory in nm produces "//", which will then be | |
| 1247 incorrectly treated as a network share. Ignore newdir in | |
| 1248 this case (keeping the drive letter). */ | |
| 1249 if (!(drive && nm[0] && IS_DIRECTORY_SEP (newdir[0]) | |
| 1250 && newdir[1] == '\0')) | |
| 1251 #endif | |
| 1252 qxestrcpy (target, newdir); | |
| 1253 } | |
| 428 | 1254 else |
| 771 | 1255 file_name_as_directory (target, newdir); |
| 428 | 1256 } |
| 1257 | |
| 771 | 1258 qxestrcat (target, nm); |
| 428 | 1259 |
| 1260 /* ASSERT (IS_DIRECTORY_SEP (target[0])) if not VMS */ | |
| 1261 | |
| 771 | 1262 /* Now canonicalize by removing `//', `/.' and `/foo/..' if they |
| 1263 appear. */ | |
| 428 | 1264 |
| 1265 p = target; | |
| 1266 o = target; | |
| 1267 | |
| 1268 while (*p) | |
| 1269 { | |
| 1270 if (!IS_DIRECTORY_SEP (*p)) | |
| 1271 { | |
| 1272 *o++ = *p++; | |
| 1273 } | |
| 1274 else if (IS_DIRECTORY_SEP (p[0]) | |
| 1275 && p[1] == '.' | |
| 1276 && (IS_DIRECTORY_SEP (p[2]) | |
| 1277 || p[2] == 0)) | |
| 1278 { | |
| 1279 /* If "/." is the entire filename, keep the "/". Otherwise, | |
| 1280 just delete the whole "/.". */ | |
| 1281 if (o == target && p[2] == '\0') | |
| 1282 *o++ = *p; | |
| 1283 p += 2; | |
| 1284 } | |
| 1285 else if (IS_DIRECTORY_SEP (p[0]) && p[1] == '.' && p[2] == '.' | |
| 1286 /* `/../' is the "superroot" on certain file systems. */ | |
| 1287 && o != target | |
| 1288 && (IS_DIRECTORY_SEP (p[3]) || p[3] == 0)) | |
| 1289 { | |
| 1290 while (o != target && (--o) && !IS_DIRECTORY_SEP (*o)) | |
| 1291 ; | |
| 1292 /* Keep initial / only if this is the whole name. */ | |
| 1293 if (o == target && IS_ANY_SEP (*o) && p[3] == 0) | |
| 1294 ++o; | |
| 1295 p += 3; | |
| 1296 } | |
| 771 | 1297 else if (p > target |
| 1298 && IS_DIRECTORY_SEP (p[0]) && IS_DIRECTORY_SEP (p[1])) | |
| 1299 { | |
| 1300 /* Collapse multiple `/' in a row. */ | |
| 1301 *o++ = *p++; | |
| 1302 while (IS_DIRECTORY_SEP (*p)) | |
| 1303 ++p; | |
| 1304 } | |
| 428 | 1305 else |
| 1306 { | |
| 1307 *o++ = *p++; | |
| 1308 } | |
| 1309 } | |
| 1310 | |
| 657 | 1311 #ifdef WIN32_FILENAMES |
| 428 | 1312 /* At last, set drive name, except for network file name. */ |
| 1313 if (drive) | |
| 1314 { | |
| 1315 target -= 2; | |
| 1316 target[0] = DRIVE_LETTER (drive); | |
| 1317 target[1] = ':'; | |
| 1318 } | |
| 657 | 1319 #ifdef WIN32_NATIVE |
| 428 | 1320 else |
| 1321 { | |
| 1322 assert (IS_DIRECTORY_SEP (target[0]) && IS_DIRECTORY_SEP (target[1])); | |
| 1323 } | |
| 657 | 1324 #endif |
| 771 | 1325 /* Reinsert the escape prefix if required. */ |
| 1326 if (is_escaped) | |
| 1327 { | |
| 1328 target -= 2; | |
| 1329 target[0] = '/'; | |
| 1330 target[1] = ':'; | |
| 1331 } | |
| 1332 | |
| 1333 *o = '\0'; | |
| 1334 | |
| 1335 { | |
| 867 | 1336 Ibyte *newtarget = mswindows_canonicalize_filename (target); |
| 771 | 1337 Lisp_Object result = build_intstring (newtarget); |
| 1726 | 1338 xfree (newtarget, Ibyte *); |
| 771 | 1339 |
| 2526 | 1340 RETURN_UNGCPRO_EXIT_PROFILING (QSin_expand_file_name, result); |
| 771 | 1341 } |
| 1342 #else /* not WIN32_FILENAMES */ | |
| 2526 | 1343 RETURN_UNGCPRO_EXIT_PROFILING (QSin_expand_file_name, |
| 1344 make_string (target, o - target)); | |
| 771 | 1345 #endif /* not WIN32_FILENAMES */ |
| 428 | 1346 } |
| 1347 | |
| 1348 DEFUN ("file-truename", Ffile_truename, 1, 2, 0, /* | |
| 444 | 1349 Return the canonical name of FILENAME. |
| 1350 Second arg DEFAULT is directory to start with if FILENAME is relative | |
| 428 | 1351 (does not start with slash); if DEFAULT is nil or missing, |
| 444 | 1352 the current buffer's value of `default-directory' is used. |
| 428 | 1353 No component of the resulting pathname will be a symbolic link, as |
| 1354 in the realpath() function. | |
| 1355 */ | |
| 1356 (filename, default_)) | |
| 1357 { | |
| 442 | 1358 /* This function can GC. GC checked 2000-07-28 ben. */ |
| 428 | 1359 Lisp_Object expanded_name; |
| 1360 struct gcpro gcpro1; | |
| 1361 | |
| 1362 CHECK_STRING (filename); | |
| 1363 | |
| 1364 expanded_name = Fexpand_file_name (filename, default_); | |
| 1365 | |
| 1366 if (!STRINGP (expanded_name)) | |
| 1367 return Qnil; | |
| 1368 | |
| 1369 GCPRO1 (expanded_name); | |
| 442 | 1370 |
| 1371 { | |
| 1372 Lisp_Object handler = | |
| 1373 Ffind_file_name_handler (expanded_name, Qfile_truename); | |
| 1374 | |
| 1375 if (!NILP (handler)) | |
| 1376 RETURN_UNGCPRO | |
| 1377 (call2_check_string (handler, Qfile_truename, expanded_name)); | |
| 1378 } | |
| 428 | 1379 |
| 1380 { | |
| 2421 | 1381 Ibyte resolved_path[PATH_MAX_INTERNAL]; |
| 771 | 1382 Bytecount elen = XSTRING_LENGTH (expanded_name); |
| 867 | 1383 Ibyte *path; |
| 1384 Ibyte *p; | |
| 771 | 1385 |
| 1386 LISP_STRING_TO_ALLOCA (expanded_name, path); | |
| 988 | 1387 |
| 1111 | 1388 #if defined (WIN32_FILENAMES) && defined (CYGWIN) |
| 988 | 1389 /* When using win32 filenames in cygwin we want file-truename to |
| 1390 detect that c:/windows == /windows for example. */ | |
| 1111 | 1391 if (! (IS_DIRECTORY_SEP (path[0]) && IS_DIRECTORY_SEP (path[1]))) |
| 1392 { | |
| 1393 LOCAL_TO_WIN32_FILE_FORMAT (path, p); | |
| 1394 path = p; | |
| 1395 } | |
| 988 | 1396 #endif |
| 428 | 1397 p = path; |
| 442 | 1398 |
| 428 | 1399 /* Try doing it all at once. */ |
| 2526 | 1400 if (!qxe_realpath (path, resolved_path, 0)) |
| 428 | 1401 { |
| 1402 /* Didn't resolve it -- have to do it one component at a time. */ | |
| 1403 /* "realpath" is a typically useless, stupid un*x piece of crap. | |
| 1404 It claims to return a useful value in the "error" case, but since | |
| 1405 there is no indication provided of how far along the pathname | |
| 1406 the function went before erring, there is no way to use the | |
| 442 | 1407 partial result returned. What a piece of junk. |
| 1408 | |
| 1409 The above comment refers to historical versions of | |
| 1410 realpath(). The Unix98 specs state: | |
| 1411 | |
| 1412 "On successful completion, realpath() returns a | |
| 1413 pointer to the resolved name. Otherwise, realpath() | |
| 1414 returns a null pointer and sets errno to indicate the | |
| 1415 error, and the contents of the buffer pointed to by | |
| 1416 resolved_name are undefined." | |
| 1417 | |
| 771 | 1418 Since we depend on undocumented semantics of various system |
| 2526 | 1419 realpath()s, we just use our own version in realpath.c. |
| 1420 | |
| 1421 Note also that our own version differs in its semantics from any | |
| 1422 standard version, since it accepts and returns internal-format | |
| 1423 text, not external-format. */ | |
| 428 | 1424 for (;;) |
| 1425 { | |
| 867 | 1426 Ibyte *pos; |
| 446 | 1427 |
| 657 | 1428 #ifdef WIN32_FILENAMES |
| 446 | 1429 if (IS_DRIVE (p[0]) && IS_DEVICE_SEP (p[1]) |
| 1430 && IS_DIRECTORY_SEP (p[2])) | |
| 1431 /* don't test c: on windows */ | |
| 1432 p = p+2; | |
| 1433 else if (IS_DIRECTORY_SEP (p[0]) && IS_DIRECTORY_SEP (p[1])) | |
| 1434 /* start after // */ | |
| 1435 p = p+1; | |
| 1436 #endif | |
| 1437 for (pos = p + 1; pos < path + elen; pos++) | |
| 1438 if (IS_DIRECTORY_SEP (*pos)) | |
| 1439 { | |
| 1440 *(p = pos) = 0; | |
| 1441 break; | |
| 1442 } | |
| 1443 if (p != pos) | |
| 1444 p = 0; | |
| 428 | 1445 |
| 2526 | 1446 if (qxe_realpath (path, resolved_path, 0)) |
| 428 | 1447 { |
| 1448 if (p) | |
| 446 | 1449 *p = DIRECTORY_SEP; |
| 428 | 1450 else |
| 1451 break; | |
| 1452 | |
| 1453 } | |
| 1454 else if (errno == ENOENT || errno == EACCES) | |
| 1455 { | |
| 1456 /* Failed on this component. Just tack on the rest of | |
| 1457 the string and we are done. */ | |
| 771 | 1458 int rlen = qxestrlen (resolved_path); |
| 428 | 1459 |
| 1460 /* "On failure, it returns NULL, sets errno to indicate | |
| 1461 the error, and places in resolved_path the absolute pathname | |
| 1462 of the path component which could not be resolved." */ | |
| 442 | 1463 |
| 1464 if (p) | |
| 428 | 1465 { |
| 1466 int plen = elen - (p - path); | |
| 1467 | |
| 446 | 1468 if (rlen > 1 && IS_DIRECTORY_SEP (resolved_path[rlen - 1])) |
| 428 | 1469 rlen = rlen - 1; |
| 1470 | |
| 1471 if (plen + rlen + 1 > countof (resolved_path)) | |
| 1472 goto toolong; | |
| 1473 | |
| 446 | 1474 resolved_path[rlen] = DIRECTORY_SEP; |
| 428 | 1475 memcpy (resolved_path + rlen + 1, p + 1, plen + 1 - 1); |
| 1476 } | |
| 1477 break; | |
| 1478 } | |
| 1479 else | |
| 1480 goto lose; | |
| 1481 } | |
| 1482 } | |
| 1483 | |
| 1484 { | |
| 442 | 1485 Lisp_Object resolved_name; |
| 771 | 1486 int rlen = qxestrlen (resolved_path); |
| 826 | 1487 if (elen > 0 && IS_DIRECTORY_SEP (string_byte (expanded_name, elen - 1)) |
| 446 | 1488 && !(rlen > 0 && IS_DIRECTORY_SEP (resolved_path[rlen - 1]))) |
| 428 | 1489 { |
| 1490 if (rlen + 1 > countof (resolved_path)) | |
| 1491 goto toolong; | |
| 446 | 1492 resolved_path[rlen++] = DIRECTORY_SEP; |
| 442 | 1493 resolved_path[rlen] = '\0'; |
| 428 | 1494 } |
| 771 | 1495 resolved_name = make_string (resolved_path, rlen); |
| 442 | 1496 RETURN_UNGCPRO (resolved_name); |
| 428 | 1497 } |
| 1498 | |
| 1499 toolong: | |
| 1500 errno = ENAMETOOLONG; | |
| 1501 goto lose; | |
| 1502 lose: | |
| 563 | 1503 report_file_error ("Finding truename", expanded_name); |
| 428 | 1504 } |
| 442 | 1505 RETURN_UNGCPRO (Qnil); |
| 428 | 1506 } |
| 1507 | |
| 1508 | |
| 1509 DEFUN ("substitute-in-file-name", Fsubstitute_in_file_name, 1, 1, 0, /* | |
| 1510 Substitute environment variables referred to in FILENAME. | |
| 1511 `$FOO' where FOO is an environment variable name means to substitute | |
| 1512 the value of that variable. The variable name should be terminated | |
| 444 | 1513 with a character, not a letter, digit or underscore; otherwise, enclose |
| 428 | 1514 the entire variable name in braces. |
| 1515 If `/~' appears, all of FILENAME through that `/' is discarded. | |
| 1516 */ | |
| 444 | 1517 (filename)) |
| 428 | 1518 { |
| 442 | 1519 /* This function can GC. GC checked 2000-07-28 ben. */ |
| 867 | 1520 Ibyte *nm; |
| 1521 | |
|
4324
5e526366d533
Don't error on unknown environment variables, #'substitute-in-file-name.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4266
diff
changeset
|
1522 Ibyte *s, *p, *o, *x, *endp, *got; |
| 867 | 1523 Ibyte *target = 0; |
| 428 | 1524 int total = 0; |
|
4324
5e526366d533
Don't error on unknown environment variables, #'substitute-in-file-name.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4266
diff
changeset
|
1525 int substituted = 0, seen_braces; |
| 867 | 1526 Ibyte *xnm; |
| 428 | 1527 Lisp_Object handler; |
| 1528 | |
| 444 | 1529 CHECK_STRING (filename); |
| 428 | 1530 |
| 1531 /* If the file name has special constructs in it, | |
| 1532 call the corresponding file handler. */ | |
| 444 | 1533 handler = Ffind_file_name_handler (filename, Qsubstitute_in_file_name); |
| 428 | 1534 if (!NILP (handler)) |
| 1535 return call2_check_string_or_nil (handler, Qsubstitute_in_file_name, | |
| 444 | 1536 filename); |
| 1537 | |
| 1538 nm = XSTRING_DATA (filename); | |
| 1539 endp = nm + XSTRING_LENGTH (filename); | |
| 428 | 1540 |
| 1541 /* If /~ or // appears, discard everything through first slash. */ | |
| 1542 | |
| 1543 for (p = nm; p != endp; p++) | |
| 1544 { | |
| 1545 if ((p[0] == '~' | |
| 657 | 1546 #if defined (WIN32_FILENAMES) |
| 440 | 1547 /* // at start of file name is meaningful in WindowsNT systems */ |
| 428 | 1548 || (IS_DIRECTORY_SEP (p[0]) && p - 1 != nm) |
| 657 | 1549 #else /* not (WIN32_FILENAMES) */ |
| 428 | 1550 || IS_DIRECTORY_SEP (p[0]) |
| 657 | 1551 #endif /* not (WIN32_FILENAMES) */ |
| 428 | 1552 ) |
| 1553 && p != nm | |
| 1554 && (IS_DIRECTORY_SEP (p[-1]))) | |
| 1555 { | |
| 1556 nm = p; | |
| 1557 substituted = 1; | |
| 1558 } | |
| 657 | 1559 #ifdef WIN32_FILENAMES |
| 428 | 1560 /* see comment in expand-file-name about drive specifiers */ |
| 1561 else if (IS_DRIVE (p[0]) && p[1] == ':' | |
| 1562 && p > nm && IS_DIRECTORY_SEP (p[-1])) | |
| 1563 { | |
| 1564 nm = p; | |
| 1565 substituted = 1; | |
| 1566 } | |
| 657 | 1567 #endif /* WIN32_FILENAMES */ |
| 428 | 1568 } |
| 1569 | |
| 1570 /* See if any variables are substituted into the string | |
| 1571 and find the total length of their values in `total' */ | |
| 1572 | |
| 1573 for (p = nm; p != endp;) | |
| 1574 if (*p != '$') | |
| 1575 p++; | |
| 1576 else | |
| 1577 { | |
| 1578 p++; | |
| 1579 if (p == endp) | |
|
4324
5e526366d533
Don't error on unknown environment variables, #'substitute-in-file-name.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4266
diff
changeset
|
1580 { |
|
5e526366d533
Don't error on unknown environment variables, #'substitute-in-file-name.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4266
diff
changeset
|
1581 /* No substitution, no error. */ |
|
5e526366d533
Don't error on unknown environment variables, #'substitute-in-file-name.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4266
diff
changeset
|
1582 break; |
|
5e526366d533
Don't error on unknown environment variables, #'substitute-in-file-name.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4266
diff
changeset
|
1583 } |
| 428 | 1584 else if (*p == '$') |
| 1585 { | |
| 1586 /* "$$" means a single "$" */ | |
| 1587 p++; | |
| 1588 total -= 1; | |
| 1589 substituted = 1; | |
| 1590 continue; | |
| 1591 } | |
| 1592 else if (*p == '{') | |
| 1593 { | |
| 1594 o = ++p; | |
| 1595 while (p != endp && *p != '}') p++; | |
|
4324
5e526366d533
Don't error on unknown environment variables, #'substitute-in-file-name.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4266
diff
changeset
|
1596 if (*p != '}') |
|
5e526366d533
Don't error on unknown environment variables, #'substitute-in-file-name.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4266
diff
changeset
|
1597 { |
|
5e526366d533
Don't error on unknown environment variables, #'substitute-in-file-name.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4266
diff
changeset
|
1598 /* No substitution, no error. Keep looking. */ |
|
5e526366d533
Don't error on unknown environment variables, #'substitute-in-file-name.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4266
diff
changeset
|
1599 p = o; |
|
5e526366d533
Don't error on unknown environment variables, #'substitute-in-file-name.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4266
diff
changeset
|
1600 continue; |
|
5e526366d533
Don't error on unknown environment variables, #'substitute-in-file-name.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4266
diff
changeset
|
1601 } |
| 428 | 1602 s = p; |
| 1603 } | |
| 1604 else | |
| 1605 { | |
| 1606 o = p; | |
| 1607 while (p != endp && (isalnum (*p) || *p == '_')) p++; | |
| 1608 s = p; | |
| 1609 } | |
| 1610 | |
| 1611 /* Copy out the variable name */ | |
| 2367 | 1612 target = alloca_ibytes (s - o + 1); |
| 771 | 1613 qxestrncpy (target, o, s - o); |
| 428 | 1614 target[s - o] = 0; |
| 442 | 1615 #ifdef WIN32_NATIVE |
| 1204 | 1616 qxestrupr (target); /* $home == $HOME etc. */ |
| 442 | 1617 #endif /* WIN32_NATIVE */ |
| 428 | 1618 |
| 1619 /* Get variable value */ | |
|
4324
5e526366d533
Don't error on unknown environment variables, #'substitute-in-file-name.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4266
diff
changeset
|
1620 got = egetenv ((CIbyte *) target); |
|
5e526366d533
Don't error on unknown environment variables, #'substitute-in-file-name.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4266
diff
changeset
|
1621 if (got) |
|
5e526366d533
Don't error on unknown environment variables, #'substitute-in-file-name.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4266
diff
changeset
|
1622 { |
|
5e526366d533
Don't error on unknown environment variables, #'substitute-in-file-name.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4266
diff
changeset
|
1623 total += qxestrlen (got); |
|
5e526366d533
Don't error on unknown environment variables, #'substitute-in-file-name.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4266
diff
changeset
|
1624 substituted = 1; |
|
5e526366d533
Don't error on unknown environment variables, #'substitute-in-file-name.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4266
diff
changeset
|
1625 } |
| 428 | 1626 } |
| 1627 | |
| 1628 if (!substituted) | |
| 444 | 1629 return filename; |
| 1630 | |
| 1631 /* If substitution required, recopy the filename and do it */ | |
| 428 | 1632 /* Make space in stack frame for the new copy */ |
| 2367 | 1633 xnm = alloca_ibytes (XSTRING_LENGTH (filename) + total + 1); |
| 428 | 1634 x = xnm; |
| 1635 | |
| 1636 /* Copy the rest of the name through, replacing $ constructs with values */ | |
| 1637 for (p = nm; *p;) | |
| 1638 if (*p != '$') | |
| 1639 *x++ = *p++; | |
| 1640 else | |
| 1641 { | |
| 1642 p++; | |
|
4324
5e526366d533
Don't error on unknown environment variables, #'substitute-in-file-name.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4266
diff
changeset
|
1643 seen_braces = 0; |
| 428 | 1644 if (p == endp) |
|
4324
5e526366d533
Don't error on unknown environment variables, #'substitute-in-file-name.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4266
diff
changeset
|
1645 { |
|
5e526366d533
Don't error on unknown environment variables, #'substitute-in-file-name.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4266
diff
changeset
|
1646 *x++ = '$'; |
|
5e526366d533
Don't error on unknown environment variables, #'substitute-in-file-name.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4266
diff
changeset
|
1647 break; |
|
5e526366d533
Don't error on unknown environment variables, #'substitute-in-file-name.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4266
diff
changeset
|
1648 } |
| 428 | 1649 else if (*p == '$') |
| 1650 { | |
| 1651 *x++ = *p++; | |
| 1652 continue; | |
| 1653 } | |
| 1654 else if (*p == '{') | |
| 1655 { | |
|
4324
5e526366d533
Don't error on unknown environment variables, #'substitute-in-file-name.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4266
diff
changeset
|
1656 seen_braces = 1; |
| 428 | 1657 o = ++p; |
| 1658 while (p != endp && *p != '}') p++; | |
|
4324
5e526366d533
Don't error on unknown environment variables, #'substitute-in-file-name.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4266
diff
changeset
|
1659 if (*p != '}') |
|
5e526366d533
Don't error on unknown environment variables, #'substitute-in-file-name.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4266
diff
changeset
|
1660 { |
|
5e526366d533
Don't error on unknown environment variables, #'substitute-in-file-name.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4266
diff
changeset
|
1661 /* Don't syntax error, don't substitute */ |
|
5e526366d533
Don't error on unknown environment variables, #'substitute-in-file-name.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4266
diff
changeset
|
1662 *x++ = '{'; |
|
5e526366d533
Don't error on unknown environment variables, #'substitute-in-file-name.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4266
diff
changeset
|
1663 p = o; |
|
5e526366d533
Don't error on unknown environment variables, #'substitute-in-file-name.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4266
diff
changeset
|
1664 continue; |
|
5e526366d533
Don't error on unknown environment variables, #'substitute-in-file-name.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4266
diff
changeset
|
1665 } |
| 428 | 1666 s = p++; |
| 1667 } | |
| 1668 else | |
| 1669 { | |
| 1670 o = p; | |
| 1671 while (p != endp && (isalnum (*p) || *p == '_')) p++; | |
| 1672 s = p; | |
| 1673 } | |
| 1674 | |
| 1675 /* Copy out the variable name */ | |
| 2367 | 1676 target = alloca_ibytes (s - o + 1); |
| 771 | 1677 qxestrncpy (target, o, s - o); |
| 428 | 1678 target[s - o] = 0; |
| 442 | 1679 #ifdef WIN32_NATIVE |
| 1204 | 1680 qxestrupr (target); /* $home == $HOME etc. */ |
| 442 | 1681 #endif /* WIN32_NATIVE */ |
| 428 | 1682 |
| 1683 /* Get variable value */ | |
|
4324
5e526366d533
Don't error on unknown environment variables, #'substitute-in-file-name.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4266
diff
changeset
|
1684 got = egetenv ((CIbyte *) target); |
|
5e526366d533
Don't error on unknown environment variables, #'substitute-in-file-name.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4266
diff
changeset
|
1685 if (got) |
|
5e526366d533
Don't error on unknown environment variables, #'substitute-in-file-name.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4266
diff
changeset
|
1686 { |
|
5e526366d533
Don't error on unknown environment variables, #'substitute-in-file-name.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4266
diff
changeset
|
1687 qxestrcpy (x, got); |
|
5e526366d533
Don't error on unknown environment variables, #'substitute-in-file-name.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4266
diff
changeset
|
1688 x += qxestrlen (got); |
|
5e526366d533
Don't error on unknown environment variables, #'substitute-in-file-name.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4266
diff
changeset
|
1689 } |
|
5e526366d533
Don't error on unknown environment variables, #'substitute-in-file-name.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4266
diff
changeset
|
1690 else |
|
5e526366d533
Don't error on unknown environment variables, #'substitute-in-file-name.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4266
diff
changeset
|
1691 { |
|
5e526366d533
Don't error on unknown environment variables, #'substitute-in-file-name.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4266
diff
changeset
|
1692 *x++ = '$'; |
|
5e526366d533
Don't error on unknown environment variables, #'substitute-in-file-name.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4266
diff
changeset
|
1693 if (seen_braces) |
|
5e526366d533
Don't error on unknown environment variables, #'substitute-in-file-name.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4266
diff
changeset
|
1694 { |
|
5e526366d533
Don't error on unknown environment variables, #'substitute-in-file-name.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4266
diff
changeset
|
1695 *x++ = '{'; |
|
5e526366d533
Don't error on unknown environment variables, #'substitute-in-file-name.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4266
diff
changeset
|
1696 /* Preserve the original case. */ |
|
5e526366d533
Don't error on unknown environment variables, #'substitute-in-file-name.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4266
diff
changeset
|
1697 qxestrncpy (x, o, s - o); |
|
5e526366d533
Don't error on unknown environment variables, #'substitute-in-file-name.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4266
diff
changeset
|
1698 x += s - o; |
|
5e526366d533
Don't error on unknown environment variables, #'substitute-in-file-name.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4266
diff
changeset
|
1699 *x++ = '}'; |
|
5e526366d533
Don't error on unknown environment variables, #'substitute-in-file-name.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4266
diff
changeset
|
1700 } |
|
5e526366d533
Don't error on unknown environment variables, #'substitute-in-file-name.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4266
diff
changeset
|
1701 else |
|
5e526366d533
Don't error on unknown environment variables, #'substitute-in-file-name.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4266
diff
changeset
|
1702 { |
|
5e526366d533
Don't error on unknown environment variables, #'substitute-in-file-name.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4266
diff
changeset
|
1703 /* Preserve the original case. */ |
|
5e526366d533
Don't error on unknown environment variables, #'substitute-in-file-name.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4266
diff
changeset
|
1704 qxestrncpy (x, o, s - o); |
|
5e526366d533
Don't error on unknown environment variables, #'substitute-in-file-name.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4266
diff
changeset
|
1705 x += s - o; |
|
5e526366d533
Don't error on unknown environment variables, #'substitute-in-file-name.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4266
diff
changeset
|
1706 } |
|
5e526366d533
Don't error on unknown environment variables, #'substitute-in-file-name.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4266
diff
changeset
|
1707 } |
| 428 | 1708 } |
| 1709 | |
| 1710 *x = 0; | |
| 1711 | |
| 1712 /* If /~ or // appears, discard everything through first slash. */ | |
| 1713 | |
| 1714 for (p = xnm; p != x; p++) | |
| 1715 if ((p[0] == '~' | |
| 657 | 1716 #if defined (WIN32_FILENAMES) |
| 428 | 1717 || (IS_DIRECTORY_SEP (p[0]) && p - 1 != xnm) |
| 657 | 1718 #else /* not WIN32_FILENAMES */ |
| 428 | 1719 || IS_DIRECTORY_SEP (p[0]) |
| 657 | 1720 #endif /* not WIN32_FILENAMES */ |
| 428 | 1721 ) |
| 1722 /* don't do p[-1] if that would go off the beginning --jwz */ | |
| 1723 && p != nm && p > xnm && IS_DIRECTORY_SEP (p[-1])) | |
| 1724 xnm = p; | |
| 657 | 1725 #ifdef WIN32_FILENAMES |
| 428 | 1726 else if (IS_DRIVE (p[0]) && p[1] == ':' |
| 1727 && p > nm && IS_DIRECTORY_SEP (p[-1])) | |
| 1728 xnm = p; | |
| 1729 #endif | |
| 1730 | |
| 1731 return make_string (xnm, x - xnm); | |
| 1732 } | |
| 1733 | |
| 1734 /* A slightly faster and more convenient way to get | |
| 1735 (directory-file-name (expand-file-name FOO)). */ | |
| 1736 | |
| 1737 Lisp_Object | |
| 1738 expand_and_dir_to_file (Lisp_Object filename, Lisp_Object defdir) | |
| 1739 { | |
| 442 | 1740 /* This function can call Lisp. GC checked 2000-07-28 ben */ |
| 428 | 1741 Lisp_Object abspath; |
| 1742 struct gcpro gcpro1; | |
| 1743 | |
| 1744 abspath = Fexpand_file_name (filename, defdir); | |
| 1745 GCPRO1 (abspath); | |
| 1746 /* Remove final slash, if any (unless path is root). | |
| 1747 stat behaves differently depending! */ | |
| 1748 if (XSTRING_LENGTH (abspath) > 1 | |
| 826 | 1749 && IS_DIRECTORY_SEP (string_byte (abspath, XSTRING_LENGTH (abspath) - 1)) |
| 1750 && !IS_DEVICE_SEP (string_byte (abspath, XSTRING_LENGTH (abspath) - 2))) | |
| 428 | 1751 /* We cannot take shortcuts; they might be wrong for magic file names. */ |
| 1752 abspath = Fdirectory_file_name (abspath); | |
| 1753 UNGCPRO; | |
| 1754 return abspath; | |
| 1755 } | |
| 1756 | |
| 1757 /* Signal an error if the file ABSNAME already exists. | |
| 1758 If INTERACTIVE is nonzero, ask the user whether to proceed, | |
| 1759 and bypass the error if the user says to go ahead. | |
| 1760 QUERYSTRING is a name for the action that is being considered | |
| 1761 to alter the file. | |
| 1762 *STATPTR is used to store the stat information if the file exists. | |
| 1763 If the file does not exist, STATPTR->st_mode is set to 0. */ | |
| 1764 | |
| 1765 static void | |
| 1333 | 1766 barf_or_query_if_file_exists (Lisp_Object absname, const CIbyte *querystring, |
| 428 | 1767 int interactive, struct stat *statptr) |
| 1768 { | |
| 442 | 1769 /* This function can call Lisp. GC checked 2000-07-28 ben */ |
| 428 | 1770 struct stat statbuf; |
| 1771 | |
| 1772 /* stat is a good way to tell whether the file exists, | |
| 1773 regardless of what access permissions it has. */ | |
| 771 | 1774 if (qxe_stat (XSTRING_DATA (absname), &statbuf) >= 0) |
| 428 | 1775 { |
| 1776 Lisp_Object tem; | |
| 1777 | |
| 1778 if (interactive) | |
| 1779 { | |
| 1780 Lisp_Object prompt; | |
| 1781 struct gcpro gcpro1; | |
| 1782 | |
| 771 | 1783 prompt = |
| 1784 emacs_sprintf_string | |
| 1785 (CGETTEXT ("File %s already exists; %s anyway? "), | |
| 1786 XSTRING_DATA (absname), CGETTEXT (querystring)); | |
| 428 | 1787 |
| 1788 GCPRO1 (prompt); | |
| 1789 tem = call1 (Qyes_or_no_p, prompt); | |
| 1790 UNGCPRO; | |
| 1791 } | |
| 1792 else | |
| 1793 tem = Qnil; | |
| 1794 | |
| 1795 if (NILP (tem)) | |
| 1796 Fsignal (Qfile_already_exists, | |
| 771 | 1797 list2 (build_msg_string ("File already exists"), |
| 428 | 1798 absname)); |
| 1799 if (statptr) | |
| 1800 *statptr = statbuf; | |
| 1801 } | |
| 1802 else | |
| 1803 { | |
| 1804 if (statptr) | |
| 1805 statptr->st_mode = 0; | |
| 1806 } | |
| 1807 return; | |
| 1808 } | |
| 1809 | |
| 1810 DEFUN ("copy-file", Fcopy_file, 2, 4, | |
| 1811 "fCopy file: \nFCopy %s to file: \np\nP", /* | |
| 444 | 1812 Copy FILENAME to NEWNAME. Both args must be strings. |
| 428 | 1813 Signals a `file-already-exists' error if file NEWNAME already exists, |
| 1814 unless a third argument OK-IF-ALREADY-EXISTS is supplied and non-nil. | |
| 1815 A number as third arg means request confirmation if NEWNAME already exists. | |
| 1816 This is what happens in interactive use with M-x. | |
| 1817 Fourth arg KEEP-TIME non-nil means give the new file the same | |
| 1818 last-modified time as the old one. (This works on only some systems.) | |
| 1819 A prefix arg makes KEEP-TIME non-nil. | |
| 1820 */ | |
| 1821 (filename, newname, ok_if_already_exists, keep_time)) | |
| 1822 { | |
| 442 | 1823 /* This function can call Lisp. GC checked 2000-07-28 ben */ |
| 428 | 1824 int ifd, ofd, n; |
| 1825 char buf[16 * 1024]; | |
| 1826 struct stat st, out_st; | |
| 1827 Lisp_Object handler; | |
| 1828 int speccount = specpdl_depth (); | |
| 1829 struct gcpro gcpro1, gcpro2; | |
| 1830 /* Lisp_Object args[6]; */ | |
| 1831 int input_file_statable_p; | |
| 1832 | |
| 1833 GCPRO2 (filename, newname); | |
| 1834 CHECK_STRING (filename); | |
| 1835 CHECK_STRING (newname); | |
| 1836 filename = Fexpand_file_name (filename, Qnil); | |
| 1837 newname = Fexpand_file_name (newname, Qnil); | |
| 1838 | |
| 1839 /* If the input file name has special constructs in it, | |
| 1840 call the corresponding file handler. */ | |
| 1841 handler = Ffind_file_name_handler (filename, Qcopy_file); | |
| 1842 /* Likewise for output file name. */ | |
| 1843 if (NILP (handler)) | |
| 1844 handler = Ffind_file_name_handler (newname, Qcopy_file); | |
| 1845 if (!NILP (handler)) | |
| 1846 { | |
| 1847 UNGCPRO; | |
| 1848 return call5 (handler, Qcopy_file, filename, newname, | |
| 1849 ok_if_already_exists, keep_time); | |
| 1850 } | |
| 1851 | |
| 1852 /* When second argument is a directory, copy the file into it. | |
| 1853 (copy-file "foo" "bar/") == (copy-file "foo" "bar/foo") | |
| 1854 */ | |
| 1855 if (!NILP (Ffile_directory_p (newname))) | |
| 1856 { | |
| 1857 Lisp_Object args[3]; | |
| 1858 struct gcpro ngcpro1; | |
| 1859 int i = 1; | |
| 1860 | |
| 1861 args[0] = newname; | |
| 1862 args[1] = Qnil; args[2] = Qnil; | |
| 1863 NGCPRO1 (*args); | |
| 1864 ngcpro1.nvars = 3; | |
| 826 | 1865 if (!IS_DIRECTORY_SEP (string_byte (newname, |
| 442 | 1866 XSTRING_LENGTH (newname) - 1))) |
| 1867 | |
| 1868 args[i++] = Fchar_to_string (Vdirectory_sep_char); | |
| 428 | 1869 args[i++] = Ffile_name_nondirectory (filename); |
| 1870 newname = Fconcat (i, args); | |
| 1871 NUNGCPRO; | |
| 1872 } | |
| 1873 | |
| 1874 if (NILP (ok_if_already_exists) | |
| 1875 || INTP (ok_if_already_exists)) | |
| 1876 barf_or_query_if_file_exists (newname, "copy to it", | |
| 1877 INTP (ok_if_already_exists), &out_st); | |
| 771 | 1878 else if (qxe_stat (XSTRING_DATA (newname), &out_st) < 0) |
| 428 | 1879 out_st.st_mode = 0; |
| 1880 | |
| 771 | 1881 ifd = qxe_interruptible_open (XSTRING_DATA (filename), |
| 1882 O_RDONLY | OPEN_BINARY, 0); | |
| 428 | 1883 if (ifd < 0) |
| 563 | 1884 report_file_error ("Opening input file", filename); |
| 428 | 1885 |
| 1886 record_unwind_protect (close_file_unwind, make_int (ifd)); | |
| 1887 | |
| 1888 /* We can only copy regular files and symbolic links. Other files are not | |
| 1889 copyable by us. */ | |
| 771 | 1890 input_file_statable_p = (qxe_fstat (ifd, &st) >= 0); |
| 428 | 1891 |
| 442 | 1892 #ifndef WIN32_NATIVE |
| 428 | 1893 if (out_st.st_mode != 0 |
| 1894 && st.st_dev == out_st.st_dev && st.st_ino == out_st.st_ino) | |
| 1895 { | |
| 1896 errno = 0; | |
| 1897 report_file_error ("Input and output files are the same", | |
| 563 | 1898 list3 (Qunbound, filename, newname)); |
| 428 | 1899 } |
| 1900 #endif | |
| 1901 | |
| 1902 #if defined (S_ISREG) && defined (S_ISLNK) | |
| 1903 if (input_file_statable_p) | |
| 1904 { | |
| 1905 if (!(S_ISREG (st.st_mode)) | |
| 1906 /* XEmacs: have to allow S_ISCHR in order to copy /dev/null */ | |
| 1907 #ifdef S_ISCHR | |
| 1908 && !(S_ISCHR (st.st_mode)) | |
| 1909 #endif | |
| 1910 && !(S_ISLNK (st.st_mode))) | |
| 1911 { | |
| 1912 #if defined (EISDIR) | |
| 1913 /* Get a better looking error message. */ | |
| 1914 errno = EISDIR; | |
| 1915 #endif /* EISDIR */ | |
| 563 | 1916 report_file_error ("Non-regular file", filename); |
| 428 | 1917 } |
| 1918 } | |
| 1919 #endif /* S_ISREG && S_ISLNK */ | |
| 1920 | |
| 771 | 1921 ofd = qxe_open (XSTRING_DATA (newname), |
| 1922 O_WRONLY | O_CREAT | O_TRUNC | OPEN_BINARY, CREAT_MODE); | |
| 428 | 1923 if (ofd < 0) |
| 563 | 1924 report_file_error ("Opening output file", newname); |
| 428 | 1925 |
| 1926 { | |
| 1927 Lisp_Object ofd_locative = noseeum_cons (make_int (ofd), Qnil); | |
| 1928 | |
| 1929 record_unwind_protect (close_file_unwind, ofd_locative); | |
| 1930 | |
| 1931 while ((n = read_allowing_quit (ifd, buf, sizeof (buf))) > 0) | |
| 1932 { | |
| 1933 if (write_allowing_quit (ofd, buf, n) != n) | |
| 563 | 1934 report_file_error ("I/O error", newname); |
| 428 | 1935 } |
| 1936 | |
| 1937 /* Closing the output clobbers the file times on some systems. */ | |
| 771 | 1938 if (retry_close (ofd) < 0) |
| 563 | 1939 report_file_error ("I/O error", newname); |
| 428 | 1940 |
| 1941 if (input_file_statable_p) | |
| 1942 { | |
| 442 | 1943 if (!NILP (keep_time)) |
| 1944 { | |
| 1945 EMACS_TIME atime, mtime; | |
| 1946 EMACS_SET_SECS_USECS (atime, st.st_atime, 0); | |
| 1947 EMACS_SET_SECS_USECS (mtime, st.st_mtime, 0); | |
| 592 | 1948 if (set_file_times (newname, atime, mtime)) |
| 1949 report_file_error ("I/O error", list1 (newname)); | |
| 442 | 1950 } |
| 771 | 1951 qxe_chmod (XSTRING_DATA (newname), st.st_mode & 07777); |
| 428 | 1952 } |
| 1953 | |
| 1954 /* We'll close it by hand */ | |
| 1955 XCAR (ofd_locative) = Qnil; | |
| 1956 | |
| 1957 /* Close ifd */ | |
| 771 | 1958 unbind_to (speccount); |
| 428 | 1959 } |
| 1960 | |
| 1961 UNGCPRO; | |
| 1962 return Qnil; | |
| 1963 } | |
| 1964 | |
| 1965 DEFUN ("make-directory-internal", Fmake_directory_internal, 1, 1, 0, /* | |
| 1966 Create a directory. One argument, a file name string. | |
| 1967 */ | |
| 1968 (dirname_)) | |
| 1969 { | |
| 1970 /* This function can GC. GC checked 1997.04.06. */ | |
| 1971 Lisp_Object handler; | |
| 1972 struct gcpro gcpro1; | |
| 771 | 1973 DECLARE_EISTRING (dir); |
| 428 | 1974 |
| 1975 CHECK_STRING (dirname_); | |
| 1976 dirname_ = Fexpand_file_name (dirname_, Qnil); | |
| 1977 | |
| 1978 GCPRO1 (dirname_); | |
| 1979 handler = Ffind_file_name_handler (dirname_, Qmake_directory_internal); | |
| 1980 UNGCPRO; | |
| 1981 if (!NILP (handler)) | |
| 1982 return (call2 (handler, Qmake_directory_internal, dirname_)); | |
| 1983 | |
| 771 | 1984 eicpy_lstr (dir, dirname_); |
| 1985 if (eigetch_char (dir, eicharlen (dir) - 1) == '/') | |
| 1986 eidel (dir, eilen (dir) - 1, -1, 1, -1); | |
| 1987 | |
| 1988 if (qxe_mkdir (eidata (dir), 0777) != 0) | |
| 563 | 1989 report_file_error ("Creating directory", dirname_); |
| 428 | 1990 |
| 1991 return Qnil; | |
| 1992 } | |
| 1993 | |
| 1994 DEFUN ("delete-directory", Fdelete_directory, 1, 1, "FDelete directory: ", /* | |
| 1995 Delete a directory. One argument, a file name or directory name string. | |
| 1996 */ | |
| 1997 (dirname_)) | |
| 1998 { | |
| 1999 /* This function can GC. GC checked 1997.04.06. */ | |
| 2000 Lisp_Object handler; | |
| 2001 struct gcpro gcpro1; | |
| 2002 | |
| 2003 CHECK_STRING (dirname_); | |
| 2004 | |
| 2005 GCPRO1 (dirname_); | |
| 2006 dirname_ = Fexpand_file_name (dirname_, Qnil); | |
| 2007 dirname_ = Fdirectory_file_name (dirname_); | |
| 2008 | |
| 2009 handler = Ffind_file_name_handler (dirname_, Qdelete_directory); | |
| 2010 UNGCPRO; | |
| 2011 if (!NILP (handler)) | |
| 2012 return (call2 (handler, Qdelete_directory, dirname_)); | |
| 2013 | |
| 771 | 2014 if (qxe_rmdir (XSTRING_DATA (dirname_)) != 0) |
| 563 | 2015 report_file_error ("Removing directory", dirname_); |
| 428 | 2016 |
| 2017 return Qnil; | |
| 2018 } | |
| 2019 | |
| 2020 DEFUN ("delete-file", Fdelete_file, 1, 1, "fDelete file: ", /* | |
| 442 | 2021 Delete the file named FILENAME (a string). |
| 2022 If FILENAME has multiple names, it continues to exist with the other names. | |
| 428 | 2023 */ |
| 2024 (filename)) | |
| 2025 { | |
| 2026 /* This function can GC. GC checked 1997.04.06. */ | |
| 2027 Lisp_Object handler; | |
| 2028 struct gcpro gcpro1; | |
| 2029 | |
| 2030 CHECK_STRING (filename); | |
| 2031 filename = Fexpand_file_name (filename, Qnil); | |
| 2032 | |
| 2033 GCPRO1 (filename); | |
| 2034 handler = Ffind_file_name_handler (filename, Qdelete_file); | |
| 2035 UNGCPRO; | |
| 2036 if (!NILP (handler)) | |
| 2037 return call2 (handler, Qdelete_file, filename); | |
| 2038 | |
| 771 | 2039 if (0 > qxe_unlink (XSTRING_DATA (filename))) |
| 563 | 2040 report_file_error ("Removing old name", filename); |
| 428 | 2041 return Qnil; |
| 2042 } | |
| 2043 | |
| 2044 static Lisp_Object | |
| 2286 | 2045 internal_delete_file_1 (Lisp_Object UNUSED (ignore), |
| 2046 Lisp_Object UNUSED (ignore2)) | |
| 428 | 2047 { |
| 2048 return Qt; | |
| 2049 } | |
| 2050 | |
| 2051 /* Delete file FILENAME, returning 1 if successful and 0 if failed. */ | |
| 2052 | |
| 2053 int | |
| 2054 internal_delete_file (Lisp_Object filename) | |
| 2055 { | |
| 2056 /* This function can GC. GC checked 1997.04.06. */ | |
| 2057 return NILP (condition_case_1 (Qt, Fdelete_file, filename, | |
| 2058 internal_delete_file_1, Qnil)); | |
| 2059 } | |
| 2060 | |
| 2061 DEFUN ("rename-file", Frename_file, 2, 3, | |
| 2062 "fRename file: \nFRename %s to file: \np", /* | |
| 444 | 2063 Rename FILENAME as NEWNAME. Both args must be strings. |
| 2064 If file has names other than FILENAME, it continues to have those names. | |
| 428 | 2065 Signals a `file-already-exists' error if a file NEWNAME already exists |
| 2066 unless optional third argument OK-IF-ALREADY-EXISTS is non-nil. | |
| 2067 A number as third arg means request confirmation if NEWNAME already exists. | |
| 2068 This is what happens in interactive use with M-x. | |
| 2069 */ | |
| 2070 (filename, newname, ok_if_already_exists)) | |
| 2071 { | |
| 2072 /* This function can GC. GC checked 1997.04.06. */ | |
| 2073 Lisp_Object handler; | |
| 2074 struct gcpro gcpro1, gcpro2; | |
| 2075 | |
| 2076 GCPRO2 (filename, newname); | |
| 2077 CHECK_STRING (filename); | |
| 2078 CHECK_STRING (newname); | |
| 2079 filename = Fexpand_file_name (filename, Qnil); | |
| 2080 newname = Fexpand_file_name (newname, Qnil); | |
| 2081 | |
| 2082 /* If the file name has special constructs in it, | |
| 2083 call the corresponding file handler. */ | |
| 2084 handler = Ffind_file_name_handler (filename, Qrename_file); | |
| 2085 if (NILP (handler)) | |
| 2086 handler = Ffind_file_name_handler (newname, Qrename_file); | |
| 2087 if (!NILP (handler)) | |
| 2088 { | |
| 2089 UNGCPRO; | |
| 2090 return call4 (handler, Qrename_file, | |
| 2091 filename, newname, ok_if_already_exists); | |
| 2092 } | |
| 2093 | |
| 2094 /* When second argument is a directory, rename the file into it. | |
| 2095 (rename-file "foo" "bar/") == (rename-file "foo" "bar/foo") | |
| 2096 */ | |
| 2097 if (!NILP (Ffile_directory_p (newname))) | |
| 2098 { | |
| 2099 Lisp_Object args[3]; | |
| 2100 struct gcpro ngcpro1; | |
| 2101 int i = 1; | |
| 2102 | |
| 2103 args[0] = newname; | |
| 2104 args[1] = Qnil; args[2] = Qnil; | |
| 2105 NGCPRO1 (*args); | |
| 2106 ngcpro1.nvars = 3; | |
| 826 | 2107 if (string_byte (newname, XSTRING_LENGTH (newname) - 1) != '/') |
| 428 | 2108 args[i++] = build_string ("/"); |
| 2109 args[i++] = Ffile_name_nondirectory (filename); | |
| 2110 newname = Fconcat (i, args); | |
| 2111 NUNGCPRO; | |
| 2112 } | |
| 2113 | |
| 2114 if (NILP (ok_if_already_exists) | |
| 2115 || INTP (ok_if_already_exists)) | |
| 2116 barf_or_query_if_file_exists (newname, "rename to it", | |
| 2117 INTP (ok_if_already_exists), 0); | |
| 2118 | |
| 442 | 2119 /* We have configure check for rename() and emulate using |
| 2120 link()/unlink() if necessary. */ | |
| 771 | 2121 if (0 > qxe_rename (XSTRING_DATA (filename), XSTRING_DATA (newname))) |
| 428 | 2122 { |
| 2123 if (errno == EXDEV) | |
| 2124 { | |
| 2125 Fcopy_file (filename, newname, | |
| 2126 /* We have already prompted if it was an integer, | |
| 2127 so don't have copy-file prompt again. */ | |
| 2128 (NILP (ok_if_already_exists) ? Qnil : Qt), | |
| 2129 Qt); | |
| 2130 Fdelete_file (filename); | |
| 2131 } | |
| 2132 else | |
| 2133 { | |
| 563 | 2134 report_file_error ("Renaming", list3 (Qunbound, filename, newname)); |
| 428 | 2135 } |
| 2136 } | |
| 2137 UNGCPRO; | |
| 2138 return Qnil; | |
| 2139 } | |
| 2140 | |
| 2141 DEFUN ("add-name-to-file", Fadd_name_to_file, 2, 3, | |
| 2142 "fAdd name to file: \nFName to add to %s: \np", /* | |
| 444 | 2143 Give FILENAME additional name NEWNAME. Both args must be strings. |
| 428 | 2144 Signals a `file-already-exists' error if a file NEWNAME already exists |
| 2145 unless optional third argument OK-IF-ALREADY-EXISTS is non-nil. | |
| 2146 A number as third arg means request confirmation if NEWNAME already exists. | |
| 2147 This is what happens in interactive use with M-x. | |
| 2148 */ | |
| 2149 (filename, newname, ok_if_already_exists)) | |
| 2150 { | |
| 2151 /* This function can GC. GC checked 1997.04.06. */ | |
| 2152 Lisp_Object handler; | |
| 2153 struct gcpro gcpro1, gcpro2; | |
| 2154 | |
| 2155 GCPRO2 (filename, newname); | |
| 2156 CHECK_STRING (filename); | |
| 2157 CHECK_STRING (newname); | |
| 2158 filename = Fexpand_file_name (filename, Qnil); | |
| 2159 newname = Fexpand_file_name (newname, Qnil); | |
| 2160 | |
| 2161 /* If the file name has special constructs in it, | |
| 2162 call the corresponding file handler. */ | |
| 2163 handler = Ffind_file_name_handler (filename, Qadd_name_to_file); | |
| 2164 if (!NILP (handler)) | |
| 2165 RETURN_UNGCPRO (call4 (handler, Qadd_name_to_file, filename, | |
| 2166 newname, ok_if_already_exists)); | |
| 2167 | |
| 2168 /* If the new name has special constructs in it, | |
| 2169 call the corresponding file handler. */ | |
| 2170 handler = Ffind_file_name_handler (newname, Qadd_name_to_file); | |
| 2171 if (!NILP (handler)) | |
| 2172 RETURN_UNGCPRO (call4 (handler, Qadd_name_to_file, filename, | |
| 2173 newname, ok_if_already_exists)); | |
| 2174 | |
| 2175 if (NILP (ok_if_already_exists) | |
| 2176 || INTP (ok_if_already_exists)) | |
| 2177 barf_or_query_if_file_exists (newname, "make it a new name", | |
| 2178 INTP (ok_if_already_exists), 0); | |
| 771 | 2179 /* #### Emacs 20.6 contains an implementation of link() in w32.c. |
| 2180 Need to port. */ | |
| 2181 #ifndef HAVE_LINK | |
| 563 | 2182 signal_error_2 (Qunimplemented, "Adding new name", filename, newname); |
| 771 | 2183 #else /* HAVE_LINK */ |
| 2184 qxe_unlink (XSTRING_DATA (newname)); | |
| 2185 if (0 > qxe_link (XSTRING_DATA (filename), XSTRING_DATA (newname))) | |
| 428 | 2186 { |
| 2187 report_file_error ("Adding new name", | |
| 563 | 2188 list3 (Qunbound, filename, newname)); |
| 428 | 2189 } |
| 771 | 2190 #endif /* HAVE_LINK */ |
| 428 | 2191 |
| 2192 UNGCPRO; | |
| 2193 return Qnil; | |
| 2194 } | |
| 2195 | |
| 2196 DEFUN ("make-symbolic-link", Fmake_symbolic_link, 2, 3, | |
| 2197 "FMake symbolic link to file: \nFMake symbolic link to file %s: \np", /* | |
| 2198 Make a symbolic link to FILENAME, named LINKNAME. Both args strings. | |
| 2199 Signals a `file-already-exists' error if a file LINKNAME already exists | |
| 2200 unless optional third argument OK-IF-ALREADY-EXISTS is non-nil. | |
| 2201 A number as third arg means request confirmation if LINKNAME already exists. | |
| 2202 This happens for interactive use with M-x. | |
|
4465
732b87cfabf2
Document Win32 symlink behaviour; adjust tests to take it into a/c.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4383
diff
changeset
|
2203 |
|
732b87cfabf2
Document Win32 symlink behaviour; adjust tests to take it into a/c.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4383
diff
changeset
|
2204 On platforms where symbolic links are not available, any file handlers will |
|
732b87cfabf2
Document Win32 symlink behaviour; adjust tests to take it into a/c.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4383
diff
changeset
|
2205 be run, but the check for the existence of LINKNAME will not be done, and |
|
732b87cfabf2
Document Win32 symlink behaviour; adjust tests to take it into a/c.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4383
diff
changeset
|
2206 the symbolic link will not be created. |
| 428 | 2207 */ |
| 2208 (filename, linkname, ok_if_already_exists)) | |
| 2209 { | |
| 2210 /* This function can GC. GC checked 1997.06.04. */ | |
| 442 | 2211 /* XEmacs change: run handlers even if local machine doesn't have symlinks */ |
| 428 | 2212 Lisp_Object handler; |
| 2213 struct gcpro gcpro1, gcpro2; | |
| 2214 | |
| 2215 GCPRO2 (filename, linkname); | |
| 2216 CHECK_STRING (filename); | |
| 2217 CHECK_STRING (linkname); | |
| 2218 /* If the link target has a ~, we must expand it to get | |
| 2219 a truly valid file name. Otherwise, do not expand; | |
| 2220 we want to permit links to relative file names. */ | |
| 826 | 2221 if (string_byte (filename, 0) == '~') |
| 428 | 2222 filename = Fexpand_file_name (filename, Qnil); |
| 2223 linkname = Fexpand_file_name (linkname, Qnil); | |
| 2224 | |
| 2225 /* If the file name has special constructs in it, | |
| 2226 call the corresponding file handler. */ | |
| 2227 handler = Ffind_file_name_handler (filename, Qmake_symbolic_link); | |
| 2228 if (!NILP (handler)) | |
| 2229 RETURN_UNGCPRO (call4 (handler, Qmake_symbolic_link, filename, linkname, | |
| 2230 ok_if_already_exists)); | |
| 2231 | |
| 2232 /* If the new link name has special constructs in it, | |
| 2233 call the corresponding file handler. */ | |
| 2234 handler = Ffind_file_name_handler (linkname, Qmake_symbolic_link); | |
| 2235 if (!NILP (handler)) | |
| 2236 RETURN_UNGCPRO (call4 (handler, Qmake_symbolic_link, filename, | |
| 2237 linkname, ok_if_already_exists)); | |
| 2238 | |
| 771 | 2239 #ifdef HAVE_SYMLINK |
| 428 | 2240 if (NILP (ok_if_already_exists) |
| 2241 || INTP (ok_if_already_exists)) | |
| 2242 barf_or_query_if_file_exists (linkname, "make it a link", | |
| 2243 INTP (ok_if_already_exists), 0); | |
| 2244 | |
| 771 | 2245 qxe_unlink (XSTRING_DATA (linkname)); |
| 2246 if (0 > qxe_symlink (XSTRING_DATA (filename), | |
| 2247 XSTRING_DATA (linkname))) | |
| 428 | 2248 { |
| 2249 report_file_error ("Making symbolic link", | |
| 563 | 2250 list3 (Qunbound, filename, linkname)); |
| 428 | 2251 } |
| 771 | 2252 #endif |
| 442 | 2253 |
| 428 | 2254 UNGCPRO; |
| 2255 return Qnil; | |
| 2256 } | |
| 2257 | |
| 2258 #ifdef HPUX_NET | |
| 2259 | |
| 2260 DEFUN ("sysnetunam", Fsysnetunam, 2, 2, 0, /* | |
| 2261 Open a network connection to PATH using LOGIN as the login string. | |
| 2262 */ | |
| 2263 (path, login)) | |
| 2264 { | |
| 2265 int netresult; | |
| 1333 | 2266 const Extbyte *path_ext; |
| 2267 const Extbyte *login_ext; | |
| 428 | 2268 |
| 2269 CHECK_STRING (path); | |
| 2270 CHECK_STRING (login); | |
| 2271 | |
| 2272 /* netunam, being a strange-o system call only used once, is not | |
| 2273 encapsulated. */ | |
| 440 | 2274 |
| 442 | 2275 LISP_STRING_TO_EXTERNAL (path, path_ext, Qfile_name); |
| 2276 LISP_STRING_TO_EXTERNAL (login, login_ext, Qnative); | |
| 440 | 2277 |
| 2278 netresult = netunam (path_ext, login_ext); | |
| 2279 | |
| 2280 return netresult == -1 ? Qnil : Qt; | |
| 428 | 2281 } |
| 2282 #endif /* HPUX_NET */ | |
| 2283 | |
| 2284 DEFUN ("file-name-absolute-p", Ffile_name_absolute_p, 1, 1, 0, /* | |
| 2285 Return t if file FILENAME specifies an absolute path name. | |
| 2286 On Unix, this is a name starting with a `/' or a `~'. | |
| 2287 */ | |
| 2288 (filename)) | |
| 2289 { | |
| 2290 /* This function does not GC */ | |
| 867 | 2291 Ibyte *ptr; |
| 428 | 2292 |
| 2293 CHECK_STRING (filename); | |
| 2294 ptr = XSTRING_DATA (filename); | |
| 2295 return (IS_DIRECTORY_SEP (*ptr) || *ptr == '~' | |
| 657 | 2296 #ifdef WIN32_FILENAMES |
| 428 | 2297 || (IS_DRIVE (*ptr) && ptr[1] == ':' && IS_DIRECTORY_SEP (ptr[2])) |
| 2298 #endif | |
| 2299 ) ? Qt : Qnil; | |
| 2300 } | |
| 2301 | |
| 2302 /* Return nonzero if file FILENAME exists and can be executed. */ | |
| 2303 | |
| 2304 static int | |
| 771 | 2305 check_executable (Lisp_Object filename) |
| 428 | 2306 { |
| 442 | 2307 #ifdef WIN32_NATIVE |
| 428 | 2308 struct stat st; |
| 771 | 2309 if (qxe_stat (XSTRING_DATA (filename), &st) < 0) |
| 428 | 2310 return 0; |
| 2311 return ((st.st_mode & S_IEXEC) != 0); | |
| 442 | 2312 #else /* not WIN32_NATIVE */ |
| 428 | 2313 #ifdef HAVE_EACCESS |
| 771 | 2314 return qxe_eaccess (XSTRING_DATA (filename), X_OK) >= 0; |
| 428 | 2315 #else |
| 2316 /* Access isn't quite right because it uses the real uid | |
| 2317 and we really want to test with the effective uid. | |
| 2318 But Unix doesn't give us a right way to do it. */ | |
| 771 | 2319 return qxe_access (XSTRING_DATA (filename), X_OK) >= 0; |
| 428 | 2320 #endif /* HAVE_EACCESS */ |
| 442 | 2321 #endif /* not WIN32_NATIVE */ |
| 428 | 2322 } |
| 2323 | |
| 2324 /* Return nonzero if file FILENAME exists and can be written. */ | |
| 2325 | |
| 2326 static int | |
| 867 | 2327 check_writable (const Ibyte *filename) |
| 428 | 2328 { |
| 3728 | 2329 #if defined(WIN32_NATIVE) || defined(CYGWIN) |
| 2330 #ifdef CYGWIN | |
| 2331 char filename_buffer[PATH_MAX]; | |
| 2332 #endif | |
| 2333 // Since this has to work for a directory, we can't just call 'CreateFile' | |
| 2334 PSECURITY_DESCRIPTOR pDesc; /* Must be freed with LocalFree */ | |
| 2335 /* these need not be freed, they point into pDesc */ | |
| 2336 PSID psidOwner; | |
| 2337 PSID psidGroup; | |
| 2338 PACL pDacl; | |
| 2339 PACL pSacl; | |
| 2340 /* end of insides of descriptor */ | |
| 2341 DWORD error; | |
| 2342 DWORD attributes; | |
| 2343 HANDLE tokenHandle; | |
| 2344 GENERIC_MAPPING genericMapping; | |
| 2345 DWORD accessMask; | |
| 2346 PRIVILEGE_SET PrivilegeSet; | |
| 2347 DWORD dwPrivSetSize = sizeof( PRIVILEGE_SET ); | |
| 2348 BOOL fAccessGranted = FALSE; | |
| 3781 | 2349 DWORD dwAccessAllowed; |
| 2350 Extbyte *fnameext; | |
| 3728 | 2351 |
| 2352 #ifdef CYGWIN | |
| 2353 cygwin_conv_to_full_win32_path(filename, filename_buffer); | |
| 2354 filename = (Ibyte*)filename_buffer; | |
| 2355 #endif | |
| 2356 | |
| 2357 C_STRING_TO_TSTR(filename, fnameext); | |
| 3781 | 2358 |
| 2359 // First check for a normal file with the old-style readonly bit | |
| 2360 attributes = qxeGetFileAttributes(fnameext); | |
| 2361 if (FILE_ATTRIBUTE_READONLY == (attributes & (FILE_ATTRIBUTE_DIRECTORY|FILE_ATTRIBUTE_READONLY))) | |
| 2362 return 0; | |
| 2363 | |
| 3728 | 2364 /* Win32 prototype lacks const. */ |
| 2365 error = qxeGetNamedSecurityInfo(fnameext, SE_FILE_OBJECT, | |
| 3781 | 2366 DACL_SECURITY_INFORMATION|GROUP_SECURITY_INFORMATION|OWNER_SECURITY_INFORMATION, |
| 2367 &psidOwner, &psidGroup, &pDacl, &pSacl, &pDesc); | |
| 3728 | 2368 if(error != ERROR_SUCCESS) { // FAT? |
| 3781 | 2369 attributes = qxeGetFileAttributes(fnameext); |
| 3728 | 2370 return (attributes & FILE_ATTRIBUTE_DIRECTORY) || (0 == (attributes & FILE_ATTRIBUTE_READONLY)); |
| 2371 } | |
| 2372 | |
| 2373 genericMapping.GenericRead = FILE_GENERIC_READ; | |
| 2374 genericMapping.GenericWrite = FILE_GENERIC_WRITE; | |
| 2375 genericMapping.GenericExecute = FILE_GENERIC_EXECUTE; | |
| 2376 genericMapping.GenericAll = FILE_ALL_ACCESS; | |
| 2377 | |
| 2378 if(!ImpersonateSelf(SecurityDelegation)) { | |
| 2379 return 0; | |
| 2380 } | |
| 2381 if(!OpenThreadToken(GetCurrentThread(), TOKEN_ALL_ACCESS, TRUE, &tokenHandle)) { | |
| 2382 return 0; | |
| 2383 } | |
| 2384 | |
| 2385 accessMask = GENERIC_WRITE; | |
| 2386 MapGenericMask(&accessMask, &genericMapping); | |
| 2387 | |
| 2388 if(!AccessCheck(pDesc, tokenHandle, accessMask, &genericMapping, | |
| 2389 &PrivilegeSet, // receives privileges used in check | |
| 2390 &dwPrivSetSize, // size of PrivilegeSet buffer | |
| 2391 &dwAccessAllowed, // receives mask of allowed access rights | |
| 2392 &fAccessGranted)) | |
| 2393 { | |
| 2394 CloseHandle(tokenHandle); | |
| 2395 RevertToSelf(); | |
| 2396 LocalFree(pDesc); | |
| 2397 return 0; | |
| 2398 } | |
| 2399 CloseHandle(tokenHandle); | |
| 2400 RevertToSelf(); | |
| 2401 LocalFree(pDesc); | |
| 2402 return fAccessGranted == TRUE; | |
| 2403 #else | |
| 428 | 2404 #ifdef HAVE_EACCESS |
| 771 | 2405 return (qxe_eaccess (filename, W_OK) >= 0); |
| 428 | 2406 #else |
| 2407 /* Access isn't quite right because it uses the real uid | |
| 2408 and we really want to test with the effective uid. | |
| 2409 But Unix doesn't give us a right way to do it. | |
| 2410 Opening with O_WRONLY could work for an ordinary file, | |
| 2411 but would lose for directories. */ | |
| 771 | 2412 return (qxe_access (filename, W_OK) >= 0); |
| 428 | 2413 #endif |
| 3728 | 2414 #endif |
| 428 | 2415 } |
| 2416 | |
| 2417 DEFUN ("file-exists-p", Ffile_exists_p, 1, 1, 0, /* | |
| 2418 Return t if file FILENAME exists. (This does not mean you can read it.) | |
| 2419 See also `file-readable-p' and `file-attributes'. | |
| 2420 */ | |
| 2421 (filename)) | |
| 2422 { | |
| 442 | 2423 /* This function can call lisp; GC checked 2000-07-11 ben */ |
| 428 | 2424 Lisp_Object abspath; |
| 2425 Lisp_Object handler; | |
| 2426 struct stat statbuf; | |
| 2427 struct gcpro gcpro1; | |
| 2428 | |
| 2429 CHECK_STRING (filename); | |
| 2430 abspath = Fexpand_file_name (filename, Qnil); | |
| 2431 | |
| 2432 /* If the file name has special constructs in it, | |
| 2433 call the corresponding file handler. */ | |
| 2434 GCPRO1 (abspath); | |
| 2435 handler = Ffind_file_name_handler (abspath, Qfile_exists_p); | |
| 2436 UNGCPRO; | |
| 2437 if (!NILP (handler)) | |
| 2438 return call2 (handler, Qfile_exists_p, abspath); | |
| 2439 | |
| 771 | 2440 return qxe_stat (XSTRING_DATA (abspath), &statbuf) >= 0 ? Qt : Qnil; |
| 428 | 2441 } |
| 2442 | |
| 2443 DEFUN ("file-executable-p", Ffile_executable_p, 1, 1, 0, /* | |
| 2444 Return t if FILENAME can be executed by you. | |
| 2445 For a directory, this means you can access files in that directory. | |
| 2446 */ | |
| 2447 (filename)) | |
| 2448 | |
| 2449 { | |
| 442 | 2450 /* This function can GC. GC checked 07-11-2000 ben. */ |
| 428 | 2451 Lisp_Object abspath; |
| 2452 Lisp_Object handler; | |
| 2453 struct gcpro gcpro1; | |
| 2454 | |
| 2455 CHECK_STRING (filename); | |
| 2456 abspath = Fexpand_file_name (filename, Qnil); | |
| 2457 | |
| 2458 /* If the file name has special constructs in it, | |
| 2459 call the corresponding file handler. */ | |
| 2460 GCPRO1 (abspath); | |
| 2461 handler = Ffind_file_name_handler (abspath, Qfile_executable_p); | |
| 2462 UNGCPRO; | |
| 2463 if (!NILP (handler)) | |
| 2464 return call2 (handler, Qfile_executable_p, abspath); | |
| 2465 | |
| 771 | 2466 return check_executable (abspath) ? Qt : Qnil; |
| 428 | 2467 } |
| 2468 | |
| 2469 DEFUN ("file-readable-p", Ffile_readable_p, 1, 1, 0, /* | |
| 2470 Return t if file FILENAME exists and you can read it. | |
| 2471 See also `file-exists-p' and `file-attributes'. | |
| 2472 */ | |
| 2473 (filename)) | |
| 2474 { | |
| 2475 /* This function can GC */ | |
| 2476 Lisp_Object abspath = Qnil; | |
| 2477 Lisp_Object handler; | |
| 2478 struct gcpro gcpro1; | |
| 2479 GCPRO1 (abspath); | |
| 2480 | |
| 2481 CHECK_STRING (filename); | |
| 2482 abspath = Fexpand_file_name (filename, Qnil); | |
| 2483 | |
| 2484 /* If the file name has special constructs in it, | |
| 2485 call the corresponding file handler. */ | |
| 2486 handler = Ffind_file_name_handler (abspath, Qfile_readable_p); | |
| 2487 if (!NILP (handler)) | |
| 2488 RETURN_UNGCPRO (call2 (handler, Qfile_readable_p, abspath)); | |
| 2489 | |
| 2526 | 2490 #if defined (WIN32_FILENAMES) |
| 428 | 2491 /* Under MS-DOS and Windows, open does not work for directories. */ |
| 2492 UNGCPRO; | |
| 771 | 2493 if (qxe_access (XSTRING_DATA (abspath), 0) == 0) |
| 428 | 2494 return Qt; |
| 2495 else | |
| 2496 return Qnil; | |
| 657 | 2497 #else /* not WIN32_FILENAMES */ |
| 428 | 2498 { |
| 771 | 2499 int desc = qxe_interruptible_open (XSTRING_DATA (abspath), |
| 2500 O_RDONLY | OPEN_BINARY, 0); | |
| 428 | 2501 UNGCPRO; |
| 2502 if (desc < 0) | |
| 2503 return Qnil; | |
| 771 | 2504 retry_close (desc); |
| 428 | 2505 return Qt; |
| 2506 } | |
| 657 | 2507 #endif /* not WIN32_FILENAMES */ |
| 428 | 2508 } |
| 2509 | |
| 2510 /* Having this before file-symlink-p mysteriously caused it to be forgotten | |
| 2511 on the RT/PC. */ | |
| 2512 DEFUN ("file-writable-p", Ffile_writable_p, 1, 1, 0, /* | |
| 2513 Return t if file FILENAME can be written or created by you. | |
| 2514 */ | |
| 2515 (filename)) | |
| 2516 { | |
| 2517 /* This function can GC. GC checked 1997.04.10. */ | |
| 2518 Lisp_Object abspath, dir; | |
| 2519 Lisp_Object handler; | |
| 2520 struct stat statbuf; | |
| 2521 struct gcpro gcpro1; | |
| 2522 | |
| 2523 CHECK_STRING (filename); | |
| 2524 abspath = Fexpand_file_name (filename, Qnil); | |
| 2525 | |
| 2526 /* If the file name has special constructs in it, | |
| 2527 call the corresponding file handler. */ | |
| 2528 GCPRO1 (abspath); | |
| 2529 handler = Ffind_file_name_handler (abspath, Qfile_writable_p); | |
| 2530 UNGCPRO; | |
| 2531 if (!NILP (handler)) | |
| 2532 return call2 (handler, Qfile_writable_p, abspath); | |
| 2533 | |
| 771 | 2534 if (qxe_stat (XSTRING_DATA (abspath), &statbuf) >= 0) |
| 2535 return (check_writable (XSTRING_DATA (abspath)) | |
| 428 | 2536 ? Qt : Qnil); |
| 2537 | |
| 2538 | |
| 2539 GCPRO1 (abspath); | |
| 2540 dir = Ffile_name_directory (abspath); | |
| 2541 UNGCPRO; | |
| 867 | 2542 return (check_writable (!NILP (dir) ? XSTRING_DATA (dir) : (Ibyte *) "") |
| 428 | 2543 ? Qt : Qnil); |
| 2544 } | |
| 2545 | |
| 2546 DEFUN ("file-symlink-p", Ffile_symlink_p, 1, 1, 0, /* | |
| 2547 Return non-nil if file FILENAME is the name of a symbolic link. | |
| 2548 The value is the name of the file to which it is linked. | |
| 2549 Otherwise returns nil. | |
| 2550 */ | |
| 2551 (filename)) | |
| 2552 { | |
| 2553 /* This function can GC. GC checked 1997.04.10. */ | |
| 442 | 2554 /* XEmacs change: run handlers even if local machine doesn't have symlinks */ |
| 771 | 2555 #ifdef HAVE_READLINK |
| 867 | 2556 Ibyte *buf; |
| 428 | 2557 int bufsize; |
| 2558 int valsize; | |
| 2559 Lisp_Object val; | |
| 442 | 2560 #endif |
| 428 | 2561 Lisp_Object handler; |
| 2562 struct gcpro gcpro1; | |
| 2563 | |
| 2564 CHECK_STRING (filename); | |
| 2565 filename = Fexpand_file_name (filename, Qnil); | |
| 2566 | |
| 2567 /* If the file name has special constructs in it, | |
| 2568 call the corresponding file handler. */ | |
| 2569 GCPRO1 (filename); | |
| 2570 handler = Ffind_file_name_handler (filename, Qfile_symlink_p); | |
| 2571 UNGCPRO; | |
| 2572 if (!NILP (handler)) | |
| 2573 return call2 (handler, Qfile_symlink_p, filename); | |
| 2574 | |
| 771 | 2575 #ifdef HAVE_READLINK |
| 428 | 2576 bufsize = 100; |
| 2577 while (1) | |
| 2578 { | |
| 867 | 2579 buf = xnew_array_and_zero (Ibyte, bufsize); |
| 771 | 2580 valsize = qxe_readlink (XSTRING_DATA (filename), |
| 2581 buf, bufsize); | |
| 428 | 2582 if (valsize < bufsize) break; |
| 2583 /* Buffer was not long enough */ | |
| 1726 | 2584 xfree (buf, Ibyte *); |
| 428 | 2585 bufsize *= 2; |
| 2586 } | |
| 2587 if (valsize == -1) | |
| 2588 { | |
| 1726 | 2589 xfree (buf, Ibyte *); |
| 428 | 2590 return Qnil; |
| 2591 } | |
| 771 | 2592 val = make_string (buf, valsize); |
| 1726 | 2593 xfree (buf, Ibyte *); |
| 428 | 2594 return val; |
| 2526 | 2595 #elif defined (WIN32_NATIVE) |
| 2596 if (mswindows_shortcuts_are_symlinks) | |
| 2597 { | |
| 2598 /* We want to resolve the directory component and leave the rest | |
| 2599 alone. */ | |
| 2600 Ibyte *path = XSTRING_DATA (filename); | |
| 2601 Ibyte *dirend = | |
| 2602 find_end_of_directory_component (path, XSTRING_LENGTH (filename)); | |
| 2603 Ibyte *fname; | |
| 2604 DECLARE_EISTRING (dir); | |
| 2605 | |
| 2606 if (dirend != path) | |
| 2607 { | |
| 2608 Ibyte *resdir; | |
| 2609 DECLARE_EISTRING (resname); | |
| 2610 | |
| 2611 eicpy_raw (dir, path, dirend - path); | |
| 2612 PATHNAME_RESOLVE_LINKS (eidata (dir), resdir); | |
| 2613 eicpy_rawz (resname, resdir); | |
| 2614 eicat_rawz (resname, dirend); | |
| 2615 path = eidata (resname); | |
| 2616 } | |
| 2617 | |
| 2618 fname = mswindows_read_link (path); | |
| 2619 if (!fname) | |
| 2620 return Qnil; | |
| 2621 { | |
| 2622 Lisp_Object val = build_intstring (fname); | |
| 2623 xfree (fname, Ibyte *); | |
| 2624 return val; | |
| 2625 } | |
| 2626 } | |
| 428 | 2627 return Qnil; |
| 2526 | 2628 #else |
| 2629 return Qnil; | |
| 2630 #endif | |
| 428 | 2631 } |
| 2632 | |
| 2633 DEFUN ("file-directory-p", Ffile_directory_p, 1, 1, 0, /* | |
| 2634 Return t if file FILENAME is the name of a directory as a file. | |
| 2635 A directory name spec may be given instead; then the value is t | |
| 2636 if the directory so specified exists and really is a directory. | |
| 2637 */ | |
| 2638 (filename)) | |
| 2639 { | |
| 2640 /* This function can GC. GC checked 1997.04.10. */ | |
| 2641 Lisp_Object abspath; | |
| 2642 struct stat st; | |
| 2643 Lisp_Object handler; | |
| 2644 struct gcpro gcpro1; | |
| 2645 | |
| 2646 GCPRO1 (current_buffer->directory); | |
| 2647 abspath = expand_and_dir_to_file (filename, | |
| 2648 current_buffer->directory); | |
| 2649 UNGCPRO; | |
| 2650 | |
| 2651 /* If the file name has special constructs in it, | |
| 2652 call the corresponding file handler. */ | |
| 2653 GCPRO1 (abspath); | |
| 2654 handler = Ffind_file_name_handler (abspath, Qfile_directory_p); | |
| 2655 UNGCPRO; | |
| 2656 if (!NILP (handler)) | |
| 2657 return call2 (handler, Qfile_directory_p, abspath); | |
| 2658 | |
| 771 | 2659 if (qxe_stat (XSTRING_DATA (abspath), &st) < 0) |
| 428 | 2660 return Qnil; |
| 2661 return (st.st_mode & S_IFMT) == S_IFDIR ? Qt : Qnil; | |
| 2662 } | |
| 2663 | |
| 2664 DEFUN ("file-accessible-directory-p", Ffile_accessible_directory_p, 1, 1, 0, /* | |
| 2665 Return t if file FILENAME is the name of a directory as a file, | |
| 2666 and files in that directory can be opened by you. In order to use a | |
| 2667 directory as a buffer's current directory, this predicate must return true. | |
| 2668 A directory name spec may be given instead; then the value is t | |
| 2669 if the directory so specified exists and really is a readable and | |
| 2670 searchable directory. | |
| 2671 */ | |
| 2672 (filename)) | |
| 2673 { | |
| 2674 /* This function can GC. GC checked 1997.04.10. */ | |
| 2675 Lisp_Object handler; | |
| 2676 | |
| 2677 /* If the file name has special constructs in it, | |
| 2678 call the corresponding file handler. */ | |
| 2679 handler = Ffind_file_name_handler (filename, Qfile_accessible_directory_p); | |
| 2680 if (!NILP (handler)) | |
| 2681 return call2 (handler, Qfile_accessible_directory_p, | |
| 2682 filename); | |
| 2683 | |
| 2526 | 2684 #if !defined (WIN32_NATIVE) |
| 428 | 2685 if (NILP (Ffile_directory_p (filename))) |
| 2686 return (Qnil); | |
| 2687 else | |
| 2688 return Ffile_executable_p (filename); | |
| 2689 #else | |
| 2690 { | |
| 2691 int tem; | |
| 2692 struct gcpro gcpro1; | |
| 2693 /* It's an unlikely combination, but yes we really do need to gcpro: | |
| 2694 Suppose that file-accessible-directory-p has no handler, but | |
| 2695 file-directory-p does have a handler; this handler causes a GC which | |
| 2696 relocates the string in `filename'; and finally file-directory-p | |
| 2697 returns non-nil. Then we would end up passing a garbaged string | |
| 2698 to file-executable-p. */ | |
| 2699 GCPRO1 (filename); | |
| 2700 tem = (NILP (Ffile_directory_p (filename)) | |
| 2701 || NILP (Ffile_executable_p (filename))); | |
| 2702 UNGCPRO; | |
| 2703 return tem ? Qnil : Qt; | |
| 2704 } | |
| 442 | 2705 #endif /* !defined(WIN32_NATIVE) */ |
| 428 | 2706 } |
| 2707 | |
| 2708 DEFUN ("file-regular-p", Ffile_regular_p, 1, 1, 0, /* | |
| 2709 Return t if file FILENAME is the name of a regular file. | |
| 2710 This is the sort of file that holds an ordinary stream of data bytes. | |
| 2711 */ | |
| 2712 (filename)) | |
| 2713 { | |
| 2714 /* This function can GC. GC checked 1997.04.10. */ | |
| 2715 Lisp_Object abspath; | |
| 2716 struct stat st; | |
| 2717 Lisp_Object handler; | |
| 2718 struct gcpro gcpro1; | |
| 2719 | |
| 2720 GCPRO1 (current_buffer->directory); | |
| 2721 abspath = expand_and_dir_to_file (filename, current_buffer->directory); | |
| 2722 UNGCPRO; | |
| 2723 | |
| 2724 /* If the file name has special constructs in it, | |
| 2725 call the corresponding file handler. */ | |
| 2726 GCPRO1 (abspath); | |
| 2727 handler = Ffind_file_name_handler (abspath, Qfile_regular_p); | |
| 2728 UNGCPRO; | |
| 2729 if (!NILP (handler)) | |
| 2730 return call2 (handler, Qfile_regular_p, abspath); | |
| 2731 | |
| 771 | 2732 if (qxe_stat (XSTRING_DATA (abspath), &st) < 0) |
| 428 | 2733 return Qnil; |
| 2734 return (st.st_mode & S_IFMT) == S_IFREG ? Qt : Qnil; | |
| 2735 } | |
| 2736 | |
| 2737 DEFUN ("file-modes", Ffile_modes, 1, 1, 0, /* | |
| 444 | 2738 Return mode bits of file named FILENAME, as an integer. |
| 428 | 2739 */ |
| 2740 (filename)) | |
| 2741 { | |
| 2742 /* This function can GC. GC checked 1997.04.10. */ | |
| 2743 Lisp_Object abspath; | |
| 2744 struct stat st; | |
| 2745 Lisp_Object handler; | |
| 2746 struct gcpro gcpro1; | |
| 2747 | |
| 2748 GCPRO1 (current_buffer->directory); | |
| 2749 abspath = expand_and_dir_to_file (filename, | |
| 2750 current_buffer->directory); | |
| 2751 UNGCPRO; | |
| 2752 | |
| 2753 /* If the file name has special constructs in it, | |
| 2754 call the corresponding file handler. */ | |
| 2755 GCPRO1 (abspath); | |
| 2756 handler = Ffind_file_name_handler (abspath, Qfile_modes); | |
| 2757 UNGCPRO; | |
| 2758 if (!NILP (handler)) | |
| 2759 return call2 (handler, Qfile_modes, abspath); | |
| 2760 | |
| 771 | 2761 if (qxe_stat (XSTRING_DATA (abspath), &st) < 0) |
| 428 | 2762 return Qnil; |
| 2763 /* Syncing with FSF 19.34.6 note: not in FSF, #if 0'ed out here. */ | |
| 2764 #if 0 | |
| 442 | 2765 #ifdef WIN32_NATIVE |
| 771 | 2766 if (check_executable (abspath)) |
| 428 | 2767 st.st_mode |= S_IEXEC; |
| 442 | 2768 #endif /* WIN32_NATIVE */ |
| 428 | 2769 #endif /* 0 */ |
| 2770 | |
| 2771 return make_int (st.st_mode & 07777); | |
| 2772 } | |
| 2773 | |
| 2774 DEFUN ("set-file-modes", Fset_file_modes, 2, 2, 0, /* | |
| 444 | 2775 Set mode bits of file named FILENAME to MODE (an integer). |
| 428 | 2776 Only the 12 low bits of MODE are used. |
| 2777 */ | |
| 2778 (filename, mode)) | |
| 2779 { | |
| 2780 /* This function can GC. GC checked 1997.04.10. */ | |
| 2781 Lisp_Object abspath; | |
| 2782 Lisp_Object handler; | |
| 2783 struct gcpro gcpro1; | |
| 2784 | |
| 2785 GCPRO1 (current_buffer->directory); | |
| 2786 abspath = Fexpand_file_name (filename, current_buffer->directory); | |
| 2787 UNGCPRO; | |
| 2788 | |
| 2789 CHECK_INT (mode); | |
| 2790 | |
| 2791 /* If the file name has special constructs in it, | |
| 2792 call the corresponding file handler. */ | |
| 2793 GCPRO1 (abspath); | |
| 2794 handler = Ffind_file_name_handler (abspath, Qset_file_modes); | |
| 2795 UNGCPRO; | |
| 2796 if (!NILP (handler)) | |
| 2797 return call3 (handler, Qset_file_modes, abspath, mode); | |
| 2798 | |
| 771 | 2799 if (qxe_chmod (XSTRING_DATA (abspath), XINT (mode)) < 0) |
| 563 | 2800 report_file_error ("Doing chmod", abspath); |
| 428 | 2801 |
| 2802 return Qnil; | |
| 2803 } | |
| 2804 | |
| 2805 DEFUN ("set-default-file-modes", Fset_default_file_modes, 1, 1, 0, /* | |
| 2806 Set the file permission bits for newly created files. | |
| 444 | 2807 The argument MODE should be an integer; if a bit in MODE is 1, |
| 2808 subsequently created files will not have the permission corresponding | |
| 2809 to that bit enabled. Only the low 9 bits are used. | |
| 428 | 2810 This setting is inherited by subprocesses. |
| 2811 */ | |
| 2812 (mode)) | |
| 2813 { | |
| 2814 CHECK_INT (mode); | |
| 2815 | |
| 2816 umask ((~ XINT (mode)) & 0777); | |
| 2817 | |
| 2818 return Qnil; | |
| 2819 } | |
| 2820 | |
| 2821 DEFUN ("default-file-modes", Fdefault_file_modes, 0, 0, 0, /* | |
| 2822 Return the default file protection for created files. | |
| 2823 The umask value determines which permissions are enabled in newly | |
| 2824 created files. If a permission's bit in the umask is 1, subsequently | |
| 2825 created files will not have that permission enabled. | |
| 2826 */ | |
| 2827 ()) | |
| 2828 { | |
| 2829 int mode; | |
| 2830 | |
| 2831 mode = umask (0); | |
| 2832 umask (mode); | |
| 2833 | |
| 2834 return make_int ((~ mode) & 0777); | |
| 2835 } | |
| 2836 | |
| 2837 DEFUN ("unix-sync", Funix_sync, 0, 0, "", /* | |
| 2838 Tell Unix to finish all pending disk updates. | |
| 2839 */ | |
| 2840 ()) | |
| 2841 { | |
| 442 | 2842 #ifndef WIN32_NATIVE |
| 428 | 2843 sync (); |
| 2844 #endif | |
| 2845 return Qnil; | |
| 2846 } | |
| 2847 | |
| 2848 | |
| 2849 DEFUN ("file-newer-than-file-p", Ffile_newer_than_file_p, 2, 2, 0, /* | |
| 2850 Return t if file FILE1 is newer than file FILE2. | |
| 2851 If FILE1 does not exist, the answer is nil; | |
| 2852 otherwise, if FILE2 does not exist, the answer is t. | |
| 2853 */ | |
| 2854 (file1, file2)) | |
| 2855 { | |
| 2856 /* This function can GC. GC checked 1997.04.10. */ | |
| 2857 Lisp_Object abspath1, abspath2; | |
| 2858 struct stat st; | |
| 2859 int mtime1; | |
| 2860 Lisp_Object handler; | |
| 2861 struct gcpro gcpro1, gcpro2, gcpro3; | |
| 2862 | |
| 2863 CHECK_STRING (file1); | |
| 2864 CHECK_STRING (file2); | |
| 2865 | |
| 2866 abspath1 = Qnil; | |
| 2867 abspath2 = Qnil; | |
| 2868 | |
| 2869 GCPRO3 (abspath1, abspath2, current_buffer->directory); | |
| 2870 abspath1 = expand_and_dir_to_file (file1, current_buffer->directory); | |
| 2871 abspath2 = expand_and_dir_to_file (file2, current_buffer->directory); | |
| 2872 | |
| 2873 /* If the file name has special constructs in it, | |
| 2874 call the corresponding file handler. */ | |
| 2875 handler = Ffind_file_name_handler (abspath1, Qfile_newer_than_file_p); | |
| 2876 if (NILP (handler)) | |
| 2877 handler = Ffind_file_name_handler (abspath2, Qfile_newer_than_file_p); | |
| 2878 UNGCPRO; | |
| 2879 if (!NILP (handler)) | |
| 2880 return call3 (handler, Qfile_newer_than_file_p, abspath1, | |
| 2881 abspath2); | |
| 2882 | |
| 771 | 2883 if (qxe_stat (XSTRING_DATA (abspath1), &st) < 0) |
| 428 | 2884 return Qnil; |
| 2885 | |
| 2886 mtime1 = st.st_mtime; | |
| 2887 | |
| 771 | 2888 if (qxe_stat (XSTRING_DATA (abspath2), &st) < 0) |
| 428 | 2889 return Qt; |
| 2890 | |
| 2891 return (mtime1 > st.st_mtime) ? Qt : Qnil; | |
| 2892 } | |
| 2893 | |
| 2894 | |
| 2895 /* Stack sizes > 2**16 is a good way to elicit compiler bugs */ | |
| 2896 /* #define READ_BUF_SIZE (2 << 16) */ | |
| 2897 #define READ_BUF_SIZE (1 << 15) | |
| 2898 | |
| 2899 DEFUN ("insert-file-contents-internal", Finsert_file_contents_internal, | |
| 2900 1, 7, 0, /* | |
| 2901 Insert contents of file FILENAME after point; no coding-system frobbing. | |
| 2902 This function is identical to `insert-file-contents' except for the | |
| 771 | 2903 handling of the CODESYS and USED-CODESYS arguments. |
| 2904 | |
| 2905 The file is decoded according to CODESYS; if omitted, no conversion | |
| 2906 happens. If USED-CODESYS is non-nil, it should be a symbol, and the actual | |
| 2907 coding system that was used for the decoding is stored into it. It will in | |
| 2908 general be different from CODESYS if CODESYS specifies automatic encoding | |
| 2909 detection or end-of-line detection. | |
| 428 | 2910 |
| 444 | 2911 Currently START and END refer to byte positions (as opposed to character |
| 771 | 2912 positions), even in Mule and under MS Windows. (Fixing this, particularly |
| 2913 under Mule, is very difficult.) | |
| 428 | 2914 */ |
| 444 | 2915 (filename, visit, start, end, replace, codesys, used_codesys)) |
| 428 | 2916 { |
| 2917 /* This function can call lisp */ | |
| 2918 struct stat st; | |
| 2919 int fd; | |
| 2920 int saverrno = 0; | |
| 2921 Charcount inserted = 0; | |
| 2922 int speccount; | |
| 3841 | 2923 struct gcpro gcpro1, gcpro2, gcpro3, gcpro4; |
| 3814 | 2924 Lisp_Object val; |
| 428 | 2925 int total; |
| 867 | 2926 Ibyte read_buf[READ_BUF_SIZE]; |
| 428 | 2927 int mc_count; |
| 2928 struct buffer *buf = current_buffer; | |
| 2929 Lisp_Object curbuf; | |
| 2930 int not_regular = 0; | |
| 771 | 2931 int do_speedy_insert = |
| 2932 coding_system_is_binary (Fget_coding_system (codesys)); | |
| 428 | 2933 |
| 2934 if (buf->base_buffer && ! NILP (visit)) | |
| 563 | 2935 invalid_operation ("Cannot do file visiting in an indirect buffer", Qunbound); |
| 428 | 2936 |
| 2937 /* No need to call Fbarf_if_buffer_read_only() here. | |
| 2938 That's called in begin_multiple_change() or wherever. */ | |
| 2939 | |
| 2940 val = Qnil; | |
| 2941 | |
| 2942 /* #### dmoore - should probably check in various places to see if | |
| 2943 curbuf was killed and if so signal an error? */ | |
| 2944 | |
| 793 | 2945 curbuf = wrap_buffer (buf); |
| 428 | 2946 |
| 3814 | 2947 GCPRO4 (filename, val, visit, curbuf); |
| 428 | 2948 |
| 2949 mc_count = (NILP (replace)) ? | |
| 2950 begin_multiple_change (buf, BUF_PT (buf), BUF_PT (buf)) : | |
| 2951 begin_multiple_change (buf, BUF_BEG (buf), BUF_Z (buf)); | |
| 2952 | |
| 2953 speccount = specpdl_depth (); /* begin_multiple_change also adds | |
| 2954 an unwind_protect */ | |
| 2955 | |
| 2956 filename = Fexpand_file_name (filename, Qnil); | |
| 2957 | |
| 2958 if (!NILP (used_codesys)) | |
| 2959 CHECK_SYMBOL (used_codesys); | |
| 2960 | |
| 444 | 2961 if ( (!NILP (start) || !NILP (end)) && !NILP (visit) ) |
| 563 | 2962 invalid_operation ("Attempt to visit less than an entire file", Qunbound); |
| 428 | 2963 |
| 2964 fd = -1; | |
| 2965 | |
| 771 | 2966 if (qxe_stat (XSTRING_DATA (filename), &st) < 0) |
| 428 | 2967 { |
| 2968 badopen: | |
| 2969 if (NILP (visit)) | |
| 563 | 2970 report_file_error ("Opening input file", filename); |
| 428 | 2971 st.st_mtime = -1; |
| 2972 goto notfound; | |
| 2973 } | |
| 2974 | |
| 2975 #ifdef S_IFREG | |
| 2976 /* Signal an error if we are accessing a non-regular file, with | |
| 444 | 2977 REPLACE, START or END being non-nil. */ |
| 428 | 2978 if (!S_ISREG (st.st_mode)) |
| 2979 { | |
| 2980 not_regular = 1; | |
| 2981 | |
| 2982 if (!NILP (visit)) | |
| 2983 goto notfound; | |
| 2984 | |
| 444 | 2985 if (!NILP (replace) || !NILP (start) || !NILP (end)) |
| 428 | 2986 { |
| 2987 end_multiple_change (buf, mc_count); | |
| 2988 | |
| 444 | 2989 RETURN_UNGCPRO |
| 2990 (Fsignal (Qfile_error, | |
| 771 | 2991 list2 (build_msg_string("not a regular file"), |
| 444 | 2992 filename))); |
| 428 | 2993 } |
| 2994 } | |
| 2995 #endif /* S_IFREG */ | |
| 2996 | |
| 444 | 2997 if (!NILP (start)) |
| 2998 CHECK_INT (start); | |
| 428 | 2999 else |
| 444 | 3000 start = Qzero; |
| 428 | 3001 |
| 3002 if (!NILP (end)) | |
| 3003 CHECK_INT (end); | |
| 3004 | |
| 3005 if (fd < 0) | |
| 3006 { | |
| 771 | 3007 if ((fd = qxe_interruptible_open (XSTRING_DATA (filename), |
| 3008 O_RDONLY | OPEN_BINARY, 0)) < 0) | |
| 428 | 3009 goto badopen; |
| 3010 } | |
| 3011 | |
| 3012 /* Replacement should preserve point as it preserves markers. */ | |
| 3013 if (!NILP (replace)) | |
| 3014 record_unwind_protect (restore_point_unwind, Fpoint_marker (Qnil, Qnil)); | |
| 3015 | |
| 3016 record_unwind_protect (close_file_unwind, make_int (fd)); | |
| 3017 | |
| 3018 /* Supposedly happens on VMS. */ | |
| 3019 if (st.st_size < 0) | |
| 563 | 3020 signal_error (Qfile_error, "File size is negative", Qunbound); |
| 428 | 3021 |
| 3022 if (NILP (end)) | |
| 3023 { | |
| 3024 if (!not_regular) | |
| 3025 { | |
| 3026 end = make_int (st.st_size); | |
| 3027 if (XINT (end) != st.st_size) | |
| 563 | 3028 out_of_memory ("Maximum buffer size exceeded", Qunbound); |
| 428 | 3029 } |
| 3030 } | |
| 3031 | |
| 3032 /* If requested, replace the accessible part of the buffer | |
| 3033 with the file contents. Avoid replacing text at the | |
| 3034 beginning or end of the buffer that matches the file contents; | |
| 771 | 3035 that preserves markers pointing to the unchanged parts. */ |
| 3036 /* The replace-mode code is currently implemented by comparing the | |
| 3037 file on disk with the contents in the buffer, character by character. | |
| 3038 That works only if the characters on disk are exactly what will go into | |
| 3039 the buffer -- i.e. `binary' conversion. | |
| 3040 | |
| 3041 FSF tries to implement this in all situations, even the non-binary | |
| 3042 conversion, by (in that case) loading the whole converted file into a | |
| 3043 separate memory area, then doing the comparison. I really don't see | |
| 3044 the point of this, and it will fail spectacularly if the file is many | |
| 3045 megabytes in size. To try to get around this, we could certainly read | |
| 3046 from the beginning and decode as necessary before comparing, but doing | |
| 3047 the same at the end gets very difficult because of the possibility of | |
| 3048 modal coding systems -- trying to decode data from any point forward | |
| 3049 without decoding previous data might always give you different results | |
| 3050 from starting at the beginning. We could try further tricks like | |
| 3051 keeping track of which coding systems are non-modal and providing some | |
| 3052 extra method for such coding systems to be given a chunk of data that | |
| 3053 came from a specified location in a specified file and ask the coding | |
| 3054 systems to return a "sync point" from which the data can be read | |
| 3055 forward and have results guaranteed to be the same as reading from the | |
| 3056 beginning to that point, but I really don't think it's worth it. If | |
| 3057 we implemented the FSF "brute-force" method, we would have to put a | |
| 3058 reasonable maximum file size on the files. Is any of this worth it? | |
| 3059 --ben | |
| 3060 | |
| 3638 | 3061 |
| 3062 It's probably not worth it, and despite what you might take from the | |
| 3063 above, we don't do it currently; that is, for non-"binary" coding | |
| 3064 systems, we don't try to implement replace-mode at all. See the | |
| 3065 do_speedy_insert variable above. The upside of this is that our API | |
| 3066 is consistent and not buggy. -- Aidan Kehoe, Fri Oct 27 21:02:30 CEST | |
| 3067 2006 | |
| 771 | 3068 */ |
| 3069 | |
| 428 | 3070 if (!NILP (replace)) |
| 3071 { | |
| 771 | 3072 if (!do_speedy_insert) |
| 3073 buffer_delete_range (buf, BUF_BEG (buf), BUF_Z (buf), | |
| 3074 !NILP (visit) ? INSDEL_NO_LOCKING : 0); | |
| 3075 else | |
| 428 | 3076 { |
| 771 | 3077 char buffer[1 << 14]; |
| 3078 Charbpos same_at_start = BUF_BEGV (buf); | |
| 3079 Charbpos same_at_end = BUF_ZV (buf); | |
| 3080 int overlap; | |
| 3081 | |
| 3082 /* Count how many chars at the start of the file | |
| 3083 match the text at the beginning of the buffer. */ | |
| 3084 while (1) | |
| 3085 { | |
| 3086 int nread; | |
| 3087 Charbpos charbpos; | |
| 3088 nread = read_allowing_quit (fd, buffer, sizeof (buffer)); | |
| 3089 if (nread < 0) | |
| 3090 report_file_error ("Reading", filename); | |
| 3091 else if (nread == 0) | |
| 3092 break; | |
| 3093 charbpos = 0; | |
| 3094 while (charbpos < nread && same_at_start < BUF_ZV (buf) | |
| 814 | 3095 && BUF_FETCH_CHAR (buf, same_at_start) == |
| 3096 buffer[charbpos]) | |
| 771 | 3097 same_at_start++, charbpos++; |
| 3098 /* If we found a discrepancy, stop the scan. | |
| 3099 Otherwise loop around and scan the next bufferful. */ | |
| 3100 if (charbpos != nread) | |
| 3101 break; | |
| 3102 } | |
| 3103 /* If the file matches the buffer completely, | |
| 3104 there's no need to replace anything. */ | |
| 3105 if (same_at_start - BUF_BEGV (buf) == st.st_size) | |
| 3106 { | |
| 3107 retry_close (fd); | |
| 3108 unbind_to (speccount); | |
| 3109 /* Truncate the buffer to the size of the file. */ | |
| 3110 buffer_delete_range (buf, same_at_start, same_at_end, | |
| 3111 !NILP (visit) ? INSDEL_NO_LOCKING : 0); | |
| 3112 goto handled; | |
| 3113 } | |
| 3114 /* Count how many chars at the end of the file | |
| 3115 match the text at the end of the buffer. */ | |
| 3116 while (1) | |
| 3117 { | |
| 3118 int total_read, nread; | |
| 814 | 3119 Charcount charbpos, curpos, trial; |
| 771 | 3120 |
| 3121 /* At what file position are we now scanning? */ | |
| 3122 curpos = st.st_size - (BUF_ZV (buf) - same_at_end); | |
| 3123 /* If the entire file matches the buffer tail, stop the scan. */ | |
| 3124 if (curpos == 0) | |
| 3125 break; | |
| 3126 /* How much can we scan in the next step? */ | |
| 3127 trial = min (curpos, (Charbpos) sizeof (buffer)); | |
| 3128 if (lseek (fd, curpos - trial, 0) < 0) | |
| 3129 report_file_error ("Setting file position", filename); | |
| 3130 | |
| 3131 total_read = 0; | |
| 3132 while (total_read < trial) | |
| 3133 { | |
| 3134 nread = read_allowing_quit (fd, buffer + total_read, | |
| 3135 trial - total_read); | |
| 3136 if (nread <= 0) | |
| 3137 report_file_error ("IO error reading file", filename); | |
| 3138 total_read += nread; | |
| 3139 } | |
| 3140 /* Scan this bufferful from the end, comparing with | |
| 3141 the Emacs buffer. */ | |
| 3142 charbpos = total_read; | |
| 3143 /* Compare with same_at_start to avoid counting some buffer text | |
| 3144 as matching both at the file's beginning and at the end. */ | |
| 3145 while (charbpos > 0 && same_at_end > same_at_start | |
| 3146 && BUF_FETCH_CHAR (buf, same_at_end - 1) == | |
| 3147 buffer[charbpos - 1]) | |
| 3148 same_at_end--, charbpos--; | |
| 3149 /* If we found a discrepancy, stop the scan. | |
| 3150 Otherwise loop around and scan the preceding bufferful. */ | |
| 3151 if (charbpos != 0) | |
| 3152 break; | |
| 3153 /* If display current starts at beginning of line, | |
| 3154 keep it that way. */ | |
| 3155 if (XBUFFER (XWINDOW (Fselected_window (Qnil))->buffer) == buf) | |
| 3156 XWINDOW (Fselected_window (Qnil))->start_at_line_beg = | |
| 3157 !NILP (Fbolp (wrap_buffer (buf))); | |
| 3158 } | |
| 3159 | |
| 3160 /* Don't try to reuse the same piece of text twice. */ | |
| 3161 overlap = same_at_start - BUF_BEGV (buf) - | |
| 3162 (same_at_end + st.st_size - BUF_ZV (buf)); | |
| 3163 if (overlap > 0) | |
| 3164 same_at_end += overlap; | |
| 3165 | |
| 3166 /* Arrange to read only the nonmatching middle part of the file. */ | |
| 3167 start = make_int (same_at_start - BUF_BEGV (buf)); | |
| 3168 end = make_int (st.st_size - (BUF_ZV (buf) - same_at_end)); | |
| 3169 | |
| 428 | 3170 buffer_delete_range (buf, same_at_start, same_at_end, |
| 3171 !NILP (visit) ? INSDEL_NO_LOCKING : 0); | |
| 771 | 3172 /* Insert from the file at the proper position. */ |
| 3173 BUF_SET_PT (buf, same_at_start); | |
| 428 | 3174 } |
| 3175 } | |
| 3176 | |
| 3177 if (!not_regular) | |
| 3178 { | |
| 444 | 3179 total = XINT (end) - XINT (start); |
| 428 | 3180 |
| 3181 /* Make sure point-max won't overflow after this insertion. */ | |
| 3182 if (total != XINT (make_int (total))) | |
| 563 | 3183 out_of_memory ("Maximum buffer size exceeded", Qunbound); |
| 428 | 3184 } |
| 3185 else | |
| 3186 /* For a special file, all we can do is guess. The value of -1 | |
| 3187 will make the stream functions read as much as possible. */ | |
| 3188 total = -1; | |
| 3189 | |
| 444 | 3190 if (XINT (start) != 0 |
| 428 | 3191 /* why was this here? asked jwz. The reason is that the replace-mode |
| 3192 connivings above will normally put the file pointer other than | |
| 3193 where it should be. */ | |
| 771 | 3194 || (!NILP (replace) && do_speedy_insert)) |
| 428 | 3195 { |
| 444 | 3196 if (lseek (fd, XINT (start), 0) < 0) |
| 563 | 3197 report_file_error ("Setting file position", filename); |
| 428 | 3198 } |
| 3199 | |
| 3200 { | |
| 665 | 3201 Charbpos cur_point = BUF_PT (buf); |
| 428 | 3202 struct gcpro ngcpro1; |
| 3203 Lisp_Object stream = make_filedesc_input_stream (fd, 0, total, | |
| 3204 LSTR_ALLOW_QUIT); | |
| 3205 | |
| 3206 NGCPRO1 (stream); | |
| 3207 Lstream_set_buffering (XLSTREAM (stream), LSTREAM_BLOCKN_BUFFERED, 65536); | |
| 771 | 3208 stream = make_coding_input_stream |
| 3209 (XLSTREAM (stream), get_coding_system_for_text_file (codesys, 1), | |
| 800 | 3210 CODING_DECODE, 0); |
| 428 | 3211 Lstream_set_buffering (XLSTREAM (stream), LSTREAM_BLOCKN_BUFFERED, 65536); |
| 3212 | |
| 3213 record_unwind_protect (delete_stream_unwind, stream); | |
| 3214 | |
| 3215 /* No need to limit the amount of stuff we attempt to read. (It would | |
| 3216 be incorrect, anyway, when Mule is enabled.) Instead, the limiting | |
| 3217 occurs inside of the filedesc stream. */ | |
| 3218 while (1) | |
| 3219 { | |
| 665 | 3220 Bytecount this_len; |
| 428 | 3221 Charcount cc_inserted; |
| 3222 | |
| 3223 QUIT; | |
| 3224 this_len = Lstream_read (XLSTREAM (stream), read_buf, | |
| 3225 sizeof (read_buf)); | |
| 3226 | |
| 3227 if (this_len <= 0) | |
| 3228 { | |
| 3229 if (this_len < 0) | |
| 3230 saverrno = errno; | |
| 3231 break; | |
| 3232 } | |
| 3233 | |
| 3234 cc_inserted = buffer_insert_raw_string_1 (buf, cur_point, read_buf, | |
| 3235 this_len, | |
| 3236 !NILP (visit) | |
| 3237 ? INSDEL_NO_LOCKING : 0); | |
| 3238 inserted += cc_inserted; | |
| 3239 cur_point += cc_inserted; | |
| 3240 } | |
| 3241 if (!NILP (used_codesys)) | |
| 3242 { | |
| 3243 Fset (used_codesys, | |
| 771 | 3244 XCODING_SYSTEM_NAME |
| 3245 (coding_stream_detected_coding_system (XLSTREAM (stream)))); | |
| 428 | 3246 } |
| 3247 NUNGCPRO; | |
| 3248 } | |
| 3249 | |
| 3250 /* Close the file/stream */ | |
| 771 | 3251 unbind_to (speccount); |
| 428 | 3252 |
| 3253 if (saverrno != 0) | |
| 3254 { | |
| 563 | 3255 errno = saverrno; |
| 3256 report_file_error ("Reading", filename); | |
| 428 | 3257 } |
| 3258 | |
| 3259 notfound: | |
| 3260 handled: | |
| 3261 | |
| 3262 end_multiple_change (buf, mc_count); | |
| 3263 | |
| 3264 if (!NILP (visit)) | |
| 3265 { | |
| 3266 if (!EQ (buf->undo_list, Qt)) | |
| 3267 buf->undo_list = Qnil; | |
| 3814 | 3268 buf->modtime = st.st_mtime; |
| 3269 buf->filename = filename; | |
| 3270 /* XEmacs addition: */ | |
| 3271 /* This function used to be in C, ostensibly so that | |
| 3272 it could be called here. But that's just silly. | |
| 3273 There's no reason C code can't call out to Lisp | |
| 3274 code, and it's a lot cleaner this way. */ | |
| 3275 /* Note: compute-buffer-file-truename is called for | |
| 3276 side-effect! Its return value is intentionally | |
| 3277 ignored. */ | |
| 3278 if (!NILP (Ffboundp (Qcompute_buffer_file_truename))) | |
| 3279 call1 (Qcompute_buffer_file_truename, wrap_buffer (buf)); | |
| 428 | 3280 BUF_SAVE_MODIFF (buf) = BUF_MODIFF (buf); |
| 3281 buf->auto_save_modified = BUF_MODIFF (buf); | |
| 3282 buf->saved_size = make_int (BUF_SIZE (buf)); | |
| 3283 #ifdef CLASH_DETECTION | |
| 3814 | 3284 if (!NILP (buf->file_truename)) |
| 3285 unlock_file (buf->file_truename); | |
| 3286 unlock_file (filename); | |
| 428 | 3287 #endif /* CLASH_DETECTION */ |
| 3288 if (not_regular) | |
| 3289 RETURN_UNGCPRO (Fsignal (Qfile_error, | |
| 771 | 3290 list2 (build_msg_string ("not a regular file"), |
| 428 | 3291 filename))); |
| 3292 | |
| 3293 /* If visiting nonexistent file, return nil. */ | |
| 3294 if (buf->modtime == -1) | |
| 3295 report_file_error ("Opening input file", | |
| 563 | 3296 filename); |
| 428 | 3297 } |
| 3298 | |
| 3299 /* Decode file format */ | |
| 3300 if (inserted > 0) | |
| 3301 { | |
| 3302 Lisp_Object insval = call3 (Qformat_decode, | |
| 3303 Qnil, make_int (inserted), visit); | |
| 3304 CHECK_INT (insval); | |
| 3305 inserted = XINT (insval); | |
| 3306 } | |
| 3307 | |
| 3308 if (inserted > 0) | |
| 3309 { | |
| 2367 | 3310 GC_EXTERNAL_LIST_LOOP_2 (p, Vafter_insert_file_functions) |
| 428 | 3311 { |
| 2367 | 3312 Lisp_Object insval = call1 (p, make_int (inserted)); |
| 428 | 3313 if (!NILP (insval)) |
| 3314 { | |
| 3315 CHECK_NATNUM (insval); | |
| 3316 inserted = XINT (insval); | |
| 3317 } | |
| 3318 } | |
| 2367 | 3319 END_GC_EXTERNAL_LIST_LOOP (p); |
| 428 | 3320 } |
| 3321 | |
| 3322 UNGCPRO; | |
| 3323 | |
| 3324 if (!NILP (val)) | |
| 3325 return (val); | |
| 3326 else | |
| 3327 return (list2 (filename, make_int (inserted))); | |
| 3328 } | |
| 3329 | |
| 3330 | |
| 3331 static int a_write (Lisp_Object outstream, Lisp_Object instream, int pos, | |
| 3332 Lisp_Object *annot); | |
| 3333 static Lisp_Object build_annotations (Lisp_Object start, Lisp_Object end); | |
| 3334 | |
| 3335 /* If build_annotations switched buffers, switch back to BUF. | |
| 3336 Kill the temporary buffer that was selected in the meantime. */ | |
| 3337 | |
| 3338 static Lisp_Object | |
| 3339 build_annotations_unwind (Lisp_Object buf) | |
| 3340 { | |
| 3341 Lisp_Object tembuf; | |
| 3342 | |
| 3343 if (XBUFFER (buf) == current_buffer) | |
| 3344 return Qnil; | |
| 3345 tembuf = Fcurrent_buffer (); | |
| 3346 Fset_buffer (buf); | |
| 3347 Fkill_buffer (tembuf); | |
| 3348 return Qnil; | |
| 3349 } | |
| 3350 | |
| 4266 | 3351 DEFUN ("write-region-internal", Fwrite_region_internal, 3, 8, |
| 428 | 3352 "r\nFWrite region to file: ", /* |
| 3353 Write current region into specified file; no coding-system frobbing. | |
| 4266 | 3354 |
| 3355 This function is almost identical to `write-region'; see that function for | |
| 3356 documentation of the START, END, FILENAME, APPEND, VISIT, and LOCKNAME | |
| 3357 arguments. CODESYS specifies the encoding to be used for the file; if it is | |
| 3358 nil, no code conversion occurs. (With `write-region' the coding system is | |
| 3359 determined automatically if not specified.) | |
| 3360 | |
| 3361 MUSTBENEW specifies that a check for an existing file of the same name | |
| 3362 should be made. If it is 'excl, XEmacs will error on detecting such a file | |
| 3363 and never write it. If it is some other non-nil value, the user will be | |
| 3364 prompted to confirm the overwriting of an existing file. If it is nil, | |
| 3365 existing files are silently overwritten when file system permissions allow | |
| 3366 this. | |
| 764 | 3367 |
| 3368 As a special kludge to support auto-saving, when START is nil START and | |
| 3369 END are set to the beginning and end, respectively, of the buffer, | |
| 3370 regardless of any restrictions. Don't use this feature. It is documented | |
| 3371 here because write-region handler writers need to be aware of it. | |
| 4266 | 3372 |
| 428 | 3373 */ |
| 4266 | 3374 (start, end, filename, append, visit, lockname, codesys, |
| 3375 mustbenew)) | |
| 428 | 3376 { |
| 442 | 3377 /* This function can call lisp. GC checked 2000-07-28 ben */ |
| 428 | 3378 int desc; |
| 3379 int failure; | |
| 3380 int save_errno = 0; | |
| 3381 struct stat st; | |
| 442 | 3382 Lisp_Object fn = Qnil; |
| 428 | 3383 int speccount = specpdl_depth (); |
| 3384 int visiting_other = STRINGP (visit); | |
| 3385 int visiting = (EQ (visit, Qt) || visiting_other); | |
| 3386 int quietly = (!visiting && !NILP (visit)); | |
| 3387 Lisp_Object visit_file = Qnil; | |
| 3388 Lisp_Object annotations = Qnil; | |
| 3389 struct buffer *given_buffer; | |
| 665 | 3390 Charbpos start1, end1; |
| 442 | 3391 struct gcpro gcpro1, gcpro2, gcpro3, gcpro4, gcpro5; |
| 3392 struct gcpro ngcpro1, ngcpro2; | |
| 793 | 3393 Lisp_Object curbuf = wrap_buffer (current_buffer); |
| 3394 | |
| 442 | 3395 |
| 3396 /* start, end, visit, and append are never modified in this fun | |
| 3397 so we don't protect them. */ | |
| 3398 GCPRO5 (visit_file, filename, codesys, lockname, annotations); | |
| 3399 NGCPRO2 (curbuf, fn); | |
| 3400 | |
| 3401 /* [[ dmoore - if Fexpand_file_name or handlers kill the buffer, | |
| 428 | 3402 we should signal an error rather than blissfully continuing |
| 3403 along. ARGH, this function is going to lose lose lose. We need | |
| 3404 to protect the current_buffer from being destroyed, but the | |
| 442 | 3405 multiple return points make this a pain in the butt. ]] we do |
| 3406 protect curbuf now. --ben */ | |
| 428 | 3407 |
| 771 | 3408 codesys = get_coding_system_for_text_file (codesys, 0); |
| 428 | 3409 |
| 3410 if (current_buffer->base_buffer && ! NILP (visit)) | |
| 442 | 3411 invalid_operation ("Cannot do file visiting in an indirect buffer", |
| 3412 curbuf); | |
| 428 | 3413 |
| 3414 if (!NILP (start) && !STRINGP (start)) | |
| 3415 get_buffer_range_char (current_buffer, start, end, &start1, &end1, 0); | |
| 3416 | |
| 3417 { | |
| 3418 Lisp_Object handler; | |
| 3419 | |
| 4266 | 3420 if (!NILP (mustbenew) && !EQ (mustbenew, Qexcl)) |
| 3421 barf_or_query_if_file_exists (filename, "overwrite", 1, NULL); | |
| 3422 | |
| 428 | 3423 if (visiting_other) |
| 3424 visit_file = Fexpand_file_name (visit, Qnil); | |
| 3425 else | |
| 3426 visit_file = filename; | |
| 3427 filename = Fexpand_file_name (filename, Qnil); | |
| 3428 | |
| 3429 if (NILP (lockname)) | |
| 3430 lockname = visit_file; | |
| 3431 | |
| 442 | 3432 /* We used to UNGCPRO here. BAD! visit_file is used below after |
| 3433 more Lisp calling. */ | |
| 428 | 3434 /* If the file name has special constructs in it, |
| 3435 call the corresponding file handler. */ | |
| 3436 handler = Ffind_file_name_handler (filename, Qwrite_region); | |
| 3437 /* If FILENAME has no handler, see if VISIT has one. */ | |
| 3438 if (NILP (handler) && STRINGP (visit)) | |
| 3439 handler = Ffind_file_name_handler (visit, Qwrite_region); | |
| 3440 | |
| 3441 if (!NILP (handler)) | |
| 3442 { | |
| 3443 Lisp_Object val = call8 (handler, Qwrite_region, start, end, | |
| 3444 filename, append, visit, lockname, codesys); | |
| 3445 if (visiting) | |
| 3446 { | |
| 3447 BUF_SAVE_MODIFF (current_buffer) = BUF_MODIFF (current_buffer); | |
| 3448 current_buffer->saved_size = make_int (BUF_SIZE (current_buffer)); | |
| 3449 current_buffer->filename = visit_file; | |
| 3450 MARK_MODELINE_CHANGED; | |
| 3451 } | |
| 442 | 3452 NUNGCPRO; |
| 3453 UNGCPRO; | |
| 428 | 3454 return val; |
| 3455 } | |
| 3456 } | |
| 3457 | |
| 3458 #ifdef CLASH_DETECTION | |
| 3459 if (!auto_saving) | |
| 442 | 3460 lock_file (lockname); |
| 428 | 3461 #endif /* CLASH_DETECTION */ |
| 3462 | |
| 3463 /* Special kludge to simplify auto-saving. */ | |
| 3464 if (NILP (start)) | |
| 3465 { | |
| 3466 start1 = BUF_BEG (current_buffer); | |
| 3467 end1 = BUF_Z (current_buffer); | |
| 3468 } | |
| 3469 | |
| 3470 record_unwind_protect (build_annotations_unwind, Fcurrent_buffer ()); | |
| 3471 | |
| 3472 given_buffer = current_buffer; | |
| 3473 annotations = build_annotations (start, end); | |
| 3474 if (current_buffer != given_buffer) | |
| 3475 { | |
| 3476 start1 = BUF_BEGV (current_buffer); | |
| 3477 end1 = BUF_ZV (current_buffer); | |
| 3478 } | |
| 3479 | |
| 3480 fn = filename; | |
| 3481 desc = -1; | |
| 3482 if (!NILP (append)) | |
| 3483 { | |
| 4266 | 3484 desc = qxe_open (XSTRING_DATA (fn), O_WRONLY | OPEN_BINARY |
| 3485 | (EQ (mustbenew, Qexcl) ? O_EXCL : 0), 0); | |
| 428 | 3486 } |
| 3487 if (desc < 0) | |
| 3488 { | |
| 771 | 3489 desc = qxe_open (XSTRING_DATA (fn), |
| 4266 | 3490 O_WRONLY | (EQ (mustbenew, Qexcl) ? O_EXCL : O_TRUNC) |
| 3491 | O_CREAT | OPEN_BINARY, | |
| 771 | 3492 auto_saving ? auto_save_mode_bits : CREAT_MODE); |
| 428 | 3493 } |
| 3494 | |
| 3495 if (desc < 0) | |
| 3496 { | |
| 3497 #ifdef CLASH_DETECTION | |
| 3498 save_errno = errno; | |
| 3499 if (!auto_saving) unlock_file (lockname); | |
| 3500 errno = save_errno; | |
| 3501 #endif /* CLASH_DETECTION */ | |
| 563 | 3502 report_file_error ("Opening output file", filename); |
| 428 | 3503 } |
| 3504 | |
| 3505 { | |
| 3506 Lisp_Object desc_locative = Fcons (make_int (desc), Qnil); | |
| 3507 Lisp_Object instream = Qnil, outstream = Qnil; | |
| 442 | 3508 struct gcpro nngcpro1, nngcpro2; |
| 3509 NNGCPRO2 (instream, outstream); | |
| 428 | 3510 |
| 3511 record_unwind_protect (close_file_unwind, desc_locative); | |
| 3512 | |
| 3513 if (!NILP (append)) | |
| 3514 { | |
| 3515 if (lseek (desc, 0, 2) < 0) | |
| 3516 { | |
| 3517 #ifdef CLASH_DETECTION | |
| 3518 if (!auto_saving) unlock_file (lockname); | |
| 3519 #endif /* CLASH_DETECTION */ | |
| 3520 report_file_error ("Lseek error", | |
| 563 | 3521 filename); |
| 428 | 3522 } |
| 3523 } | |
| 3524 | |
| 3525 failure = 0; | |
| 3526 | |
| 3527 /* Note: I tried increasing the buffering size, along with | |
| 3528 various other tricks, but nothing seemed to make much of | |
| 3529 a difference in the time it took to save a large file. | |
| 3530 (Actually that's not true. With a local disk, changing | |
| 3531 the buffer size doesn't seem to make much difference. | |
| 3532 With an NFS-mounted disk, it could make a lot of difference | |
| 3533 because you're affecting the number of network requests | |
| 3534 that need to be made, and there could be a large latency | |
| 3535 for each request. So I've increased the buffer size | |
| 3536 to 64K.) */ | |
| 3537 outstream = make_filedesc_output_stream (desc, 0, -1, 0); | |
| 3538 Lstream_set_buffering (XLSTREAM (outstream), | |
| 3539 LSTREAM_BLOCKN_BUFFERED, 65536); | |
| 3540 outstream = | |
| 800 | 3541 make_coding_output_stream (XLSTREAM (outstream), codesys, |
| 3542 CODING_ENCODE, 0); | |
| 428 | 3543 Lstream_set_buffering (XLSTREAM (outstream), |
| 3544 LSTREAM_BLOCKN_BUFFERED, 65536); | |
| 3545 if (STRINGP (start)) | |
| 3546 { | |
| 3547 instream = make_lisp_string_input_stream (start, 0, -1); | |
| 3548 start1 = 0; | |
| 3549 } | |
| 3550 else | |
| 3551 instream = make_lisp_buffer_input_stream (current_buffer, start1, end1, | |
| 3552 LSTR_SELECTIVE | | |
| 3553 LSTR_IGNORE_ACCESSIBLE); | |
| 3554 failure = (0 > (a_write (outstream, instream, start1, | |
| 3555 &annotations))); | |
| 3556 save_errno = errno; | |
| 3557 /* Note that this doesn't close the desc since we created the | |
| 3558 stream without the LSTR_CLOSING flag, but it does | |
| 3559 flush out any buffered data. */ | |
| 3560 if (Lstream_close (XLSTREAM (outstream)) < 0) | |
| 3561 { | |
| 3562 failure = 1; | |
| 3563 save_errno = errno; | |
| 3564 } | |
| 3565 Lstream_close (XLSTREAM (instream)); | |
| 3566 | |
| 3567 #ifdef HAVE_FSYNC | |
| 3568 /* Note fsync appears to change the modtime on BSD4.2 (both vax and sun). | |
| 3569 Disk full in NFS may be reported here. */ | |
| 3570 /* mib says that closing the file will try to write as fast as NFS can do | |
| 3571 it, and that means the fsync here is not crucial for autosave files. */ | |
|
4499
eb82259f265d
Port write-region-inhibit-sync, allowing avoidance of bad FS performance.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4465
diff
changeset
|
3572 if (!auto_saving && !write_region_inhibit_fsync && fsync (desc) < 0 |
| 428 | 3573 /* If fsync fails with EINTR, don't treat that as serious. */ |
| 3574 && errno != EINTR) | |
| 3575 { | |
| 3576 failure = 1; | |
| 3577 save_errno = errno; | |
| 3578 } | |
| 3579 #endif /* HAVE_FSYNC */ | |
| 3580 | |
| 440 | 3581 /* Spurious "file has changed on disk" warnings used to be seen on |
| 3582 systems where close() can change the modtime. This is known to | |
| 3583 happen on various NFS file systems, on Windows, and on Linux. | |
| 3584 Rather than handling this on a per-system basis, we | |
| 771 | 3585 unconditionally do the qxe_stat() after the retry_close(). */ |
| 428 | 3586 |
| 3587 /* NFS can report a write failure now. */ | |
| 771 | 3588 if (retry_close (desc) < 0) |
| 428 | 3589 { |
| 3590 failure = 1; | |
| 3591 save_errno = errno; | |
| 3592 } | |
| 3593 | |
| 3594 /* Discard the close unwind-protect. Execute the one for | |
| 3595 build_annotations (switches back to the original current buffer | |
| 3596 as necessary). */ | |
| 3597 XCAR (desc_locative) = Qnil; | |
| 771 | 3598 unbind_to (speccount); |
| 442 | 3599 |
| 3600 NNUNGCPRO; | |
| 428 | 3601 } |
| 3602 | |
| 771 | 3603 qxe_stat (XSTRING_DATA (fn), &st); |
| 428 | 3604 |
| 3605 #ifdef CLASH_DETECTION | |
| 3606 if (!auto_saving) | |
| 3607 unlock_file (lockname); | |
| 3608 #endif /* CLASH_DETECTION */ | |
| 3609 | |
| 3610 /* Do this before reporting IO error | |
| 3611 to avoid a "file has changed on disk" warning on | |
| 3612 next attempt to save. */ | |
| 3613 if (visiting) | |
| 3614 current_buffer->modtime = st.st_mtime; | |
| 3615 | |
| 3616 if (failure) | |
| 442 | 3617 { |
| 3618 errno = save_errno; | |
| 563 | 3619 report_file_error ("Writing file", fn); |
| 442 | 3620 } |
| 428 | 3621 |
| 3622 if (visiting) | |
| 3623 { | |
| 3624 BUF_SAVE_MODIFF (current_buffer) = BUF_MODIFF (current_buffer); | |
| 3625 current_buffer->saved_size = make_int (BUF_SIZE (current_buffer)); | |
| 3626 current_buffer->filename = visit_file; | |
| 3627 MARK_MODELINE_CHANGED; | |
| 3628 } | |
| 3629 else if (quietly) | |
| 3630 { | |
| 442 | 3631 NUNGCPRO; |
| 3632 UNGCPRO; | |
| 428 | 3633 return Qnil; |
| 3634 } | |
| 3635 | |
| 3636 if (!auto_saving) | |
| 3637 { | |
| 3638 if (visiting_other) | |
| 3639 message ("Wrote %s", XSTRING_DATA (visit_file)); | |
| 3640 else | |
| 3641 { | |
| 446 | 3642 Lisp_Object fsp = Qnil; |
| 442 | 3643 struct gcpro nngcpro1; |
| 3644 | |
| 3645 NNGCPRO1 (fsp); | |
| 428 | 3646 fsp = Ffile_symlink_p (fn); |
| 3647 if (NILP (fsp)) | |
| 3648 message ("Wrote %s", XSTRING_DATA (fn)); | |
| 3649 else | |
| 3650 message ("Wrote %s (symlink to %s)", | |
| 3651 XSTRING_DATA (fn), XSTRING_DATA (fsp)); | |
| 442 | 3652 NNUNGCPRO; |
| 428 | 3653 } |
| 3654 } | |
| 442 | 3655 NUNGCPRO; |
| 3656 UNGCPRO; | |
| 428 | 3657 return Qnil; |
| 3658 } | |
| 3659 | |
| 3660 /* #### This is such a load of shit!!!! There is no way we should define | |
| 3661 something so stupid as a subr, just sort the fucking list more | |
| 3662 intelligently. */ | |
| 3663 DEFUN ("car-less-than-car", Fcar_less_than_car, 2, 2, 0, /* | |
| 3664 Return t if (car A) is numerically less than (car B). | |
| 3665 */ | |
| 3666 (a, b)) | |
| 3667 { | |
| 3668 Lisp_Object objs[2]; | |
| 3669 objs[0] = Fcar (a); | |
| 3670 objs[1] = Fcar (b); | |
| 3671 return Flss (2, objs); | |
| 3672 } | |
| 3673 | |
| 3674 /* Heh heh heh, let's define this too, just to aggravate the person who | |
| 3675 wrote the above comment. */ | |
| 3676 DEFUN ("cdr-less-than-cdr", Fcdr_less_than_cdr, 2, 2, 0, /* | |
| 3677 Return t if (cdr A) is numerically less than (cdr B). | |
| 3678 */ | |
| 3679 (a, b)) | |
| 3680 { | |
| 3681 Lisp_Object objs[2]; | |
| 3682 objs[0] = Fcdr (a); | |
| 3683 objs[1] = Fcdr (b); | |
| 3684 return Flss (2, objs); | |
| 3685 } | |
| 3686 | |
| 3687 /* Build the complete list of annotations appropriate for writing out | |
| 3688 the text between START and END, by calling all the functions in | |
| 3689 write-region-annotate-functions and merging the lists they return. | |
| 3690 If one of these functions switches to a different buffer, we assume | |
| 3691 that buffer contains altered text. Therefore, the caller must | |
| 3692 make sure to restore the current buffer in all cases, | |
| 3693 as save-excursion would do. */ | |
| 3694 | |
| 3695 static Lisp_Object | |
| 3696 build_annotations (Lisp_Object start, Lisp_Object end) | |
| 3697 { | |
| 3698 /* This function can GC */ | |
| 3699 Lisp_Object annotations; | |
| 3700 Lisp_Object p, res; | |
| 3701 struct gcpro gcpro1, gcpro2; | |
| 793 | 3702 Lisp_Object original_buffer = wrap_buffer (current_buffer); |
| 3703 | |
| 428 | 3704 |
| 3705 annotations = Qnil; | |
| 3706 p = Vwrite_region_annotate_functions; | |
| 3707 GCPRO2 (annotations, p); | |
| 3708 while (!NILP (p)) | |
| 3709 { | |
| 3710 struct buffer *given_buffer = current_buffer; | |
| 3711 Vwrite_region_annotations_so_far = annotations; | |
| 3712 res = call2 (Fcar (p), start, end); | |
| 3713 /* If the function makes a different buffer current, | |
| 3714 assume that means this buffer contains altered text to be output. | |
| 3715 Reset START and END from the buffer bounds | |
| 3716 and discard all previous annotations because they should have | |
| 3717 been dealt with by this function. */ | |
| 3718 if (current_buffer != given_buffer) | |
| 3719 { | |
| 3720 start = make_int (BUF_BEGV (current_buffer)); | |
| 3721 end = make_int (BUF_ZV (current_buffer)); | |
| 3722 annotations = Qnil; | |
| 3723 } | |
| 3724 Flength (res); /* Check basic validity of return value */ | |
| 3725 annotations = merge (annotations, res, Qcar_less_than_car); | |
| 3726 p = Fcdr (p); | |
| 3727 } | |
| 3728 | |
| 3729 /* Now do the same for annotation functions implied by the file-format */ | |
| 3730 if (auto_saving && (!EQ (Vauto_save_file_format, Qt))) | |
| 3731 p = Vauto_save_file_format; | |
| 3732 else | |
| 3733 p = current_buffer->file_format; | |
| 3734 while (!NILP (p)) | |
| 3735 { | |
| 3736 struct buffer *given_buffer = current_buffer; | |
| 3737 Vwrite_region_annotations_so_far = annotations; | |
| 3738 res = call4 (Qformat_annotate_function, Fcar (p), start, end, | |
| 3739 original_buffer); | |
| 3740 if (current_buffer != given_buffer) | |
| 3741 { | |
| 3742 start = make_int (BUF_BEGV (current_buffer)); | |
| 3743 end = make_int (BUF_ZV (current_buffer)); | |
| 3744 annotations = Qnil; | |
| 3745 } | |
| 3746 Flength (res); | |
| 3747 annotations = merge (annotations, res, Qcar_less_than_car); | |
| 3748 p = Fcdr (p); | |
| 3749 } | |
| 3750 UNGCPRO; | |
| 3751 return annotations; | |
| 3752 } | |
| 3753 | |
| 3754 /* Write to stream OUTSTREAM the characters from INSTREAM (it is read until | |
| 3755 EOF is encountered), assuming they start at position POS in the buffer | |
| 3756 of string that STREAM refers to. Intersperse with them the annotations | |
| 3757 from *ANNOT that fall into the range of positions we are reading from, | |
| 3758 each at its appropriate position. | |
| 3759 | |
| 3760 Modify *ANNOT by discarding elements as we output them. | |
| 3761 The return value is negative in case of system call failure. */ | |
| 3762 | |
| 3763 /* 4K should probably be fine. We just need to reduce the number of | |
| 3764 function calls to reasonable level. The Lstream stuff itself will | |
| 3765 batch to 64K to reduce the number of system calls. */ | |
| 3766 | |
| 3767 #define A_WRITE_BATCH_SIZE 4096 | |
| 3768 | |
| 3769 static int | |
| 3770 a_write (Lisp_Object outstream, Lisp_Object instream, int pos, | |
| 3771 Lisp_Object *annot) | |
| 3772 { | |
| 3773 Lisp_Object tem; | |
| 3774 int nextpos; | |
| 3775 unsigned char largebuf[A_WRITE_BATCH_SIZE]; | |
| 3776 Lstream *instr = XLSTREAM (instream); | |
| 3777 Lstream *outstr = XLSTREAM (outstream); | |
| 3778 | |
| 3779 while (LISTP (*annot)) | |
| 3780 { | |
| 3781 tem = Fcar_safe (Fcar (*annot)); | |
| 3782 if (INTP (tem)) | |
| 3783 nextpos = XINT (tem); | |
| 3784 else | |
| 3785 nextpos = INT_MAX; | |
| 3786 #ifdef MULE | |
| 3787 /* If there are annotations left and we have Mule, then we | |
| 867 | 3788 have to do the I/O one ichar at a time so we can |
| 428 | 3789 determine when to insert the annotation. */ |
| 3790 if (!NILP (*annot)) | |
| 3791 { | |
| 867 | 3792 Ichar ch; |
| 3793 while (pos != nextpos && (ch = Lstream_get_ichar (instr)) != EOF) | |
| 428 | 3794 { |
| 867 | 3795 if (Lstream_put_ichar (outstr, ch) < 0) |
| 428 | 3796 return -1; |
| 3797 pos++; | |
| 3798 } | |
| 3799 } | |
| 3800 else | |
| 3801 #endif /* MULE */ | |
| 3802 { | |
| 3803 while (pos != nextpos) | |
| 3804 { | |
| 3805 /* Otherwise there is no point to that. Just go in batches. */ | |
| 3806 int chunk = min (nextpos - pos, A_WRITE_BATCH_SIZE); | |
| 3807 | |
| 3808 chunk = Lstream_read (instr, largebuf, chunk); | |
| 3809 if (chunk < 0) | |
| 3810 return -1; | |
| 3811 if (chunk == 0) /* EOF */ | |
| 3812 break; | |
| 771 | 3813 if (Lstream_write (outstr, largebuf, chunk) < 0) |
| 428 | 3814 return -1; |
| 3815 pos += chunk; | |
| 3816 } | |
| 3817 } | |
| 3818 if (pos == nextpos) | |
| 3819 { | |
| 3820 tem = Fcdr (Fcar (*annot)); | |
| 3821 if (STRINGP (tem)) | |
| 3822 { | |
| 3823 if (Lstream_write (outstr, XSTRING_DATA (tem), | |
| 3824 XSTRING_LENGTH (tem)) < 0) | |
| 3825 return -1; | |
| 3826 } | |
| 3827 *annot = Fcdr (*annot); | |
| 3828 } | |
| 3829 else | |
| 3830 return 0; | |
| 3831 } | |
| 3832 return -1; | |
| 3833 } | |
| 3834 | |
| 3835 | |
| 3836 | |
| 3837 #if 0 | |
| 3838 #include <des_crypt.h> | |
| 3839 | |
| 3840 #define CRYPT_BLOCK_SIZE 8 /* bytes */ | |
| 3841 #define CRYPT_KEY_SIZE 8 /* bytes */ | |
| 3842 | |
| 3843 DEFUN ("encrypt-string", Fencrypt_string, 2, 2, 0, /* | |
| 3844 Encrypt STRING using KEY. | |
| 3845 */ | |
| 3846 (string, key)) | |
| 3847 { | |
| 2367 | 3848 /* !!#### Needs work */ |
| 1333 | 3849 Extbyte *encrypted_string, *raw_key; |
| 3850 Extbyte *string_ext, *key_ext; | |
| 3851 Bytecount string_size_ext, key_size_ext, rounded_size, extra, key_size; | |
| 3852 | |
| 428 | 3853 CHECK_STRING (string); |
| 3854 CHECK_STRING (key); | |
| 3855 | |
| 1333 | 3856 LISP_STRING_TO_SIZED_EXTERNAL (string, string_ext, string_size_ext, Qbinary); |
| 3857 LISP_STRING_TO_SIZED_EXTERNAL (key, key_ext, key_size_ext, Qbinary); | |
| 3858 | |
| 3859 extra = string_size_ext % CRYPT_BLOCK_SIZE; | |
| 3860 rounded_size = string_size_ext + extra; | |
| 851 | 3861 encrypted_string = ALLOCA (rounded_size + 1); |
| 1333 | 3862 memcpy (encrypted_string, string_ext, string_size_ext); |
| 428 | 3863 memset (encrypted_string + rounded_size - extra, 0, extra + 1); |
| 3864 | |
| 1333 | 3865 key_size = min (CRYPT_KEY_SIZE, key_size_ext); |
| 428 | 3866 |
| 851 | 3867 raw_key = ALLOCA (CRYPT_KEY_SIZE + 1); |
| 1333 | 3868 memcpy (raw_key, key_ext, key_size); |
| 428 | 3869 memset (raw_key + key_size, 0, (CRYPT_KEY_SIZE + 1) - key_size); |
| 3870 | |
| 3871 ecb_crypt (raw_key, encrypted_string, rounded_size, | |
| 3872 DES_ENCRYPT | DES_SW); | |
| 1333 | 3873 return make_ext_string (encrypted_string, rounded_size, Qbinary); |
| 428 | 3874 } |
| 3875 | |
| 3876 DEFUN ("decrypt-string", Fdecrypt_string, 2, 2, 0, /* | |
| 3877 Decrypt STRING using KEY. | |
| 3878 */ | |
| 3879 (string, key)) | |
| 3880 { | |
| 1333 | 3881 Extbyte *decrypted_string, *raw_key; |
| 3882 Extbyte *string_ext, *key_ext; | |
| 3883 Bytecount string_size_ext, key_size_ext, string_size, key_size; | |
| 428 | 3884 |
| 3885 CHECK_STRING (string); | |
| 3886 CHECK_STRING (key); | |
| 3887 | |
| 1333 | 3888 LISP_STRING_TO_SIZED_EXTERNAL (string, string_ext, string_size_ext, Qbinary); |
| 3889 LISP_STRING_TO_SIZED_EXTERNAL (key, key_ext, key_size_ext, Qbinary); | |
| 3890 | |
| 3891 string_size = string_size_ext + 1; | |
| 851 | 3892 decrypted_string = ALLOCA (string_size); |
| 1333 | 3893 memcpy (decrypted_string, string_ext, string_size); |
| 428 | 3894 decrypted_string[string_size - 1] = '\0'; |
| 3895 | |
| 1333 | 3896 key_size = min (CRYPT_KEY_SIZE, key_size_ext); |
| 428 | 3897 |
| 851 | 3898 raw_key = ALLOCA (CRYPT_KEY_SIZE + 1); |
| 1333 | 3899 memcpy (raw_key, key_ext, key_size); |
| 428 | 3900 memset (raw_key + key_size, 0, (CRYPT_KEY_SIZE + 1) - key_size); |
| 3901 | |
| 3902 | |
| 3903 ecb_crypt (raw_key, decrypted_string, string_size, D | DES_SW); | |
| 1333 | 3904 return make_ext_string (decrypted_string, string_size - 1, Qbinary); |
| 428 | 3905 } |
| 3906 #endif /* 0 */ | |
| 3907 | |
| 3908 | |
| 3909 DEFUN ("verify-visited-file-modtime", Fverify_visited_file_modtime, 1, 1, 0, /* | |
| 444 | 3910 Return t if last mod time of BUFFER's visited file matches what BUFFER records. |
| 428 | 3911 This means that the file has not been changed since it was visited or saved. |
| 3912 */ | |
| 444 | 3913 (buffer)) |
| 428 | 3914 { |
| 442 | 3915 /* This function can call lisp; GC checked 2000-07-11 ben */ |
| 428 | 3916 struct buffer *b; |
| 3917 struct stat st; | |
| 3918 Lisp_Object handler; | |
| 3919 | |
| 444 | 3920 CHECK_BUFFER (buffer); |
| 3921 b = XBUFFER (buffer); | |
| 428 | 3922 |
| 3923 if (!STRINGP (b->filename)) return Qt; | |
| 3924 if (b->modtime == 0) return Qt; | |
| 3925 | |
| 3926 /* If the file name has special constructs in it, | |
| 3927 call the corresponding file handler. */ | |
| 3928 handler = Ffind_file_name_handler (b->filename, | |
| 3929 Qverify_visited_file_modtime); | |
| 3930 if (!NILP (handler)) | |
| 444 | 3931 return call2 (handler, Qverify_visited_file_modtime, buffer); |
| 428 | 3932 |
| 771 | 3933 if (qxe_stat (XSTRING_DATA (b->filename), &st) < 0) |
| 428 | 3934 { |
| 3935 /* If the file doesn't exist now and didn't exist before, | |
| 3936 we say that it isn't modified, provided the error is a tame one. */ | |
| 3937 if (errno == ENOENT || errno == EACCES || errno == ENOTDIR) | |
| 3938 st.st_mtime = -1; | |
| 3939 else | |
| 3940 st.st_mtime = 0; | |
| 3941 } | |
| 3942 if (st.st_mtime == b->modtime | |
| 3943 /* If both are positive, accept them if they are off by one second. */ | |
| 3944 || (st.st_mtime > 0 && b->modtime > 0 | |
| 3945 && (st.st_mtime == b->modtime + 1 | |
| 3946 || st.st_mtime == b->modtime - 1))) | |
| 3947 return Qt; | |
| 3948 return Qnil; | |
| 3949 } | |
| 3950 | |
| 3951 DEFUN ("clear-visited-file-modtime", Fclear_visited_file_modtime, 0, 0, 0, /* | |
| 3952 Clear out records of last mod time of visited file. | |
| 3953 Next attempt to save will certainly not complain of a discrepancy. | |
| 3954 */ | |
| 3955 ()) | |
| 3956 { | |
| 3957 current_buffer->modtime = 0; | |
| 3958 return Qnil; | |
| 3959 } | |
| 3960 | |
| 3961 DEFUN ("visited-file-modtime", Fvisited_file_modtime, 0, 0, 0, /* | |
| 3962 Return the current buffer's recorded visited file modification time. | |
| 3963 The value is a list of the form (HIGH . LOW), like the time values | |
| 3964 that `file-attributes' returns. | |
| 3965 */ | |
| 3966 ()) | |
| 3967 { | |
| 3968 return time_to_lisp ((time_t) current_buffer->modtime); | |
| 3969 } | |
| 3970 | |
| 3971 DEFUN ("set-visited-file-modtime", Fset_visited_file_modtime, 0, 1, 0, /* | |
| 3972 Update buffer's recorded modification time from the visited file's time. | |
| 3973 Useful if the buffer was not read from the file normally | |
| 3974 or if the file itself has been changed for some known benign reason. | |
| 3975 An argument specifies the modification time value to use | |
| 3976 \(instead of that of the visited file), in the form of a list | |
| 3977 \(HIGH . LOW) or (HIGH LOW). | |
| 3978 */ | |
| 3979 (time_list)) | |
| 3980 { | |
| 3981 /* This function can call lisp */ | |
| 3982 if (!NILP (time_list)) | |
| 3983 { | |
| 3984 time_t the_time; | |
| 3985 lisp_to_time (time_list, &the_time); | |
| 3986 current_buffer->modtime = (int) the_time; | |
| 3987 } | |
| 3988 else | |
| 3989 { | |
| 446 | 3990 Lisp_Object filename = Qnil; |
| 428 | 3991 struct stat st; |
| 3992 Lisp_Object handler; | |
| 3993 struct gcpro gcpro1, gcpro2, gcpro3; | |
| 3994 | |
| 3995 GCPRO3 (filename, time_list, current_buffer->filename); | |
| 3996 filename = Fexpand_file_name (current_buffer->filename, Qnil); | |
| 3997 | |
| 3998 /* If the file name has special constructs in it, | |
| 3999 call the corresponding file handler. */ | |
| 4000 handler = Ffind_file_name_handler (filename, Qset_visited_file_modtime); | |
| 4001 UNGCPRO; | |
| 4002 if (!NILP (handler)) | |
| 4003 /* The handler can find the file name the same way we did. */ | |
| 4004 return call2 (handler, Qset_visited_file_modtime, Qnil); | |
| 771 | 4005 else if (qxe_stat (XSTRING_DATA (filename), &st) >= 0) |
| 428 | 4006 current_buffer->modtime = st.st_mtime; |
| 4007 } | |
| 4008 | |
| 4009 return Qnil; | |
| 4010 } | |
| 4011 | |
| 4012 static Lisp_Object | |
| 2286 | 4013 auto_save_error (Lisp_Object UNUSED (condition_object), |
| 4014 Lisp_Object UNUSED (ignored)) | |
| 428 | 4015 { |
| 4016 /* This function can call lisp */ | |
| 4017 if (gc_in_progress) | |
| 4018 return Qnil; | |
| 4019 /* Don't try printing an error message after everything is gone! */ | |
| 4020 if (preparing_for_armageddon) | |
| 4021 return Qnil; | |
| 4022 clear_echo_area (selected_frame (), Qauto_saving, 1); | |
| 4023 Fding (Qt, Qauto_save_error, Qnil); | |
| 4024 message ("Auto-saving...error for %s", XSTRING_DATA (current_buffer->name)); | |
| 4025 Fsleep_for (make_int (1)); | |
| 4026 message ("Auto-saving...error!for %s", XSTRING_DATA (current_buffer->name)); | |
| 4027 Fsleep_for (make_int (1)); | |
| 4028 message ("Auto-saving...error for %s", XSTRING_DATA (current_buffer->name)); | |
| 4029 Fsleep_for (make_int (1)); | |
| 4030 return Qnil; | |
| 4031 } | |
| 4032 | |
| 4033 static Lisp_Object | |
| 2286 | 4034 auto_save_1 (Lisp_Object UNUSED (ignored)) |
| 428 | 4035 { |
| 4036 /* This function can call lisp */ | |
| 4037 /* #### I think caller is protecting current_buffer? */ | |
| 4038 struct stat st; | |
| 4039 Lisp_Object fn = current_buffer->filename; | |
| 4040 Lisp_Object a = current_buffer->auto_save_file_name; | |
| 4041 | |
| 4042 if (!STRINGP (a)) | |
| 4043 return (Qnil); | |
| 4044 | |
| 4045 /* Get visited file's mode to become the auto save file's mode. */ | |
| 4046 if (STRINGP (fn) && | |
| 771 | 4047 qxe_stat (XSTRING_DATA (fn), &st) >= 0) |
| 428 | 4048 /* But make sure we can overwrite it later! */ |
| 4049 auto_save_mode_bits = st.st_mode | 0600; | |
| 4050 else | |
| 4051 /* default mode for auto-save files of buffers with no file is | |
| 4052 readable by owner only. This may annoy some small number of | |
| 4053 people, but the alternative removes all privacy from email. */ | |
| 4054 auto_save_mode_bits = 0600; | |
| 4055 | |
| 4056 return | |
| 4057 Fwrite_region_internal (Qnil, Qnil, a, Qnil, Qlambda, Qnil, | |
| 771 | 4058 #if 1 /* #### Kyle wants it changed to not use escape-quoted. Think |
| 4059 carefully about how this works. */ | |
| 4266 | 4060 Qescape_quoted, |
| 771 | 4061 #else |
| 4266 | 4062 current_buffer->buffer_file_coding_system, |
| 428 | 4063 #endif |
| 4266 | 4064 Qnil); |
| 428 | 4065 } |
| 4066 | |
| 4067 static Lisp_Object | |
| 2286 | 4068 auto_save_expand_name_error (Lisp_Object condition_object, |
| 4069 Lisp_Object UNUSED (ignored)) | |
| 428 | 4070 { |
| 771 | 4071 warn_when_safe_lispobj |
| 793 | 4072 (Qfile, Qerror, |
| 771 | 4073 Fcons (build_msg_string ("Invalid auto-save list-file"), |
| 4074 Fcons (Vauto_save_list_file_name, | |
| 4075 condition_object))); | |
| 428 | 4076 return Qnil; |
| 4077 } | |
| 4078 | |
| 4079 static Lisp_Object | |
| 4080 auto_save_expand_name (Lisp_Object name) | |
| 4081 { | |
| 4082 struct gcpro gcpro1; | |
| 4083 | |
| 4084 /* note that caller did NOT gc protect name, so we do it. */ | |
| 771 | 4085 /* [[dmoore - this might not be necessary, if condition_case_1 |
| 4086 protects it. but I don't think it does.]] indeed it doesn't. --ben */ | |
| 428 | 4087 GCPRO1 (name); |
| 4088 RETURN_UNGCPRO (Fexpand_file_name (name, Qnil)); | |
| 4089 } | |
| 4090 | |
| 4091 | |
| 4092 static Lisp_Object | |
| 4093 do_auto_save_unwind (Lisp_Object fd) | |
| 4094 { | |
| 771 | 4095 retry_close (XINT (fd)); |
| 428 | 4096 return (fd); |
| 4097 } | |
| 4098 | |
| 4099 /* Fdo_auto_save() checks whether a GC is in progress when it is called, | |
| 4100 and if so, tries to avoid touching lisp objects. | |
| 4101 | |
| 4102 The only time that Fdo_auto_save() is called while GC is in progress | |
| 2500 | 4103 is if we're going down, as a result of an ABORT() or a kill signal. |
| 428 | 4104 It's fairly important that we generate autosave files in that case! |
| 4105 */ | |
| 4106 | |
| 4107 DEFUN ("do-auto-save", Fdo_auto_save, 0, 2, "", /* | |
| 4108 Auto-save all buffers that need it. | |
| 4109 This is all buffers that have auto-saving enabled | |
| 4110 and are changed since last auto-saved. | |
| 4111 Auto-saving writes the buffer into a file | |
| 4112 so that your editing is not lost if the system crashes. | |
| 4113 This file is not the file you visited; that changes only when you save. | |
| 4114 Normally we run the normal hook `auto-save-hook' before saving. | |
| 4115 | |
| 4116 Non-nil first argument means do not print any message if successful. | |
| 4117 Non-nil second argument means save only current buffer. | |
| 4118 */ | |
| 4119 (no_message, current_only)) | |
| 4120 { | |
| 4121 /* This function can call lisp */ | |
| 4122 struct buffer *b; | |
| 4123 Lisp_Object tail, buf; | |
| 4124 int auto_saved = 0; | |
| 4125 int do_handled_files; | |
| 4126 Lisp_Object oquit = Qnil; | |
| 4127 Lisp_Object listfile = Qnil; | |
| 4128 Lisp_Object old; | |
| 4129 int listdesc = -1; | |
| 4130 int speccount = specpdl_depth (); | |
| 4131 struct gcpro gcpro1, gcpro2, gcpro3; | |
| 4132 | |
| 793 | 4133 old = wrap_buffer (current_buffer); |
| 428 | 4134 GCPRO3 (oquit, listfile, old); |
| 4135 check_quit (); /* make Vquit_flag accurate */ | |
| 4136 /* Ordinarily don't quit within this function, | |
| 4137 but don't make it impossible to quit (in case we get hung in I/O). */ | |
| 4138 oquit = Vquit_flag; | |
| 4139 Vquit_flag = Qnil; | |
| 4140 | |
| 4141 /* No further GCPRO needed, because (when it matters) all Lisp_Object | |
| 4142 variables point to non-strings reached from Vbuffer_alist. */ | |
| 4143 | |
| 4144 if (minibuf_level != 0 || preparing_for_armageddon) | |
| 4145 no_message = Qt; | |
| 4146 | |
| 4147 run_hook (Qauto_save_hook); | |
| 4148 | |
| 4149 if (STRINGP (Vauto_save_list_file_name)) | |
| 4150 listfile = condition_case_1 (Qt, | |
| 4151 auto_save_expand_name, | |
| 4152 Vauto_save_list_file_name, | |
| 4153 auto_save_expand_name_error, Qnil); | |
| 4154 | |
| 853 | 4155 internal_bind_int (&auto_saving, 1); |
| 428 | 4156 |
| 4157 /* First, save all files which don't have handlers. If Emacs is | |
| 4158 crashing, the handlers may tweak what is causing Emacs to crash | |
| 4159 in the first place, and it would be a shame if Emacs failed to | |
| 4160 autosave perfectly ordinary files because it couldn't handle some | |
| 4161 ange-ftp'd file. */ | |
| 4162 for (do_handled_files = 0; do_handled_files < 2; do_handled_files++) | |
| 4163 { | |
| 4164 for (tail = Vbuffer_alist; | |
| 4165 CONSP (tail); | |
| 4166 tail = XCDR (tail)) | |
| 4167 { | |
| 4168 buf = XCDR (XCAR (tail)); | |
| 4169 b = XBUFFER (buf); | |
| 4170 | |
| 4171 if (!NILP (current_only) | |
| 4172 && b != current_buffer) | |
| 4173 continue; | |
| 4174 | |
| 4175 /* Don't auto-save indirect buffers. | |
| 4176 The base buffer takes care of it. */ | |
| 4177 if (b->base_buffer) | |
| 4178 continue; | |
| 4179 | |
| 4180 /* Check for auto save enabled | |
| 4181 and file changed since last auto save | |
| 4182 and file changed since last real save. */ | |
| 4183 if (STRINGP (b->auto_save_file_name) | |
| 4184 && BUF_SAVE_MODIFF (b) < BUF_MODIFF (b) | |
| 4185 && b->auto_save_modified < BUF_MODIFF (b) | |
| 4186 /* -1 means we've turned off autosaving for a while--see below. */ | |
| 4187 && XINT (b->saved_size) >= 0 | |
| 4188 && (do_handled_files | |
| 4189 || NILP (Ffind_file_name_handler (b->auto_save_file_name, | |
| 4190 Qwrite_region)))) | |
| 4191 { | |
| 4192 EMACS_TIME before_time, after_time; | |
| 4193 | |
| 4194 EMACS_GET_TIME (before_time); | |
| 4195 /* If we had a failure, don't try again for 20 minutes. */ | |
| 4196 if (!preparing_for_armageddon | |
| 4197 && b->auto_save_failure_time >= 0 | |
| 4198 && (EMACS_SECS (before_time) - b->auto_save_failure_time < | |
| 4199 1200)) | |
| 4200 continue; | |
| 4201 | |
| 4202 if (!preparing_for_armageddon && | |
| 4203 (XINT (b->saved_size) * 10 | |
| 4204 > (BUF_Z (b) - BUF_BEG (b)) * 13) | |
| 4205 /* A short file is likely to change a large fraction; | |
| 4206 spare the user annoying messages. */ | |
| 4207 && XINT (b->saved_size) > 5000 | |
| 4208 /* These messages are frequent and annoying for `*mail*'. */ | |
| 4209 && !NILP (b->filename) | |
| 4210 && NILP (no_message) | |
| 4211 && disable_auto_save_when_buffer_shrinks) | |
| 4212 { | |
| 4213 /* It has shrunk too much; turn off auto-saving here. | |
| 4214 Unless we're about to crash, in which case auto-save it | |
| 4215 anyway. | |
| 4216 */ | |
| 4217 message | |
| 4218 ("Buffer %s has shrunk a lot; auto save turned off there", | |
| 4219 XSTRING_DATA (b->name)); | |
| 4220 /* Turn off auto-saving until there's a real save, | |
| 4221 and prevent any more warnings. */ | |
| 4222 b->saved_size = make_int (-1); | |
| 4223 if (!gc_in_progress) | |
| 4224 Fsleep_for (make_int (1)); | |
| 4225 continue; | |
| 4226 } | |
| 4227 set_buffer_internal (b); | |
| 4228 if (!auto_saved && NILP (no_message)) | |
| 4229 { | |
| 1333 | 4230 static const Ibyte *msg = (const Ibyte *) "Auto-saving..."; |
| 428 | 4231 echo_area_message (selected_frame (), msg, Qnil, |
| 1333 | 4232 0, qxestrlen (msg), |
| 428 | 4233 Qauto_saving); |
| 4234 } | |
| 4235 | |
| 4236 /* Open the auto-save list file, if necessary. | |
| 4237 We only do this now so that the file only exists | |
| 4238 if we actually auto-saved any files. */ | |
| 444 | 4239 if (!auto_saved && !inhibit_auto_save_session |
| 4240 && !NILP (Vauto_save_list_file_prefix) | |
| 4241 && STRINGP (listfile) && listdesc < 0) | |
| 428 | 4242 { |
| 771 | 4243 listdesc = |
| 4244 qxe_open (XSTRING_DATA (listfile), | |
| 4245 O_WRONLY | O_TRUNC | O_CREAT | OPEN_BINARY, | |
| 4246 CREAT_MODE); | |
| 428 | 4247 |
| 4248 /* Arrange to close that file whether or not we get | |
| 4249 an error. */ | |
| 4250 if (listdesc >= 0) | |
| 4251 record_unwind_protect (do_auto_save_unwind, | |
| 4252 make_int (listdesc)); | |
| 4253 } | |
| 4254 | |
| 4255 /* Record all the buffers that we are auto-saving in | |
| 4256 the special file that lists them. For each of | |
| 4257 these buffers, record visited name (if any) and | |
| 4258 auto save name. */ | |
| 4259 if (listdesc >= 0) | |
| 4260 { | |
| 442 | 4261 const Extbyte *auto_save_file_name_ext; |
| 665 | 4262 Bytecount auto_save_file_name_ext_len; |
| 428 | 4263 |
| 440 | 4264 TO_EXTERNAL_FORMAT (LISP_STRING, b->auto_save_file_name, |
| 4265 ALLOCA, (auto_save_file_name_ext, | |
| 4266 auto_save_file_name_ext_len), | |
| 771 | 4267 Qescape_quoted); |
| 428 | 4268 if (!NILP (b->filename)) |
| 4269 { | |
| 442 | 4270 const Extbyte *filename_ext; |
| 665 | 4271 Bytecount filename_ext_len; |
| 428 | 4272 |
| 440 | 4273 TO_EXTERNAL_FORMAT (LISP_STRING, b->filename, |
| 4274 ALLOCA, (filename_ext, | |
| 4275 filename_ext_len), | |
| 771 | 4276 Qescape_quoted); |
| 4277 retry_write (listdesc, filename_ext, filename_ext_len); | |
| 428 | 4278 } |
| 771 | 4279 retry_write (listdesc, "\n", 1); |
| 4280 retry_write (listdesc, auto_save_file_name_ext, | |
| 428 | 4281 auto_save_file_name_ext_len); |
| 771 | 4282 retry_write (listdesc, "\n", 1); |
| 428 | 4283 } |
| 4284 | |
| 4285 /* dmoore - In a bad scenario we've set b=XBUFFER(buf) | |
| 4286 based on values in Vbuffer_alist. auto_save_1 may | |
| 4287 cause lisp handlers to run. Those handlers may kill | |
| 4288 the buffer and then GC. Since the buffer is killed, | |
| 4289 it's no longer in Vbuffer_alist so it might get reaped | |
| 4290 by the GC. We also need to protect tail. */ | |
| 4291 /* #### There is probably a lot of other code which has | |
| 4292 pointers into buffers which may get blown away by | |
| 4293 handlers. */ | |
| 4294 { | |
| 4295 struct gcpro ngcpro1, ngcpro2; | |
| 4296 NGCPRO2 (buf, tail); | |
| 4297 condition_case_1 (Qt, | |
| 4298 auto_save_1, Qnil, | |
| 4299 auto_save_error, Qnil); | |
| 4300 NUNGCPRO; | |
| 4301 } | |
| 4302 /* Handler killed our saved current-buffer! Pick any. */ | |
| 4303 if (!BUFFER_LIVE_P (XBUFFER (old))) | |
| 793 | 4304 old = wrap_buffer (current_buffer); |
| 428 | 4305 |
| 4306 set_buffer_internal (XBUFFER (old)); | |
| 4307 auto_saved++; | |
| 4308 | |
| 4309 /* Handler killed their own buffer! */ | |
| 4310 if (!BUFFER_LIVE_P(b)) | |
| 4311 continue; | |
| 4312 | |
| 4313 b->auto_save_modified = BUF_MODIFF (b); | |
| 4314 b->saved_size = make_int (BUF_SIZE (b)); | |
| 4315 EMACS_GET_TIME (after_time); | |
| 4316 /* If auto-save took more than 60 seconds, | |
| 4317 assume it was an NFS failure that got a timeout. */ | |
| 4318 if (EMACS_SECS (after_time) - EMACS_SECS (before_time) > 60) | |
| 4319 b->auto_save_failure_time = EMACS_SECS (after_time); | |
| 4320 } | |
| 4321 } | |
| 4322 } | |
| 4323 | |
| 4324 /* Prevent another auto save till enough input events come in. */ | |
| 4325 if (auto_saved) | |
| 4326 record_auto_save (); | |
| 4327 | |
| 4328 /* If we didn't save anything into the listfile, remove the old | |
| 4329 one because nothing needed to be auto-saved. Do this afterwards | |
| 4330 rather than before in case we get a crash attempting to autosave | |
| 4331 (in that case we'd still want the old one around). */ | |
| 4332 if (listdesc < 0 && !auto_saved && STRINGP (listfile)) | |
| 771 | 4333 qxe_unlink (XSTRING_DATA (listfile)); |
| 428 | 4334 |
| 4335 /* Show "...done" only if the echo area would otherwise be empty. */ | |
| 4336 if (auto_saved && NILP (no_message) | |
| 4337 && NILP (clear_echo_area (selected_frame (), Qauto_saving, 0))) | |
| 4338 { | |
| 1333 | 4339 static const Ibyte *msg = (const Ibyte *)"Auto-saving...done"; |
| 428 | 4340 echo_area_message (selected_frame (), msg, Qnil, 0, |
| 1333 | 4341 qxestrlen (msg), Qauto_saving); |
| 428 | 4342 } |
| 4343 | |
| 4344 Vquit_flag = oquit; | |
| 4345 | |
| 771 | 4346 RETURN_UNGCPRO (unbind_to (speccount)); |
| 428 | 4347 } |
| 4348 | |
| 4349 DEFUN ("set-buffer-auto-saved", Fset_buffer_auto_saved, 0, 0, 0, /* | |
| 4350 Mark current buffer as auto-saved with its current text. | |
| 4351 No auto-save file will be written until the buffer changes again. | |
| 4352 */ | |
| 4353 ()) | |
| 4354 { | |
| 4355 current_buffer->auto_save_modified = BUF_MODIFF (current_buffer); | |
| 4356 current_buffer->saved_size = make_int (BUF_SIZE (current_buffer)); | |
| 4357 current_buffer->auto_save_failure_time = -1; | |
| 4358 return Qnil; | |
| 4359 } | |
| 4360 | |
| 4361 DEFUN ("clear-buffer-auto-save-failure", Fclear_buffer_auto_save_failure, 0, 0, 0, /* | |
| 4362 Clear any record of a recent auto-save failure in the current buffer. | |
| 4363 */ | |
| 4364 ()) | |
| 4365 { | |
| 4366 current_buffer->auto_save_failure_time = -1; | |
| 4367 return Qnil; | |
| 4368 } | |
| 4369 | |
| 4370 DEFUN ("recent-auto-save-p", Frecent_auto_save_p, 0, 0, 0, /* | |
| 4371 Return t if buffer has been auto-saved since last read in or saved. | |
| 4372 */ | |
| 4373 ()) | |
| 4374 { | |
| 4375 return (BUF_SAVE_MODIFF (current_buffer) < | |
| 4376 current_buffer->auto_save_modified) ? Qt : Qnil; | |
| 4377 } | |
| 4378 | |
| 4379 | |
| 4380 /************************************************************************/ | |
| 4381 /* initialization */ | |
| 4382 /************************************************************************/ | |
| 4383 | |
| 4384 void | |
| 4385 syms_of_fileio (void) | |
| 4386 { | |
| 563 | 4387 DEFSYMBOL (Qexpand_file_name); |
| 4388 DEFSYMBOL (Qfile_truename); | |
| 4389 DEFSYMBOL (Qsubstitute_in_file_name); | |
| 4390 DEFSYMBOL (Qdirectory_file_name); | |
| 4391 DEFSYMBOL (Qfile_name_directory); | |
| 4392 DEFSYMBOL (Qfile_name_nondirectory); | |
| 996 | 4393 DEFSYMBOL (Qfile_name_sans_extension); |
| 563 | 4394 DEFSYMBOL (Qunhandled_file_name_directory); |
| 4395 DEFSYMBOL (Qfile_name_as_directory); | |
| 4396 DEFSYMBOL (Qcopy_file); | |
| 4397 DEFSYMBOL (Qmake_directory_internal); | |
| 4398 DEFSYMBOL (Qdelete_directory); | |
| 4399 DEFSYMBOL (Qdelete_file); | |
| 4400 DEFSYMBOL (Qrename_file); | |
| 4401 DEFSYMBOL (Qadd_name_to_file); | |
| 4402 DEFSYMBOL (Qmake_symbolic_link); | |
| 844 | 4403 DEFSYMBOL (Qmake_temp_name); |
| 563 | 4404 DEFSYMBOL (Qfile_exists_p); |
| 4405 DEFSYMBOL (Qfile_executable_p); | |
| 4406 DEFSYMBOL (Qfile_readable_p); | |
| 4407 DEFSYMBOL (Qfile_symlink_p); | |
| 4408 DEFSYMBOL (Qfile_writable_p); | |
| 4409 DEFSYMBOL (Qfile_directory_p); | |
| 4410 DEFSYMBOL (Qfile_regular_p); | |
| 4411 DEFSYMBOL (Qfile_accessible_directory_p); | |
| 4412 DEFSYMBOL (Qfile_modes); | |
| 4413 DEFSYMBOL (Qset_file_modes); | |
| 4414 DEFSYMBOL (Qfile_newer_than_file_p); | |
| 4415 DEFSYMBOL (Qinsert_file_contents); | |
| 4416 DEFSYMBOL (Qwrite_region); | |
| 4417 DEFSYMBOL (Qverify_visited_file_modtime); | |
| 4418 DEFSYMBOL (Qset_visited_file_modtime); | |
| 4419 DEFSYMBOL (Qcar_less_than_car); /* Vomitous! */ | |
| 4266 | 4420 DEFSYMBOL (Qexcl); |
| 563 | 4421 |
| 4422 DEFSYMBOL (Qauto_save_hook); | |
| 4423 DEFSYMBOL (Qauto_save_error); | |
| 4424 DEFSYMBOL (Qauto_saving); | |
| 4425 | |
| 4426 DEFSYMBOL (Qformat_decode); | |
| 4427 DEFSYMBOL (Qformat_annotate_function); | |
| 4428 | |
| 4429 DEFSYMBOL (Qcompute_buffer_file_truename); | |
| 4430 | |
| 442 | 4431 DEFERROR_STANDARD (Qfile_already_exists, Qfile_error); |
| 428 | 4432 |
| 4433 DEFSUBR (Ffind_file_name_handler); | |
| 4434 | |
| 4435 DEFSUBR (Ffile_name_directory); | |
| 4436 DEFSUBR (Ffile_name_nondirectory); | |
| 4437 DEFSUBR (Funhandled_file_name_directory); | |
| 4438 DEFSUBR (Ffile_name_as_directory); | |
| 4439 DEFSUBR (Fdirectory_file_name); | |
| 4440 DEFSUBR (Fmake_temp_name); | |
| 4441 DEFSUBR (Fexpand_file_name); | |
| 4442 DEFSUBR (Ffile_truename); | |
| 4443 DEFSUBR (Fsubstitute_in_file_name); | |
| 4444 DEFSUBR (Fcopy_file); | |
| 4445 DEFSUBR (Fmake_directory_internal); | |
| 4446 DEFSUBR (Fdelete_directory); | |
| 4447 DEFSUBR (Fdelete_file); | |
| 4448 DEFSUBR (Frename_file); | |
| 4449 DEFSUBR (Fadd_name_to_file); | |
| 4450 DEFSUBR (Fmake_symbolic_link); | |
| 4451 #ifdef HPUX_NET | |
| 4452 DEFSUBR (Fsysnetunam); | |
| 4453 #endif /* HPUX_NET */ | |
| 4454 DEFSUBR (Ffile_name_absolute_p); | |
| 4455 DEFSUBR (Ffile_exists_p); | |
| 4456 DEFSUBR (Ffile_executable_p); | |
| 4457 DEFSUBR (Ffile_readable_p); | |
| 4458 DEFSUBR (Ffile_writable_p); | |
| 4459 DEFSUBR (Ffile_symlink_p); | |
| 4460 DEFSUBR (Ffile_directory_p); | |
| 4461 DEFSUBR (Ffile_accessible_directory_p); | |
| 4462 DEFSUBR (Ffile_regular_p); | |
| 4463 DEFSUBR (Ffile_modes); | |
| 4464 DEFSUBR (Fset_file_modes); | |
| 4465 DEFSUBR (Fset_default_file_modes); | |
| 4466 DEFSUBR (Fdefault_file_modes); | |
| 4467 DEFSUBR (Funix_sync); | |
| 4468 DEFSUBR (Ffile_newer_than_file_p); | |
| 4469 DEFSUBR (Finsert_file_contents_internal); | |
| 4470 DEFSUBR (Fwrite_region_internal); | |
| 4471 DEFSUBR (Fcar_less_than_car); /* Vomitous! */ | |
| 4472 DEFSUBR (Fcdr_less_than_cdr); /* Yeah oh yeah bucko .... */ | |
| 4473 #if 0 | |
| 4474 DEFSUBR (Fencrypt_string); | |
| 4475 DEFSUBR (Fdecrypt_string); | |
| 4476 #endif | |
| 4477 DEFSUBR (Fverify_visited_file_modtime); | |
| 4478 DEFSUBR (Fclear_visited_file_modtime); | |
| 4479 DEFSUBR (Fvisited_file_modtime); | |
| 4480 DEFSUBR (Fset_visited_file_modtime); | |
| 4481 | |
| 4482 DEFSUBR (Fdo_auto_save); | |
| 4483 DEFSUBR (Fset_buffer_auto_saved); | |
| 4484 DEFSUBR (Fclear_buffer_auto_save_failure); | |
| 4485 DEFSUBR (Frecent_auto_save_p); | |
| 4486 } | |
| 4487 | |
| 4488 void | |
| 4489 vars_of_fileio (void) | |
| 4490 { | |
| 2526 | 4491 QSin_expand_file_name = |
| 4492 build_msg_string ("(in expand-file-name)"); | |
| 4493 staticpro (&QSin_expand_file_name); | |
| 4494 | |
| 428 | 4495 DEFVAR_LISP ("auto-save-file-format", &Vauto_save_file_format /* |
| 4496 *Format in which to write auto-save files. | |
| 4497 Should be a list of symbols naming formats that are defined in `format-alist'. | |
| 4498 If it is t, which is the default, auto-save files are written in the | |
| 4499 same format as a regular save would use. | |
| 4500 */ ); | |
| 4501 Vauto_save_file_format = Qt; | |
| 4502 | |
| 4503 DEFVAR_LISP ("file-name-handler-alist", &Vfile_name_handler_alist /* | |
| 4504 *Alist of elements (REGEXP . HANDLER) for file names handled specially. | |
| 4505 If a file name matches REGEXP, then all I/O on that file is done by calling | |
| 4506 HANDLER. | |
| 4507 | |
| 4508 The first argument given to HANDLER is the name of the I/O primitive | |
| 4509 to be handled; the remaining arguments are the arguments that were | |
| 4510 passed to that primitive. For example, if you do | |
| 4511 (file-exists-p FILENAME) | |
| 4512 and FILENAME is handled by HANDLER, then HANDLER is called like this: | |
| 4513 (funcall HANDLER 'file-exists-p FILENAME) | |
| 4514 The function `find-file-name-handler' checks this list for a handler | |
| 4515 for its argument. | |
| 4516 */ ); | |
| 4517 Vfile_name_handler_alist = Qnil; | |
| 4518 | |
| 4519 DEFVAR_LISP ("after-insert-file-functions", &Vafter_insert_file_functions /* | |
| 4520 A list of functions to be called at the end of `insert-file-contents'. | |
| 4521 Each is passed one argument, the number of bytes inserted. It should return | |
| 4522 the new byte count, and leave point the same. If `insert-file-contents' is | |
| 4523 intercepted by a handler from `file-name-handler-alist', that handler is | |
| 4524 responsible for calling the after-insert-file-functions if appropriate. | |
| 4525 */ ); | |
| 4526 Vafter_insert_file_functions = Qnil; | |
| 4527 | |
| 4528 DEFVAR_LISP ("write-region-annotate-functions", | |
| 4529 &Vwrite_region_annotate_functions /* | |
| 4530 A list of functions to be called at the start of `write-region'. | |
| 4531 Each is passed two arguments, START and END, as for `write-region'. | |
| 4532 It should return a list of pairs (POSITION . STRING) of strings to be | |
| 4533 effectively inserted at the specified positions of the file being written | |
| 4534 \(1 means to insert before the first byte written). The POSITIONs must be | |
| 4535 sorted into increasing order. If there are several functions in the list, | |
| 4536 the several lists are merged destructively. | |
| 4537 */ ); | |
| 4538 Vwrite_region_annotate_functions = Qnil; | |
| 4539 | |
| 4540 DEFVAR_LISP ("write-region-annotations-so-far", | |
| 4541 &Vwrite_region_annotations_so_far /* | |
| 4542 When an annotation function is called, this holds the previous annotations. | |
| 4543 These are the annotations made by other annotation functions | |
| 4544 that were already called. See also `write-region-annotate-functions'. | |
| 4545 */ ); | |
| 4546 Vwrite_region_annotations_so_far = Qnil; | |
| 4547 | |
| 4548 DEFVAR_LISP ("inhibit-file-name-handlers", &Vinhibit_file_name_handlers /* | |
| 4549 A list of file name handlers that temporarily should not be used. | |
| 4550 This applies only to the operation `inhibit-file-name-operation'. | |
| 4551 */ ); | |
| 4552 Vinhibit_file_name_handlers = Qnil; | |
| 4553 | |
| 4554 DEFVAR_LISP ("inhibit-file-name-operation", &Vinhibit_file_name_operation /* | |
| 4555 The operation for which `inhibit-file-name-handlers' is applicable. | |
| 4556 */ ); | |
| 4557 Vinhibit_file_name_operation = Qnil; | |
| 4558 | |
| 4559 DEFVAR_LISP ("auto-save-list-file-name", &Vauto_save_list_file_name /* | |
| 4560 File name in which we write a list of all auto save file names. | |
| 4561 */ ); | |
| 4562 Vauto_save_list_file_name = Qnil; | |
| 4563 | |
|
4499
eb82259f265d
Port write-region-inhibit-sync, allowing avoidance of bad FS performance.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4465
diff
changeset
|
4564 #ifdef HAVE_FSYNC |
|
eb82259f265d
Port write-region-inhibit-sync, allowing avoidance of bad FS performance.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4465
diff
changeset
|
4565 DEFVAR_BOOL ("write-region-inhibit-fsync", &write_region_inhibit_fsync /* |
|
eb82259f265d
Port write-region-inhibit-sync, allowing avoidance of bad FS performance.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4465
diff
changeset
|
4566 *Non-nil means don't call fsync in `write-region'. |
|
eb82259f265d
Port write-region-inhibit-sync, allowing avoidance of bad FS performance.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4465
diff
changeset
|
4567 This variable affects calls to `write-region' as well as save commands. |
|
eb82259f265d
Port write-region-inhibit-sync, allowing avoidance of bad FS performance.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4465
diff
changeset
|
4568 A non-nil value may result in data loss! |
|
eb82259f265d
Port write-region-inhibit-sync, allowing avoidance of bad FS performance.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4465
diff
changeset
|
4569 */ ); |
|
eb82259f265d
Port write-region-inhibit-sync, allowing avoidance of bad FS performance.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4465
diff
changeset
|
4570 write_region_inhibit_fsync = 0; |
|
eb82259f265d
Port write-region-inhibit-sync, allowing avoidance of bad FS performance.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4465
diff
changeset
|
4571 #endif |
|
eb82259f265d
Port write-region-inhibit-sync, allowing avoidance of bad FS performance.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4465
diff
changeset
|
4572 |
| 444 | 4573 DEFVAR_LISP ("auto-save-list-file-prefix", &Vauto_save_list_file_prefix /* |
| 4574 Prefix for generating auto-save-list-file-name. | |
| 4575 Emacs's pid and the system name will be appended to | |
| 4576 this prefix to create a unique file name. | |
| 4577 */ ); | |
| 4578 Vauto_save_list_file_prefix = build_string ("~/.saves-"); | |
| 4579 | |
| 4580 DEFVAR_BOOL ("inhibit-auto-save-session", &inhibit_auto_save_session /* | |
| 4581 When non-nil, inhibit auto save list file creation. | |
| 4582 */ ); | |
| 4583 inhibit_auto_save_session = 0; | |
| 4584 | |
| 428 | 4585 DEFVAR_BOOL ("disable-auto-save-when-buffer-shrinks", |
| 4586 &disable_auto_save_when_buffer_shrinks /* | |
| 4587 If non-nil, auto-saving is disabled when a buffer shrinks too much. | |
| 4588 This is to prevent you from losing your edits if you accidentally | |
| 4589 delete a large chunk of the buffer and don't notice it until too late. | |
| 4590 Saving the buffer normally turns auto-save back on. | |
| 4591 */ ); | |
| 4592 disable_auto_save_when_buffer_shrinks = 1; | |
| 4593 | |
| 4594 DEFVAR_LISP ("directory-sep-char", &Vdirectory_sep_char /* | |
| 4595 Directory separator character for built-in functions that return file names. | |
| 4596 The value should be either ?/ or ?\\ (any other value is treated as ?\\). | |
| 4597 This variable affects the built-in functions only on Windows, | |
| 4598 on other platforms, it is initialized so that Lisp code can find out | |
| 4599 what the normal separator is. | |
| 4600 */ ); | |
| 771 | 4601 Vdirectory_sep_char = make_char (DEFAULT_DIRECTORY_SEP); |
| 428 | 4602 } |
| 442 | 4603 |
| 4604 void | |
| 4605 reinit_vars_of_fileio (void) | |
| 4606 { | |
| 4607 /* We want temp_name_rand to be initialized to a value likely to be | |
| 4608 unique to the process, not to the executable. The danger is that | |
| 4609 two different XEmacs processes using the same binary on different | |
| 4610 machines creating temp files in the same directory will be | |
| 4611 unlucky enough to have the same pid. If we randomize using | |
| 4612 process startup time, then in practice they will be unlikely to | |
| 4613 collide. We use the microseconds field so that scripts that start | |
| 4614 simultaneous XEmacs processes on multiple machines will have less | |
| 4615 chance of collision. */ | |
| 4616 { | |
| 4617 EMACS_TIME thyme; | |
| 4618 | |
| 4619 EMACS_GET_TIME (thyme); | |
| 4620 temp_name_rand = (unsigned int) (EMACS_SECS (thyme) ^ EMACS_USECS (thyme)); | |
| 4621 } | |
| 4622 } |
