DEC C
Run-Time Library Reference Manual for OpenVMS Systems


Previous Contents Index

The elements of grouping and mon_grouping are interpreted as follows:
Value Interpretation
CHAR_MAX No further grouping is performed.
0 The previous element is to be used repeatedly for the remainder of the digits.
other The integer value is the number of digits that comprise the current group. The next element is examined to determine the size of the next group of digits before the current group.

The values of p_sign_posn and n_sign_posn are interpreted as follows:
Value Interpretation
0 Parentheses surround the number and currency symbol.
1 The sign string precedes the number and currency symbol.
2 The sign string succeeds the number and currency symbol.
3 The sign string immediately precedes the number and currency symbol.
4 The sign string immediately succeeds the number and currency symbol.


Return Value

x Pointer to the lconv structure.

Example


#include <stdlib.h> 
#include <stdio.h> 
#include <limits.h> 
#include <locale.h> 
#include <string.h>                                        
 
/* The following test program will set up the British English locale,    */ 
/* and then extract the International Currency symbol and the            */ 
/* International Fractional Digits fields for this locale and print them */ 
 
 
int main() 
{ 
    /*                                                                    */ 
    /* Declare variables                                                  */ 
    /*                                                                    */ 
    char  *return_val; 
    struct lconv *lconv_ptr; 
 
    
    /*                                                                    */ 
    /* Load a locale                                                      */ 
    /*                                                                    */ 
    return_val = (char *)setlocale(LC_ALL,"en_GB.iso8859-1"); 
 
    /*                                                                    */ 
    /* Did the locale load successfully?                                  */ 
    /*                                                                    */ 
    if (return_val == NULL) 
    { 
        /*                                                                */ 
        /* It failed to load the locale                                   */ 
        /*                                                                */ 
        printf("ERROR : The locale is unknown"); 
        exit(EXIT_FAILURE); 
    } 
 
    /*                                                                    */ 
    /*  Get the lconv structure from the locale                           */ 
    /*                                                                    */ 
    lconv_ptr = (struct lconv *)localeconv(); 
 
    /*                                                                    */ 
    /* Compare the international currency symbol string with an empty     */ 
    /* string. If they are equal then the international currency          */ 
    /* symbol is not defined in the locale.                               */ 
    /*                                                                    */ 
 
    if(strcmp (lconv_ptr -> int_curr_symbol,"")) 
    { 
        printf("International Currency Symbol = %s\n", 
                                            lconv_ptr -> int_curr_symbol); 
    } 
    else 
    { 
        printf("International Currency Symbol ="); 
        printf("[Not available in this locale]\n"); 
    } 
 
    /*                                                                    */ 
    /* Compare International Fractional Digits with CHAR_MAX. If they     */ 
    /* are equal then International Fractional Digits are not defined in  */ 
    /* this locale.                                                       */ 
    /*                                                                    */ 
    if ((unsigned char)(lconv_ptr -> int_frac_digits) != CHAR_MAX) 
    { 
        printf("International Fractional Digits = %d\n", 
         lconv_ptr -> int_frac_digits); 
    } 
    else 
    { 
        printf("International Fractional Digits ="); 
        printf("[Not available in this locale]\n"); 
    } 
} 

Running the example program produces the following result:


International Currency Symbol = GBP 
International Fractional Digits = 2 


localtime

Converts a time value to broken-down local time.

Format

#include <time.h>

struct tm *localtime (const time_t *bintim);

Function Variants Compiling with the _DECC_V4_SOURCE and _VMS_V6_SOURCE feature-test macros defined enables a local-time-based entry point to this function that is equivalent to the behavior before OpenVMS Version 7.0.

ARGUMENT

bintim

A pointer to a time in seconds since the Epoch. You can generate this time by using the time function or you can supply a time.

DESCRIPTION

This function converts the time (in seconds since the Epoch) pointed to by timer into a broken-down time, expressed as a local time.

The function corrects for the time zone and any seasonal time adjustments. Local time-zone information is used as if localtime called tzset .

The converted time value is placed in a time structure defined in the <time.h> header file with the tag tm . Table REF-4 describes the member names that are offsets into the structure.

Table REF-4 Member Names
int tm_sec ; Seconds after the minute (0-60)
int tm_min ; Minutes after the hour (0-59)
int tm_hour ; Hours since midnight (0-23)
int tm_mday ; Day of the month (1-31)
int tm_mon ; Months since January (1-11)
int tm_year ; Years since 1900
int tm_wday ; Days since Sunday (0-6)
int tm_yday ; Days since January 1 (0-365)
int tm_isdst ; Daylight Savings Time flag
  • tm_isdst = 0 for Standard Time
  • tm_isdst = 1 for Daylight Time
long tm_gmtoff ;1 Seconds east of Greenwich (Negative values indicate seconds west of Greenwich)
char * tm_zone ;1 Time zone string, for example "GMT"


