home *** CD-ROM | disk | FTP | other *** search
- Newsgroups: comp.os.linux
- Path: sparky!uunet!usc!zaphod.mps.ohio-state.edu!saimiri.primate.wisc.edu!usenet.coe.montana.edu!news.u.washington.edu!serval!luke.eecs.wsu.edu!hlu
- From: hlu@luke.eecs.wsu.edu (H.J. Lu)
- Subject: Re: Library 4.1 bug/feature? fopen("fifo","a") fails
- Message-ID: <1993Jan7.104939.10424@serval.net.wsu.edu>
- Sender: news@serval.net.wsu.edu (USENET News System)
- Organization: Washington State University!
- References: <1igs2mINNdpp@nz12.rz.uni-karlsruhe.de>
- Date: Thu, 7 Jan 93 10:49:39 GMT
- Lines: 50
-
- 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.
-
- ----
- #include <stdio.h>
-
-
- int main()
- {
- int i;
-
- for (i = 0; i < 3; i++) {
- if (lseek (i, 0, 2) < 0)
- perror ("lseek");
- }
- }
- ----
-
- H.J.
-