Mercurial > emacs
comparison src/fileio.c @ 109126:aec1143e8d85
Convert (most) functions in src to standard C.
* src/alloc.c: Convert function definitions to standard C.
* src/atimer.c:
* src/bidi.c:
* src/bytecode.c:
* src/callint.c:
* src/callproc.c:
* src/casefiddle.c:
* src/casetab.c:
* src/category.c:
* src/ccl.c:
* src/character.c:
* src/charset.c:
* src/chartab.c:
* src/cmds.c:
* src/coding.c:
* src/composite.c:
* src/data.c:
* src/dbusbind.c:
* src/dired.c:
* src/dispnew.c:
* src/doc.c:
* src/doprnt.c:
* src/ecrt0.c:
* src/editfns.c:
* src/fileio.c:
* src/filelock.c:
* src/filemode.c:
* src/fns.c:
* src/font.c:
* src/fontset.c:
* src/frame.c:
* src/fringe.c:
* src/ftfont.c:
* src/ftxfont.c:
* src/gtkutil.c:
* src/indent.c:
* src/insdel.c:
* src/intervals.c:
* src/keymap.c:
* src/lread.c:
* src/macros.c:
* src/marker.c:
* src/md5.c:
* src/menu.c:
* src/minibuf.c:
* src/prefix-args.c:
* src/print.c:
* src/ralloc.c:
* src/regex.c:
* src/region-cache.c:
* src/scroll.c:
* src/search.c:
* src/sound.c:
* src/strftime.c:
* src/syntax.c:
* src/sysdep.c:
* src/termcap.c:
* src/terminal.c:
* src/terminfo.c:
* src/textprop.c:
* src/tparam.c:
* src/undo.c:
* src/unexelf.c:
* src/window.c:
* src/xfaces.c:
* src/xfns.c:
* src/xfont.c:
* src/xftfont.c:
* src/xgselect.c:
* src/xmenu.c:
* src/xrdb.c:
* src/xselect.c:
* src/xsettings.c:
* src/xsmfns.c:
* src/xterm.c: Likewise.
author | Dan Nicolaescu <dann@ics.uci.edu> |
---|---|
date | Sun, 04 Jul 2010 00:50:25 -0700 |
parents | 2bc9a0c04c87 |
children | 907fcf8bd2ef |
comparison
equal
deleted
inserted
replaced
109125:12b02558bf51 | 109126:aec1143e8d85 |
---|---|
244 Lisp_Object *, struct coding_system *); | 244 Lisp_Object *, struct coding_system *); |
245 static int e_write (int, Lisp_Object, int, int, struct coding_system *); | 245 static int e_write (int, Lisp_Object, int, int, struct coding_system *); |
246 | 246 |
247 | 247 |
248 void | 248 void |
249 report_file_error (string, data) | 249 report_file_error (const char *string, Lisp_Object data) |
250 const char *string; | |
251 Lisp_Object data; | |
252 { | 250 { |
253 Lisp_Object errstring; | 251 Lisp_Object errstring; |
254 int errorno = errno; | 252 int errorno = errno; |
255 char *str; | 253 char *str; |
256 | 254 |
284 Fcons (build_string (string), Fcons (errstring, data))); | 282 Fcons (build_string (string), Fcons (errstring, data))); |
285 } | 283 } |
286 } | 284 } |
287 | 285 |
288 Lisp_Object | 286 Lisp_Object |
289 close_file_unwind (fd) | 287 close_file_unwind (Lisp_Object fd) |
290 Lisp_Object fd; | |
291 { | 288 { |
292 emacs_close (XFASTINT (fd)); | 289 emacs_close (XFASTINT (fd)); |
293 return Qnil; | 290 return Qnil; |
294 } | 291 } |
295 | 292 |
296 /* Restore point, having saved it as a marker. */ | 293 /* Restore point, having saved it as a marker. */ |
297 | 294 |
298 Lisp_Object | 295 Lisp_Object |
299 restore_point_unwind (location) | 296 restore_point_unwind (Lisp_Object location) |
300 Lisp_Object location; | |
301 { | 297 { |
302 Fgoto_char (location); | 298 Fgoto_char (location); |
303 Fset_marker (location, Qnil, Qnil); | 299 Fset_marker (location, Qnil, Qnil); |
304 return Qnil; | 300 return Qnil; |
305 } | 301 } |
537 return Ffile_name_directory (filename); | 533 return Ffile_name_directory (filename); |
538 } | 534 } |
539 | 535 |
540 | 536 |
541 char * | 537 char * |
542 file_name_as_directory (out, in) | 538 file_name_as_directory (char *out, char *in) |
543 char *out, *in; | |
544 { | 539 { |
545 int size = strlen (in) - 1; | 540 int size = strlen (in) - 1; |
546 | 541 |
547 strcpy (out, in); | 542 strcpy (out, in); |
548 | 543 |
602 | 597 |
603 * Value is nonzero if the string output is different from the input. | 598 * Value is nonzero if the string output is different from the input. |
604 */ | 599 */ |
605 | 600 |
606 int | 601 int |
607 directory_file_name (src, dst) | 602 directory_file_name (char *src, char *dst) |
608 char *src, *dst; | |
609 { | 603 { |
610 long slen; | 604 long slen; |
611 | 605 |
612 slen = strlen (src); | 606 slen = strlen (src); |
613 | 607 |
686 | 680 |
687 This function signals an error if no unique file name could be | 681 This function signals an error if no unique file name could be |
688 generated. */ | 682 generated. */ |
689 | 683 |
690 Lisp_Object | 684 Lisp_Object |
691 make_temp_name (prefix, base64_p) | 685 make_temp_name (Lisp_Object prefix, int base64_p) |
692 Lisp_Object prefix; | |
693 int base64_p; | |
694 { | 686 { |
695 Lisp_Object val; | 687 Lisp_Object val; |
696 int len, clen; | 688 int len, clen; |
697 int pid; | 689 int pid; |
698 unsigned char *p, *data; | 690 unsigned char *p, *data; |
1556 } | 1548 } |
1557 #endif | 1549 #endif |
1558 | 1550 |
1559 /* If /~ or // appears, discard everything through first slash. */ | 1551 /* If /~ or // appears, discard everything through first slash. */ |
1560 static int | 1552 static int |
1561 file_name_absolute_p (filename) | 1553 file_name_absolute_p (const unsigned char *filename) |
1562 const unsigned char *filename; | |
1563 { | 1554 { |
1564 return | 1555 return |
1565 (IS_DIRECTORY_SEP (*filename) || *filename == '~' | 1556 (IS_DIRECTORY_SEP (*filename) || *filename == '~' |
1566 #ifdef DOS_NT | 1557 #ifdef DOS_NT |
1567 || (IS_DRIVE (*filename) && IS_DEVICE_SEP (filename[1]) | 1558 || (IS_DRIVE (*filename) && IS_DEVICE_SEP (filename[1]) |
1569 #endif | 1560 #endif |
1570 ); | 1561 ); |
1571 } | 1562 } |
1572 | 1563 |
1573 static unsigned char * | 1564 static unsigned char * |
1574 search_embedded_absfilename (nm, endp) | 1565 search_embedded_absfilename (unsigned char *nm, unsigned char *endp) |
1575 unsigned char *nm, *endp; | |
1576 { | 1566 { |
1577 unsigned char *p, *s; | 1567 unsigned char *p, *s; |
1578 | 1568 |
1579 for (p = nm + 1; p < endp; p++) | 1569 for (p = nm + 1; p < endp; p++) |
1580 { | 1570 { |
1821 | 1811 |
1822 /* A slightly faster and more convenient way to get | 1812 /* A slightly faster and more convenient way to get |
1823 (directory-file-name (expand-file-name FOO)). */ | 1813 (directory-file-name (expand-file-name FOO)). */ |
1824 | 1814 |
1825 Lisp_Object | 1815 Lisp_Object |
1826 expand_and_dir_to_file (filename, defdir) | 1816 expand_and_dir_to_file (Lisp_Object filename, Lisp_Object defdir) |
1827 Lisp_Object filename, defdir; | |
1828 { | 1817 { |
1829 register Lisp_Object absname; | 1818 register Lisp_Object absname; |
1830 | 1819 |
1831 absname = Fexpand_file_name (filename, defdir); | 1820 absname = Fexpand_file_name (filename, defdir); |
1832 | 1821 |
1851 If STATPTR is null, we don't store into it. | 1840 If STATPTR is null, we don't store into it. |
1852 | 1841 |
1853 If QUICK is nonzero, we ask for y or n, not yes or no. */ | 1842 If QUICK is nonzero, we ask for y or n, not yes or no. */ |
1854 | 1843 |
1855 void | 1844 void |
1856 barf_or_query_if_file_exists (absname, querystring, interactive, statptr, quick) | 1845 barf_or_query_if_file_exists (Lisp_Object absname, unsigned char *querystring, int interactive, struct stat *statptr, int quick) |
1857 Lisp_Object absname; | |
1858 unsigned char *querystring; | |
1859 int interactive; | |
1860 struct stat *statptr; | |
1861 int quick; | |
1862 { | 1846 { |
1863 register Lisp_Object tem, encoded_filename; | 1847 register Lisp_Object tem, encoded_filename; |
1864 struct stat statbuf; | 1848 struct stat statbuf; |
1865 struct gcpro gcpro1; | 1849 struct gcpro gcpro1; |
1866 | 1850 |
2226 report_file_error ("Removing old name", list1 (filename)); | 2210 report_file_error ("Removing old name", list1 (filename)); |
2227 return Qnil; | 2211 return Qnil; |
2228 } | 2212 } |
2229 | 2213 |
2230 static Lisp_Object | 2214 static Lisp_Object |
2231 internal_delete_file_1 (ignore) | 2215 internal_delete_file_1 (Lisp_Object ignore) |
2232 Lisp_Object ignore; | |
2233 { | 2216 { |
2234 return Qt; | 2217 return Qt; |
2235 } | 2218 } |
2236 | 2219 |
2237 /* Delete file FILENAME, returning 1 if successful and 0 if failed. | 2220 /* Delete file FILENAME, returning 1 if successful and 0 if failed. |
2493 } | 2476 } |
2494 | 2477 |
2495 /* Return nonzero if file FILENAME exists and can be executed. */ | 2478 /* Return nonzero if file FILENAME exists and can be executed. */ |
2496 | 2479 |
2497 static int | 2480 static int |
2498 check_executable (filename) | 2481 check_executable (char *filename) |
2499 char *filename; | |
2500 { | 2482 { |
2501 #ifdef DOS_NT | 2483 #ifdef DOS_NT |
2502 int len = strlen (filename); | 2484 int len = strlen (filename); |
2503 char *suffix; | 2485 char *suffix; |
2504 struct stat st; | 2486 struct stat st; |
2518 } | 2500 } |
2519 | 2501 |
2520 /* Return nonzero if file FILENAME exists and can be written. */ | 2502 /* Return nonzero if file FILENAME exists and can be written. */ |
2521 | 2503 |
2522 static int | 2504 static int |
2523 check_writable (filename) | 2505 check_writable (char *filename) |
2524 char *filename; | |
2525 { | 2506 { |
2526 #ifdef MSDOS | 2507 #ifdef MSDOS |
2527 struct stat st; | 2508 struct stat st; |
2528 if (stat (filename, &st) < 0) | 2509 if (stat (filename, &st) < 0) |
2529 return 0; | 2510 return 0; |
3233 o move all markers and overlays to BEG. | 3214 o move all markers and overlays to BEG. |
3234 o remove all text properties. | 3215 o remove all text properties. |
3235 o set back the buffer multibyteness. */ | 3216 o set back the buffer multibyteness. */ |
3236 | 3217 |
3237 static Lisp_Object | 3218 static Lisp_Object |
3238 decide_coding_unwind (unwind_data) | 3219 decide_coding_unwind (Lisp_Object unwind_data) |
3239 Lisp_Object unwind_data; | |
3240 { | 3220 { |
3241 Lisp_Object multibyte, undo_list, buffer; | 3221 Lisp_Object multibyte, undo_list, buffer; |
3242 | 3222 |
3243 multibyte = XCAR (unwind_data); | 3223 multibyte = XCAR (unwind_data); |
3244 unwind_data = XCDR (unwind_data); | 3224 unwind_data = XCDR (unwind_data); |
3271 Read non_regular_trytry bytes max from non_regular_fd. | 3251 Read non_regular_trytry bytes max from non_regular_fd. |
3272 Non_regular_inserted specifies where to put the read bytes. | 3252 Non_regular_inserted specifies where to put the read bytes. |
3273 Value is the number of bytes read. */ | 3253 Value is the number of bytes read. */ |
3274 | 3254 |
3275 static Lisp_Object | 3255 static Lisp_Object |
3276 read_non_regular () | 3256 read_non_regular (void) |
3277 { | 3257 { |
3278 EMACS_INT nbytes; | 3258 EMACS_INT nbytes; |
3279 | 3259 |
3280 immediate_quit = 1; | 3260 immediate_quit = 1; |
3281 QUIT; | 3261 QUIT; |
3289 | 3269 |
3290 /* Condition-case handler used when reading from non-regular files | 3270 /* Condition-case handler used when reading from non-regular files |
3291 in insert-file-contents. */ | 3271 in insert-file-contents. */ |
3292 | 3272 |
3293 static Lisp_Object | 3273 static Lisp_Object |
3294 read_non_regular_quit () | 3274 read_non_regular_quit (void) |
3295 { | 3275 { |
3296 return Qnil; | 3276 return Qnil; |
3297 } | 3277 } |
3298 | 3278 |
3299 | 3279 |
4446 } | 4426 } |
4447 | 4427 |
4448 static Lisp_Object build_annotations (Lisp_Object, Lisp_Object); | 4428 static Lisp_Object build_annotations (Lisp_Object, Lisp_Object); |
4449 | 4429 |
4450 static Lisp_Object | 4430 static Lisp_Object |
4451 build_annotations_unwind (arg) | 4431 build_annotations_unwind (Lisp_Object arg) |
4452 Lisp_Object arg; | |
4453 { | 4432 { |
4454 Vwrite_region_annotation_buffers = arg; | 4433 Vwrite_region_annotation_buffers = arg; |
4455 return Qnil; | 4434 return Qnil; |
4456 } | 4435 } |
4457 | 4436 |
4921 that buffer contains altered text. Therefore, the caller must | 4900 that buffer contains altered text. Therefore, the caller must |
4922 make sure to restore the current buffer in all cases, | 4901 make sure to restore the current buffer in all cases, |
4923 as save-excursion would do. */ | 4902 as save-excursion would do. */ |
4924 | 4903 |
4925 static Lisp_Object | 4904 static Lisp_Object |
4926 build_annotations (start, end) | 4905 build_annotations (Lisp_Object start, Lisp_Object end) |
4927 Lisp_Object start, end; | |
4928 { | 4906 { |
4929 Lisp_Object annotations; | 4907 Lisp_Object annotations; |
4930 Lisp_Object p, res; | 4908 Lisp_Object p, res; |
4931 struct gcpro gcpro1, gcpro2; | 4909 struct gcpro gcpro1, gcpro2; |
4932 Lisp_Object original_buffer; | 4910 Lisp_Object original_buffer; |
5011 We modify *ANNOT by discarding elements as we use them up. | 4989 We modify *ANNOT by discarding elements as we use them up. |
5012 | 4990 |
5013 The return value is negative in case of system call failure. */ | 4991 The return value is negative in case of system call failure. */ |
5014 | 4992 |
5015 static int | 4993 static int |
5016 a_write (desc, string, pos, nchars, annot, coding) | 4994 a_write (int desc, Lisp_Object string, int pos, register int nchars, Lisp_Object *annot, struct coding_system *coding) |
5017 int desc; | |
5018 Lisp_Object string; | |
5019 register int nchars; | |
5020 int pos; | |
5021 Lisp_Object *annot; | |
5022 struct coding_system *coding; | |
5023 { | 4995 { |
5024 Lisp_Object tem; | 4996 Lisp_Object tem; |
5025 int nextpos; | 4997 int nextpos; |
5026 int lastpos = pos + nchars; | 4998 int lastpos = pos + nchars; |
5027 | 4999 |
5061 encoding them with coding system CODING. If STRING is nil, START | 5033 encoding them with coding system CODING. If STRING is nil, START |
5062 and END are character positions of the current buffer, else they | 5034 and END are character positions of the current buffer, else they |
5063 are indexes to the string STRING. */ | 5035 are indexes to the string STRING. */ |
5064 | 5036 |
5065 static int | 5037 static int |
5066 e_write (desc, string, start, end, coding) | 5038 e_write (int desc, Lisp_Object string, int start, int end, struct coding_system *coding) |
5067 int desc; | |
5068 Lisp_Object string; | |
5069 int start, end; | |
5070 struct coding_system *coding; | |
5071 { | 5039 { |
5072 if (STRINGP (string)) | 5040 if (STRINGP (string)) |
5073 { | 5041 { |
5074 start = 0; | 5042 start = 0; |
5075 end = SCHARS (string); | 5043 end = SCHARS (string); |
5257 | 5225 |
5258 return Qnil; | 5226 return Qnil; |
5259 } | 5227 } |
5260 | 5228 |
5261 Lisp_Object | 5229 Lisp_Object |
5262 auto_save_error (error) | 5230 auto_save_error (Lisp_Object error) |
5263 Lisp_Object error; | |
5264 { | 5231 { |
5265 Lisp_Object args[3], msg; | 5232 Lisp_Object args[3], msg; |
5266 int i, nbytes; | 5233 int i, nbytes; |
5267 struct gcpro gcpro1; | 5234 struct gcpro gcpro1; |
5268 char *msgbuf; | 5235 char *msgbuf; |
5294 UNGCPRO; | 5261 UNGCPRO; |
5295 return Qnil; | 5262 return Qnil; |
5296 } | 5263 } |
5297 | 5264 |
5298 Lisp_Object | 5265 Lisp_Object |
5299 auto_save_1 () | 5266 auto_save_1 (void) |
5300 { | 5267 { |
5301 struct stat st; | 5268 struct stat st; |
5302 Lisp_Object modes; | 5269 Lisp_Object modes; |
5303 | 5270 |
5304 auto_save_mode_bits = 0666; | 5271 auto_save_mode_bits = 0666; |
5320 NILP (Vauto_save_visited_file_name) ? Qlambda : Qt, | 5287 NILP (Vauto_save_visited_file_name) ? Qlambda : Qt, |
5321 Qnil, Qnil); | 5288 Qnil, Qnil); |
5322 } | 5289 } |
5323 | 5290 |
5324 static Lisp_Object | 5291 static Lisp_Object |
5325 do_auto_save_unwind (arg) /* used as unwind-protect function */ | 5292 do_auto_save_unwind (Lisp_Object arg) /* used as unwind-protect function */ |
5326 Lisp_Object arg; | 5293 |
5327 { | 5294 { |
5328 FILE *stream = (FILE *) XSAVE_VALUE (arg)->pointer; | 5295 FILE *stream = (FILE *) XSAVE_VALUE (arg)->pointer; |
5329 auto_saving = 0; | 5296 auto_saving = 0; |
5330 if (stream != NULL) | 5297 if (stream != NULL) |
5331 { | 5298 { |
5335 } | 5302 } |
5336 return Qnil; | 5303 return Qnil; |
5337 } | 5304 } |
5338 | 5305 |
5339 static Lisp_Object | 5306 static Lisp_Object |
5340 do_auto_save_unwind_1 (value) /* used as unwind-protect function */ | 5307 do_auto_save_unwind_1 (Lisp_Object value) /* used as unwind-protect function */ |
5341 Lisp_Object value; | 5308 |
5342 { | 5309 { |
5343 minibuffer_auto_raise = XINT (value); | 5310 minibuffer_auto_raise = XINT (value); |
5344 return Qnil; | 5311 return Qnil; |
5345 } | 5312 } |
5346 | 5313 |
5347 static Lisp_Object | 5314 static Lisp_Object |
5348 do_auto_save_make_dir (dir) | 5315 do_auto_save_make_dir (Lisp_Object dir) |
5349 Lisp_Object dir; | |
5350 { | 5316 { |
5351 Lisp_Object mode; | 5317 Lisp_Object mode; |
5352 | 5318 |
5353 call2 (Qmake_directory, dir, Qt); | 5319 call2 (Qmake_directory, dir, Qt); |
5354 XSETFASTINT (mode, 0700); | 5320 XSETFASTINT (mode, 0700); |
5355 return Fset_file_modes (dir, mode); | 5321 return Fset_file_modes (dir, mode); |
5356 } | 5322 } |
5357 | 5323 |
5358 static Lisp_Object | 5324 static Lisp_Object |
5359 do_auto_save_eh (ignore) | 5325 do_auto_save_eh (Lisp_Object ignore) |
5360 Lisp_Object ignore; | |
5361 { | 5326 { |
5362 return Qnil; | 5327 return Qnil; |
5363 } | 5328 } |
5364 | 5329 |
5365 DEFUN ("do-auto-save", Fdo_auto_save, Sdo_auto_save, 0, 2, "", | 5330 DEFUN ("do-auto-save", Fdo_auto_save, Sdo_auto_save, 0, 2, "", |
5625 #endif | 5590 #endif |
5626 return Qnil; | 5591 return Qnil; |
5627 } | 5592 } |
5628 | 5593 |
5629 Lisp_Object | 5594 Lisp_Object |
5630 Fread_file_name (prompt, dir, default_filename, mustmatch, initial, predicate) | 5595 Fread_file_name (Lisp_Object prompt, Lisp_Object dir, Lisp_Object default_filename, Lisp_Object mustmatch, Lisp_Object initial, Lisp_Object predicate) |
5631 Lisp_Object prompt, dir, default_filename, mustmatch, initial, predicate; | |
5632 { | 5596 { |
5633 struct gcpro gcpro1, gcpro2; | 5597 struct gcpro gcpro1, gcpro2; |
5634 Lisp_Object args[7]; | 5598 Lisp_Object args[7]; |
5635 | 5599 |
5636 GCPRO1 (default_filename); | 5600 GCPRO1 (default_filename); |
5644 RETURN_UNGCPRO (Ffuncall (7, args)); | 5608 RETURN_UNGCPRO (Ffuncall (7, args)); |
5645 } | 5609 } |
5646 | 5610 |
5647 | 5611 |
5648 void | 5612 void |
5649 syms_of_fileio () | 5613 syms_of_fileio (void) |
5650 { | 5614 { |
5651 Qoperations = intern_c_string ("operations"); | 5615 Qoperations = intern_c_string ("operations"); |
5652 Qexpand_file_name = intern_c_string ("expand-file-name"); | 5616 Qexpand_file_name = intern_c_string ("expand-file-name"); |
5653 Qsubstitute_in_file_name = intern_c_string ("substitute-in-file-name"); | 5617 Qsubstitute_in_file_name = intern_c_string ("substitute-in-file-name"); |
5654 Qdirectory_file_name = intern_c_string ("directory-file-name"); | 5618 Qdirectory_file_name = intern_c_string ("directory-file-name"); |