HP C
Run-Time Library Reference Manual for OpenVMS Systems


Previous Contents Index


clock_getres (ALPHA, I64)

Gets the resolution for the specified clock.

Format

#include <time.h>

int clock_getres (clockid_t clock_id, struct timespec *res);


Arguments

clock_id

The clock type used to obtain the resolution. The CLOCK_REALTIME clock is supported and represents the TIME-OF-DAY clock for the system.

res

A pointer to the timespec data structure that receives the value of the clock's resolution.

Description

The clock_getres function obtains the resolution value for the specified clock. Clock resolutions are implementation-dependent and cannot be set by a process.

If the res argument is not NULL, the resolution of the specified clock is stored in the location pointed to by res.

If res is NULL, the clock resolution is not stored.

If the time argument (tp) of clock_settime is not a multiple of res, then the value is truncated to a multiple of res.

On success, the function returns 0.

On failure, the function returns - 1 and sets errno to indicate the error.

See also clock_gettime , clock_settime , time , and ctime .


Return Values

0 Indicates success.
- 1 Indicates failure; errno is set to the following value:
  • EINVAL -- The clock_id argument does not specify a known clock.

clock_gettime (ALPHA, I64)

Returns the current time (in seconds and nanoseconds) for the specified clock.

Format

#include <time.h>

int clock_gettime (clockid_t clock_id, struct timespec *tp);


Arguments

clock_id

The clock type used to obtain the time for the clock that is set. The CLOCK_REALTIME clock is supported and represents the TIME-OF-DAY clock for the system.

tp

A pointer to a timespec data structure.

Description

The clock_gettime function returns the current tp value for the specified clock, clock_id.

On success, the function returns 0.

On failure, the function returns - 1 and sets errno to indicate the error.

See also clock_getres , clock_settime , time , and ctime .


Return Values

0 Indicates success.
- 1 Indicates failure; errno is set to the following value:
  • EINVAL -- The clock_id argument does not specify a known clock, or the tp argument specifies a nanosecond value less than 0 or greater than or equal to 1 billion.

clock_settime (ALPHA, I64)

Sets the specified clock.

Format

#include <time.h>

int clock_settime (clockid_t clock_id, const struct timespec *tp);


Arguments

clock_id

The clock type used for the clock that is to be set. The CLOCK_REALTIME clock is supported and represents the TIME-OF-DAY clock for the system.

tp

A pointer to a timespec data structure.

Description

The clock_settime function sets the specified clock, clock_id, to the value specified by tp. Time values that are between two consecutive non-negative integer multiples of the resolution of the specified clock are truncated down to the smaller multiple of the resolution.

A clock can be systemwide (that is, visible to all processes) or per-process (measuring time that is meaningful only within a process).

The CLOCK_REALTIME clock, defined in <time.h> , represents the realtime clock for the system. For this clock, the values specified by clock_settime and returned by clock_gettime represent the amount of time elapsed, in seconds and nanoseconds, since the Epoch. The Epoch is defined as 00:00:00:00 January 1, 1970 Greenwich Mean Time (GMT).

You must have OPER, LOG_IO, and SYSPRV privileges to use the clock_settime function.

On success, the function returns 0.

On failure, the function returns - 1 and sets errno to indicate the error.

See also clock_getres , clock_gettime , time , and ctime .


Return Values

0 Indicates success.
- 1 Indicates failure; errno is set to the following value:
  • EINVAL -- The clock_id argument does not specify a known clock, or the tp argument is outside the range for the given clock_id or specifies a nanosecond value less than 0 or greater than or equal to 1 billion.
  • EPERM -- The requesting process does not have the appropriate privilege to set the specified clock.

close

Closes the file associated with a file descriptor.

Format

#include <unistd.h>

int close (int file_desc);


Argument

file_desc

A file descriptor.

Description

