DEC C
Run-Time Library Reference Manual for OpenVMS Systems


Previous Contents Index

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.

exp

Returns the base e raised to the power of the argument.

Format

#include <math.h>

double exp (double x);


ARGUMENT

x

A real value.

DESCRIPTION

If an overflow occurs, the exp function returns the largest possible floating-point value and sets errno to ERANGE. The constant HUGE_VAL is defined in the <math.h> header file to be the largest possible floating-point value.

Return Value

x The base e raised to the power of the argument.
HUGE_VAL Indicates overflow; errno is set to ERANGE.

fabs

Returns the absolute value of a floating-point value.

Format

#include <math.h>

double fabs (double x);


ARGUMENT

x

A real value.

Return Value

x The absolute value of the argument.

fclose

Closes a file by flushing any buffers associated with the file control block and freeing the file control block and buffers previously associated with the file pointer.

Format

#include <stdio.h>

int fclose (FILE *file_ptr);


ARGUMENT

file_ptr

A pointer to the file to be closed.

DESCRIPTION

When a program terminates normally, the fclose function is automatically called for all open files.

The fclose 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 is exceeded, for example), fclose continues executing. It closes the VMS 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 fclose .


Return Values

0 Indicates success.
EOF Indicates that the file control block is not associated with an open file.

fcvt

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 location created by the DEC C RTL.

Format

#include <stdlib.h>

