MCPcopy Create free account
hub / github.com/CodingGay/BlackDex / ReadFdToString

Function ReadFdToString

Bcore/src/main/cpp/android-base/file.cpp:51–68  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

49using namespace android_lkchan::base::utf8;
50
51bool ReadFdToString(int fd, std::string* content) {
52 content->clear();
53
54 // Although original we had small files in mind, this code gets used for
55 // very large files too, where the std::string growth heuristics might not
56 // be suitable. https://code.google.com/p/android/issues/detail?id=258500.
57 struct stat sb;
58 if (fstat(fd, &sb) != -1 && sb.st_size > 0) {
59 content->reserve(sb.st_size);
60 }
61
62 char buf[BUFSIZ];
63 ssize_t n;
64 while ((n = TEMP_FAILURE_RETRY(read(fd, &buf[0], sizeof(buf)))) > 0) {
65 content->append(buf, n);
66 }
67 return (n == 0) ? true : false;
68}
69
70bool ReadFileToString(const std::string& path, std::string* content, bool follow_symlinks) {
71 content->clear();

Callers 1

ReadFileToStringFunction · 0.85

Calls 1

clearMethod · 0.45

Tested by

no test coverage detected