>
> getpwnam() returns NULL if:
>
> a) the user doesn't exits
> b) an error occurred
>
> When an error occurred, errno is set appropriately. When the user
> doesn't exist, errno is NOT set. Thus you want to use some code as
follows:
>
> struct passwd *pw;
>
> /* we reset errno so we can tell whether an error happens in getpwnam()
> * or not */
> errno = 0;
> pw = getpwnam("some_user");
> if (!pw) {
> if (errno) fprintf(stderr, "error: %s\n", strerror(errno));
> else fprintf(stderr, "no such user\n");
> }
>
> Greetings,
> Aaron
> --
> Aaron Isotton | http://www.isotton.com/
> You know it's Monday when you wake up and it's Tuesday. -- Garfield
But the problem is I always pass the same user(exist in the system) to
getpwnam, sometimes it works but sometimes it fails with NULL. Any idea?