DEC C
Run-Time Library Reference Manual for OpenVMS Systems


Previous Contents Index

In line-buffered I/O, characters are buffered in an area of memory until a new-line character is seen, at which point the appropriate RMS routine is called to transmit the entire buffer. Line buffering is more efficient than unbuffered I/O since it reduces the system overhead, but it delays the availability of the data to the user or disk on output.

In fully buffered I/O, characters are buffered in an area of memory until the buffer is full, regardless of the presence of break characters. Full buffering is more efficient than line buffering or unbuffered I/O, but it delays the availability of output data even longer than line buffering.

Use the values _IONBF, _IOLBF, and _IOFBF defined in <stdio.h> for the type argument to specify unbuffered, line-buffered, and fully buffered I/O, respectively.

If _IONBF is specified for type, I/O will be unbuffered and the buffer and size arguments are ignored.

If _IOLBF or _IOFBF is specified for type, the DEC C RTL will use line-buffered I/O if file_ptr specifies a terminal device; otherwise, it will use fully buffered I/O.

The DEC C RTL automatically allocates a buffer to use for each I/O stream. So there are several buffer allocation possibilities:

User programs must not depend on the contents of buffer once I/O has been performed on the stream. The DEC C RTL might or might not use buffer for any given I/O operation.

Generally, it is unnecessary to use setvbuf or setbuf to control the buffer size used by the DEC C RTL. The automatically allocated buffer sizes are chosen for efficiency based on the kind of I/O operations performed and the device characteristics (such as terminal, disk, or socket).

The setvbuf and setbuf functions are useful to introduce buffering for improved performance when writing a large amount of text to the stdout stream. This stream is unbuffered by default when bound to a terminal device (the normal case), and therefore incurs a large number of OpenVMS buffered I/O operations unless DEC C RTL buffering is introduced by a call to setvbuf or setbuf .

The setvbuf function is used only to control the buffering used by the DEC C RTL, not the buffering used by the underlying RMS I/O operations. You can modify RMS default buffering behavior by specifying various values for the ctx, fop, rat, gbc, mbc, mbf, rfm, and rop RMS keywords when the file is opened by the creat , freopen or open functions.


Return Values

0 Indicates success.
nonzero value Indicates that an invalid input value was specifed for type or file_ptr, or because file_ptr is being used by another thread (see Section 1.7.1).

sigaction

Specifies the action to take upon delivery of a signal.

Format

#include <signal.h>

int sigaction (int sig, const struct sigaction *action, struct sigaction *o_action);


ARGUMENTS

sig

The signal for which the action is to be taken.

action

A pointer to a sigaction structure that describes the action to take when you receive the signal specified by the sig argument.

o_action

A pointer to a sigaction structure. When the sigaction function returns from a call, the action previously attached to the specified signal is stored in this structure.

DESCRIPTION

When a process requests the sigaction function, the process can both examine and specify what action to perform when the specified signal is delivered. The arguments determine the behavior of the sigaction function as follows:

The sigaction structure consists of the following members:


  void        (*sa_handler)(int); 
  sigset_t    sa_mask; 
  int         sa_flags; 

The sigaction structure members are defined as follows:
sa_handler This member can contain the following values:
  • SIG_DFL -- Specifies the default action taken when the signal is delivered.
  • SIG_IGN -- Specifies that the signal has no effect on the receiving process.
  • Function pointer -- Requests to catch the signal. The signal causes the function call.
sa_mask This member can request that individual signals, in addition to those in the process signal mask, are blocked from delivery while the signal handler function specified by the sa_handler member is executing.
sa_flags This member can set the flags to enable further control over the actions taken when a signal is delivered.

The sa_flags member of the sigaction structure has the following values:
SA_ONSTACK Setting this bit causes the system to run the signal catching function on the signal stack specified by the sigstack function. If this bit is not set, the function runs on the stack of the process where the signal is delivered.
SA_RESETHAND Setting this bit resets the signal to SIG_DFL. Be aware that you cannot automatically reset SIGILL and SIGTRAP.
SA_NODEFER Setting this bit does not automatically block the signal as it is caught.
SA_NOCLDSTOP If this bit is set and the sig argument is equal to SIGCHLD and a child process of the calling process stops, then a SIGCHLD signal is sent to the calling process only if SA_NOCLDSTOP is not set for SIGCHLD.

When a signal is caught by a signal-catching function installed by sigaction , a new signal mask is calculated and installed for the duration of the signal-catching function (or until a call to either sigprocmask or sigsuspend is made. This mask is formed by taking the union of the current signal mask and the value of the sa_mask for the signal being delivered unless SA_NODEFER or SA_RESETHAND is set, and then including the signal being delivered. If and when the user's signal handler returns normally, the original signal mask is restored.

Once an action is installed for a specific signal, it remains installed until another action is explicitly requested (by another call to sigaction ), until the SA_RESETHAND flag causes resetting of the handler, or until one of the exec functions is called.

If the previous action for a specified signal had been established by signal , the values of the fields returned in the structure pointed to by the o_action argument of sigaction are unspecified, and in particular o_action->sa_handler is not necessarily the same value passed to signal . However, if a pointer to the same structure or a copy thereof is passed to a subsequent call to sigaction by means of the action argument of sigaction ), the signal is handled as if the original call to signal were repeated.

