bug-gnu-emacs
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

bug#18370: insert-file-contents: forbids also beg, end for non-regular (


From: Lars Ingebrigtsen
Subject: bug#18370: insert-file-contents: forbids also beg, end for non-regular (special) files
Date: Wed, 11 May 2022 17:22:56 +0200
User-agent: Gnus/5.13 (Gnus v5.13) Emacs/29.0.50 (gnu/linux)

Ivan Shmakov <ivan@siamics.net> writes:

>       As currently implemented, insert-file-contents disallows not
>       only (as per (elisp.info) Reading from Files) the case of either
>       ‘visit’ or ‘replace’ arguments being non-nil, but also when
>       non-nil are either ‘beg’ or ‘end’ (or both):

[...]

>       This, however, precludes the use of insert-file-contents not
>       only on named pipes, but also on /dev/cdrom, /dev/random, and
>       the like, – for (and especially in the case of the latter) the
>       ‘end’ argument gets rather essential here, as otherwise the
>       function is likely to read much more than the caller will be
>       able to handle at any single time.
>
>       Instead, I’d suggest that ‘end’ is always allowed, and ‘beg’ is
>       allowed when the file in question is /seekable/, – which, ISTR,
>       is possible to check beforehand (lseek (fd, 0, SEEK_CUR) < 0?)
>
>       From a glance over the code, this new behavior wouldn’t be all
>       that hard to implement (some not_regular checks will have to be
>       replaced with the ones against beg_offset, end_offset, etc.),
>       but from what I read, – it’s already going to be more than I can
>       test right now.  So no .diff this time, alas.

(I'm going through old bug reports that unfortunately weren't resolved
at the time.)

Simple test case:

(insert-file-contents "/dev/urandom" nil nil 10)

This still fails in Emacs 29, and it would indeed be nice if it worked.
I seem to remember this being discussed previously, and that...  er...
no, I can't really recall anything more than that.

Does anybody see any good reasons why we shouldn't allow this?  If not,
I can take a stab at implementing it...

-- 
(domestic pets only, the antidote for overdose, milk.)
   bloggy blog: http://lars.ingebrigtsen.no





reply via email to

[Prev in Thread] Current Thread [Next in Thread]