[Date Prev][Date Next] [Thread Prev][Thread Next] [Date Index] [Thread Index]

Re: oddness from getgrnam()



In article <cistron.XFMail.990416000128.shaleh@livenet.net>,
Shaleh  <shaleh@livenet.net> wrote:
>I was testing a program and to see how it handled an invalid group I did:
>
>gr = getgrnam("bob");
>
>Now obviously this failed.  However the string from perror() states:
>
>"Could not find file or directory"
>

The manual page for getgrnam(2) states the ENOMEM is the only valid
errno getgrnam() can return.

So that should be:

	gr = getgrnam("bob");
	if (gr == NULL) {
		if (errno == ENOMEM)
			perror("getgrnam");
		else
			fprintf(stderr, "getgrnam: bob not found\n");
	}

>Why is this?  Seems like a counter intuitive error.
>(Yes I know UNIX is sometimes like that, but this one is odd)

Basically in non-system calls (not section 2 of the manual) you cannot
use errno generically. It's just a numeric value which in a lot of
cases only makes sense with system calls.

getgrnam() probably set it to ENOENT, which is the most sensible
thing to do, but the correspondig string doesn't make much sense
for a non-file related call.

Mike.
-- 
Indifference will certainly be the downfall of mankind, but who cares?


Reply to: