Subject: insert-file-contents: forbids also beg, end for non-regular (special) files

From: Ivan Shmakov <[email-masked]>
Date: Sun, 31 Aug 2014 19:50:09 +0000

Package:  emacs
Severity: minor

	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):

  3506	  /* This code will need to be changed in order to work on named
  3507	     pipes, and it's probably just not worth it.  So we should at
  3508	     least signal an error.  */
  3509	  if (!S_ISREG (st.st_mode))
  3510	    {
  3511	      not_regular = 1;
⋯
  3516	      if (! NILP (replace) || ! NILP (beg) || ! NILP (end))
  3517		xsignal2 (Qfile_error,
  3518			  build_string ("not a regular file"), orig_filename);
  3519	    }

	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.

-- 
FSF associate member #7257  http://boycottsystemd.org/  … 3013 B6A0 230E 334A