home *** CD-ROM | disk | FTP | other *** search
/ NetNews Usenet Archive 1992 #31 / NN_1992_31.iso / spool / comp / sys / sgi / 18335 < prev    next >
Encoding:
Text File  |  1992-12-24  |  1.8 KB  |  42 lines

  1. Newsgroups: comp.sys.sgi
  2. Path: sparky!uunet!psinntp!pixar!news
  3. From: Bruce@Pixar.com (Bruce Perens)
  4. Subject: tempnam() and errno non-bug
  5. Message-ID: <1992Dec24.201259.21103@pixar.com>
  6. Sender: news@pixar.com (Usenet Newsmaster)
  7. Nntp-Posting-Host: kvetch.pixar.com
  8. Organization: Pixar -- Point Richmond, California
  9. References: <1992Dec24.011451.497@pixar.com>
  10. Date: Thu, 24 Dec 1992 20:12:59 GMT
  11. Lines: 29
  12.  
  13. In article <1992Dec24.011451.497@pixar.com> aaa@pixar.com (Tony Apodaca)  
  14. writes:
  15. [Regarding tempnam() setting errno even though tempnam() has not failed.]
  16. > It *is* a bug, in the
  17. > following sense: the man pages explicitly state that errno is set if a
  18. > system call gets an error, but is untouched otherwise.  I think library
  19. > utility functions fall into the "otherwise" category, don't you?
  20.  
  21. I don't agree that it's a bug.
  22.  
  23. Library functions are allowed to make system calls, thus library functions
  24. may set errno when the system calls fail. This is
  25. the case with tempnam() - it uses a system call to check if the name
  26. it has created exists in /tmp. If the system call succeeds, the name
  27. exists and tmpnam() picks another name and uses the system call to
  28. check it. Thus, the system call must fail before tempnam() returns.
  29.  
  30. The cautious programmer always checks the return value of a system call
  31. for a failure indication, and never looks at errno except immediately
  32. after a system call has returned indicating an error. The value of errno
  33. is un-defined at any other time if you are using library functions, since
  34. those library functions may make system calls as they please, and those
  35. system calls may fail.
  36.  
  37. Most Unix programmers stumble over this at some point.
  38. It's certainly non-intuitive. A more modern design would use something
  39. other than a global variable for errors - perhaps the C++ "exception"
  40. facility will help here.
  41.                     Bruce Perens
  42.