gtpc2m6b | C/C++ Language Support User's Guide |
This function sets the effective group ID (GID) of the calling function's process to gid.
Format
#include <unistd.h> int setegid(uid_t gid);
Normal Return
If successful, the setegid function returns an integer value of 0.
Error Return
If unsuccessful, the setegid function returns -1 and sets errno to one of the following:
Programming Considerations
This function sets the effective GID of the calling function's process to gid if gid is equal to the real GID or saved set GID of the calling process, or if the process has appropriate privileges.
The appropriate privileges are if the calling program has the key 0 option set on in the PAT or having the effective UID 0 (root). Otherwise, the real GID and the saved set GID are not changed.
Examples
The following example provides information for the effective group ID (GID) of the caller and sets its effective GID:
#include <unistd.h> #include <stdio.h> int main(void) { printf("Your effective group id is %d\n", (int) getegid() ); if ( setegid ( 100 ) != 0 ) perror ( "setegid() error" ); else printf("Your effective group id was changed to %d\n", (int) setegid() ); return 0; }
Related Information