gtpc2m6dC/C++ Language Support User's Guide

seteuid-Set the Effective User ID

This function sets the effective user ID (UID) to uid.

Format

#include <unistd.h>
int seteuid(uid_t uid);

uid
The user ID numeric value used in setting the effective user ID.

Normal Return

If successful, the seteuid function returns an integer value of 0 and the effective user ID is set to uid. The real UID and the saved set UID are not changed.

Error Return

If unsuccessful, the seteuid function returns -1 and sets errno to one of the following:

EINVAL
The value specified for uid is not supported.

EPERM
The process does not have the appropriate privileges or uid does not match the real UID or the saved set UID.

Programming Considerations

Examples

The following example provides information for the effective user ID of the caller and sets its effective UID.

#include <unistd.h>
#include <stdio.h>
 
int main(void) {
 
  printf("Your effective user id is %d\n", (int) geteuid() );
  if ( seteuid ( 25 ) != 0 )
      perror ( "seteuid() error" );
  else
       printf("Your effective user id was changed to %d\n",
                              (int) geteuid() );
  return 0;
}

The seteuid function returns 0.

Related Information