HP C
Run-Time Library Reference Manual for OpenVMS Systems


Previous Contents Index


sigwait (ALPHA, I64)

Suspends a calling thread and waits for queued signals to arrive.

Format

#include <signal.h>

int sigwait (const sigset_t set, int *sig);


Arguments

set

The set of signals to wait for.

sig

Returns the signal number of the selected signal.

Description

The sigwait function suspends the calling thread until at least one of the signals in the set argument is in the caller's set of pending signals. When this happens, one of those signals is automatically selected and removed from the set of pending signals. The signal number identifying that signal is then returned in the location referenced by sig.

The effect is unspecified if any signals in the set argument are not blocked when the sigwait function is called.

The set argument is created using the set manipulation functions sigemptyset , sigfillset , sigaddset , and sigdelset .

If, while the sigwait function is waiting, a signal occurs that is eligible for delivery (that is, not blocked by the signal mask), that signal is handled asynchronously and the wait is interrupted.

See also sigtimedwait and sigwaitinfo .

See Section 4.2 for more information on signal handling.


Return Values

0 Upon successful completion, sigwait stores the signal number of the received signal at the location referenced by sig and returns 0.
nonzero Indicates that an error occurred; errno is set to the following value:
  • EINVAL -- The set argument contains an invalid or unsupported signal number.

sigwaitinfo (ALPHA, I64)

Suspends a calling thread and waits for queued signals to arrive.

Format

#include <signal.h>

int sigwaitinfo (const sigset_t set, siginfo_t *info);


Arguments

set

The set of signals to wait for.

info

Pointer to a siginfo structure that is receiving data describing the signal, including any application-defined data specified when the signal was posted.

Description

The sigwaitinfo function behaves the same as the sigwait function if the info argument is NULL.

If the info argument is non-NULL, the sigwaitinfo function behaves the same as sigwait , except that the selected signal number is stored in the si_signo member of the siginfo structure, and the cause of the signal is stored in the si_code member. If any value is queued to the selected signal, the first such queued value is dequeued and the value is stored in the si_value member of info. The system resource used to queue the signal is released and made available to queue other signals. If no value is queued, the content of the si_value member is undefined. If no further signals are queued for the selected signal, the pending indication for that signal is reset.

See also sigtimedwait and sigwait .

See Section 4.2 for more information on signal handling.


Return Values

x Upon successful completion, the signal number selected is returned.
- 1 Indicates that an error occurred; errno is set to one of the following values:
  • EINVAL -- The set argument contains an invalid or unsupported signal number.
  • EINTR -- The wait was interrupted by an unblocked, caught signal.

sin

Returns the sine of its radian argument.

Format

#include <math.h>

double sin (double x);

float sinf (float x); (ALPHA, I64)

long double sinl (long double x); (ALPHA, I64)

double sind (double x); (ALPHA, I64)

float sindf (float x); (ALPHA, I64)

long double sindl (long double x); (ALPHA, I64)


Argument

x

A radian expressed as a floating-point number.

Description

The sin functions compute the sine of x measured in radians.

The sind functions compute the sine of x measured in degrees.


Return Values

x The sine of the argument.
NaN x = ±Infinity or NaN; errno is set to EDOM.
0 Undeflow occurred; errno is set to ERANGE.

sinh

Returns the hyperbolic sine of its argument.

Format

#include <math.h>

double sinh (double x);

float sinhf (float x); (ALPHA, I64)

long double sinhl (long double x); (ALPHA, I64)


Argument

x

A real number.

Return Values

n The hyperbolic sine of the argument.
HUGE_VAL Overflow occurred; errno is set to ERANGE.
0 Underflow occurred; errno is set to ERANGE.
NaN x is NaN; errno is set to EDOM.

sleep

Suspends the execution of the current process (or thread in a threaded program) for at least the number of seconds indicated by its argument.

Format

#include <unistd.h>

unsigned int sleep (unsigned seconds); (_DECC_V4_SOURCE)