char *fcvt (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 after the decimal point to be used in the converted string.

decpt

The position of the decimal point relative to the first character in the returned string. The returned string does not contain the actual decimal point. A negative int value means that the decimal point is decpt number of spaces to the left of the returned digits (the spaces are 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 fcvt function places a nonzero value at the address specified by sign. Otherwise, the functions assign 0 to the address specified by sign.

DESCRIPTION

This function converts value to a null-terminated string and returns a pointer to it. The resulting low-order digit is rounded to the correct digit for outputting ndigits digits in C F-format. The decpt argument is assigned the position of the decimal point relative to the first character in the string.

In C F-format, ndigits is the number of digits desired after the decimal point. Very large numbers produce a very long string of digits before the decimal point, and ndigit of digits after the decimal point. For large numbers, it is preferable to use the gcvt or ecvt function so that E-format is used.

Repeated calls to the fcvt 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 ecvt in this section.


Return Value

x A pointer to the converted string.

fdopen

Associates a file pointer with a file descriptor returned by an open , creat , dup , dup2 , or pipe function.

Format

#include <stdio.h>

FILE *fdopen (int file_desc, char *a_mode);


ARGUMENTS

file_desc

The file descriptor returned by open , creat , dup , dup2 , or pipe .

a_mode

The access mode indicator. Use one of the following character strings: "r", "w", "a", "r+", "w+", "rb", "r+b", "rb+", "wb", "w+b", "wb+", "ab", "a+b", "ab+", or "a+".

These access modes have the following effects:

The update access modes allow a file to be opened for both reading and writing. When used with existing files, "r+" and "a+" differ only in the initial positioning within the file. The modes are as follows:


DESCRIPTION

This function allows you to access a file, originally opened by one of the UNIX I/O functions, with Standard I/O functions. Ordinarily, a file can be accessed by either a file descriptor or by a file pointer, but not both, depending on the way you open it. For more information, see Chapters 1 and 2.

Return Values

pointer Indicates that the operation has succeeded.
NULL Indicates that an error has occurred.

feof

Tests a file to see if the end-of-file has been reached.

Format

#include <stdio.h>

int feof (FILE *file_ptr);


ARGUMENT

file_ptr

A file pointer.

Return Values

nonzero integer Indicates that the end-of-file has been reached.
0 Indicates that the end-of-file has not been reached.

ferror

Returns a nonzero integer if an error occurred while reading or writing a file.

Format

#include <stdio.h>

int ferror (FILE *file_ptr);


ARGUMENT

file_ptr

A file pointer.

DESCRIPTION

A call to ferror continues to return a nonzero integer until the file is closed or until clearerr is called.

Return Values

0 Indicates success.
nonzero integer Indicates that an error has occurred.

fflush

Writes out any buffered information for the specified file.

Format

#include <stdio.h>

int fflush (FILE *file_ptr);


ARGUMENT

file_ptr

A file pointer. If this argument is a NULL pointer, all buffers associated with all currently open files are flushed.

DESCRIPTION

The output files are normally buffered only if they are not directed to a terminal, except for stderr, which is not buffered by default.

The fflush function flushes the DEC C RTL buffers. However, RMS has its own buffers. The fflush function does not guarantee that the file will be written to disk. (See the description of fsync for a way to flush buffers to disk.)

If the file pointed to by file_ptr was opened in record mode and if there is unwritten data in the buffer, then fflush always generates a record.


Return Values

0 Indicates that the operation is successful.
EOF Indicates that the buffered data cannot be written to the file, or that the file control block is not associated with an output file.

ffs

Finds the index of the first bit set in a string.

Format

#include <strings.h>

int ffs (int iteger);


ARGUMENTS

integer

The integer to be examined for the first bit set.

DESCRIPTION

This function finds the first bit set (beginning with the least significant bit) and returns the index of that bit. Bits are numbered starting at 1 (the least significant bit).

Return Values

x The index of the first bit set.
0 If index is 0.

fgetc

Returns the next character from a specified file.

Format

#include <stdio.h>

int fgetc (FILE *file_ptr);


ARGUMENT

file_ptr

A pointer to the file to be accessed.

DESCRIPTION

See the getc macro in this section.


Return Values

x The returned character.
EOF Indicates the end-of-file or an error.

fgetname

Returns the file specification associated with a file pointer.

Format

#include <stdio.h>

char *fgetname (FILE *file_ptr, char *buffer, ...);

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

file_ptr

A file pointer.

buffer

A pointer to a character string that is large enough to hold the file specification.

...

An optional additional argument that can be either 1 or 0. If you specify 1, the fgetname function returns the file specification in OpenVMS format. If you specify 0, fgetname returns the file specification in UNIX style format. If you do not specify this argument, fgetname returns the file name according to your current command language interpreter. For more information about UNIX style file specifications, see Section 1.4.3.

DESCRIPTION

This function places the file specification at the address given in the buffer. The buffer should be an array large enough to contain a fully qualified file specification (the maximum length is 256 characters).

Return Values

n The address of the buffer.
0 Indicates an error.

RESTRICTION

This function is specific to the DEC C RTL and is not portable.

fgetpos

Stores the current file position for a given file.

Format

#include <stdio.h>

int fgetpos (FILE *stream, fpos_t *pos);


ARGUMENTS

stream

A file pointer.

pos

A pointer to an implementation-defined structure. The fgetpos function fills this structure with information that can be used on subsequent calls to fsetpos .

DESCRIPTION

This function stores the current value of the file position indicator for the stream pointed to by stream into the object pointed to by pos.

Return Values

0 Indicates successful completion.
--1 Indicates that there are errors.

Example


#include <stdio.h> 
 
main() 
{ 
FILE *fp; 
int stat,i; 
int character; 
unsigned char ch, c_ptr[130], d_ptr[130]; 
fpos_t posit; 
 
/* Open a file for writing.  */ 
        
if ((fp = fopen ("file.dat","w+") ) == NULL) 
    { 
     perror ("open"); 
     exit(1); 
    } 
 
/* Get the beginning position in the file.  */ 
        
if (fgetpos(fp, &posit) != 0)    
   perror ("fgetpos"); 
 
/* Write some data to the file. */ 
      
if (fprintf(fp,"this is a test\n") == 0) 
   { 
    perror ("fprintf"); 
    exit(1); 
   } 
 
/* Set the file position back to the beginning. */ 
        
if(fsetpos(fp, &posit) != 0)    
    perror ("fsetpos"); 
 
fgets(c_ptr,130,fp); 
puts(c_ptr);  /* Should be "this is a test."  */ 
 
/* Close the file. */ 
        
if (fclose (fp) != 0) 
    { 
     perror ("close"); 
     exit(1); 
    } 
 
} 


fgets

Reads a line from the specified file, up to one less than the specified maximum number of characters or up to and including the new-line character, whichever comes first. The function stores the string in str.

Format

#include <stdio.h>

char *fgets (char *str, int maxchar, FILE *file_ptr);

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

str

A pointer to a character string that is large enough to hold the information fetched from the file.

maxchar

The maximum number of characters to fetch.

file_ptr

A file pointer.

DESCRIPTION

This function terminates the line with a null character (\0). Unlike gets , fgets places the new-line character that terminates the input line into the user buffer if more than maxchar characters have not already been fetched.

When the file pointed to by file_ptr is opened in record mode, fgets treats the end of a record the same as a new-line character, so it reads up to and including a new-line character or to the end of the record.


Return Values

x Pointer to str.
NULL Indicates the end-of-file or an error. The contents of str are undefined if a read error occurs.

Example


#include <stdio.h> 
#include <stdlib.h> 
 
main() 
{ 
FILE *fp; 
char c_ptr[130]; 
 
   /* Open a file with some data -"THIS IS A TEST."   */ 
     
if ((fp = fopen ("file.dat","r+") ) == NULL) 
     perror ("open error"),exit(1); 
 
fgets(c_ptr,130,fp); 
puts(c_ptr);  /* Display what fgets got.  */ 
fclose(fp); 
} 


fgetwc

Reads the next character from a specified file, and converts it to a wide-character code.

Format

#include <wchar.h>

wint_t fgetwc (FILE *file_ptr);


ARGUMENTS

file_ptr

A pointer to the file to be accessed.

DESCRIPTION

Upon successful completion, the fgetwc function returns the wide-character code read from the file pointed to by file_ptr and converted to type wint_t . If the file is at end-of-file, the end-of-file indicator is set, and WEOF is returned. If an I/O read error occurred, then the error indicator is set, and WEOF is returned.

Applications can use ferror or feof to distinguish between an error condition and an end-of-file condition.


Return Values

x The wide-character code of the character read.
WEOF Indicates the end-of-file or an error. If a read error occurs, the function sets errno to one of the following:
  • EALREADY -- An operation is already in progress on the same file.
  • EBADF -- The file descriptor is not valid.
  • EILSEQ -- Invalid character detected.

fgetws

Reads a line of wide characters from a specified file.

Format

#include <wchar.h>

wchar_t *fgetws (wchar_t *wstr, int maxchar, FILE *file_ptr);

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

wstr

A pointer to a wide-character string large enough to hold the information fetched from the file.

maxchar

The maximum number of wide characters to fetch.

file_ptr

A file pointer.

DESCRIPTION

This function reads wide characters from the specified file and stores them in the array pointed to by wstr. The function reads up to maxchar-1 characters or until the newline character is read, converted, and transferred to wstr, or until an end-of-file condition is encountered. The function terminates the line with a null wide character. fgetws places the newline that terminates the input line into the user buffer, unless maxchar characters have already been fetched.

Return Values

x Pointer to wstr.
NULL Indicates the end-of-file or an error occurred. The contents of wstr are undefined if a read error occurs. If a read error occurs, the function sets errno . For a list of possible errno values, see fgetwc in this section.

Example


#include <stdlib.h> 
#include <stdio.h> 
#include <locale.h> 
#include <wchar.h> 
 
main() 
{ 
    wchar_t wstr[80], *ret; 
    FILE *fp; 
 
    /* Open a test file containing : "THIS IS A TEST." */ 
 
    if ((fp = fopen("file.dat", "r")) == (FILE*) NULL) { 
        perror ("File open error"); 
        exit(EXIT_FAILURE); 
    } 
 
    ret = fgetws(wstr, 80, fp); 
    if (ret == (wchar_t *) NULL) { 
        perror ("fgetws failure"); 
        exit(EXIT_FAILURE); 
    } 
 
    fputws(wstr,stdout); 
 
    fclose(fp); 
} 
 


fileno

Returns the file descriptor associated with the specified file pointer.

Format

#include <stdio.h>

int fileno (FILE *file_ptr);


ARGUMENT

file_ptr

A file pointer.

Return Value

x Integer file descriptor.
--1 Indicates an error.

floor

Returns (as a double ) the largest integer that is less than or equal to its argument.

Format

#include <math.h>

double floor (double x);


ARGUMENT

x

A real value.

fmod

Computes the floating-point remainder of the first argument divided by the second. If the second argument is 0, the function returns 0.

Format

#include <math.h>

double fmod (double x, double y);


ARGUMENTS

x

A real value.

y

A real value.

Return Values

0 Indicates that y is 0.
x The value f, which has the same sign as the argument x, such that x == i * y + f for some integer i, where the magnitude of f is less than the magnitude of y.

fopen

Opens a file by returning the address of a FILE structure.

Format

#include <stdio.h>

FILE *fopen (const char *file_spec, const char *a_mode);

(ANSI C) FILE *fopen (const char *file_spec, const char *a_mode, ...);

(DEC C EXTENSION)


ARGUMENTS

file_spec

A character string containing a valid file specification.

a_mode

The access mode indicator. Use one of the following character strings: "r", "w", "a", "r+", "w+", "rb", "r+b", "rb+", "wb", "w+b", "wb+", "ab", "a+b", "ab+", or "a+".


Previous Next Contents Index