fgetspent()

QNX SDP8.0C Library ReferenceAPIDeveloper

Get an entry from the shadow password database

Synopsis:

#include <sys/types.h>
#include <shadow.h>

struct spwd* fgetspent( FILE* f );

Arguments:

f
The stream from which to read the shadow password database entry.

Library:

libc

Use the -l c option to qcc to link against this library. This library is usually included automatically.

Description:

The fgetspent() works like the getspent() function but it assumes that it's reading from a file formatted like a shadow password database file. This function uses a static buffer that's overwritten by each call.

Note:
The fgetspent(), getspent(), and getspnam() functions share the same static buffer.

Returns:

A pointer to a struct spwd object containing the next entry from the password database. For more information about this structure, see putspent().

Errors:

ENOMEM
There's insufficient memory to complete the request.
ERANGE
There are no more entries in the shadow password database file.

In addition to the errno settings listed above, a call to fgetspent() can result in errno being set by any of the following functions:

Examples:

#include <stdio.h>
#include <stdlib.h>
#include <pwd.h>
#include <shadow.h>

/*
 * This program reads entries from a file that is formatted like
 * a shadow password file. Each loop iteration reads the next
 * shadow password entry.
 */
int main( int argc, char** argv )
{
    FILE* fp;
    struct spwd* sp;

    if (argc < 2) {
        printf("%s filename \n", argv[0]);
        return(EXIT_FAILURE);
    }

    if (!(fp = fopen(argv[1], "r"))) {
        fprintf(stderr, "Can't open file %s \n", argv[1]);
        return(EXIT_FAILURE);
    }

    while( (sp = fgetspent(fp)) != (struct spwd *) 0 ) {
        printf( "Username: %s\n", sp->sp_namp );
        printf( "Password: %s\n", sp->sp_pwdp );
    }

    fclose(fp);
    return(EXIT_SUCCESS);
}

Classification:

Unix

Safety:
Cancellation pointYes
Signal handlerNo
ThreadNo
Page updated: