On 2026-01-11 09:23, Alexander Jones wrote:
The proposed solution of deferring the diagnostic to the actual file
I/O raises three key issues. First, red (restricted ed) will still
give its own diagnostic for the example argument:
FILE/: Directory access restricted
This diagnostic cannot be removed, as red is designed not to have
access to other directories.
That's fine; let's leave that part of GNU ed alone, as that part already
operates on file names and does not care about file types or contents.
Secondly, the function being modified is invoked by several ed
commands, including the "f" command, which does no immediate I/O and
thus will not trigger any warning of its own at all with the patched
code and given example:
*f FILE/
FILE/
That's fine too. It's what Solaris /usr/bin/ed does. It gives no warning
until you write the file:
$ ed
f /dev/null/
/dev/null/
w
?
That is, it treats /dev/null/ consistently with how it treats any file
that does not exist and cannot be created, e.g.:
$ ed
f /no/such/file
/no/such/file
w
?
It makes sense to follow in the Unix 'ed' tradition here.
Thirdly, once a file is written with the example filename, errno is
still set in such a way as to display basically the same diagnostic as
before:
*w
FILE/: Is a directory
?
*h
Cannot open output file
That's also OK. Here GNU, ed calls fopen ("FILE/", "w"), and POSIX
allows this to fail with errno == EISDIR, which elicits the "Is a
directory" diagnostic. This is because the fopen fails for two reasons:
first, FILE/ doesn't exist, and second if FILE/ did exist it would be a
directory and you can't open directories for writing, and POSIX says
that when multiple errnos apply, fopen can fail with any of them.
As an aside, when I compiled the executable with the patch, it was
exactly the same size as the build of the currently released version.
On my platform the executable file size was the same, but the text size
(which is what what I was referring to, and which is what the CPU cares
about) was a bit smaller: the text size (which I computed by running
"size ed") shrank from 52002 to 51978 bytes. Admittedly not a big
savings but hey! This is ed!