Lely core libraries 2.3.4
fwbuf.h
Go to the documentation of this file.
1
36#ifndef LELY_UTIL_FWBUF_H_
37#define LELY_UTIL_FWBUF_H_
38
39#include <lely/libc/sys/types.h>
40#include <lely/util/util.h>
41
42#include <stddef.h>
43#include <stdint.h>
44
45struct __fwbuf;
46#ifndef __cplusplus
48typedef struct __fwbuf fwbuf_t;
49#endif
50
51#ifdef __cplusplus
52extern "C" {
53#endif
54
55void *__fwbuf_alloc(void);
56void __fwbuf_free(void *ptr);
57struct __fwbuf *__fwbuf_init(struct __fwbuf *buf, const char *filename);
58void __fwbuf_fini(struct __fwbuf *buf);
59
71fwbuf_t *fwbuf_create(const char *filename);
72
80void fwbuf_destroy(fwbuf_t *buf);
81
89intmax_t fwbuf_get_size(fwbuf_t *buf);
90
102int fwbuf_set_size(fwbuf_t *buf, intmax_t size);
103
113intmax_t fwbuf_get_pos(fwbuf_t *buf);
114
126intmax_t fwbuf_set_pos(fwbuf_t *buf, intmax_t pos);
127
142ssize_t fwbuf_write(fwbuf_t *buf, const void *ptr, size_t size);
143
160ssize_t fwbuf_pwrite(fwbuf_t *buf, const void *ptr, size_t size, intmax_t pos);
161
180void *fwbuf_map(fwbuf_t *buf, intmax_t pos, size_t *psize);
181
191int fwbuf_unmap(fwbuf_t *buf);
192
199void fwbuf_clearerr(fwbuf_t *buf);
200
208int fwbuf_error(fwbuf_t *buf);
209
214void fwbuf_cancel(fwbuf_t *buf);
215
226int fwbuf_commit(fwbuf_t *buf);
227
228#ifdef __cplusplus
229}
230#endif
231
232#endif // !LELY_UTIL_FWBUF_H_
int fwbuf_error(fwbuf_t *buf)
Returns 1 if the error indicator of a write file buffer is set, and 0 if not.
Definition: fwbuf.c:942
intmax_t fwbuf_set_pos(fwbuf_t *buf, intmax_t pos)
Sets the current offset (in bytes) of a write file buffer with respect to the beginning of the file.
Definition: fwbuf.c:447
int fwbuf_set_size(fwbuf_t *buf, intmax_t size)
Sets the new size (in bytes) of the a write file buffer.
Definition: fwbuf.c:369
void * fwbuf_map(fwbuf_t *buf, intmax_t pos, size_t *psize)
Maps (part of) the contents of a write file buffer to memory.
Definition: fwbuf.c:658
ssize_t fwbuf_write(fwbuf_t *buf, const void *ptr, size_t size)
Writes bytes to the current position in a write file buffer.
Definition: fwbuf.c:489
int fwbuf_unmap(fwbuf_t *buf)
Unmaps the current memory map of a write file buffer, if it exists, and writes the changes to disk.
Definition: fwbuf.c:827
void fwbuf_destroy(fwbuf_t *buf)
Destroys a write file buffer.
Definition: fwbuf.c:330
int fwbuf_commit(fwbuf_t *buf)
Commits all changes to a write file buffer to disk if all previous file operations were successful,...
Definition: fwbuf.c:979
intmax_t fwbuf_get_pos(fwbuf_t *buf)
Returns the current offset (in bytes) of a write file buffer with respect to the beginning of the fil...
Definition: fwbuf.c:415
ssize_t fwbuf_pwrite(fwbuf_t *buf, const void *ptr, size_t size, intmax_t pos)
Writes bytes to the specified position in a write file buffer.
Definition: fwbuf.c:543
void fwbuf_cancel(fwbuf_t *buf)
Cancels any further file operations by setting the error indicator of a write file buffer to ERRNUM_C...
Definition: fwbuf.c:962
intmax_t fwbuf_get_size(fwbuf_t *buf)
Returns the current size (in bytes) of the a write file buffer, or -1 on error.
Definition: fwbuf.c:339
fwbuf_t * fwbuf_create(const char *filename)
Creates a new (atomic) write file buffer.
Definition: fwbuf.c:305
void fwbuf_clearerr(fwbuf_t *buf)
Clears the error indicator of a write file buffer, allowing fwbuf_commit() to write the file to disk.
Definition: fwbuf.c:928
This is the public header file of the utilities library.
This header file is part of the C11 and POSIX compatibility library; it includes <stddef....
This header file is part of the C11 and POSIX compatibility library; it includes <stdint....
An (atomic) write file buffer struct.
Definition: fwbuf.c:59
char * filename
A pointer to the name of the file.
Definition: fwbuf.c:61
This header file is part of the C11 and POSIX compatibility library; it includes <sys/types....