static bool ReadFile( const RString &sPath, RString &sBuf ) { sBuf.clear(); int fd = open( sPath, O_RDONLY ); if( fd == -1 ) { // "No such file or directory" is understandable if (errno != ENOENT) LOG->Warn( "Error opening \"%s\": %s", sPath.c_str(), strerror(errno) ); return false; } while(1) { char buf[1024]; int iGot = read( fd, buf, sizeof(buf) ); if( iGot == -1 ) { close(fd); LOG->Warn( "Error reading \"%s\": %s", sPath.c_str(), strerror(errno) ); return false; } sBuf.append( buf, iGot ); if( iGot < (int) sizeof(buf) ) break; } close(fd); return true; }
u64 enoFile::readLine(RString& str, const c8 *delimiter, bool joinDelimiter) { RString out; s64 readCount = 0; u64 availBufSize; s64 derimsearchoffset = 0; const s64 delimLength = strlen(delimiter); while (true) { availBufSize = read_end-read_offset; if (availBufSize == 0) { if (FillBuffer() == 0) { break; } continue; } out.append(read_offset, availBufSize); const c8 *delimoff = mystrnstr(out.c_str()+derimsearchoffset, delimiter, out.size()-derimsearchoffset); if (delimoff != nullptr) { s64 noff = (delimoff-out.c_str()); noff+=delimLength-readCount; read_offset += noff; readCount = (delimoff-out.c_str())+(joinDelimiter?delimLength:0); break; } readCount += availBufSize; derimsearchoffset = readCount-delimLength; read_offset = read_end; } if (readCount != 0) { str = out.substr(0, readCount); } return readCount; }