comparison src/fileio.c @ 28846:0027ff9c083a

(Fwrite_region): If APPEND arg is an integer, seek to that offset before writing. Move gcpro region past call of Ffile_regular_p.
author Dave Love <fx@gnu.org>
date Wed, 10 May 2000 08:52:47 +0000
parents 7d587a158d1f
children 242cad59b698
comparison
equal deleted inserted replaced
28845:6b355411e13a 28846:0027ff9c083a
1 /* File IO for GNU Emacs. 1 /* File IO for GNU Emacs.
2 Copyright (C) 1985,86,87,88,93,94,95,96,97,98,1999 Free Software Foundation, Inc. 2 Copyright (C) 1985,86,87,88,93,94,95,96,97,98,99,2000
3 Free Software Foundation, Inc.
3 4
4 This file is part of GNU Emacs. 5 This file is part of GNU Emacs.
5 6
6 GNU Emacs is free software; you can redistribute it and/or modify 7 GNU Emacs is free software; you can redistribute it and/or modify
7 it under the terms of the GNU General Public License as published by 8 it under the terms of the GNU General Public License as published by
4315 "r\nFWrite region to file: \ni\ni\ni\np", 4316 "r\nFWrite region to file: \ni\ni\ni\np",
4316 "Write current region into specified file.\n\ 4317 "Write current region into specified file.\n\
4317 When called from a program, takes three arguments:\n\ 4318 When called from a program, takes three arguments:\n\
4318 START, END and FILENAME. START and END are buffer positions.\n\ 4319 START, END and FILENAME. START and END are buffer positions.\n\
4319 Optional fourth argument APPEND if non-nil means\n\ 4320 Optional fourth argument APPEND if non-nil means\n\
4320 append to existing file contents (if any).\n\ 4321 append to existing file contents (if any). If it is an integer,\n\
4322 seek to that offset in the file before writing.\n\
4321 Optional fifth argument VISIT if t means\n\ 4323 Optional fifth argument VISIT if t means\n\
4322 set the last-save-file-modtime of buffer to this file's modtime\n\ 4324 set the last-save-file-modtime of buffer to this file's modtime\n\
4323 and mark buffer not modified.\n\ 4325 and mark buffer not modified.\n\
4324 If VISIT is a string, it is a second file name;\n\ 4326 If VISIT is a string, it is a second file name;\n\
4325 the output goes to FILENAME, but the buffer is marked as visiting VISIT.\n\ 4327 the output goes to FILENAME, but the buffer is marked as visiting VISIT.\n\
4613 | (EQ (mustbenew, Qexcl) ? O_EXCL : 0), 4615 | (EQ (mustbenew, Qexcl) ? O_EXCL : 0),
4614 auto_saving ? auto_save_mode_bits : 0666); 4616 auto_saving ? auto_save_mode_bits : 0666);
4615 #endif /* not DOS_NT */ 4617 #endif /* not DOS_NT */
4616 #endif /* not VMS */ 4618 #endif /* not VMS */
4617 4619
4618 UNGCPRO;
4619
4620 if (desc < 0) 4620 if (desc < 0)
4621 { 4621 {
4622 #ifdef CLASH_DETECTION 4622 #ifdef CLASH_DETECTION
4623 save_errno = errno; 4623 save_errno = errno;
4624 if (!auto_saving) unlock_file (lockname); 4624 if (!auto_saving) unlock_file (lockname);
4625 errno = save_errno; 4625 errno = save_errno;
4626 #endif /* CLASH_DETECTION */ 4626 #endif /* CLASH_DETECTION */
4627 UNGCPRO;
4627 report_file_error ("Opening output file", Fcons (filename, Qnil)); 4628 report_file_error ("Opening output file", Fcons (filename, Qnil));
4628 } 4629 }
4629 4630
4630 record_unwind_protect (close_file_unwind, make_number (desc)); 4631 record_unwind_protect (close_file_unwind, make_number (desc));
4631 4632
4632 if (!NILP (append) && !NILP (Ffile_regular_p (filename))) 4633 if (!NILP (append) && !NILP (Ffile_regular_p (filename)))
4633 if (lseek (desc, 0, 2) < 0) 4634 {
4634 { 4635 long ret;
4636
4637 if (NUMBERP (append))
4638 ret = lseek (desc, XINT (append), 1);
4639 else
4640 ret = lseek (desc, 0, 2);
4641 if (ret < 0)
4642 {
4635 #ifdef CLASH_DETECTION 4643 #ifdef CLASH_DETECTION
4636 if (!auto_saving) unlock_file (lockname); 4644 if (!auto_saving) unlock_file (lockname);
4637 #endif /* CLASH_DETECTION */ 4645 #endif /* CLASH_DETECTION */
4638 report_file_error ("Lseek error", Fcons (filename, Qnil)); 4646 UNGCPRO;
4639 } 4647 report_file_error ("Lseek error", Fcons (filename, Qnil));
4648 }
4649 }
4650
4651 UNGCPRO;
4640 4652
4641 #ifdef VMS 4653 #ifdef VMS
4642 /* 4654 /*
4643 * Kludge Warning: The VMS C RTL likes to insert carriage returns 4655 * Kludge Warning: The VMS C RTL likes to insert carriage returns
4644 * if we do writes that don't end with a carriage return. Furthermore 4656 * if we do writes that don't end with a carriage return. Furthermore