MCPcopy Create free account
hub / github.com/couchbase/fleece / readFile

Function readFile

Fleece/Support/sliceIO.cc:42–56  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

40namespace fleece {
41
42 alloc_slice readFile(const char *path) {
43 int fd = ::_open(path, O_RDONLY | O_BINARY);
44 if (fd < 0)
45 FleeceException::_throwErrno("Can't open file %s", path);
46 struct stat stat;
47 fstat(fd, &stat);
48 if (stat.st_size > SIZE_MAX)
49 throw std::logic_error("File too big for address space");
50 alloc_slice data(narrow_cast<size_t>(stat.st_size));
51 ssize_t bytesRead = narrow_cast<ssize_t>(::_read(fd, (void*)data.buf, narrow_cast<unsigned int>(data.size)));
52 if (bytesRead < narrow_cast<ssize_t>(data.size))
53 FleeceException::_throwErrno("Can't read file %s", path);
54 ::_close(fd);
55 return data;
56 }
57
58 void writeToFile(slice s, const char *path, int mode) {
59 int fd = ::_open(path, mode | O_WRONLY | O_BINARY, 0600);

Callers 5

API_ValueTests.ccFile · 0.85
EncoderTests.ccFile · 0.85
readTestFileFunction · 0.85
SupportTests.ccFile · 0.85
ValueTests.ccFile · 0.85

Calls

no outgoing calls

Tested by 1

readTestFileFunction · 0.68