emacs_close (fd);
}
+void
+close_file_ptr_unwind (void *fdp)
+{
+ int fd = *((int *) fdp);
+ if (fd >= 0)
+ emacs_close (fd);
+}
+
void
fclose_unwind (void *arg)
{
fclose (stream);
}
+void
+fclose_ptr_unwind (void *arg)
+{
+ FILE *stream = *((void **) arg);
+ if (stream)
+ fclose (stream);
+}
+
/* Restore point, having saved it as a marker. */
void
if (ifd < 0)
report_file_error ("Opening input file", file);
- record_unwind_protect_int (close_file_unwind, ifd);
+ record_unwind_protect_int_1 (close_file_unwind, ifd, false);
if (fstat (ifd, &st) != 0)
report_file_error ("Input file status", file);
if (ofd < 0)
report_file_error ("Opening output file", newname);
- record_unwind_protect_int (close_file_unwind, ofd);
+ record_unwind_protect_int_1 (close_file_unwind, ofd, false);
if (already_exists)
{
#endif /* MSDOS */
#endif /* not WINDOWSNT */
- /* Discard the unwind protects. */
- specpdl_ptr = specpdl + count;
+ unbind_to (count, Qnil);
UNGCPRO;
return Qnil;
}
fd_index = SPECPDL_INDEX ();
- record_unwind_protect_int (close_file_unwind, fd);
+ record_unwind_protect_ptr (close_file_ptr_unwind, &fd);
/* Replacement should preserve point as it preserves markers. */
if (!NILP (replace))
report_file_error ("Read error", orig_filename);
else if (nread > 0)
{
- struct buffer *prev = current_buffer;
Lisp_Object workbuf;
struct buffer *buf;
+ ptrdiff_t count1 = SPECPDL_INDEX ();
record_unwind_current_buffer ();
workbuf = Fget_buffer_create (build_string (" *code-converting-work*"));
TEMP_SET_PT_BOTH (BEG, BEG_BYTE);
coding_system = call2 (Vset_auto_coding_function,
filename, make_number (nread));
- set_buffer_internal (prev);
- /* Discard the unwind protect for recovering the
- current buffer. */
- specpdl_ptr--;
+ unbind_to (count1, Qnil);
/* Rewind the file for the actual read done later. */
if (lseek (fd, 0, SEEK_SET) < 0)
if (same_at_start - BEGV_BYTE == end_offset - beg_offset)
{
emacs_close (fd);
- clear_unwind_protect (fd_index);
+ fd = -1;
/* Truncate the buffer to the size of the file. */
del_range_1 (same_at_start, same_at_end, 0, 0);
if (this < 0)
report_file_error ("Read error", orig_filename);
emacs_close (fd);
- clear_unwind_protect (fd_index);
+ fd = -1;
if (unprocessed > 0)
{
Vdeactivate_mark = Qt;
emacs_close (fd);
- clear_unwind_protect (fd_index);
+ fd = -1;
if (how_much < 0)
report_file_error ("Read error", orig_filename);
}
count1 = SPECPDL_INDEX ();
- record_unwind_protect_int (close_file_unwind, desc);
+ record_unwind_protect_int_1 (close_file_unwind, desc, false);
}
if (NUMBERP (append))
if (emacs_close (desc) < 0)
ok = 0, save_errno = errno;
- /* Discard the unwind protect for close_file_unwind. */
- specpdl_ptr = specpdl + count1;
+ unbind_to (count1, Qnil);
}
/* Some file systems have a bug where st_mtime is not updated