home *** CD-ROM | disk | FTP | other *** search
/ NetNews Usenet Archive 1992 #31 / NN_1992_31.iso / spool / comp / sys / sgi / 18328 < prev    next >
Encoding:
Internet Message Format  |  1992-12-24  |  3.1 KB

  1. Xref: sparky comp.sys.sgi:18328 comp.sys.sgi.bugs:44 comp.unix.ultrix:9075
  2. Newsgroups: comp.sys.sgi,comp.sys.sgi.bugs,comp.unix.ultrix
  3. Path: sparky!uunet!mcsun!sun4nl!fwi.uva.nl!casper
  4. From: casper@fwi.uva.nl (Casper H.S. Dik)
  5. Subject: Re: tempnam(3S) bug, possibly on all MIPS
  6. Message-ID: <1992Dec24.090322.14403@fwi.uva.nl>
  7. Sender: news@fwi.uva.nl
  8. Nntp-Posting-Host: adam.fwi.uva.nl
  9. Organization: FWI, University of Amsterdam
  10. References: <1gu849INNp6k@menudo.uh.edu> <tqcnepk@zuni.esd.sgi.com> <1992Dec24.011451.497@pixar.com>
  11. Date: Thu, 24 Dec 1992 09:03:22 GMT
  12. Lines: 65
  13.  
  14. aaa@pixar.com (Tony Apodaca) writes:
  15.  
  16. >In an article, svec5@menudo.uh.edu (T.C. Zhao) writes:
  17. >>| It appears that tempnam(3S) is broken on three MIPS machines I have
  18. >>| access to:   IRIX 3.3, Ultrix 4.1, UMIPS 4.52:
  19.  
  20. >In an article, olson@anchor.esd.sgi.com (Dave Olson) writes:
  21. >>Since tempnam() needs to make sure the file it is existing doesn't
  22. >>exist, it isn't surprising that errno is set (but you shouldn't
  23. >>count on it either way!).
  24.  
  25. >In an article, murphy@ufp.dco.dec.com (Rick Murphy) writes:
  26. >>Looking at errno after calling a library routine that hasn't failed isn't
  27. >>a useful thing to do. The call succeeded - you've got no reason to go looking
  28. >>at errno.
  29.  
  30. >    This is not really the point.  The point is that a smart programmer
  31. >checks errno after every system call.
  32.  
  33. You have a totally different conception of smart than most of us.
  34. You may only inspect errno after a FAILED system call. If you examine
  35. errno after a library call or after a succesfull system call,
  36. it can have any value. Some manuals explicitly state that a successfull
  37. system call will not touch errno, others even leave room for that.
  38.  
  39. It is generally accepted, though that errno is not touched by successful
  40. system calls for one simpel reason: some system calls can return any
  41. value, and must be called in the following manner:
  42.         errno = 0; val = syscal(); if (errno) .....
  43.  
  44. >It makes you go into defensive programming mode, setting errno to 0 before
  45. >every system call because you don't know if there are any *other* library
  46. >routines which break the rules and have unexpected unfriendly side effects
  47. >like this.
  48.  
  49. >    Okay, maybe I'm exaggerating to make a point, but I don't think
  50. >it's fair to insinuate that Mr. Zhao is wrong.  It *is* a bug, in the
  51. >following sense: the man pages explicitly state that errno is set if a
  52. >system call gets an error, but is untouched otherwise.  I think library
  53. >utility functions fall into the "otherwise" category, don't you?
  54.  
  55. No, the manual states that errno isn't touched on `successfull SYSTEM calls'.
  56. It says nothing about other successfull calls. It is in
  57. fact quite common for a library call to set errno to some unexpected value.
  58.  
  59. E.g., this piece of code has a bug:
  60.  
  61.     if (write (....) == -1) {
  62.         fprintf(stderr,"some message")'
  63.         perror("write");
  64.         exit(1);
  65.     }
  66.  
  67. (Hint: why do a number of programs always print ``Not a typewriter'' or
  68.  ``Inappropriate ioctl for device'' when they detect an error code?)
  69.  
  70. Or do you want all library programs to bracket their code with:
  71.  
  72.     savederrno = errno;
  73.     ......
  74.     errno = savederrno; /* on successfull returns only */
  75.  
  76. I think not.
  77.  
  78. Casper
  79.