| 49 | using namespace android_lkchan::base::utf8; |
| 50 | |
| 51 | bool 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 | |
| 70 | bool ReadFileToString(const std::string& path, std::string* content, bool follow_symlinks) { |
| 71 | content->clear(); |
no test coverage detected