Chapter Contents

Previous

Next
getuid

getuid



Determine Real User ID

Portability: POSIX.1 conforming, UNIX compatible


SYNOPSIS
DESCRIPTION
RETURN VALUE
EXAMPLE
RELATED FUNCTIONS


SYNOPSIS

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

uid_t getuid(void);


DESCRIPTION

getuid determines the real user ID of the calling process.


RETURN VALUE

If successful, getuid returns the real user ID of the calling process. Under unusual conditions (for instance, if USS is not running) getuid can fail. In this case, getuid issues an OS/390 user ABEND 1230 to indicate the error.


EXAMPLE

The following code fragment illustrates the use of getuid to determine the real user ID of a calling process. The user ID is then passed to the getpwuid function to obtain a pointer to the user's passwd structure.

#include <sys/types.h>
#include <pwd.h>
#include <unistd.h>
#include <stdio.h>


.
.
.
struct passwd *p;
uid_t uid;
 if ((p = getpwuid(uid = getuid())) == NULL)
    perror("getpwuid() error");
 else
 {
    printf("getpwuid returned the following name and directory for
      your user ID\n", (int) uid);
    printf("pw_name : %s\n", p->  pw_name);
    printf("pw_dir  : %d\n", p->  pw_dir);
}

.
.
.


RELATED FUNCTIONS

geteuid , getgid , setuid


Chapter Contents

Previous

Next

Top of Page

Copyright © 2001 by SAS Institute Inc., Cary, NC, USA. All rights reserved.