X_IO_VERSION_MAJOR
#define X_IO_VERSION_MAJOR 2
STDX - IO (file I/O utility functions) Part of the STDX General Purpose C Library by marciovmf License: MIT https://github.com/marciovmf/stdx
Provides utility functions for reading and writing files.
To compile the implementation define X_IMPL_IO
in one source file before including this header.
To customize how this module allocates memory, define
X_IO_ALLOC / X_IO_FREE before including.
#define X_IO_VERSION_MAJOR 2
#define X_IO_VERSION_MINOR 3
#define X_IO_VERSION_PATCH 0
#define X_IO_VERSION(X_IO_VERSION_MAJOR *10000+X_IO_VERSION_MINOR *100+X_IO_VERSION_PATCH)
typedef struct XFile_t XFile;
Open a file with mode ("r", "rb", "w", etc.).
X_IO_API XFile * x_io_open(
const char *filename,
const char *mode
);
Close a file and free internal memory.
X_IO_API void x_io_close(XFile *file);
Read up to `size` bytes into buffer. Returns bytes read.
X_IO_API size_t x_io_read(
XFile *file,
void *buffer,
size_t size
);
Read the entire file into a buffer. Returns buffer (null-terminated, but not for text safety). Caller must free.
X_IO_API char * x_io_read_all(
XFile *file,
size_t *out_size
);
Convenience: open, read, close. Returns null-terminated text.
X_IO_API char * x_io_read_text(
const char *filename,
size_t *out_size
);
Write `size` bytes to file. Returns number of bytes written.
X_IO_API size_t x_io_write(
XFile *file,
const void *data,
size_t size
);
Write null-terminated text to a file (overwrite).
X_IO_API bool x_io_write_text(
const char *filename,
const char *text
);
Append null-terminated text to file.
X_IO_API bool x_io_append_text(
const char *filename,
const char *text
);
Seek within file.
X_IO_API bool x_io_seek(
XFile *file,
long offset,
int32_t origin
);
Return current file position.
X_IO_API long x_io_tell(XFile *file);
Rewind file to beginning.
X_IO_API bool x_io_rewind(XFile *file);
Flush file buffer.
X_IO_API bool x_io_flush(XFile *file);
Check end-of-file.
X_IO_API bool x_io_eof(XFile *file);
Check for file error.
X_IO_API bool x_io_error(XFile *file);
Clear file error and EOF flags.
X_IO_API void x_io_clearerr(XFile *file);
Return underlying file descriptor.
X_IO_API int32_t x_io_fileno(XFile *file);
#define X_IO_ALLOC(sz) malloc(sz)
#define X_IO_FREE(p) free(p)
struct XFile_t{
FILE *fp;
};