|
Compaq C
Compaq C Run-Time Library Reference Manual for
OpenVMS Systems
dup, dup2
Allocate a new descriptor that refers to a file specified by a file
descriptor returned by
open
,
creat
, or
pipe
.
Format
#include <unistd.h>
int dup (int file_desc1);
int dup2 (int file_desc1, int file_desc2);
Arguments
file_desc1
The file descriptor being duplicated.
file_desc2
The new file descriptor to be assigned to the file designated by
file_desc1.
Description
The
dup
function causes a previously unallocated descriptor to refer to its
argument, while the
dup2
function causes its second argument to refer to the same file as its
first argument.
The argument file_desc1 is invalid if it does not describe an
open file; file_desc2 is invalid if the new file descriptor
cannot be allocated. If file_desc2 is connected to an open
file, that file is closed.
Return Values
n
|
The new file descriptor.
|
--1
|
Indicates that an invalid argument was passed to the function.
|
[no]echo
Set the terminal so that characters may or may not be echoed on the
terminal screen. This mode of single-character input is only supported
with Curses.
Format
#include <curses.h>
void echo (void);
void noecho (void);
Description
The
noecho
function may be helpful when accepting input from the terminal screen
with
wgetch
and
wgetstr
; it prevents the input characters from being written onto the screen.
ecvt
Converts its argument to a null-terminated string of ASCII digits and
returns the address of the string. The string is stored in a
thread-specific memory location created by the Compaq C RTL.
Format
#include <stdlib.h>
char *ecvt (double value, int ndigits, int
*decpt, int *sign);
Arguments
value
An object of type
double
that is converted to a null-terminated string of ASCII digits.
ndigits
The number of ASCII digits to be used in the converted string.
decpt
The position of the decimal point relative to the first character in
the returned string. A negative
int
value means that the decimal point is decpt number of spaces
to the left of the returned digits, (the spaces being filled with
zeros). A 0 value means that the decimal point is immediately to the
left of the first digit in the returned string.
sign
An integer value that indicates whether the value argument is
positive or negative. If value is negative, the function
places a nonzero value at the address specified by sign.
Otherwise, the function assigns 0 to the address specified by
sign.
Description
This function converts value to a null-terminated string of
length ndigits, and returns a pointer to it. The resulting
low-order digit is rounded to the correct digit for outputting
ndigits digits in C E-format. The decpt argument is
assigned the position of the decimal point relative to the first
character in the string.
Repeated calls to the
ecvt
function overwrite any existing string.
The
ecvt
,
fcvt
, and
gcvt
functions represent the following special values specified in the IEEE
Standard for floating-point arithmetic:
Value |
Representation |
Quiet NaN
|
NaNQ
|
Signalling NaN
|
NaNS
|
+Infinity
|
Infinity
|
--Infinity
|
--Infinity
|
The sign associated with each of these values is stored into the
sign argument. In IEEE floating-point representation, a value
of 0 (zero) can be positive or negative, as set by the sign
argument.
See also
gcvt
and
fcvt
in this section.
Return Value
x
|
The value of the converted string.
|
endpwent
Closes the user database.
Format
#include <stdio.h>
#include <pwd.h>
void endpwent (void);
Description
This function closes the user database. The user database basic user
attributes are accessed with the
getpwent
,
getpwuid
,
getpwnam
, or
setpwent
functions.
See also
getpwent
,
getpwuid
,
getpwnam
, and
setpwent
in this section
endwin
Clears the terminal screen and frees any virtual memory allocated to
Curses data structures.
Format
#include <curses.h>
void endwin (void);
Description
A program that calls Curses functions must call the
endwin
function before exiting to restore the previous environment of the
terminal screen.
erand48
Generate uniformly distributed pseudorandom number sequences. Returns
48-bit nonnegative, double-precision, floating-point values.
Format
#include <stdlib.h>
double erand48 (unsigned short int xsubi[3]);
Argument
xsubi
An array of three
short int
, which form a 48-bit integer when concatentated together.
Description
This function generates pseudorandom numbers using the linear
congruential algorithm and 48-bit integer arithmetic.
It returns nonnegative, double-precision, floating-point values
uniformly distributed over the range of y values, such that, 0.0 <= y
< 1.0.
The
erand48
function works by generating a sequence of 48-bit integer values, Xi,
according to the linear congruential formula:
Xn+1 = (aXn+c)mod m n >= 0
|
The argument m equals 248 , so 48-bit integer
arithmetic is performed. Unless you invoke the
lcong48
function, the multiplier value a and the addend value
c are:
a = 5DEECE66D16 = 2736731631558
c = B16 = 138
|
The
erand48
function requires that the calling program pass an array as the
xsubi argument. For the first call, the array must be
initialized to the value of the pseudorandom number sequence. Unlike the
drand48
function, it is not necessary to call an initialization function prior
to the first call.
By using different arguments, the
erand48
function allows separate modules of a large program to generate several
independent sequences of pseudorandom numbers; for example, the
sequence of numbers that one module generates does not depend upon how
many times the function is called by other modules.
Return Values
n
|
A nonnegative, double-precision, floating-point value.
|
[w]erase
Erase the window by painting it with blanks. The
erase
function acts on the
stdscr
window.
Format
#include <curses.h>
int erase();
int werase (WINDOW *win);
Argument
win
A pointer to the window.
Description
Both the
erase
and
werase
functions leave the cursor at the current position on the terminal
screen after completion; they do not return the cursor to the home
coordinates of (0,0).
Return Values
OK
|
Indicates success.
|
ERR
|
Indicates an error.
|
erf
Returns the error function of its argument.
Format
#include <math.h>
double erf (double x);
float erff (float x); (ALPHA ONLY)
long double erfl (long double x); (ALPHA ONLY)
double erfc (double x); (ALPHA ONLY)
float erfcf (float x); (ALPHA ONLY)
long double erfcl (long double x); (ALPHA ONLY)
Argument
x
A radian expressed as a real number.
Description
The
erf
functions return the error function of x, where
erf
(x),
erff
(x), and
erfl
(x) equal (2/sqrt(pi)) times the area under the curve e**(-t**2)
between 0 and x.
The
erfc
functions return (1.0 - erf(x)). The
erfc
function can result in an underflow as x gets large.
Return Values
x
|
The value of the error function (
erf
) or complementary error function (
erfc
).
|
NaN
|
x is NaN;
errno
is set to EDOM.
|
0
|
Underflow ocurred;
errno
is set to ERANGE.
|
execl
Passes the name of an image to be activated in a child process. This
function is nonreentrant.
Format
#include <unistd.h>
int execl (const char *file_spec, const char *arg0,
..., (char *)0); (ISO POSIX-1)
int execl (char *file_spec, ...); (COMPATABILITY)
Arguments
file_spec
The full file specification of a new image to be activated in the child
process.
arg0, ...
A sequence of pointers to null-terminated character strings.
If the POSIX-1 format is used, at least one argument must be present
and must point to a string that is the same as the new process file
name (or its last component). (This pointer can also be the NULL
pointer, but then
execle
would accomplish nothing.) The last pointer must be the NULL pointer.
This is also the convention if the compatibility format is used.
Description
To understand how the exec functions operate, consider how the OpenVMS
system calls any Compaq C program, as shown in the following
syntax:
int main (int argc, char *argv[], char *envp[]);
|
The identifier argc is the argument count; argv is an
array of argument strings. The first member of the array
(argv[0]) contains the name of the image. The arguments are
placed in subsequent elements of the array. The last element of the
array is always the NULL pointer.
An exec function calls a child process in the same way that the
run-time system calls any other Compaq C program. The exec
functions pass the name of the image to be activated in the child; this
value is placed in argv[0]. However, the functions differ in
the way they pass arguments and environment information to the child:
- Arguments can be passed in separate character strings (
execl
,
execle
, and
execlp
) or in an array of character strings (
execv
,
execve
, and
execvp
).
- The environment can be explicitly passed in an array (
execle
and
execve
) or taken from the parent's environment (
execl
,
execv
,
execlp
, and
execvp
).
If
vfork
was called before invoking an exec function, then when the exec
function completes, control is returned to the parent process at the
point of the
vfork
call. If
vfork
was not called, the exec function waits until the child has completed
execution and then exits the parent process. See
vfork
in this section and Chapter 5 for more information.
Return Value
execle
Passes the name of an image to be activated in a child process. This
function is nonreentrant.
Format
#include <unistd.h>
int execle (char *file_spec, char *arg0, ..., (char
*)0, char *envp[]); (ISO POSIX-1)
int execle (char *file_spec, ...); (COMPATABILITY)
Arguments
file_spec
The full file specification of a new image to be activated in the child
process.
arg0, ...
A sequence of pointers to null-terminated character strings.
If the POSIX-1 format is used, at least one argument must be present
and must point to a string that is the same as the new process file
name (or its last component). (This pointer can also be the NULL
pointer, but then
execle
would accomplish nothing.) The last pointer must be the NULL pointer.
This is also the convention if the compatibility format is used.
envp
An array of strings that specifies the program's environment. Each
string in envp has the following form:
The name can be one of the following names and the value is a
null-terminated string to be associated with the name:
- HOME---Your login directory
- TERM---The type of terminal being used
- PATH---The default device and directory
- USER---The name of the user who initiated the process
The last element in envp must be the NULL pointer.
When the operating system executes the program, it places a copy of the
current environment vector (envp) in the external variable
environ.
Description
See
execl
in this section for a description of how the exec functions operate.
Return Value
execlp
Passes the name of an image to be activated in a child process. This
function is nonreentrant.
Format
#include <unistd.h>
int execlp (const char *file_name, const char *arg0,
..., (char *)0); (ISO POSIX-1)
int execlp (char *file_name, ...); (COMPATABILITY)
Arguments
file_name
The file name of a new image to be activated in the child process. The
device and directory specification for the file is obtained by
searching the environment name VAXC$PATH.
argn
A sequence of pointers to null-terminated character strings. By
convention, at least one argument must be present and must point to a
string that is the same as the new process file name (or its last
component).
...
A sequence of pointers to strings. At least one pointer must exist to
terminate the list. This pointer must be the NULL pointer.
Description
See
execl
in this section for a description of how the exec functions operate.
Return Value
execv
Passes the name of an image to be activated in a child process. This
function is nonreentrant.
Format
#include <unistd.h>
int execv (char *file_spec, char *argv[]);
Arguments
file_spec
The full file specification of a new image to be activated in the child
process.
argv
An array of pointers to null-terminated character strings. These
strings constitute the argument list available to the new process. By
convention, argv[0] must point to a string that is the same as
the new process file name (or its last component). argv is
terminated by a NULL pointer.
Description
See
execl
in this section for a description of how the exec functions operate.
Return Value
execve
Passes the name of an image to be activated in a child process. This
function is nonreentrant.
Format
#include <unistd.h>
int execve (const char *file_spec, char *argv[], char
*envp[]);
Arguments
file_spec
The full file specification of a new image to be activated in the child
process.
argv
An array of pointers to null-terminated character strings. These
strings constitute the argument list available to the new process. By
convention, argv[0] must point to a string that is the same as
the new process file name (or its last component). argv is
terminated by a NULL pointer.
envp
An array of strings that specifies the program's environment. Each
string in envp has the following form:
The name can be one of the following names and the value is a
null-terminated string to be associated with the name:
- HOME---Your login directory
- TERM---The type of terminal being used
- PATH---The default device and directory
- USER---The name of the user who initiated the process
The last element in envp must be the NULL pointer.
When the operating system executes the program, it places a copy of the
current environment vector (envp) in the external variable
environ
.
Description
See
execl
in this section for a description of how the exec functions operate.
Return Value
execvp
Passes the name of an image to be activated in a child process. This
function is nonreentrant.
Format
#include <unistd.h>
int execvp (const char *file_name, char *argv[]);
Arguments
file_name
The file name of a new image to be activated in the child process. The
device and directory specification for the file is obtained by
searching the environment name VAXC$PATH.
argv
An array of pointers to null-terminated character strings. These
strings constitute the argument list available to the new process. By
convention, argv[0] must point to a string that is the same as
the new process file name (or its last component). argv is
terminated by a NULL pointer.
Description
See
execl
in this section for a description of how the exec functions operate.
Return Value
exit, _exit
Terminate execution of the program from which they are called. These
functions are nonreentrant.
Format
#include <stdlib.h>
void exit (int status);
#include <unistd.h>
void _exit (int status);
Argument
status
A status value of EXIT_SUCCESS (0), EXIT_FAILURE (1), or a number from
2 to 255:
- A status value of 0 or EXIT_SUCCESS is translated to the OpenVMS
SS$_NORMAL status code to return the OpenVMS success value.
- A status value of 1 or EXIT_FAILURE is translated to an error-level
exit status. The status value is passed to the parent process.
- Any other status value is left the same.
To use these status values as described, include
<unistd.h>
and compile with the
_POSIX_EXIT
feature-test macro set (either with /DEFINE=_POSIX_EXIT or with
#define _POSIX_EXIT
at the top of your file, before any file inclusions). This behavior is
available only on OpenVMS Version 7.0 and higher systems.
Description
If the process was invoked by the DIGITAL Command Language (DCL), the
status is interpreted by DCL and a message is displayed.
If the process was a child process created using
vfork
or an exec function, then the child process exits and control returns
to the parent. The two functions are identical; the
_exit
function is retained for reasons of compatibility with VAX C.
The
exit
and
_exit
functions make use of the $EXIT system service. If your process is
being invoked by the RUN command using any of the hibernation and
scheduled wakeup qualifiers, the process might not correctly return to
hibernation state when an
exit
or
_exit
call is made.
Note
EXIT_SUCCESS and EXIT_FAILURE are portable across any ANSI C compiler
to indicate success or failure. On OpenVMS systems, they are mapped to
OpenVMS condition codes with the severity set to success or failure,
respectively. Values in the range of 2 to 255 can be used by a child
process to communicate a small amount of data to the parent. The parent
retreives this data using the
wait
,
wait3
,
wait4
, or
waitpid
functions.
|
|
|
|