The close function tries to write buffered data by using an implicit call to fflush . If the write fails (because the disk is full or the user's quota was exceeded, for example), close continues executing. It closes the OpenVMS channel, deallocates any buffers, and releases the memory associated with the file descriptor (or FILE pointer). Any buffered data is lost, and the file descriptor (or FILE pointer) no longer refers to the file.

If your program needs to recover from errors when flushing buffered data, it should make an explicit call to fsync (or fflush ) before calling close .


Return Values

0 Indicates that the file is properly closed.
- 1 Indicates that the file descriptor is undefined or an error occurred while the file was being closed (for example, if the buffered data cannot be written out).

Example


 
#include <unistd.h> 
 
int fd; 
   .
   .
   .
fd = open ("student.dat", 1); 
   .
   .
   .
close(fd); 


closedir

Closes directories.

Format

#include <dirent.h>

int closedir (DIR *dir_pointer);


Argument

dir_pointer

Pointer to the dir structure of an open directory.

Description

The closedir function closes a directory stream and frees the structure associated with the dir_pointer argument. Upon return, the value of dir_pointer does not necessarily point to an accessible object of the type DIR .

The type DIR , which is defined in the <dirent.h> header file, represents a directory stream that is an ordered sequence of all the directory entries in a particular directory. Directory entries represent files. You can remove files from or add files to a directory asynchronously to the operation of the readdir function.

Note

An open directory must always be closed with the closedir function to ensure that the next attempt to open the directory is successful.

Example

The following example shows how to search a directory for the entry name, using the opendir , readdir , and closedir functions:


#include <dirent.h> 
#include <stdio.h> 
#include <stdlib.h> 
#include <string.h> 
 
#define FOUND     1 
#define NOT_FOUND 0 
 
static int dir_example(const char *name, unsigned int unix_style) 
{ 
    DIR *dir_pointer; 
    struct dirent *dp; 
 
    if ( unix_style ) 
        dir_pointer = opendir("."); 
    else 
        dir_pointer = opendir(getenv("PATH")); 
 
    if ( !dir_pointer ) { 
        perror("opendir"); 
        return NOT_FOUND; 
    } 
 
    /* Note, that if opendir() was called with UNIX style file  */ 
    /* spec like ".", readdir() will return only a single       */ 
    /* version of each file in the directory. In this case the  */ 
    /* name returned in d_name member of the dirent structure   */ 
    /* will contain only file name and file extension fields,   */ 
    /* both lowercased like "foo.bar".                          */ 
   
    /* If opendir() was called with OpenVMS style file spec,    */ 
    /* readdir() will return every version of each file in the  */ 
    /* directory. In this case the name returned in d_name      */ 
    /* member of the dirent structure will contain file name,   */ 
    /* file extension and file version fields. All in upper     */ 
    /* case, like "FOO.BAR;1".                                  */ 
 
    for ( dp = readdir(dir_pointer); 
          dp && strcmp(dp->d_name, name); 
          dp = readdir(dir_pointer) ) 
        ; 
 
    closedir(dir_pointer); 
 
    if ( dp != NULL ) 
        return FOUND; 
    else 
        return NOT_FOUND; 
} 
 
int main(void) 
{ 
   char *filename = "foo.bar"; 
   FILE *fp; 
 
   remove(filename); 
 
   if ( !(fp = fopen(filename, "w")) ) { 
        perror("fopen"); 
        return (EXIT_FAILURE); 
   } 
 
   if ( dir_example( "FOO.BAR;1", 0 ) == FOUND ) 
        puts("OpenVMS style: found"); 
   else 
        puts("OpenVMS style: not found"); 
 
   if ( dir_example( "foo.bar", 1 ) == FOUND ) 
        puts("UNIX style: found"); 
   else 
        puts("UNIX style: not found"); 
 
   fclose(fp); 
   remove(filename); 
   return( EXIT_SUCCESS ); 
} 


Return Values

0 Indicates success.
- 1 Indicates an error and is further specified in the global errno .

[w]clrattr

Deactivate the video display attribute attr within the window. The clrattr function acts on the stdscr window.

Format

#include <curses.h>

int clrattr (int attr);

int wclrattr (WINDOW *win, int attr);


Arguments

win

A pointer to the window.

attr

Video display attributes that can be blinking, boldface, reverse video, and underlining; they are represented by the defined constants _BLINK, _BOLD, _REVERSE, and _UNDERLINE. To clear multiple attributes, separate them with a bitwise OR operator (|) as follows:


clrattr(_BLINK | _UNDERLINE); 


Description

These functions are specific to HP C for OpenVMS Systems and are not portable.

Return Values

OK Indicates success.
ERR Indicates an error.

[w]clrtobot

Erase the contents of the window from the current position of the cursor to the bottom of the window. The clrtobot function acts on the stdscr window.

Format

#include <curses.h>

int clrtobot();

int wclrtobot (WINDOW *win);


Argument

win

A pointer to the window.

Return Values

OK Indicates success.
ERR Indicates an error.

[w]clrtoeol

Erase the contents of the window from the current cursor position to the end of the line on the specified window. The clrtoeol function acts on the stdscr window.

Format

#include <curses.h>

int clrtoeol();

int wclrtoeol (WINDOW *win);


Argument

win

A pointer to the window.

Return Values

OK Indicates success.
ERR Indicates an error.

confstr

Determines the current value of a specified system variable defined by a string value.

Format

#include <unistd.h>

size_t confstr (int name, char *buf, size_t len);


Arguments

name

The system variable setting. Valid values for the name argument are the _CS_X names defined in the <unistd.h> header file.

buf

Pointer to the buffer where the confstr function copies the name value.

len

The size of the buffer storing the name value.

Description

The confstr function allows an application to determine the current setting of certain system parameters, limits, or options that are defined by a string value. The function is mainly used by applications to find the system default value for the PATH environment variable.

If the following conditions are true, then the confstr function copies that value into a len-byte buffer pointed to by buf:

If the returned string is longer than len bytes, including the terminating null, then the confstr function truncates the string to len - 1 bytes and adds a terminating null to the result. The application can detect that the string was truncated by comparing the value returned by the confstr function with the value of the len argument.

The <limits.h> header file contains system-defined limits. The <unistd.h> header file contains system-defined environmental variables.


Example

To find out how big a buffer is needed to store the string value of name, enter:


 confstr(_CS_PATH, NULL, (size_t) 0) 

The confstr function returns the size of the buffer necessary.


Return Values

0 Indicates an error. When the specified name value:
  • Is invalid, errno is set to EINVAL.
  • Does not have a system-defined value, errno is not set.
n The size of the buffer needed to hold the value.
  • When the value of the name argument is system-defined, confstr returns the size of the buffer needed to hold the entire value. If this return value is greater than the len value, the string returned as the buf value is truncated.
  • When the value of the len argument is set to 0 or the buf value is NULL, confstr returns the size of the buffer needed to hold the entire system-defined value. The string value is not copied.

copysign (ALPHA, I64)

Returns x with the same sign as y.

Format

#include <math.h>

double copysign (double x, double y);

float copysignf (float x, float y); (ALPHA, I64)

long double copysignl (long double x, long double y); (ALPHA, I64)


Arguments

x

A real value.

y

A real value.

Description

The copysign functions return x with the same sign as y. IEEE 754 requires copysign (x,NaN), copysignf (x,NaN), and copysignl (x,NaN) to return +x or - x.

Return Value

x The value of x with the same sign as y.

cos

Returns the cosine of its radian argument.

Format

#include <math.h>

double cos (double x);

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

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

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

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

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


Argument

x

A radian expressed as a real value.

Description

The cos functions return the cosine of their argument, measured in radians.

The cosd functions return the cosine of their argument, measured in degrees.

|x| = Infinity is an invalid argument.


Return Values

x The cosine of the argument.
HUGE_VAL Indicates that the argument is too large; errno is set to ERANGE.

cosh

Returns the hyperbolic cosine of its radian argument.

Format

#include <math.h>

double cosh (double x);

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

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


Argument

x

A radian expressed as a real number.

Description

The cosh functions return the hyperbolic cosine of x and are defined as (e**x + e**( - x))/2.

Return Values

x The hyperbolic cosine of the argument.
HUGE_VAL Indicates that the argument is too large; errno is set to ERANGE.

cot

Returns the cotangent of its radian argument.

Format

#include <math.h>

double cot (double x);

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

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

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

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

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


Argument

x

A radian expressed as a real number.

Description

The cot functions return the cotangent of their argument, measured in radians.

The cotd functions return the cotangent of their argument, measured in degrees.

x = 0 is an invalid argument.


Return Values

x The cotangent of the argument.
HUGE_VAL Indicates that the argument is zero; errno is set to ERANGE.


Previous Next Contents Index