summaryrefslogtreecommitdiff
path: root/src/fileio.c
AgeCommit message (Collapse)Author
2026-05-26ARRAYELTS → countofPaul Eggert
C2y will standardize countof as the macro that Emacs uses the name ARRAYELTS for. Switch to the standard name, which is supported by GCC 16+, by Clang 21, and by the Gnulib stdcountof-h module already in use for compilers that do not support countof. Also, use countof in a few places where we missed using ARRAYELTS. * admin/coccinelle/arrayelts.cocci: Suggest countof, not ARRAYELTS. * admin/merge-gnulib (GNULIB_MODULES): Add stdcountof-h, as it is now a direct rather than an indirect dependency. * exec/trace.c, src/lisp.h, src/sfnt.c: Include <stdcountof.h>. (ARRAYELTS): Remove. All uses replaced by countof. * lib-src/ebrowse.c, lib-src/etags.c, lib-src/make-docfile.c: * lib-src/seccomp-filter.c, lwlib/lwlib-Xaw.c: Prefer <stdcountof.h> and countof to doing things by hand.
2026-05-26Omit useless casts found by GCC 16Paul Eggert
GCC 16’s -Wuseless-cast warning can be useful. Fix the useless casts it identifies, and also fix false positives by using compound literals, which are safer anyway than casts. * src/composite.c (composition_adjust_point) (Ffind_composition_internal): * lwlib/xlwmenu.c (xlwMenuResources, xlwMenuClassRec) (resource_widget_value, XlwMenuDestroy, Select): * src/alloc.c (process_mark_stack): * src/data.c (Faref): * src/emacs-module.c (module_extract_big_integer): * src/fileio.c (Finsert_file_contents): * src/frame.h (FRAME_MESSAGE_BUF_SIZE): * src/gtkutil.c (xg_tool_item_stale_p, update_frame_tool_bar): * src/image.c (pbm_load, png_load_body, jpeg_load_body) (tiff_load, gif_load): * src/pdumper.c (ptrdiff_t_to_dump_off, dump_queue_dequeue) (field_relpos, dump_field_emacs_ptr) (dump_object_start_pseudovector, pdumper_remember_scalar_impl) (pdumper_load, syms_of_pdumper): * src/regex-emacs.c (BUF_PUSH, BUF_PUSH_2, POINTER_TO_OFFSET): * src/xdisp.c (remember_mouse_glyph, pint2str): * src/xterm.c (cvt_string_to_pixel, handle_one_xevent): Omit useless casts. Perhaps they were formerly needed, but they should not be needed now. * src/alloc.c (Fmemory_info): * src/category.c (Fdefine_category, Fmodify_category_entry): * src/data.c (Fash): * src/dispextern.h (GLYPH_CODE_P): * src/emacs.c (load_seccomp): * src/fns.c (Flocale_info, maybe_resize_hash_table): * src/indent.c (check_display_width): * src/json.c (symset_size): * src/lisp.h (XUNTAG, BOOL_VECTOR_LENGTH_MAX, obarray_size) (hash_table_index_size): * src/lread.c (make_obarray, grow_obarray, Fobarray_clear): * src/menu.c (digest_single_submenu, x_popup_menu_1): * src/term.c (init_tty): * src/widget.c (update_wm_hints): * src/xdisp.c (truncate_echo_area): * src/xfns.c (x_set_border_pixel): * src/xfont.c (xfont_match, xfont_open): * src/xmenu.c (set_frame_menubar): * test/src/emacs-module-resources/mod-test.c (emacs_module_init): Use compound literal instead of a cast that is useless in some platforms but not others. * src/dispextern.h, src/haikugui.h, src/w32gui.h: (WINDOW_HANDLE_UINTPTR): New macro. * src/frame.c (gui_report_frame_params): * src/xterm.c (x_try_cr_xlib_drawable): Use it. * src/lisp.h (XUNTAG): And tag with UINTPTR_MAX to pacify gcc warning about a constant out of range. (hash_idx_t): Make it int_least32_t, as it need not be exactly 32 bits. (PRIdHASH_IDX): New macro. * src/pdumper.c (dump_queue_dequeue): Use it. * src/profiler.c (setup_cpu_timer): Make a local EMACS_INT rather than int, to avoid need for casting later. * src/syntax.c (uninitialized_interval): Use 1u rather than 1 so the cast is always useful. A compound literal wouldn’t do here, as this macro needs to be an integer constant expression. * src/xfns.c (XICCallback, XICProc): Remove macros. (Xxic_preedit_start_callback): Use a cleaner way to specify it, avoiding the need for type macros, and for a cast if HAVE_XICCALLBACK_CALLBACK. * src/xterm.c (handle_one_xevent): 2nd arg is now XEvent * on all platforms, as there is no need to diverge, and diverging meant we needed lots of unnecessary casts.
2026-05-17Allow child processes to continue after EPIPEJim Porter
This ensures that if the child process closed its stdin and Emacs tries to write to it, the process can still do any remaining work and exit normally. In practice, this can occur with commands like "head(1)" (bug#79079). * src/fileio.c (file_for_stream): New function, extracted from... (Fset_binary_mode): ... here. (Ffile__close_stream): New function. * src/process.c (send_process): When encountering EPIPE, only close the fd for the pipe to the child process's stdin. * lisp/eshell/esh-io.el (eshell-output-object-to-target): Don't check for process liveness anymore. * test/src/process-tests.el (process-tests/broken-pipe): New function. (process-tests/broken-pipe/pipe, process-tests/broken-pipe/pty) (process-tests/broken-pipe/pipe-stdin) (process-tests/broken-pipe/pty-stdin): New tests. * etc/NEWS: Announce this change.
2026-04-04; Improve documentation of 'make-temp-file'Eli Zaretskii
* doc/lispref/files.texi (Unique File Names): * lisp/files.el (make-temp-file): * src/fileio.c (Fmake_temp_file_internal): Doc fixes.
2026-03-10Use single-arg form of `signal` to re-throw an errorStefan Monnier
* lisp/vc/smerge-mode.el (smerge-extend): * lisp/vc/diff-mode.el (diff-beginning-of-file-and-junk): * lisp/transient.el (transient--with-emergency-exit): * lisp/textmodes/tex-mode.el (latex-forward-sexp): * lisp/tar-mode.el (tar-mode): * lisp/savehist.el (savehist--reload): * lisp/progmodes/octave.el (inferior-octave-resync-dirs): * lisp/progmodes/js.el (js--re-search-forward): * lisp/plstore.el (plstore--decrypt): * lisp/net/dbus.el (dbus-ignore-errors, dbus-register-signal) (dbus-handle-event): * lisp/mouse.el (mouse-drag-track, mouse-drag-region-rectangle): * lisp/minibuffer.el (completion-pcm--find-all-completions): * lisp/mail/rfc2231.el (rfc2231-parse-string): * lisp/mail/rfc2047.el (rfc2047-encode-region): * lisp/jit-lock.el (jit-lock-fontify-now): * lisp/international/ja-dic-utl.el (skkdic-lookup-key): * lisp/gnus/nnselect.el (nnselect-generate-artlist): * lisp/gnus/mml-sec.el (mml-secure-epg-encrypt, mml-secure-epg-sign): * lisp/gnus/mail-source.el (mail-source-fetch-pop) (mail-source-check-pop): * lisp/gnus/gnus-art.el (gnus-article-read-summary-keys): * lisp/files.el (basic-save-buffer-2, files--ensure-directory) (files--force, copy-directory): * lisp/eshell/esh-io.el (eshell-output-object-to-target): * lisp/epa.el (epa-decrypt-file, epa-verify-file, epa-sign-file) (epa-encrypt-file, epa-decrypt-region, epa-verify-region) (epa-sign-region, epa-encrypt-region, epa-delete-keys) (epa-export-keys, epa-insert-keys): * lisp/emacs-lisp/package.el (package--unless-error): * lisp/emacs-lisp/multisession.el (multisession--read-file-value): * lisp/emacs-lisp/lisp.el (up-list-default-function): * lisp/desktop.el (desktop-kill): * lisp/calendar/time-date.el (date-to-time): * lisp/calendar/appt.el (appt-display-message): * lisp/calc/calc.el (calc-do): * lisp/bookmark.el (bookmark-handle-bookmark): * src/fileio.c (report_file_errno): * lisp/vc/vc.el (vc-checkout, vc-pull): Use `(signal err)` instead of `(signal (car err) (cdr err))`.
2026-02-12; * src/dispnew.c (box_default): Shut up compilation warnings (bug#80386).Eli Zaretskii
2026-01-01; Add 2026 to copyright years.Sean Whitton
2025-12-08Fix some C symbol extern visibilityPaul Eggert
Make some C symbols static if they don’t need to be extern. Also, remove a couple of functions that were discovered to be unused as a result of this process, and mark two extern functions intended to be usable from GDB. * src/buffer.c (previous_overlay_change): * src/composite.c (composition_lisp_table): * src/fileio.c (file_name_directory): * src/frame.c (check_tty): * src/insdel.c (adjust_markers_for_insert): * src/keyboard.c (unread_switch_frame, read_char) (requeued_events_pending_p): * src/sysdep.c (renameat_noreplace) [!HAVE_ANDROID]: * src/textconv.c (get_conversion_field) [!HAVE_ANDROID]: * src/treesit.c (TREESIT_BOB_LINECOL, TREESIT_TS_POINT_1_0) (treesit_buf_tracks_linecol_p, make_treesit_parser) (make_treesit_node): * src/xdisp.c (x_y_to_hpos_vpos): * src/xfaces.c (load_color) [!MSDOS]: * src/xfns.c (x_real_pos_and_offsets): * src/xterm.c (x_dnd_do_unsupported_drop): Now static. Move up if necessary. * src/coding.c (utf8_string_p): * src/keyboard.c (detect_input_pending_ignore_squeezables): Remove; unused. * src/frame.c (gui_set_alpha): * src/textconv.c (start_batch_edit, end_batch_edit, commit_text) (finish_composing_text, set_composing_text) (set_composing_region, textconv_set_point_and_mark) (delete_surrounding_text, request_point_update) (textconv_barrier, replace_text, get_extracted_text) (get_surrounding_text): * src/xdisp.c (gui_union_rectangles): * src/xterm.c (xi_frame_selected_for): Define only if needed. * src/treesit.c (treesit_debug_print_parser_list) (treesit_debug_print_linecol): Declare EXTERNALLY_VISIBLE. * src/xdisp.c (x_y_to_column_row): New function, defined only if needed. All external callers to x_y_to_hpos_vpos changed.
2025-08-02Port better to Linux with 1 MiB pagesPaul Eggert
* src/lisp.h: Include <sys-limits.h>. (MAX_RW_COUNT): Remove, as it is the same thing as sys-limits.h’s SYS_BUFSIZE_MAX. All uses replaced by SYS_BUFSIZE_MAX.
2025-07-23Don’t read before BEG in insert-file-contentsPaul Eggert
* src/fileio.c (Finsert_file_contents): Don’t sample bytes before BEG. Give up optimizing if the file size shrinks to less than BEG.
2025-07-23Simplify file end finding in insert-file-contentsPaul Eggert
* src/fileio.c (Finsert_file_contents): Don’t give up finding the file’s end merely because SEEK_END fails. Try a small test read anyway. This might work in non-POSIX file systems where SEEK_END is not allowed, and trying is easy and simplifies the code.
2025-07-21insert-file-contents respect END betterPaul Eggert
This fixes some longstanding bugs, along with bugs recently introduced as part of fixes for Bug#77315. * src/fileio.c (Finsert_file_contents): Arrange for END_OFFSET to never be less than BEG_OFFSET, to simplify the code. Do not go past END_OFFSET when sampling or optimizing reading. Avoid a few unnecessary lseeks.
2025-07-21insert-file-contents shrinking Solaris file fixPaul Eggert
This is related to recent fixes for Bug#77315. * src/fileio.c (Finsert_file_contents): Defend against a file shrinking to be smaller than its initial offset. This can happen only on platforms like Solaris where the initial offset can be positive.
2025-07-21Refactor insert-file-contents overlap checkPaul Eggert
* src/fileio.c (Finsert_file_contents): Simplify and clarify file overlap check.
2025-07-21insert-file-contents refactor xlseekPaul Eggert
* src/fileio.c (xlseek): New arg WHENCE. All uses changed. This generalizes xlseek and should simplify future changes.
2025-07-21Say why quit is captured in insert-file-contentsPaul Eggert
* src/fileio.c (Finsert_file_contents): Add comment.
2025-07-21insert-file-contents read size increasePaul Eggert
This increases the max read size from 0.25 to 1 MiB, which is a bit better for Emacs in my measurements. The old value was taken from coreutils, but was for a different purpose. * src/fileio.c (INSERT_READ_SIZE_MAX): New constant, replacing IO_BUFSIZE. All uses changed. (Finsert_file_contents): Do not use a read buffer that is larger than INSERT_READ_SIZE_MAX.
2025-07-21Fix insert-file-contents infloop with unlucky ENDPaul Eggert
This partially reverts 55f41ca3aa8fe487d10730708a7396137a2c9d18, which was a partial fix for Bug#77315. * src/fileio.c (Finsert_file_contents): Go back to accepting partial reads when doing the optimized way when code conversion is not needed. This avoids an unlikely bug when END happens to lie at a buffer boundary, causing an infloop. For consistency, do the same when doing code conversion (though there’s no bug in then), as there’s not a real need for emacs_full_read there either.
2025-07-21insert-file-contents from seekable non-regularPaul Eggert
* src/fileio.c (Finsert_file_contents): Be more conservative when reading from seekable non-regular files when END is given. The code assumed that in this case, reads would succeed or fail quickly so there was no need to call internal_condition_case_1. However, in some cases, e.g., /dev/random, it could take a while. This fixes a glitch introduced in commit cb4579ed6ba45c81ee7ec627bf197e1def121f24 dated 2022-06-11.
2025-07-21insert-file-contents beware buffer relocationPaul Eggert
This fixes a potential (albeit quite unlikely) bug introduced during recent fixes to Bug#77315. * src/fileio.c (union read_non_regular.s.inserted): Bring back this member. (read_non_regular, Finsert_file_contents): Work in the unlikely case when internal_condition_case_1 relocates the buffer before calling read_non_regular.
2025-07-21insert-file-contents 1 KiB seek fixPaul Eggert
This improves on recent fixes to Bug#77315. When sampling the first 1 KiB and last 3 KiB, do not seek before BEG if given. Instead, sample starting at BEG, to be consistent with the non-optimized version. * src/fileio.c (xlseek): Return POS, for convenience. (Finsert_file_contents): Sample the first 1 KiB correctly when BEG. In a CURPOS local, keep track of the input file offset, or for nonseekable files the number of bytes read, while this value is important. This lets us avoid some unnecessary seeks. Report an error earlier if the file is not seekable and BEG is nonzero, to save work and simplify the code. When sampling, discard less data, as this is simpler and there’s little point to discarding it.
2025-07-21insert-file-contents seek refactoringPaul Eggert
* src/fileio.c (xlseek): New function. (Finsert_file_contents): Use it instead of doing things by hand. (write_region): Match diagnostic wording to xlseek’s.
2025-07-21Fix insert-file-contents optimization glitchPaul Eggert
This improves on recent fixes to Bug#77315. * src/fileio.c (Finsert_file_contents): When optimizing do not seek to 0 if the initial file offset is positive, as that causes the optimized code to behave differently from the nonoptimized.
2025-07-21insert-file-contents SEEK_END optimizationPaul Eggert
This improves on recent fixes to Bug#77315. * src/fileio.c (Finsert_file_contents): Do not give up on seeking merely because SEEK_END fails. On some files (/proc/cpuinfo, say) SEEK_END can fail even though SEEK_SET and SEEK_CUR succeed, and the code still works in this case.
2025-07-21insert-file-contents st_size cleanupPaul Eggert
* src/fileio.c (Finsert_file_contents): Store st_size, not file_size_hint, into current_buffer->modtime_size, since modtime_size is compared to a later st_size, not to the actual file size. Simplify buffer overflow detection from file size, since this occurred only on regular files.
2025-07-16Don’t optimize insert-file-contents for GNUPaul Eggert
* src/fileio.c (Finsert_file_contents): Remove a microoptimization for GNU/Linux and Android.
2025-07-16insert-file-contents small gap bugPaul Eggert
Problem reported by Zhengyi Fu (Bug#79031). * src/fileio.c (Finsert_file_contents): Do not read more than requested, even when the gap is so small that we use a local buffer.
2025-07-16insert-file-contents likely-end memory objectsPaul Eggert
* src/fileio.c (Finsert_file_contents): Treat memory objects like regular files when inferring likely end. Simplify likely end computation.
2025-07-16Port insert-file-contents dir behavior to UnixPaul Eggert
* src/fileio.c (Finsert_file_contents): Port better to traditional Unix platforms like Solaris, where in some cases 'read' can succeed on directories.
2025-07-15Fix insert-file-contents overlap checkPaul Eggert
In commit 61a8ce0280668980a4452b112103c9bc879e1f49 I mistakenly focused on overlap in the buffer. The code also needs to check for overlap in the inserted file data. Problem reported by Gerd Möllmann (Bug#79020). * src/fileio.c (Finsert_file_contents): Prevent overlap in both the buffer head and tail, and in the inserted file’s head and tail. Also, shrink the file’s head if the file shrank to be smaller than its head.
2025-07-14Fix the Android portPo Lu
* src/fileio.c (emacs_full_read): Retype FD param to `emacs_fd'. (Fcopy_file): Label newsize MAYBE_UNUSED.
2025-07-13; Fix indentation.Paul Eggert
2025-07-13Speed up insert-file-contents readsPaul Eggert
This change makes insert-file-contents-literally 30% faster on my platform, when inserting xdisp.c. * src/fileio.c (READ_BUF_SIZE): Remove, replacing with ... (IO_BUFSIZE): ... this new constant from Coreutils. All uses of READ_BUF_SIZE changed to either MAX_ALLOCA or IO_BUFSIZE.
2025-07-13Avoid some tiny /proc file readsPaul Eggert
* src/fileio.c (union read_non_regular): New members buf and bufsize replace inserted and trytry. (read_non_regular): Adjust to this new, simpler interface. (Finsert_file_contents): If the gap is smaller than read_buf and we want to read more than the gap, read into read_buf first, to avoid lots of tiny reads from /proc files.
2025-07-13insert-file-contents file shrinkage in scanbackPaul Eggert
* src/fileio.c (emacs_full_read): New function. (Fcopy_file, Finsert_file_contents): Use it. (Finsert_file_contents): Check for partial reads when scanning backwards through the file’s tail, as this indicates the file shrank while we read it. Also, use emacs_full_read in other situations where it’s simpler and should be a bit faster.
2025-07-13int → ptrdiff_t for read resultsPaul Eggert
* src/fileio.c (Finsert_file_contents): Use ptrdiff_t, not int, to store results returned by emacs_fd_read, which return ptrdiff_t. This doesn’t fix any bugs since the values happen to fit in int, but is a bit clearer and may simplify future changes.
2025-07-13insert-file-contents unexpected end shrinkagePaul Eggert
* src/fileio.c (Finsert_file_contents): If the file unexpectedly shrinks while reading its tail backwards, give up searching for the match end.
2025-07-13fileio.c comment spelling fixPaul Eggert
2025-07-13insert-file-contents byte vs char confusionPaul Eggert
* src/fileio.c (Finsert_file_contents): Use del_range_byte, not del_range_1, since we are passing byte counts, not character counts. Problem reported by Pip Cet (Bug#77315).
2025-07-13Fix insert-file-contents overlap calculationPaul Eggert
* src/fileio.c (Finsert_file_contents): Overlap is impossible, so omit incorrect overflow adjustments that caused later index calculations to go off the rails (Bug#77315). Change a ‘ZV_BYTE’ to ‘same_at_end’ for clarity; they have the same value here.
2025-07-13insert-file-contents do not rely on st_sizePaul Eggert
This fix was prompted by Bug#77315. * src/fileio.c (Finsert_file_contents): Do not rely on st_size for anything other than a hint about the file size. Trust only the file size as revealed by a read that returns 0.
2025-07-13insert-file-contents file size hint improvementPaul Eggert
* src/fileio.c (Finsert_file_contents): When reading yields 0, update the file size hint to match. This should improve its accuracy.
2025-07-13insert-file-contents file end EOF fixesPaul Eggert
* src/fileio.c (Finsert_file_contents): When counting bytes at file end, don’t trust lseek to seek to the end of the file. Instead, read a bit after lseeking, to make sure we get to the end, give up if we don’t get to EOF. This works around problems on /proc filesystems where lseek pretends the file is empty. Update file_size_hint when reaching EOF.
2025-07-13Fix insert-file-contents integer overflowsPaul Eggert
* src/fileio.c (Finsert_file_contents): Change ‘total’ from ptrdiff_t to off_t since it might not fit in ptrdiff_t. Check for overflow when estimating the insertion size.
2025-07-13Remove ineffective overflow checkPaul Eggert
* src/fileio.c (Finsert_file_contents): Remove check for overflow. The overflow is not possible, and the check was incorrectly written and would not have caught it anyway.
2025-07-13insert-file-contents END enforcementPaul Eggert
* src/fileio.c (Finsert_file_contents): When matching text at buffer start, don’t go past END if specified.
2025-07-13insert-file-contents initial offset fixPaul Eggert
* src/fileio.c (Finsert_file_contents): Don’t assume that a newly-opened file is at offset 0, even if it is a regular file. This might not be true for files like /dev/stdin.
2025-07-13insert-file-contents end offset infinityPaul Eggert
* src/fileio.c (Finsert_file_contents): Simplify end_offset calculation by defaulting to effectively infinity.
2025-07-13Refactor negative file size checkingPaul Eggert
* src/fileio.c (Finsert_file_contents): Check for negative file sizes earlier, as it’s easy, avoids some unnecessary work, and will simplify later changes.
2025-07-13Non-nil orig_filename in insert-file-contentsPaul Eggert
* src/fileio.c (Finsert_file_contents): Don’t let orig_filename be nil, as that might mess up later diagnostics.