generate a string containing the effective user ID
#include <stdio.h> char *cuserid( char *s );
The cuserid() function generates a string that contains the name associated with the effective user ID of the calling process. If s isn't NULL, it must point to an array of at least L_cuserid bytes (see <stdio.h>); the string is returned in this array. If s is a NULL pointer, the string is built in a static buffer that is overwritten by subsequent calls to cuserid().
A pointer to the process owners user ID, or a NULL pointer if the user ID cant be found. This pointer is to the array s (if non-NULL), or to cuserids static buffer.
/* This process prints its username. */ #include <stdio.h> #include <stdlib.h> int main( void ) { char username[L_cuserid]; if( cuserid( username ) == NULL ) { fprintf( stderr, "cannot find login name\n" ); exit( 1 ); } printf( "%s\n", username ); return( EXIT_SUCCESS ); }
UNIX
Safety: | |
---|---|
Interrupt handler | No |
Signal handler | No |
Thread | No |
getlogin(), getpwuid(), getuid()