------- Additional Comments From sgk at troutmask dot apl dot washington dot
edu 2005-06-18 16:19 -------
Subject: Re: FAIL: gfortran.dg/dev_null.f90
> int main (void)
> {
> int fd = open ("/dev/null", O_RDWR);
> ftruncate (fd, 0);
> printf ("%d\n", errno);
> close (fd);
> return 0;
> }
>
> On linux, this code outputs 22 (EINVAL), while on freebsd it outputs 0. I
> suppose the reason of the failure is similar for other platforms.
>
> I'm sure what to do, but I don't think I'll take too much time thinking about
> it, since this a low-priority bug really.
According to null(4) man page, reading or writing to /dev/null
on FreeBSD always succeeds. According to the ftruncate man page,
upon successful completion, the value 0 is returned.
The redhat system that I checked, identifies /dev/null as "a
special file" in null(4). The ftruncate man page specifically
states the behavior for "regular files". So redhat has wiggle
room with its use of errno.
POSIX
http://www.opengroup.org/onlinepubs/009695399/toc.htm
If fildes refers to any other file type, except a shared memory
object, the result is unspecified.
So, we need to check both the return value of ftruncate and
the value of errno.
--
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=21593