1This field is an extention to the ANSI C tm structure. It is present unless you compile your program with /STANDARD=ANSI89 or with _DECC_V4_SOURCE defined.

Note

Return values point to per-thread static storage, which is overwritten by subsequent calls to the localtime function. You must make a copy if you wish to save it.

The type time_t is defined in the <time.h> header file as follows:


typedef long int time_t 


Return Value

pointer A pointer to the time structure.

log, log10

Return the logarithm of their arguments.

Format

#include <math.h>

double log (double x);

double log10 (double x);


ARGUMENT

x

A real number of type double .

DESCRIPTION

The log function performs a natural (base e) logarithm.

The log10 functions performs a base 10 logarithm.


Return Values

x The logarithm of the argument (in the appropriate base).
--HUGE_VAL Indicates that the argument is 0 or negative; errno is set to ERANGE.

longjmp

Provides a way to transfer control from a nested series of function invocations back to a predefined point without returning normally; that is, by not using a series of return statements. The longjmp function restores the context of the environment buffer.

Format

#include <setjmp.h>

void longjmp (jmp_buf env, int value);


ARGUMENTS

env

The environment buffer, which must be an array of integers long enough to hold the register context of the calling function. The type jmp_buf is defined in the <setjmp.h> header file. The contents of the general-purpose registers, including the program counter (PC), are stored in the buffer.

value

Passed from longjmp to setjmp , and then becomes the subsequent return value of the setjmp call. If value is passed as 0, it is converted to 1.

DESCRIPTION

When setjmp is first called, it returns the value 0. If longjmp is then called, naming the same environment as the call to setjmp , control is returned to the setjmp call as if it had returned normally a second time. The return value of setjmp in this second return is the value you supply in the longjmp call. To preserve the true value of setjmp , the function calling setjmp must not be called again until the associated longjmp is called.

The setjmp function preserves the hardware general purpose registers, and the longjmp function restores them. After a longjmp , all variables have their values as of the time of the longjmp except for local automatic variables not marked volatile . These variables have indeterminate values.

The setjmp and longjmp functions rely on the OpenVMS condition-handling facility to effect a nonlocal goto with a signal handler. The longjmp function is implemented by generating a DEC C RTL specified signal and allowing the OpenVMS condition-handling facility to unwind back to the desired destination. The DEC C RTL must be in control of signal handling for any DEC C image.

For DEC C to be in control of signal handling, you must establish all exception handlers through a call to the vaxc$establish function (rather than LIB$ESTABLISH). See Section 4.2.5 and the vaxc$establish function in this section for more information.


RESTRICTIONS

You cannot invoke the longjmp function from a OpenVMS condition handler. However, you may invoke longjmp from a signal handler that has been established for any signal supported by the DEC C RTL, subject to the following nesting restrictions:

longname

Returns the full name of the terminal.

Format

#include <curses.h>

void longname (char *termbuf, char *name);

Function Variants This function also has variants named _longname32 and _longname64 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

termbuf

A string containing the name of the terminal.

name

A character-string buffer with a minimum length of 64 characters.

DESCRIPTION

The terminal name is in a readable format so that you can double-check to be sure that Curses has correctly identified your terminal. The dummy argument termbuf is required for UNIX software compatibility and serves no function in the OpenVMS environment. If portability is a concern, you must write a set of dummy routines to perform the functionality provided by the database termcap in the UNIX system environment.

lrand48

Generates uniformly distributed pseudorandom number sequences. Returns 48-bit signed long integers.

Format

#include <stdlib.h>

long int lrand48 (void);


DESCRIPTION

This function generates pseudorandom numbers using the linear congruential algorithm and 48-bit integer arithmetic.

It returns nonnegative, long integers uniformly distributed over the range of y values such that 0 <= y < 2^31 .