If sigaction fails, no new signal handler is installed.

It is unspecified whether an attempt to set the action for a signal that cannot be caught or ignored to SIG_DFL is ignored or causes an error to be returned with errno set to EINVAL.

See Section 4.2 for more information on signal handling.

Note

The sigvec and signal functions are provided for compatibility to old UNIX systems; their function is a subset of that available with the sigaction function.

See also sigstack , sigvec , signal , wait , read , and write , in this section.


Return Values

0 Indicates success.
--1 Indicates an error; A new signal handler is not installed. errno is set to one of the following values:
  • EFAULT -- The action or o_action argument points to a location outside of the allocated address space of the process.
  • EINVAL -- The sig argument is not a valid signal number. Or an attempt was made to ignore or supply a handler for the SIGKILL, SIGSTOP, and SIGCONT signals.

sigaddset

Adds the specified individual signal.

Format

#include <signal.h>

int sigaddset (sigset_t *set, int sig_number);


ARGUMENTS

set

The signal set.

sig_number

The individual signal.

DESCRIPTION

This function manipulates sets of signals. This function operates on data objects that you can address by the application, not on any set of signals known to the system. For example, this function does not operate on the set blocked from delivery to a process or the set pending for a process.

The sigaddset function adds the individual signal specified by sig_number from the signal set specified by set.


Example

The following example shows how to generate and use a signal mask that blocks only the SIGINT signal from delivery.


       #include <signal.h> 
       int return_value; 
       sigset_t newset; 
         . . . 
       sigemptyset(&newset); 
       sigaddset(&newset, SIGINT); 
       return_value = sigprocmask (SIG_SETMASK, &newset, NULL); 


Return Values

0 Indicates success.
--1 Indicates an error; errno is set to one of the following values:
  • EINVAL -- The value of sig_number is not a valid signal number.

sigblock

Adds the signals in mask to the current set of signals being blocked from delivery.

Format

#include <signal.h>

int sigblock (int mask);


ARGUMENT

mask

The signals to be blocked.

DESCRIPTION

Signal i is blocked if the i -- 1 bit in mask is a 1. For example, to add the protection-violation signal to the set of blocked signals, use the following line:


sigblock(1 << (SIGBUS - 1)); 

You can express signals in mnemonics (such as SIGBUS for a protection violation) or numbers as defined in the <signal.h> header file, and you can express combinations of signals by using the bitwise OR operator (|).


Return Value

x Indicates the previous set of masked signals.

sigdelset

Deletes a specified individual signal.

Format

#include <signal.h>

int sigdelset (sigset_t *set, int sig_number;)


ARGUMENTS

set

The signal set.

sig_number

The individual signal.

DESCRIPTION

The sigdelset function deletes the individual signal specified by sig_number from the signal set specified by set.

This function operates on data objects that you can address by the application, not on any set of signals known to the system. For example, this function does not operate on the set blocked from delivery to a process or the set pending for a process.


Return Values

0 Indicates success.
--1 Indicates an error; errno is set to one of the following values:
  • EINVAL -- The value of sig_number is not a valid signal number.

sigemptyset

Initializes the signal set to exclude all signals.

Format

#include <signal.h>

int sigemptyset (sigset_t *set);


ARGUMENTS

set

The signal set.

DESCRIPTION

The sigemptyset function initializes the signal set pointed to by set such that you exclude all signals. A call to sigemptyset or sigfillset must be made at least once for each object of type sigset_t prior to any other use of that object.

This function operates on data objects that you can address by the application, not on any set of signals known to the system. For example, this function does not operate on the set blocked from delivery to a process or the set pending for a process.

See also sigfillset in this section.


Example

The following example shows how to generate and use a signal mask that blocks only the SIGINT signal from delivery.


       #include <signal.h> 
       int return_value; 
       sigset_t newset; 
         . . . 
       sigemptyset(&newset); 
       sigaddset(&newset, SIGINT); 
       return_value = sigprocmask (SIG_SETMASK, &newset, NULL); 


Return Values

0 Indicates success.
--1 Indicates an error; the global errno is set to indicate the error.

sigfillset

Initializes the signal set to include all signals.

Format

#include <signal.h>

int sigfillset (sigset_t *set);


ARGUMENTS

set

The signal set.

DESCRIPTION

The sigfillset function initializes the signal set pointed to by set such that you include all signals. A call to sigemptyset or sigfillset must be made at least once for each object of type sigset_t prior to any other use of that object.