int sleep (unsigned seconds); (NOT _DECC_V4_SOURCE)


Argument

seconds

The number of seconds.

Description

The sleep function sleeps for the specified number of seconds, or until a signal is received, or until the process (or thread in a threaded program) executes a call to SYS$WAKE.

If a SIGALRM signal is generated, but blocked or ignored, the sleep function returns. For all other signals, a blocked or ignored signal does not cause sleep to return.


Return Values

x The number of seconds that the process awoke early.
0 If the process slept the full number of seconds specified by seconds.

snprintf

Performs formatted output to a string in memory.

Format

#include <stdio.h>

int snprintf (char *str, size_t n, const char *format_spec, ...);


Arguments

str

The address of the string that will receive the formatted output.

n

The size of the buffer referred to by str.

format_spec

A pointer to a character string that contains the format specification. For more information about format specifications and conversion characters, see Chapter 2.

...

Optional expressions whose resultant types correspond to conversion specifications given in the format specification.

If no conversion specifications are given, you may omit the output sources. Otherwise, the function calls must have at least as many output sources as there are conversion specifications, and the conversion specifications must match the types of the output sources.

Conversion specifications are matched to output sources in left-to-right order. Excess output pointers, if any, are ignored.


Description

The snprintf function is identical to the sprintf function with the addition of the n argument, which specifies the size of the buffer referred to by str.

On successful completion, snprintf returns the number of bytes (excluding the terminating null byte) that would be written to str if n is sufficiently large.

If n is 0, nothing is written, the number of bytes (excluding the terminating null) that would be written if n were sufficiently large are returned, and str might be a NULL pointer. Otherwise, output bytes beyond the n - 1st are discarded instead of being written to the array, and a null byte is written at the end of the bytes actually written into the array.

If an output error is encountered, a negative value is returned.

For a complete description of the format specification and the output source, see Chapter 2.


Return Values

x The number of bytes (excluding the terminating null byte) that would be written to str if n is sufficiently large.
Negative value Indicates an output error occurred. The function sets errno . For a list of errno values set by this function, see fprintf .

sprintf

Performs formatted output to a string in memory.

Format

#include <stdio.h>

int sprintf (char *str, const char *format_spec, ...);


Arguments

str

The address of the string that will receive the formatted output. It is assumed that this string is large enough to hold the output.

format_spec

A pointer to a character string that contains the format specification. For more information about format specifications and conversion characters, see Chapter 2.

...

Optional expressions whose resultant types correspond to conversion specifications given in the format specification.

If no conversion specifications are given, you may omit the output sources. Otherwise, the function calls must have at least as many output sources as there are conversion specifications, and the conversion specifications must match the types of the output sources.

Conversion specifications are matched to output sources in left-to-right order. Excess output pointers, if any, are ignored.


Description

The sprintf function places output followed by the null character (\0) in consecutive bytes starting at *str. The user must ensure that enough space is available.

Consider the following example of a conversion specification:


#include <stdio.h> 
 
main() 
{ 
   int  temp = 4, temp2 = 17; 
   char s[80]; 
 
   sprintf(s, "The answers are %d, and %d.", temp, temp2); 
} 

In this example, character string s has the following contents:


The answers are 4, and 17. 

For a complete description of the format specification and the output source, see Chapter 2.


Return Values

x The number of characters placed in the output string, not including the final null character.
Negative value Indicates an output error occurred. The function sets errno . For a list of errno values set by this function, see fprintf .

sqrt

Returns the square root of its argument.

Format

#include <math.h>

double sqrt (double x);

float sqrtf (float x); (ALPHA, I64)

long double sqrtl (long double x); (ALPHA, I64)


Argument

x

A real number.

Return Values

val The square root of x, if x is nonnegative.
0 x is negative; errno is set to EDOM.
NaN x is NaN; errno is set to EDOM.

srand

Initializes the pseudorandom-number generator rand .

Format

#include <stdlib.h>

void srand (unsigned int seed);


Argument

seed

