Flow123d
release_3.0.0-1094-g626f1a1
|
I/O functions with filename storing, able to track current line in opened file. All standard stdio functions working with files (not stdin, stdout, stderr) should be replaced by their equivalents from XIO library. More...
#include <string.h>
#include <strings.h>
#include <stdarg.h>
#include <errno.h>
#include <limits.h>
#include <iostream>
#include <algorithm>
#include <iterator>
#include "xio.h"
Go to the source code of this file.
Macros | |
#define | XIO_WARN(f) LogOut() << "File pointer '" << (f) << "' not in xfiles_map. Opened with regular fopen() or already closed?" << std::endl; |
#define | XIO_PRINT_INFO(f) printf( "XIO: In function '%s', %s\n", __func__, xio_getfulldescription( f ) ) |
#define | XIO_DEBUG(f) do { if ( Xio::get_instance()->get_verbosity() > 0 ) XIO_PRINT_INFO(f); } while (0) |
Functions | |
static XFILE * | xio_getfptr (FILE *f) |
Internal XIO locator. More... | |
char * | xio_getfname (FILE *f) |
Get file name from pointer to FILE structure. More... | |
char * | xio_getfmode (FILE *f) |
Get file mode from file stream. More... | |
int | xio_getlinesread (FILE *f) |
Get number of lines that were completely read from file since fopen() or rewind() More... | |
char * | xio_getfulldescription (FILE *f) |
Get pointer to string with full file description. More... | |
FILE * | xfopen (const std::string &fname, const char *mode) |
FILE * | xfopen (const char *fname, const char *mode) |
fopen() with error handling and filename store More... | |
int | xfflush (FILE *f) |
Flush file stream. More... | |
int | xfclose (FILE *stream) |
FCLOSE WITH ERROR HANDLING. More... | |
FILE * | xfreopen (const char *filename, const char *mode, FILE *stream) |
Reopen stream with different file or mode. More... | |
int | xfprintf (FILE *out, const char *fmt,...) |
FPRINTF WITH ERROR HANDLING. More... | |
int | xfscanf (FILE *in, const char *fmt,...) |
FSCANF WITH ERROR HANDLING. More... | |
int | xgetc (FILE *f) |
getc() with error handling and line count More... | |
int | xfgetc (FILE *f) |
fgetc() with error handling and line count More... | |
int | xungetc (int c, FILE *f) |
ungetc() with error handling and line count More... | |
int | xrename (const char *oldname, const char *newname) |
Changes the name of the file or directory specified by oldname to newname. More... | |
size_t | xfread (void *ptr, size_t size, size_t count, FILE *stream) |
Read block of data from stream, handle errors. More... | |
size_t | xfwrite (const void *ptr, size_t size, size_t count, FILE *stream) |
Write block of data to stream, handle errors. More... | |
char * | xfgets (char *s, int n, FILE *in) |
FGETS WITH ERROR HANDLING and line count. More... | |
void | xrewind (FILE *f) |
Rewind file, handle line count. More... | |
int | xfeof (FILE *f) |
Check END OF FILE. More... | |
Variables | |
static XFILE | xstdin = {&std::string("stdin")[0], &std::string("r")[0], 0} |
basic definitions More... | |
static XFILE | xstdout = {&std::string("stdout")[0], &std::string("w")[0], 0} |
static XFILE | xstderr = {&std::string("stderr")[0], &std::string("w")[0], 0} |
I/O functions with filename storing, able to track current line in opened file. All standard stdio functions working with files (not stdin, stdout, stderr) should be replaced by their equivalents from XIO library.
* Copyright (C) 2015 Technical University of Liberec. All rights reserved.
This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License version 3 as published by the Free Software Foundation. (http://www.gnu.org/licenses/gpl-3.0.en.html)
This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
Definition in file xio.cc.
#define XIO_DEBUG | ( | f | ) | do { if ( Xio::get_instance()->get_verbosity() > 0 ) XIO_PRINT_INFO(f); } while (0) |
#define XIO_PRINT_INFO | ( | f | ) | printf( "XIO: In function '%s', %s\n", __func__, xio_getfulldescription( f ) ) |
#define XIO_WARN | ( | f | ) | LogOut() << "File pointer '" << (f) << "' not in xfiles_map. Opened with regular fopen() or already closed?" << std::endl; |
int xfclose | ( | FILE * | stream | ) |
int xfeof | ( | FILE * | f | ) |
int xfflush | ( | FILE * | f | ) |
int xfgetc | ( | FILE * | f | ) |
char* xfgets | ( | char * | s, |
int | n, | ||
FILE * | in | ||
) |
FGETS WITH ERROR HANDLING and line count.
Character input/output.
[out] | s | Pointer to an array of chars where the string read is stored |
[in] | n | Maximum number of characters to be read (including the final null-character) |
[in,out] | in | Pointer to a FILE |
Definition at line 563 of file xio.cc.
FILE* xfopen | ( | const std::string & | fname, |
const char * | mode | ||
) |
FILE* xfopen | ( | const char * | fname, |
const char * | mode | ||
) |
int xfprintf | ( | FILE * | out, |
const char * | fmt, | ||
... | |||
) |
size_t xfread | ( | void * | ptr, |
size_t | size, | ||
size_t | count, | ||
FILE * | stream | ||
) |
Read block of data from stream, handle errors.
Direct input/output.
[out] | ptr | Pointer to a block of memory with a minimum size of (size*count) bytes. |
[in] | size | Size in bytes of each element to be read. |
[in] | count | Number of elements, each one with a size of size bytes. |
[in,out] | stream | Pointer to a FILE object that specifies an input stream. |
FILE* xfreopen | ( | const char * | filename, |
const char * | mode, | ||
FILE * | stream | ||
) |
int xfscanf | ( | FILE * | in, |
const char * | fmt, | ||
... | |||
) |
size_t xfwrite | ( | const void * | ptr, |
size_t | size, | ||
size_t | count, | ||
FILE * | stream | ||
) |
Write block of data to stream, handle errors.
[in] | ptr | Pointer to a block of memory with a minimum size of (size*count) bytes. |
[in] | size | Size in bytes of each element to be written. |
[in] | count | Number of elements, each one with a size of size bytes. |
[in,out] | stream | Pointer to a FILE object that specifies an output stream. |
int xgetc | ( | FILE * | f | ) |
char* xio_getfmode | ( | FILE * | f | ) |
char* xio_getfname | ( | FILE * | f | ) |
|
static |
char* xio_getfulldescription | ( | FILE * | f | ) |
int xio_getlinesread | ( | FILE * | f | ) |
int xrename | ( | const char * | oldname, |
const char * | newname | ||
) |
void xrewind | ( | FILE * | f | ) |
int xungetc | ( | int | c, |
FILE * | f | ||
) |
|
static |
|
static |