[an error occurred while processing this directive]
HP OpenVMS SystemsC Programming Language |
HP C
|
Previous | Contents | Index |
Opens a file by returning the address of a FILE structure.
#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, ...); (HP C EXTENSION)
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+".These access modes have the following effects:
- "r" opens an existing file for reading.
- "w" creates a new file, if necessary, and opens the file for writing. If the file exists, it creates a new file with the same name and a higher version number.
- "a" opens the file for append access. An existing file is positioned at the end-of-file, and data is written there. If the file does not exist, the HP C RTL creates it.
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:
- "r+" opens an existing file for read update access. It is opened for reading, positioned first at the beginning-of-file, but writing is also allowed.
- "w+" opens a new file for write update access.
- "a+" opens a file for append update access. The file is first positioned at the end-of-file (writing). If the file does not exist, the HP C RTL creates it.
- "b" means binary access mode. In this case, no conversion of carriage-control information is attempted.
...
Optional file attribute arguments. The file attribute arguments are the same as those used in the creat function. For more information, see the creat function.
If a version of the file exists, a new file created with fopen inherits certain attributes from the existing file unless those attributes are specified in the fopen call. The following attributes are inherited:Record format
Maximum record size
Carriage control
File protectionIf you specify a directory in the file name and it is a search list that contains an error, HP C for OpenVMS Systems interprets it as a file open error.
The file control block can be freed with the fclose function, or by default on normal program termination.
x File pointer. NULL Indicates an error. The constant NULL is defined in the <stdio.h> header file to be the NULL pointer value. The function returns NULL to signal the following errors:
- File protection violations
- Attempts to open a nonexistent file for read access
- Failure to open the specified file
Determines the class of IEEE floating-point values.
#include <math.h>int fp_class (double x);
int fp_classf (float x);
int fp_classl (long double x);
x
An IEEE floating-point number.
The fp_class functions determine the class of the specified IEEE floating-point number, returning a constant from the <fp_class.h> header file. They never cause an exception, even for signaling NaNs (Not-a-Number). These functions implement the recommended class(x) function in the appendix of the IEEE 754-1985 standard for binary floating-point arithmetic. The constants in <fp_class.h> refer to the following classes of values:
FP_SNAN Signaling NaN (Not-a-Number) FP_QNAN Quiet NaN FP_POS_INF +Infinity FP_NEG_INF - Infinity FP_POS_NORM positive normalized FP_NEG_NORM negative normalized FP_POS_DENORM positive denormalized FP_NEG_DENORM negative denormalized FP_POS_ZERO +0.0 (positive zero) FP_NEG_ZERO - 0.0 (negative zero)
x A constant from the <fp_class.h> header file.
Retrieves file implementation characteristics.
#include <unistd.h>long int fpathconf (int filedes, int name);
filedes
An open file descriptor.name
The configuration attribute to query. If this attribute is not applicable to the file specified by the filesdes argument, fpathconf returns an error.
The fpathconf function allows an application to retrieve the characteristics of operations supported by the file system underlying the file named by the filesdes argument. Read, write, or execute permission of the named file is not required, but you must be able to search all directories in the path leading to the file.Symbolic values for the name argument are defined in the <unistd.h> header file as follows:
_PC_LINK_MAX The maximum number of links to the file. If the filedes argument refers to a directory, the value returned applies to the directory itself. _PC_MAX_CANON The maximum number of bytes in a canonical input line. This is applicable only to terminal devices. _PC_MAX_INPUT The number of types allowed in an input queue. This is applicable only to terminal devices. _PC_NAME_MAX Maximum number of bytes in a file name (not including a terminating null). The byte range value is between 13 and 255. This is applicable only to a directory file. The value returned applies to filenames within the directory. _PC_PATH_MAX Maximum number of bytes in a pathname (not including a terminating null). The value is never larger than 65,535. This is applicable only to a directory file. The value returned is the maximum length of a relative pathname when the specified directory is the working directory. _PC_PIPE_BUF Maximum number of bytes guaranteed to be written atomically. This is applicable only to a FIFO. The value returned applies to the referenced object. If the path argument refers to a directory, the value returned applies to any FIFO that exists or can be created within the directory. _PC_CHOWN_RESTRICTED The value returned applies to any files (other than directories) that exist or can be created within the directory. This is applicable only to a directory file. _PC_NO_TRUNC Returns 1 if supplying a component name longer than allowed by NAME_MAX causes an error. Returns 0 (zero) if long component names are truncated. This is applicable only to a directory file. _PC_VDISABLE This is always 0 (zero); no disabling character is defined. This is applicable only to a terminal device.
x The resultant value for the configuration attribute specified in the name argument. - 1 Indicates an error; errno is set to one of the following values:
- EINVAL -- The name argument specifies an unknown or inapplicable characteristic.
- EBADF -- the filedes argument is not a valid file descriptor.
Performs formatted output to a specified file.
#include <stdio.h>int fprintf (FILE *file_ptr, const char *format_spec, ...);
file_ptr
A pointer to the file to which the output is directed.format_spec
A pointer to a character string that contains the format specification. For more information on 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, the output sources can be omitted. Otherwise, the function calls must have exactly 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. Any excess output sources are ignored.
An example of a conversion specification follows:
#include <stdio.h> main() { int temp = 4, temp2 = 17; fprintf(stdout, "The answers are %d, and %d.", temp, temp2); }This example outputs the following to the stdout file:
The answers are 4, and 17.For a complete description of the format specification and the output source, see Chapter 2.
x The number of bytes written, excluding the null terminator. Negative value Indicates an error. The function sets errno to one of the following:
- EILSEQ -- Invalid character detected.
- EINVAL -- Insufficient arguments.
- ENOMEM -- Not enough memory available for conversion.
- ERANGE -- Floating-point calculations overflow.
- EVMSERR -- Nontranslatable OpenVMS error. vaxc$errno contains the OpenVMS error code. This might indicate that conversion to a numeric value failed because of overflow.
The function can also set errno to the following as a result of errors returned from the I/O subsystem:
- EBADF -- The file descriptor is not valid.
- EIO -- I/O error.
- ENOSPC -- No free space on the device containing the file.
- ENXIO -- Device does not exist.
- EPIPE -- Broken pipe.
- ESPIPE -- Illegal seek in a file opened for append.
- EVMSERR -- Nontranslatable OpenVMS error. vaxc$errno contains the OpenVMS error code. This indicates that an I/O error occurred for which there is no equivalent C error code.
Writes a character to a specified file.
#include <stdio.h>int fputc (int character, FILE *file_ptr);
character
An object of type int .file_ptr
A file pointer.
The fputc function writes a single character to the specified file and returns the character.See also the fputc_unlocked function and the putc macro.
x The character written to the file. Indicates success. EOF Indicates an output error.
Same as the fputc function, except used only within a scope protected by flockfile and funlockfile .
#include <stdio.h>int fputc_unlocked (int character, FILE *file_ptr);
character
The character to be written. An object of type int .file_ptr
A file pointer.
See the putc_unlocked macro.See also flockfile , ftrylockfile , and funlockfile .
n The returned character. EOF Indicates the end-of-file or an error.
Writes a character string to a file without copying the string's null terminator (\0).
#include <stdio.h>int fputs (const char *str, FILE *file_ptr);
str
A pointer to a character string.file_ptr
A file pointer.
Unlike puts , the fputs function does not append a new-line character to the output string.See also puts .
Nonnegative value Indicates success. EOF Indicates an error.
Converts a wide character to its corresponding multibyte value, and writes the result to a specified file.
#include <wchar.h>wint_t fputwc (wint_t wc, FILE *file_ptr);
wc
An object of type wint_t .file_ptr
A file pointer.
The fputwc function writes a wide character to a file and returns the character.See also putwc .
x The character written to the file. Indicates success. WEOF Indicates an output error. The function sets errno to the following:
- EILSEQ -- Invalid wide-character code detected.
The function can also set errno to the following as a result of errors returned from the I/O subsystem:
- EBADF -- The file descriptor is not valid.
- EIO -- I/O error.
- ENOSPC -- No free space on the device containing the file.
- ENXIO -- Device does not exist.
- EPIPE -- Broken pipe.
- ESPIPE -- Illegal seek in a file opened for append.
- EVMSERR -- Nontranslatable OpenVMS error. vaxc$errno contains the OpenVMS error code. This indicates that an I/O error occurred for which there is no equivalent C error code.
Writes a wide-character string to a file without copying the null-terminating character.
#include <wchar.h>int fputws (const wchar_t *wstr, FILE *file_ptr);
wstr
A pointer to a wide-character string.file_ptr
A file pointer.
The fputws function converts the specified wide-character string to a multibyte character string and writes it to the specified file. The function does not append a terminating null byte corresponding to the null wide-character to the output string.
Nonnegative value Indicates success. - 1 Indicates an error. The function sets errno . For a list of the values, see fputwc .
Reads a specified number of items from the file.
#include <stdio.h>size_t fread (void *ptr, size_t size_of_item, size_t number_items, FILE *file_ptr);
ptr
A pointer to the location, within memory, where you place the information being read. The type of the object pointed to is determined by the type of the item being read.size_of_item
The size of the items being read, in bytes.number_items
The number of items to be read.file_ptr
A pointer that indicates the file from which the items are to be read.
The type size_t is defined in the header file <stdio.h> as follows:
typedef unsigned int size_tThe reading begins at the current location in the file. The items read are placed in storage beginning at the location given by the first argument. You must also specify the size of an item, in bytes.
If the file pointed to by file_ptr was opened in record mode, fread will read size_of_item multiplied by number_items bytes from the file. That is, it does not necessarily read number_items records.
n The number of bytes read divided by size_of_item. 0 Indicates the end-of-file or an error.
Makes available for reallocation the area allocated by a previous calloc , malloc , or realloc call.
#include <stdlib.h>void free (void *ptr);
ptr
The address returned by a previous call to malloc , calloc , or realloc . If ptr is a NULL pointer, no action occurs.
The ANSI C standard defines free as not returning a value; therefore, the function prototype for free is declared with a return type of void . However, since a free can fail, and since previous versions of the HP C RTL have declared free to return an int , the implementation of free does return 0 on success and - 1 on failure.
Substitutes the file named by a file specification for the open file addressed by a file pointer. The latter file is closed.
#include <stdio.h>FILE *freopen (const char *file_spec, const char *a_mode, FILE *file_ptr, ...);
file_spec
A pointer to a string that contains a valid OpenVMS or UNIX style file specification. After the function call, the given file pointer is associated with this file.a_mode
The access mode indicator. See the fopen function for a description.file_ptr
A file pointer....
Optional file attribute arguments. The file attribute arguments are the same as those used in the creat function.
The freopen function is typically used to associate one of the predefined names stdin , stdout , or stderr with a file. For more information about these predefined names, see Chapter 2.
file_ptr The file pointer, if freopen is successful. NULL Indicates an error.
Previous | Next | Contents | Index |