This function operates on data objects that you can address by the application, not on any set of signals known to the system. For example, this function does not operate on the set blocked from delivery to a process or the set pending for a process.

See also sigemptyset in this section.


Return Values

0 Indicates success.
--1 Indicates an error; errno is set to one of the following values:
  • EINVAL -- The value of the sig_number argument is not a valid signal number.

sigismember

Tests whether a specified signal is a member of the signal set.

Format

#include <signal.h>

int sigismember (const sigset_t *set, int sig_number);


ARGUMENTS

set

The signal set.

sig_number

The individual signal.

DESCRIPTION

The sigismember function tests whether sig_number is a member of the signal set pointed to by set.

This function operates on data objects that you can address by the application, not on any set of signals known to the system. For example, this function does not operate on the set blocked from delivery to a process or the set pending for a process.


Return Values

1 Indicates success. The specified signal is a member of the specified set.
0 Indicates an error. The specified signal is not a member of the specified set.

siglongjmp

Nonlocal goto with signal handling.

Format

#include <setjmp.h>

void siglongjmp (sigjmp_buf env, int value);


ARGUMENTS

env

An address for a sigjmp_buf structure.

value

A nonzero value.

DESCRIPTION

This function restores the environment saved by the most recent call to sigsetjmp in the same process with the corresponding sigjmp_buf argument.

All accessible objects have values when siglongjmp is called, with one exception: values of objects of automatic storage duration that changed between the sigsetjmp call and siglongjmp call are indeterminate.

Because it bypasses the usual function call and return mechanisms, siglongjmp executes correctly during interrupts, signals, and any of their associated functions. However, if you invoke siglongjmp from a nested signal handler (for example, from a function invoked as a result of a signal raised during the handling of another signal), the behavior is undefined.

The siglongjmp function restores the saved signal mask only if you initialize the env argument by a call to sigsetjmp with a nonzero savemask argument.

After siglongjmp is completed, program execution continues as if the corresponding call of sigsetjmp just returned the value specified by value. The siglongjmp function cannot cause sigsetjmp to return 0 (zero); if value is 0, sigsetjmp returns 1

See also sigsetjmp in this section.


sigmask

Constructs the mask for a given signal number.

Format

#include <signal.h>

int sigmask (signum);


ARGUMENT

signum

The signal number for which the mask is to be constructed.

DESCRIPTION

This function is used to contruct the mask for a given signum. This mask can be used with the sigblock function.


Return Value

x The mask constructed for signum

signal

Allows you to specify the way in which the signal sig is to be handled: use the default handling for the signal, ignore the signal, or call the signal handler at the address specified.

Format

#include <signal.h>

void (*signal (int sig, void (*func) (int))) (int);


ARGUMENTS

sig

The number or mnemonic associated with a signal. This argument is usually one of the mnemonics defined in the <signal.h> header file.

func

Either the action to take when the signal is raised, or the address of a function needed to handle the signal.

DESCRIPTION

If func is the constant SIG_DFL, the action for the given signal is reset to the default action, which is to terminate the receiving process. If the argument is SIG_IGN, the signal is ignored. Not all signals can be ignored.

If func is neither SIG_DFL nor SIG_IGN, it specifies the address of a signal-handling function. When the signal is raised, the addressed function is called with sig as its argument. When the addressed function returns, the interrupted process continues at the point of interruption. (This is called catching a signal. Signals are reset to SIG_DFL after they are caught, except as shown in Chapter 4.)

You must call the signal function each time you want to catch a signal.

See Section 4.2 for more information on signal handling.

To cause a OpenVMS exception or a signal to generate a UNIX style signal, user OpenVMS condition handlers must return SS$_RESIGNAL upon receiving any exception that they do not want to handle. Returning SS$_CONTINUE prevents the correct generation of a UNIX style signal. See Chapter 4 for a list of OpenVMS exceptions that correspond to UNIX signals.


Return Values

x The address of the function previously established to handle the signal.
SIG_ERR Indicates that the sig argument is out of range.

sigpause

Assigns mask to the current set of masked signals and then waits for a signal.

Format

#include <signal.h>

int sigpause (int mask);


ARGUMENT

mask

The signals to be blocked.

DESCRIPTION

See the sigblock function in this section for information about the mask argument.

When control returns to sigpause , the function restores the previous set of masked signals, sets errno to EINTR, and returns --1 to indicate an interrupt. The value EINTR is defined in the <errno.h> header file.


Return Value

--1 Indicates an interrupt. errno is set to EINTR.

sigpending

Examines pending signals.

Format

#include <signal.h>

int sigpending (sigset_t *set);


ARGUMENTS

set

A pointer to a sigset_t structure.

DESCRIPTION

This function stores the set of signals that are blocked from delivery and pending to the calling process in the location pointed to by the set argument.


Previous Next Contents Index