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/g/getspnam.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/g/getspnam.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/g/getspnam.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/g/getspnam.html on line 8

getspnam(), getspnam_r()

Get information about a user with a given name

Synopsis:

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

struct spwd* getspnam( char* name );

struct spwd* getspnam_r( const char* name, 
                         struct spwd* result, 
                         char* buffer, 
                         size_t bufsize );

Arguments:

name
The name of the user.
result
(getspnam_r() only) A pointer to a spwd structure where the function can store the entry. For more information about this structure, see putspent().
buffer
(getspnam_r() only) A block of memory that the function can use to allocate storage referenced by the spwd structure. You can determine the maximum size needed for this buffer by calling sysconf() with an argument of _SC_GETPW_R_SIZE_MAX.
bufsize
(getspnam_r() only) The size of the block that buffer points to, in characters.

Library:

libc

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

Description:

The getspnam() and getspnam_r() functions allow a process to gain more knowledge about a user name. The getspnam() 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 an entry from the group database with a matching name, or NULL if an error occurred or the function couldn't find a matching entry.

Examples:

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

/*
 * Print information from the password entry
 * about the user name given as argv[1].
 */

int main( int argc, char** argv ) 
{
    struct spwd* sp;

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

    if( ( sp = getspnam( argv[1] ) ) == (struct spwd*)0) {
      fprintf( stderr, "getspnam: unknown %s\n",
        argv[1] );
      return( EXIT_FAILURE );
    }
    printf( "login name  %s\n", sp->sp_namp );
    printf( "password    %s\n", sp->sp_pwdp );
    return( EXIT_SUCCESS );
}

Classification:

Unix

getspnam()

Safety:
Cancellation point Yes
Interrupt handler No
Signal handler No
Thread No

getspnam_r()

Safety:
Cancellation point Yes
Interrupt handler No
Signal handler No
Thread Yes

See also:

fgetspent(), getlogin(), getspent(), getpwuid(), 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/g/getspnam.html on line 208

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/g/getspnam.html on line 208