Load a file from disk into a buffer.
More...
|
| void | c4::yml::file_get_contents (const char *filename, FILE *fp, size_t filesz, void *buf, size_t bufsz) |
| | load a file of specified size from disk into an existing contiguous buffer. More...
|
| |
| size_t | c4::yml::file_get_contents (const char *filename, FILE *fp, void *buf, size_t bufsz) |
| | load a file from disk into an existing contiguous buffer. More...
|
| |
| size_t | c4::yml::file_get_contents (const char *filename, void *buf, size_t bufsz, const char *access="rb") |
| | load a file from disk into an existing contiguous buffer. More...
|
| |
| template<class ContiguousContainer > |
| void | c4::yml::file_get_contents (ContiguousContainer *v, const char *filename, const char *access="rb") |
| | load a file from disk into an existing ContiguousContainer, resizing it to fit the file's contents More...
|
| |
| template<class ContiguousContainer > |
| ContiguousContainer | c4::yml::file_get_contents (const char *filename, const char *access="rb") |
| | load a file from disk and return a newly created ContiguousContainer with the file contents More...
|
| |
Load a file from disk into a buffer.
| void c4::yml::file_get_contents |
( |
const char * |
filename, |
|
|
FILE * |
fp, |
|
|
size_t |
filesz, |
|
|
void * |
buf, |
|
|
size_t |
bufsz |
|
) |
| |
|
inline |
load a file of specified size from disk into an existing contiguous buffer.
Definition at line 106 of file file.hpp.
Referenced by c4::yml::file_get_contents(), and main().
108 RYML_ASSERT_BASIC_(filesz <= bufsz);(void)bufsz;
109 size_t read = std::fread(buf, 1, filesz, fp);
110 if C4_UNLIKELY(read != filesz)
111 RYML_ERR_BASIC_("{}: failed file read: expected={}B actual={}B
", filename, filesz, read); // LCOV_EXCL_LINE
ReadResult read(ConstNodeRef const &n, T *v)
| size_t c4::yml::file_get_contents |
( |
const char * |
filename, |
|
|
FILE * |
fp, |
|
|
void * |
buf, |
|
|
size_t |
bufsz |
|
) |
| |
|
inline |
load a file from disk into an existing contiguous buffer.
- Returns
- true if the file was successfully read and the buffer was large enough to fit the file size
Definition at line 119 of file file.hpp.
121 std::fseek(fp, 0, SEEK_END);
122 size_t filesz =
static_cast<size_t>(std::ftell(fp));
ContiguousContainer file_get_contents(const char *filename, const char *access="rb")
load a file from disk and return a newly created ContiguousContainer with the file contents ...
| size_t c4::yml::file_get_contents |
( |
const char * |
filename, |
|
|
void * |
buf, |
|
|
size_t |
bufsz, |
|
|
const char * |
access = "rb" |
|
) |
| |
|
inline |
load a file from disk into an existing contiguous buffer.
- Returns
- the size required for the buffer. It is up to the caller to check that the returned size is smaller than the buffer's size.
Definition at line 135 of file file.hpp.
137 detail::ScopedFILE f(filename, access);
ContiguousContainer file_get_contents(const char *filename, const char *access="rb")
load a file from disk and return a newly created ContiguousContainer with the file contents ...
template<class ContiguousContainer >
| void c4::yml::file_get_contents |
( |
ContiguousContainer * |
v, |
|
|
const char * |
filename, |
|
|
const char * |
access = "rb" |
|
) |
| |
load a file from disk into an existing ContiguousContainer, resizing it to fit the file's contents
Definition at line 145 of file file.hpp.
147 using value_type =
typename ContiguousContainer::value_type;
148 using size_type =
typename ContiguousContainer::size_type;
149 detail::ScopedFILE f(filename, access);
150 void * dat = !v->empty() ? &(*v)[0] :
nullptr;
151 size_t vsz =
static_cast<size_t>(v->size());
153 size_t num_elms = fsz /
sizeof(value_type);
154 if C4_UNLIKELY(fsz != num_elms *
sizeof(value_type))
155 RYML_ERR_BASIC_("{}: file size ({}B) not a multiple of element size ({}B)
", filename, fsz, sizeof(value_type));
156 v->resize(static_cast<size_type>(num_elms));
157 if(fsz > vsz * sizeof(value_type))
158 file_get_contents(filename, f.file, fsz, &(*v)[0], fsz);
ContiguousContainer file_get_contents(const char *filename, const char *access="rb")
load a file from disk and return a newly created ContiguousContainer with the file contents ...
template<class ContiguousContainer >
| ContiguousContainer c4::yml::file_get_contents |
( |
const char * |
filename, |
|
|
const char * |
access = "rb" |
|
) |
| |
load a file from disk and return a newly created ContiguousContainer with the file contents
Definition at line 165 of file file.hpp.
167 ContiguousContainer cc;
ContiguousContainer file_get_contents(const char *filename, const char *access="rb")
load a file from disk and return a newly created ContiguousContainer with the file contents ...