On Tuesday 07 May 2013 15:45:55 you wrote: > On Tue, May 07, 2013 at 03:25:04PM +0200, Remco wrote: > | The way I read the man page on my OpenBSD 5.2 system, as well as on the > | www.openbsd.org web site, errno has no specific meaning when getpwuid > | returns. It only tells you whether it succeeded or not, it doesn't say it
Maybe this sentence would have been clearer as follows: The man page only tells you how to check whether the getpwuid function succeeded or not, it doesn't say it > | sets errno, nor does it provide a clear way to determine why the function > | didn't succeed. (however, if you're right the man page may be lacking) > > Where do you see that ? errno is not used to tell you wether a call > succeeded or not. If a call did not succeed, errno would get set. If > a call was successful, it never sets errno. > > From intro(2) (get there via the errno(2) mlink): > > When a system call detects an error, it returns an > integer value indicating failure (usually -1) and > sets the variable errno accordingly. (This allows > interpretation of the failure on receiving a -1 > and to take action accordingly.) Successful calls > never set errno; once set, it remains until > another error occurs. It should only be examined > after an error. > > This is how errno should behave across the entire system. If you find > a case where this is not true, please report it. > > Paul 'WEiRD' de Weerd It might be that errno gets set by getpwuid by doing system calls behind the scenes. However, my point was that errno has no specific meaning when getpwuid returns because it does not provide me with any useful context about what failed. (And simply put, the man page does not instruct me to check errno, so errno cannot have meaning here) Otherwise, if errno does have meaning anyway, I think the man page lacks that specific information about what errno values could possibly be set. Apart from being able to tell that some system call failed, I don't really see much point in checking errno as a way to check for specific errors upon returning from getpwuid. I feel that the OP's program behaves as expected and the way he checks for errors, by not adhering to the instructions in the man page, is simply asking for unnecessary trouble. I hope this clarifies my point.