View Single Post

   
  #4 (permalink)  
Old 01-16-2008, 07:15 PM
Jim Hollenback
 
Posts: n/a
Default Re: getpwnam problem

ultra (ultraman@rogers_NOSPAM.com) wrote:
: >
: > 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");
: > }
: >

: 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?

what is the errno when it fails?

--
Jim Hollenback
jholly@cup.hp.com
my opinion.
Reply With Quote