[Search for users] [Overall Top Noters] [List of all Conferences] [Download this site]

Conference turris::digital_unix

Title:DIGITAL UNIX(FORMERLY KNOWN AS DEC OSF/1)
Notice:Welcome to the Digital UNIX Conference
Moderator:SMURF::DENHAM
Created:Thu Mar 16 1995
Last Modified:Fri Jun 06 1997
Last Successful Update:Fri Jun 06 1997
Number of topics:10068
Total number of notes:35879

9504.0. "Undefined: setpwent_r getpwent_r in 3.2c" by TAV02::JEREMY () Tue Apr 15 1997 07:31

    
    
    The following routine compiles fine under 4.0*, but under 3.2*
    returns:
    
    #  cc   iz1.c  -o iz1
    ld:
    Unresolved:
    setpwent_r
    getpwent_r
    endpwent_r
    
    Here's the code:
    
    #include <pwd.h>
    #include <stdio.h>
    #include <unistd.h>
    #include <sys/types.h>
    main(argc, argv)
    int argc;
    char *argv[];
    {
    struct passwd pwbuf;
    char buffer[1024];
    int len;
    int count=0;
    FILE *pwf = NULL;
    setpwent_r(&pwf);
    while (getpwent_r(&pwbuf, buffer, 1024, &pwf) != -1){
       count++;
       printf("%s\n",buffer);
       }
    endpwent_r(&pwf);
    printf("lines=%d\n",count);
    }
    
T.RTitleUserPersonal
Name
DateLines
9504.1COL01::LINNARTZTue Apr 15 1997 07:384
    with V4.0 ther was a major cleanup with libc to make it thread safe
    and rentrant. before V4.0 you had to add -lc_r to your commandline
    
    Pit
9504.2EurekaTAV02::JEREMYTue Apr 15 1997 09:301
    Thanks a lot that did the trick! (And an answer within ten minutes!)
9504.3TAV02::JEREMYWed Apr 16 1997 03:062
    Spoke too soon. It compiles OK, but puts out just blank lines.
    Any more ideas?
9504.4take a look at pwbuf :-)COL01::LINNARTZThu Apr 17 1997 17:311
    
9504.5don't assume working buffer has valid dataTAV02::GOVERKobi GoverThu Apr 24 1997 02:3416
>>                                 <<< Note 9504.4 by COL01::LINNARTZ >>>
>>                                     -< take a look at pwbuf :-) >-

Damn assumptions,
the buffer parameter in getpwent_r is just a working area, and just because
if have some valid content in unix 4.0 shouldn't lead us to think
it's content in unix 3.2C will be valid.

in the call
   getpwent_r(&pwbuf,buffer, 1024, &pwf)
valid data is only in the pwbuf 
 
thanks to Pit Linnartz for hinting us on this.                                               

Kobi.