getspnam(), getspnam_r()

QNX SDP8.0C Library ReferenceAPIDeveloper

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 shadow file 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

Table 1. getspnam()
Safety:
Cancellation pointYes
Signal handlerNo
ThreadNo
Table 2. getspnam_r()
Safety:
Cancellation pointYes
Signal handlerNo
ThreadYes
Page updated: