United States    
COMPAQ
Compaq C

Compaq C
Run-Time Library Reference Manual for OpenVMS Systems


Previous Contents Index


geteuid

Returns, in OpenVMS terms, the member number from the user identification code (UIC). For example, if the UIC is [313,031], 031 is the member number.

Format

#include <unistd.h>

uid_t geteuid (void);


Description

In Compaq C for OpenVMS Systems, getuid and geteuid perform the same function.

For programs compiled with the _VMS_V6_SOURCE feature-test macro or programs that do not include the <unistd.h> header file, the getuid and geteuid functions return the member number of the OpenVMS UIC. For example, if the UIC is [313,31], then the member number, 31, is returned.

For programs compiled without the _VMS_V6_SOURCE feature-test macro that do include the <unistd.h> header file, the full UIC is returned. For example, if the UIC is [313, 31] then 20512799 (31 + 313 * 65536) is returned.

See the getegid or getgid functions in this section for the functions that return the group number.

Note (ALPHA ONLY)

On OpenVMS Alpha systems, this function has been enhanced to take advantage of the new OpenVMS support for POSIX-style user, group, and session IDs available on a version of OpenVMS Alpha after Version 7.3.

The new functionality, based on PERSONA VMS services, is the default on those versions of OpenVMS Alpha where the underlying operating system support is available.

To request the old behavior, define the DECC$GETJPI_BASED_UID logical name to "ENABLE":


$ DEFINE DECC$GETJPI_BASED_UID ENABLE 


Return Value

x The member number from the current UIC.

getgid

Returns, in OpenVMS terms, the group number from the user identification code (UIC). For example, if the UIC is [313,031], 313 is the group number.

Format

#include <unistd.h>

gid_t getgid (void);


Description

In Compaq C for OpenVMS Systems, the getgid and getegid functions both return the group number from the current UIC. Similarly, getuid and geteuid both return the member number from the current UIC.

Note (ALPHA ONLY)

On OpenVMS Alpha systems, this function has been enhanced to take advantage of the new OpenVMS support for POSIX-style user, group, and session IDs available on a version of OpenVMS Alpha after Version 7.3.

The new functionality, based on PERSONA VMS services, is the default on those versions of OpenVMS Alpha where the underlying operating system support is available.

To request the old behavior, define the DECC$GETJPI_BASED_UID logical name to "ENABLE":


$ DEFINE DECC$GETJPI_BASED_UID ENABLE 


Return Value

x The group number from the current UIC.

getitimer

Returns the value of interval timers.

Format

#include <time.h>

int getitimer (int which, struct itimerval *value);


Arguments

which

The type of interval timer. The Compaq C RTL supports only ITIMER_REAL.

value

Pointer to an itimerval structure whose members specify a timer interval and the time left to the end of the interval.

Description

This function returns the current value for the timer specified by the which argument in the structure pointed to by value .

A timer value is defined by the itimerval structure:


       struct itimerval { 
               struct  timeval it_interval; 
               struct  timeval it_value; 
       }; 

The following table lists the values for the itimerval structure members:
itimerval Member Value Meaning
it_interval = 0 Disables a timer after its next expiration Assumes it_value is nonzero.
it_interval = nonzero Specifies a value used in reloading it_value when the timer expires.
it_value = 0 Disables a timer.
it_value = nonzero Indicates the time to the next timer expiration.

Time values smaller than the resolution of the system clock are rounded up to this resolution.

The Compaq C RTL provides each process with one interval timer, defined in the <time.h> header file as ITIMER_REAL. This timer decrements in real time and delivers a SIGALRM signal when the timer expires.


Return Values

0 Indicates success.
--1 Indicates an error; errno is set to EINVAL (The value argument specified a time that was too large to handle.)

getlogin

Gets the login name.

Format

#include <unistd.h>

char *getlogin (void);


Description

The getlogin function returns the login name of the user associated with the current session.

Return Values

x A pointer to a null-terminated string in a static buffer.
NULL Indicates an error. Login name is not set.

getname

Returns the file specification associated with a file descriptor.

Format

#include <unixio.h>

char *getname (int file_desc, char *buffer, ...);

Function Variants This function also has variants named _getname32 and _getname64 for use with 32-bit and 64-bit pointer sizes, respectively. See Section 1.8 for more information on using pointer-size-specific functions.

Arguments

file_desc

A file descriptor.

buffer

A pointer to a character string that is large enough to hold the file specification.

...

An optional argument that can be either 1 or 0. If you specify 1, the getname function returns the file specification in OpenVMS format. If you specify 0, the getname function returns the file specification in UNIX style format. If you do not specify this argument, the getname function returns the file name according to your current command-language interpreter (CLI). For more information about UNIX style file specifications, see Section 1.4.3.

Description

This function places the file specification into the area pointed to by buffer and returns that address. The area pointed to by buffer should be an array large enough to contain a fully qualified file specification (the maximum length is 256 characters).

Return Values

x The address passed in the buffer argument.
0 Indicates an error.

getopt

A command-line parser that can be used by applications that follow Unix command-line conventions.

Format

#include <unistd.h> (X/OPEN, POSIX-1)

#include <stdio.h> (X/OPEN, POSIX-2)

int getopt (int argc, char * const argv[], const char *optstring);

extern char *optarg;

extern int optind, opterr, optopt;


Arguments

argc

The argument count as passed to main .

argv

The argument array as passed to main .

optstring

A string of recognized option characters. If a character is followed by a colon, the option takes an argument.

Description

The variable optind is the index of the next element of the argv vector to be processed. It is initialized to 1 by the system, and it is updated by getopt when it finishes with each element of argv. When an element of argv contains multiple option characters, it is unspecified how getopt determines which options have already been processed.

The getopt function returns the next option character (if one is found) from argv that matches a character in optstring, if there is one that matches. If the option takes an argument, getopt sets the variable optarg to point to the option-argument as follows:

If one of the following is true, getopt returns --1 without changing optind :

argv[ optind ] is a NULL pointer
*argv[ optind ] is not the character --
argv[ optind ] points to the string "--"

If argv[ optind ] points to the string "-- --" getopt returns --1 after incrementing optind .

If getopt encounters an option character not contained in optstring, the question-mark character (?) is returned.

If getopt detects a missing argument, the colon character (:) is returned if the first character of optstring is a colon; otherwise a question-mark character is returned.

In either of the previous two cases, getopt sets the variable optopt to the option character that caused the error. If the application has not set the variable opterr to 0 and the first character of optstring is not a colon, getopt also prints a diagnostic message to stderr.


Return Values

x The next option character specified on the command line.

A colon is returned if getopt detects a missing argument and the first character of optstring is a colon.

A question mark is returned if getopt encounters an option character not in optstring or detects a missing argument and the first character of optstring is not a colon.

--1 When all command-line options are parsed.

Example

The following example shows how you might process the arguments for a utility that can take the mutually exclusive options a and b and the options f and o, both of which require arguments:


#include <unistd.h> 
 
int main (int argc, char *argv[ ]) 
{ 
         int c; 
         int bflg, aflg, errflg; 
         char *ifile; 
         char *ofile; 
         extern char *optarg; 
         extern int optind, optopt; 
         . 
         . 
         . 
         while ((c = getopt(argc, argv, ":abf:o:)) != -1) {    
 
                switch (c) { 
                case 'a': 
                        if (bflg)  
                                errflg++; 
                        else  
                                aflg++; 
                        break; 
                case 'b': 
                        if (aflg)  
                               errflg++; 
                        else { 
                               bflg++; 
                               bproc(); 
                        }           
 
                        break; 
                case 'f': 
                        ifile = optarg; 
                        break; 
                case 'o': 
                        ofile = optarg; 
                        break; 
                case ':':      /* -f or -o without operand */ 
                        fprintf (stderr, 
                                "Option -%c requires an operand\n"' optopt); 
                        errflg++; 
                        break; 
                case '?': 
                        fprintf (stderr, 
                                "Unrecognized option -%c\n"' optopt); 
                        errflg++; 
                }   
         }               
         if (errflg) { 
                fprintf (stderr, "usage: ..."); 
                exit(2); 
         } 
         for ( ; optind < argc; optind++)  { 
                if (access(argv[optind], R_OK)) { 
         . 
         . 
         . 
} 

This sample code accepts any of the following as equivalent:


cmd -ao arg path path 
cmd -a -o arg path path 
cmd -o arg -a path path 
cmd -a -o arg -- path path 
cmd -a -oarg path path 
cmd -aoarg path path 


getpagesize

Gets the system page size.

Format

#include <unistd.h>

int getpagesize (void);


Description

This function returns the number of bytes in a page. The system page size is useful for specifying arguments to memory management system calls.

The page size is a system page size and is not necessarily the same as the underlying hardware page size.


Return Values

x Always indicates success. Returns the number of bytes in a page.

getpid

Returns the process ID of the current process.

Format

#include <unistd.h>

pid_t getpid (void);


Return Value

x The process ID of the current process.

getppid

Returns the parent process ID of the calling process.

Format

#include <unistd.h>

pid_t getppid (void);


Return Values

x The parent process ID.
0 Indicates that the calling process does not have a parent process.

getpwnam

Accesses user-name information in the user database.

Format

#include <pwd.h>

struct passwd *getpwnam (const char name);


Arguments

name

The name of the user for which the attributes are to be read.

Description

This function returns the first user entry in the database with the pw_name member of the passwd structure that matches the name argument.

The passwd structure is defined in the <pwd.h> header file as follows:
pw_name The user's login name.
pw_uid The numerical user ID.
pw_gid The numerical group ID.
pw_dir The home directory of the user.
pw_shell The initial program for the user.

Note

All information generated by the getpwnam function is stored in a static area and is overwritten on subsequent calls to the function.

Return Values

x A pointer to a valid password structure.
NULL An error occurred. errno is set to indicate the error.

getpwuid

Accesses user-ID information in the rights database.

Format

#include <pwd.h>

struct passwd *getpwuid (uid_t uid);


Arguments

uid

The ID of the user for which the attributes are to be read.

Description

This function accesses the identifier names of all identifiers in the rights database. It returns the first user entry in the rights database with a pw_uid member of the passwd structure that matches the uid argument.

The passwd structure is defined in the <pwd.h> header file as follows:
pw_name The user's login name.
pw_uid The numerical user ID.
pw_gid The numerical group ID.
pw_dir The home directory of the user.
pw_shell The initial program for the user.

To check for error situations, applications should set errno to zero before calling getpwuid . If errno is non-zero on return, then an error occurred.

Note

All information generated by the getpwuid function is stored in a per-thread static area and is overwritten on subsequent calls to the function.

Return Values

x A pointer to a valid password structure.
NULL An error occurred. errno is set to indicate the error.

gets

Reads a line from the standard input (stdin).

Format

#include <stdio.h>

char *gets (char *str);

Function Variants This function also has variants named _gets32 and _gets64 for use with 32-bit and 64-bit pointer sizes, respectively. See Section 1.8 for more information on using pointer-size-specific functions.

Argument

str

A pointer to a character string that is large enough to hold the information fetched from stdin.

Description

The new-line character (\n) that ends the line is replaced by the function with an ASCII null character (\0).

When stdin is opened in record mode, gets treats the end of a record the same as a new-line character and, therefore, reads up to and including a new-line character or to the end of the record.


Return Values

x A pointer to the str argument.
NULL Indicates that an error has occurred or that the end-of-file was encountered before a new-line character was encountered. The contents of str are undefined if a read error occurs.


Previous Next Contents Index
  

1.800.AT.COMPAQ

privacy and legal statement