From: H.J. Lu (hlu@luke.eecs.wsu.edu)
Date: 01/07/93


From: hlu@luke.eecs.wsu.edu (H.J. Lu)
Subject: Re: Library 4.1 bug/feature?  fopen("fifo","a") fails
Date: Thu, 7 Jan 1993 10:49:39 GMT

In article <1igs2mINNdpp@nz12.rz.uni-karlsruhe.de> ig25@rz.uni-karlsruhe.de writes:
>Is it a bug or a feature that fopen("fifo","a"), where "fifo" is a named
>pipe, fails with an 'illegal lseek' in the 4.1 version of the library?
>The opinion on comp.std.unix seems to be that there should be no
>problem...

That is a feature of stdio/kernel. I was told that according to ANSI
standard, fopen ("foo", "a") should do a lseek () to the end after
calling open (). But linux kernel refuses to any lseek () on
non-regular files. The fixes are

1. Change stdio such that ignore error from lseek (). I don't
   like this one.
2. Change kernel such that if a file can not lseek (), just return
   without error.
3. Change kernel such that if a file can not lseek (), just return
   with a special error which can be recognized by stdio that a
   lseek is requested on a non-suported file.
4. Change your source code to use fopen ("foo", "w').

I prefer (3). We need change one line in xxxxx__lseek () from

        return -EBADF;

to

        return -ELSEEK; or return -ESPIPE;

We can just add

#define ELSEEK ESPIPE

BTW, some Unices just do (2). Try this one on your Unix machines.