Warning: main(/www/www/htdocs/style/globals.php) [function.main]: failed to open stream: No such file or directory in /www/www/docs/6.4.1/neutrino/lib_ref/f/fgetspent.html on line 1

Warning: main() [function.include]: Failed opening '/www/www/htdocs/style/globals.php' for inclusion (include_path='.:/www/www/common:/www/www/php/lib/php') in /www/www/docs/6.4.1/neutrino/lib_ref/f/fgetspent.html on line 1

Warning: main(/www/www/htdocs/style/header.php) [function.main]: failed to open stream: No such file or directory in /www/www/docs/6.4.1/neutrino/lib_ref/f/fgetspent.html on line 8

Warning: main() [function.include]: Failed opening '/www/www/htdocs/style/header.php' for inclusion (include_path='.:/www/www/common:/www/www/php/lib/php') in /www/www/docs/6.4.1/neutrino/lib_ref/f/fgetspent.html on line 8

fgetspent()

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.

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 an object of type struct spwd containing the next entry from the password database. For more information about this structure, see putspent().

Errors:

The fgetspent() function uses the following functions, and as a result errno can be set to an error for any of these calls:

Examples:

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

/*
 * This program loops, reading a entries from a file
 * (which is formatted in the shadow password way)
 * reading the next shadow password entry.
 * For example this_file /etc/shadow
 */

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 point Yes
Interrupt handler No
Signal handler No
Thread No

See also:

errno, getgrent(), getlogin(), getpwnam(), getpwuid(), getspent(), getspnam(), putspent()


Warning: main(/www/www/htdocs/style/footer.php) [function.main]: failed to open stream: No such file or directory in /www/www/docs/6.4.1/neutrino/lib_ref/f/fgetspent.html on line 195

Warning: main() [function.include]: Failed opening '/www/www/htdocs/style/footer.php' for inclusion (include_path='.:/www/www/common:/www/www/php/lib/php') in /www/www/docs/6.4.1/neutrino/lib_ref/f/fgetspent.html on line 195