Before you call the lrand48 function use either srand48 , seed48 , or lcong48 to initialize the random number generator. You must initialize prior to invoking the lrand48 function, because it stores the last 48-bit Xi generated into an internal buffer. (Although it is not recommended, constant default initializer values are supplied automatically if the drand48 , lrand48 , or mrand48 functions are called without first 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 2^48 , 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 value returned by the lrand48 function is computed by first generating the next 48-bit Xi in the sequence. Then the appropriate bits, according to the type of data item to be returned, are copied from the high-order (most significant) bits of Xi and transformed into the returned value.

See also drand48 , lcong48 , mrand48 , seed48 , and srand48 in this section.


Return Values

n Signed nonnegative long integers uniformly distributed over the range 0 <= y < 2^ 31 .

lseek

Positions a file to an arbitrary byte position and returns the new position as an int .

Format

#include <unistd.h>

off_t lseek (int file_desc, off_t offset, int direction);


ARGUMENTS

file_desc

An integer returned by open , creat , dup , or dup2 .

offset

The offset, specified in bytes.

direction

An integer indicating whether the offset is to be measured forward from the beginning of the file (direction=SEEK_SET), forward from the current position (direction=SEEK_CUR), or backward from the end of the file (direction=SEEK_END).

DESCRIPTION

This function can position fixed-length record-access file with no carriage control or a stream-access file on any byte offset, but can position all other files only on record boundaries.

The available Standard I/O functions position a record file at its first byte, at the end-of-file, or on a record boundary. Therefore, the arguments given to lseek must specify either the beginning or end of the file, a 0 offset from the current position (an arbitrary record boundary), or the position returned by a previous, valid lseek call.

For a portable way to position an arbitrary byte location with any type of file, see the fgetpos and fsetpos functions in this section.

CAUTION

If, while accessing a stream file, you seek beyond the end-of-file and then write to the file, the lseek function creates a hole by filling the skipped bytes with zeros.

In general, for record files, lseek should only be directed to an absolute position that was returned by a previous valid call to lseek or to the beginning or end of a file. If a call to lseek does not satisfy these conditions, the results are unpredictable.

See also open , creat , dup , dup2 , and fseek in this section.


Return Values

x The new file position.
--1 Indicates that the file descriptor is undefined, or a seek was attempted before the beginning of the file.

lwait

Waits for I/O on a specific file to complete.

Format

#include <stdio.h>

int lwait (int fd);


ARGUMENT

fd

A file descriptor corresponding to an open file.

DESCRIPTION

This function is used primarily to wait for completion of pending asynchronous I/O.

Return Values

0 Indicates successful completion.
--1 Indicates an error.

malloc

Allocates an area of memory. These functions are AST-reentrant.

Format

#include <stdlib.h>

void *malloc (size_t size);

Function Variants This function also has variants named _malloc32 and _malloc64 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

size

The total number of bytes to be allocated.

DESCRIPTION

This function allocates a contiguous area of memory whose size, in bytes, is supplied as an argument. The space is not initialized.

Return Values

x The address of the first byte, which is aligned on a quadword boundary.
NULL Indicates that the function is unable to allocate enough memory. errno is set to ENOMEM.

mblen

Determines the number of bytes comprising a multibyte character.

Format

#include <stdlib.h>

int mblen (const char *s, size_t n);


ARGUMENTS

s

A pointer to the multibyte character.

n

The maximum number of bytes that comprise the multibyte character.

DESCRIPTION

If the character is n bytes or less, this function returns the number of bytes comprising the multibyte character pointed to by s. If the character is greater than n bytes, the function returns --1 to indicate an error.

This function is affected by the LC_CTYPE category of the program's current locale.


Return Values

x The number of bytes that comprise the multibyte character, if the next n or fewer bytes form a valid character.
0 If s is NULL or a pointer to the NULL character.
--1 Indicates an error occurred. The function sets errno to EILSEQ -- Invalid character detected.

mbrlen

Determines the number of bytes comprising a multibyte character.

Format

#include <wchar.h>

size_t mbrlen (const char *s, size_t n, mbstate_t *ps);


ARGUMENTS

s

A pointer to a multibyte character.

n

The maximum number of bytes that comprise the multibyte character.

ps

A pointer to the mbstate_t object. If a NULL pointer is specified, the function uses its internal mbstate_t object.

DESCRIPTION

The mbrlen function is equivalent to the call:


    mbrtowc(NULL, s, n, ps != NULL ? ps : &internal) 

Where internal is the mbstate_t object for the mbrlen function.

If the multibyte character pointed to by s is of n bytes or less, the function returns the number of bytes comprising the character (including any shift sequences).

If either an encoding error occurs or the next n bytes contribute to an incomplete but potentially valid multibyte character, the function returns --1 or --2, respectively.

See also mbrtowc in this section.


Return Values

x The number of bytes comprising the multibyte character.
0 Indicates that s is a NULL pointer or a pointer to a null byte.
--1 Indicates an encoding error, in which case the next n or fewer bytes do not contribute to a complete and valid multibyte character. errno is set to EILSEQ; the conversion state is undefined.
--2 Indicates an incomplete but potentially valid multibyte character (all n bytes have been processed).

mbrtowc

Converts a multibyte character to its wide-character representation.

Format

#include <wchar.h>

size_t mbrtowc (wchar_t *pwc, const char *s, size_t n, mbstate_t *ps);


ARGUMENTS

pwc

A pointer to the resulting wide-character code.

s

A pointer to a multibyte character.

n

The maximum number of bytes that comprise the multibyte character.

ps

A pointer to the mbstate_t object. If a NULL pointer is specified, the function uses its internal mbstate_t object.

DESCRIPTION

If s is a NULL pointer, mbrtowc is equivalent to the call:


Previous Next Contents Index