home *** CD-ROM | disk | FTP | other *** search
/ NetNews Usenet Archive 1993 #1 / NN_1993_1.iso / spool / comp / os / linux / 23054 < prev    next >
Encoding:
Text File  |  1993-01-07  |  1.8 KB  |  62 lines

  1. Newsgroups: comp.os.linux
  2. 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
  3. From: hlu@luke.eecs.wsu.edu (H.J. Lu)
  4. Subject: Re: Library 4.1 bug/feature?  fopen("fifo","a") fails
  5. Message-ID: <1993Jan7.104939.10424@serval.net.wsu.edu>
  6. Sender: news@serval.net.wsu.edu (USENET News System)
  7. Organization: Washington State University!
  8. References: <1igs2mINNdpp@nz12.rz.uni-karlsruhe.de>
  9. Date: Thu, 7 Jan 93 10:49:39 GMT
  10. Lines: 50
  11.  
  12. In article <1igs2mINNdpp@nz12.rz.uni-karlsruhe.de> ig25@rz.uni-karlsruhe.de writes:
  13. >Is it a bug or a feature that fopen("fifo","a"), where "fifo" is a named
  14. >pipe, fails with an 'illegal lseek' in the 4.1 version of the library?
  15. >The opinion on comp.std.unix seems to be that there should be no
  16. >problem...
  17.  
  18. That is a feature of stdio/kernel. I was told that according to ANSI
  19. standard, fopen ("foo", "a") should do a lseek () to the end after
  20. calling open (). But linux kernel refuses to any lseek () on
  21. non-regular files. The fixes are
  22.  
  23. 1. Change stdio such that ignore error from lseek (). I don't
  24.    like this one.
  25. 2. Change kernel such that if a file can not lseek (), just return
  26.    without error.
  27. 3. Change kernel such that if a file can not lseek (), just return
  28.    with a special error which can be recognized by stdio that a
  29.    lseek is requested on a non-suported file.
  30. 4. Change your source code to use fopen ("foo", "w').
  31.  
  32. I prefer (3). We need change one line in xxxxx__lseek () from
  33.  
  34.     return -EBADF;
  35.  
  36. to
  37.  
  38.     return -ELSEEK; or return -ESPIPE;
  39.  
  40. We can just add
  41.  
  42. #define     ELSEEK    ESPIPE
  43.  
  44. BTW, some Unices just do (2). Try this one on your Unix machines.
  45.  
  46. ----
  47. #include <stdio.h>
  48.  
  49.  
  50. int main()
  51. {
  52.   int i;
  53.  
  54.   for (i = 0; i < 3; i++) {
  55.    if (lseek (i, 0, 2) < 0)
  56.      perror ("lseek");
  57.   }
  58. }
  59. ----
  60.  
  61. H.J.
  62.