![]() |
Code_Saturne
CFD tool
|
#include "ecs_def.h"
Go to the source code of this file.
Typedefs | |
typedef typedefBEGIN_C_DECLS struct _ecs_file_t | ecs_file_t |
Pointer to opaque file descriptor. More... | |
typedef long long | ecs_file_off_t |
Enumerations | |
enum | ecs_file_type_t { ECS_FILE_TYPE_TEXT, ECS_FILE_TYPE_BINARY, ECS_FILE_TYPE_FORTRAN_BINARY } |
enum | ecs_file_mode_t { ECS_FILE_MODE_READ, ECS_FILE_MODE_WRITE, ECS_FILE_MODE_APPEND } |
enum | ecs_file_seek_t { ECS_FILE_SEEK_SET, ECS_FILE_SEEK_CUR, ECS_FILE_SEEK_END } |
Functions | |
ecs_file_t * | ecs_file_open (const char *name, const ecs_file_mode_t mode, const ecs_file_type_t type) |
Create a `ecs_file_t' file descriptor and open the associated file. More... | |
ecs_file_t * | ecs_file_free (ecs_file_t *f) |
Destroy a `ecs_file_t' descriptor and close the associated file. More... | |
ecs_file_t * | ecs_file_free_descriptor (ecs_file_t *f) |
int | ecs_file_open_stream (ecs_file_t *f, ecs_file_mode_t mode) |
Open `ecs_file_t' descriptor's associated file. More... | |
int | ecs_file_close_stream (ecs_file_t *f) |
Close a ecs_file_t file descriptor's associated file. More... | |
int | ecs_file_eof (const ecs_file_t *f) |
Test the end-of-file indicator for a given file. More... | |
int | ecs_file_flush (ecs_file_t *f) |
Force write of all user-space buffered data for a given file. More... | |
ecs_file_off_t | ecs_file_tell (ecs_file_t *f) |
Obtain the current value of a file's position indicator. More... | |
void | ecs_file_rewind (ecs_file_t *f) |
Sets the file position indicator to the beginning of the file. More... | |
int | ecs_file_seek (ecs_file_t *f, const ecs_file_off_t offset, const ecs_file_seek_t whence) |
Sets a file's position indicator. More... | |
const char * | ecs_file_get_name (const ecs_file_t *f) |
Return a file's name. More... | |
ecs_file_type_t | ecs_file_get_type (const ecs_file_t *f) |
Return a file's type. More... | |
void | ecs_file_set_type (ecs_file_t *f, const ecs_file_type_t type) |
Change a file's type. More... | |
void | ecs_file_set_big_endian (ecs_file_t *f) |
Ensure that data is read or written in big-endian (network standard) format. More... | |
int | ecs_file_get_swap_endian (const ecs_file_t *f) |
Return a file's byte-swapping behavior. More... | |
void | ecs_file_set_swap_endian (ecs_file_t *f, const int swap) |
Set a file's byte-swapping behavior. More... | |
int | ecs_file_read_check_error (const ecs_file_t *f, const int line) |
Test a file's error or EOF condition. More... | |
int | ecs_file_printf (const ecs_file_t *const f, const char *const format,...) |
Formatted output to a text file (as fprintf()). More... | |
char * | ecs_file_gets (char *s, const int size, const ecs_file_t *f, int *line) |
Formatted input from a text file (as fgets()). More... | |
char * | ecs_file_gets_try (char *s, const int size, const ecs_file_t *f, int *line) |
Formatted input from a text file if possible (as fgets()). More... | |
size_t | ecs_file_read (void *rec, const size_t size, const size_t ni, const ecs_file_t *f) |
Read a binary C or Fortran type record. More... | |
size_t | ecs_file_read_try (void *rec, const size_t size, const size_t ni, const ecs_file_t *f) |
Read a binary C or Fortran type record. More... | |
size_t | ecs_file_write (const void *rec, const size_t size, const size_t ni, const ecs_file_t *f) |
Write a binary C or Fortran type record. More... | |
void | ecs_file_swap_endian (void *dest, const void *src, const size_t size, const size_t ni) |
Convert data from "little-endian" to "big-endian" or the reverse. More... | |
int | ecs_file_mkdir_default (const char *pathname) |
Create a new directory using default permissions. More... | |
int | ecs_file_isreg (const char *name) |
Check if a file exists and is a regular file. More... | |
int | ecs_file_isdir (const char *name) |
Check if a directory exists. More... | |
const char * | ecs_file_version_zlib (void) |
Indicate Zlib version available at run time. More... | |
const char * | ecs_file_version_build_zlib (void) |
Indicate Zlib version available at compilation time. More... | |
typedef long long ecs_file_off_t |
Pointer to opaque file descriptor.
enum ecs_file_mode_t |
enum ecs_file_seek_t |
enum ecs_file_type_t |
int ecs_file_close_stream | ( | ecs_file_t * | f | ) |
Close a ecs_file_t file descriptor's associated file.
If the file is already closed, this function does nothing.
[in] | f | ecs_file_t descriptor. |
int ecs_file_eof | ( | const ecs_file_t * | f | ) |
Test the end-of-file indicator for a given file.
[in] | f | ecs_file_t descriptor. |
int ecs_file_flush | ( | ecs_file_t * | f | ) |
Force write of all user-space buffered data for a given file.
[in] | f | ecs_file_t descriptor. |
ecs_file_t* ecs_file_free | ( | ecs_file_t * | f | ) |
Destroy a `ecs_file_t' descriptor and close the associated file.
The descriptor may only be destroyed if the file was successfully closed. To force destruction of a ecs_file_t descriptor even if the associated file was not closed, use (ecs_file_free_force()).
The associated file is only closed if this was not already the case.
[in] | f | ecs_file_t descriptor. |
ecs_file_t* ecs_file_free_descriptor | ( | ecs_file_t * | f | ) |
const char* ecs_file_get_name | ( | const ecs_file_t * | f | ) |
Return a file's name.
[in] | f | ecs_file_t descriptor. |
int ecs_file_get_swap_endian | ( | const ecs_file_t * | f | ) |
Return a file's byte-swapping behavior.
[in] | f | ecs_file_t descriptor. |
ecs_file_type_t ecs_file_get_type | ( | const ecs_file_t * | f | ) |
Return a file's type.
[in] | f | ecs_file_t descriptor. |
char* ecs_file_gets | ( | char * | s, |
const int | size, | ||
const ecs_file_t * | f, | ||
int * | line | ||
) |
Formatted input from a text file (as fgets()).
[out] | s | buffer to which string is to be read. |
[in] | size | maximum number of characters to be read plus one. |
[in] | f | ecs_file_t descriptor. |
[in,out] | line | file line number if available, or NULL. |
char* ecs_file_gets_try | ( | char * | s, |
const int | size, | ||
const ecs_file_t * | f, | ||
int * | line | ||
) |
Formatted input from a text file if possible (as fgets()).
This function is similar to ecs_file_gets(), but failure to read a line due to an end-of-file condition is not considered an error with this variant, which may be used to read text files or sections thereof of unknown length.
[out] | s | buffer to which string is to be read. |
[in] | size | maximum number of characters to be read plus one. |
[in] | f | ecs_file_t descriptor. |
[in,out] | line | file line number if available, or NULL. |
int ecs_file_isdir | ( | const char * | name | ) |
Check if a directory exists.
[in] | name | directory name. |
int ecs_file_isreg | ( | const char * | name | ) |
Check if a file exists and is a regular file.
[in] | name | file name. |
int ecs_file_mkdir_default | ( | const char * | pathname | ) |
Create a new directory using default permissions.
This function is similar to the POSIX function mkdir(), except that it has no "mode" argument: by default, on a POSIX type system, permissions include read, write, and execute access for the user, group and others, modified by the users umask value (so with a typical configuration, the user will have read, write, and execute pemission, the group and others will only have read and execute permission, but this behavior may be modified).
Also, contrary to the usual mkdir(), if the directory already exists (and is truly a directory), this is considered a success and not a failure, and 0 is returned: the aim of this function is to make a directory available, so if it already exists, this is considered acceptable.
[in] | pathname | name of new directory. |
ecs_file_t* ecs_file_open | ( | const char * | name, |
const ecs_file_mode_t | mode, | ||
const ecs_file_type_t | type | ||
) |
Create a `ecs_file_t' file descriptor and open the associated file.
By default, data is written or read in native format (as regards big-endian or little-endian). This behavior may be modified by ecs_file_set_big_endian() or ecs_file_set_swap_endian().
[in] | name | file name. |
[in] | mode | file acces mode: read, write, or append. |
[in] | type | file type: text, binary, or Fortran binary. |
int ecs_file_open_stream | ( | ecs_file_t * | f, |
ecs_file_mode_t | mode | ||
) |
Open `ecs_file_t' descriptor's associated file.
If the file is already open, this function does nothing.
[in] | f | ecs_file_t descriptor. |
[in] | mode | file acces mode: read, write, or append. |
int ecs_file_printf | ( | const ecs_file_t *const | f, |
const char *const | format, | ||
... | |||
) |
Formatted output to a text file (as fprintf()).
[in] | f | ecs_file_t descriptor. |
[in] | format | format string, as printf() and family. |
[in] | ... | variable arguments based on format string. |
size_t ecs_file_read | ( | void * | rec, |
const size_t | size, | ||
const size_t | ni, | ||
const ecs_file_t * | f | ||
) |
Read a binary C or Fortran type record.
A Fortran record compatible with most compilers is structured as follows:
A C record contains only the raw data.
[out] | rec | pointer to location receiving data. |
[in] | size | size of each item of data in bytes. |
[in] | ni | number of items to read. |
[in] | f | ecs_file_t descriptor. |
int ecs_file_read_check_error | ( | const ecs_file_t * | f, |
const int | line | ||
) |
Test a file's error or EOF condition.
[in] | f | ecs_file_t descriptor. |
[in,out] | line | file line number if available, or NULL. |
size_t ecs_file_read_try | ( | void * | rec, |
const size_t | size, | ||
const size_t | ni, | ||
const ecs_file_t * | f | ||
) |
Read a binary C or Fortran type record.
This function is similar to ecs_file_read(), but failure to read a record due to an end-of-file condition is not considered an error with this variant, which may be used to read records whose presence in the file is unknown.
A Fortran record compatible with most compilers is structured as follows:
A C record contains only the raw data.
[out] | rec | pointer to location receiving data. |
[in] | size | size of each item of data in bytes. |
[in] | ni | number of items to read. |
[in] | f | ecs_file_t descriptor. |
void ecs_file_rewind | ( | ecs_file_t * | f | ) |
Sets the file position indicator to the beginning of the file.
A successful call to this function clears the end-of-file indicator for this file.
[in] | f | ecs_file_t descriptor. |
int ecs_file_seek | ( | ecs_file_t * | f, |
const ecs_file_off_t | offset, | ||
const ecs_file_seek_t | whence | ||
) |
Sets a file's position indicator.
This function may call the libc's fseek() function, or Zlib's gzseek() function. The C 99 standard draft specifies that for a text file, the offset argument to fseek() should be zero or a value returned by an earlier successful call to ftell() (here ecs_file_ftell()) on a stream (here a ecs_file_t structure). Zlib's gzseek() does not support SEEK_END, at least as of version 1.2.1.
A successful call to this function clears the end-of-file indicator for this file.
[in] | f | ecs_file_t descriptor. |
[in] | offset | add to position specified to whence to obtain new position, measured in characters from the beginning of the file. |
[in] | whence | beginning if ECS_FILE_SEEK_SET, current if ECS_FILE_SEEK_CUR, or end-of-file if ECS_FILE_SEEK_END. |
void ecs_file_set_big_endian | ( | ecs_file_t * | f | ) |
Ensure that data is read or written in big-endian (network standard) format.
By default, data is written or read in native format (as regards big-endian or little-endian)..
[in,out] | f | ecs_file_t descriptor. |
void ecs_file_set_swap_endian | ( | ecs_file_t * | f, |
const int | swap | ||
) |
Set a file's byte-swapping behavior.
Using this function assumes one is familiar with a file's coding or structure; use with caution.
[in] | f | ecs_file_t descriptor. |
[in] | swap | 1 if bytes must be swapped, 0 otherwise. |
void ecs_file_set_type | ( | ecs_file_t * | f, |
const ecs_file_type_t | type | ||
) |
Change a file's type.
Using this function assumes one is familiar with a file's coding or structure; use with caution.
[in,out] | f | ecs_file_t descriptor. |
[in] | type | text, binary, or Fortran binary type descriptor. |
void ecs_file_swap_endian | ( | void * | dest, |
const void * | src, | ||
const size_t | size, | ||
const size_t | ni | ||
) |
Convert data from "little-endian" to "big-endian" or the reverse.
The memory areas pointed to by src and dest should overlap either exactly or not at all.
[out] | dest | pointer to converted data location. |
[in] | src | pointer to source data location. |
[in] | size | size of each item of data in bytes. |
[in] | ni | number of data items. |
ecs_file_off_t ecs_file_tell | ( | ecs_file_t * | f | ) |
Obtain the current value of a file's position indicator.
[in] | f | ecs_file_t descriptor. |
const char* ecs_file_version_build_zlib | ( | void | ) |
Indicate Zlib version available at compilation time.
It may be useful to compare the Zlib version used at compile and link time in case we use dynamic libraries.
const char* ecs_file_version_zlib | ( | void | ) |
Indicate Zlib version available at run time.
It may be useful to compare the Zlib version used at compile and run time in case we use dynamic libraries.
size_t ecs_file_write | ( | const void * | rec, |
const size_t | size, | ||
const size_t | ni, | ||
const ecs_file_t * | f | ||
) |
Write a binary C or Fortran type record.
A Fortran record compatible with most compilers is structured as follows:
A C record contains only the raw data.
[in] | rec | pointer to location containing data. |
[in] | size | size of each item of data in bytes. |
[in] | ni | number of items to write. |
[in] | f | ecs_file_t descriptor. |