An unsigned integer.

Description

The srand function uses the argument as a seed for a new sequence of pseudorandom numbers to be returned by subsequent calls to rand .

If srand is then called with the same seed value, the sequence of pseudorandom numbers is repeated.

If rand is called before any calls to srand , the same sequence of pseudorandom numbers is generated as when srand is first called with a seed value of 1.


srand48

Initializes a 48-bit random-number generator.

Format

#include <stdlib.h>

void srand48 (long int seed_val);


Argument

seed_val

The initialization value to begin randomization. Changing this value changes the randomization pattern.

Description

The srand48 function initializes the random-number generator. You can use this function in your program before calling the drand48 , lrand48 , or mrand48 functions. (Although it is not recommended practice, constant default initializer values are automatically supplied if you call drand48 , lrand48 , or mrand48 without calling an initialization function).

The 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 initializer function srand48 sets the high-order 32 bits of Xi to the low-order 32 bits contained in its argument. The low-order 16 bits of Xi are set to the arbitrary value 330E _16 .

See also drand48 , lrand48 , and mrand48 .


srandom

Initializes the pseudorandom-number generator random .

Format

#include <stdlib.h>

int srandom (unsigned seed);


Argument

seed

An initial seed value.

Description

The srandom function uses the argument as a seed for a new sequence of pseudorandom numbers to be returned by subsequent calls to random . This function has virtually the same calling sequence and initialization properties as the srand function, but produce sequences that are more random.

The srandom function initializes the current state with the initial seed value. The srandom function, unlike the srand function, does not return the old seed because the amount of state information used is more than a single word.

See also rand , srand , random , setstate , and initstate .


Return Values

0 Indicates success. Initializes the state seed.
- 1 Indicates an error, further specified in the global errno .

sscanf

Reads input from a character string in memory, interpreting it according to the format specification.

Format

#include <stdio.h>

int sscanf (const char *str, const char *format_spec, ...);


Arguments

str

The address of the character string that provides the input text to sscanf .

format_spec

A pointer to a character string that contains the format specification. For more information about format specifications and conversion characters, see Chapter 2.

...

Optional expressions whose resultant types correspond to conversion specifications given in the format specification.

If no conversion specifications are given, you can omit the input pointers. Otherwise, the function calls must have at least as many input pointers as there are conversion specifications, and the conversion specifications must match the types of the input pointers.

Conversion specifications are matched to input sources in left-to-right order. Excess input pointers, if any, are ignored.


Description

The following is an example of a conversion specification:


main () 
{ 
   char str[] = "4 17"; 
   int   temp, 
         temp2; 
 
   sscanf(str, "%d %d", &temp, &temp2); 
   printf("The answers are %d and %d.", temp, temp2); 
} 

This example produces the following output:


$ RUN  EXAMPLE
The answers are 4 and 17.

For a complete description of the format specification and the input pointers, see Chapter 2.


Return Values

x The number of successfully matched and assigned input items.
EOF Indicates that a read error occurred before any conversion. The function sets errno . For a list of the values set by this function, see fscanf .

ssignal

Allows you to specify the action to take when a particular signal is raised.

Format

#include <signal.h>

void (*ssignal (int sig, void (*func) (int, ...))) (int, ...);


Arguments

sig

A number or mnemonic associated with a signal. The symbolic constants for signal values are defined in the <signal.h> header file (see Chapter 4).

func

The action to take when the signal is raised, or the address of a function that is executed when the signal is raised.

Description

The ssignal function is equivalent to the signal function except for the return value on error conditions.

Since the signal function is defined by the ANSI C standard and the ssignal function is not, use signal for greater portability.

See Section 4.2 for more information on signal handling.


Return Values

x The address of the function previously established as the action for the signal. The address may be the value SIG_DFL (0) or SIG_IGN (1).
0 Indicates errors. For this reason, there is no way to know whether a return status of 0 indicates failure, or whether it indicates that a previous action was SIG_DFL (0).


Previous Next Contents Index