f3ad877eb05befbc862b0233d985758c0caef29aEvan Hunt * Copyright (C) 2011 - 2015 Nominum, Inc.
f3ad877eb05befbc862b0233d985758c0caef29aEvan Hunt * Permission to use, copy, modify, and distribute this software and its
f3ad877eb05befbc862b0233d985758c0caef29aEvan Hunt * documentation for any purpose with or without fee is hereby granted,
f3ad877eb05befbc862b0233d985758c0caef29aEvan Hunt * provided that the above copyright notice and this permission notice
f3ad877eb05befbc862b0233d985758c0caef29aEvan Hunt * appear in all copies.
f3ad877eb05befbc862b0233d985758c0caef29aEvan Hunt * THE SOFTWARE IS PROVIDED "AS IS" AND NOMINUM DISCLAIMS ALL WARRANTIES
f3ad877eb05befbc862b0233d985758c0caef29aEvan Hunt * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
f3ad877eb05befbc862b0233d985758c0caef29aEvan Hunt * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL NOMINUM BE LIABLE FOR
f3ad877eb05befbc862b0233d985758c0caef29aEvan Hunt * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
f3ad877eb05befbc862b0233d985758c0caef29aEvan Hunt * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
f3ad877eb05befbc862b0233d985758c0caef29aEvan Hunt * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT
f3ad877eb05befbc862b0233d985758c0caef29aEvan Hunt * OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
f3ad877eb05befbc862b0233d985758c0caef29aEvan Huntstatic inline void
f3ad877eb05befbc862b0233d985758c0caef29aEvan Huntperf_datafile_open(isc_mem_t *mctx, const char *filename)
f3ad877eb05befbc862b0233d985758c0caef29aEvan Hunt isc_buffer_init(&dfile->data, dfile->databuf, BUFFER_SIZE);
f3ad877eb05befbc862b0233d985758c0caef29aEvan Hunt perf_log_fatal("unable to open file: %s", filename);
f3ad877eb05befbc862b0233d985758c0caef29aEvan Hunt if (fstat(dfile->fd, &buf) == 0 && S_ISREG(buf.st_mode)) {
f3ad877eb05befbc862b0233d985758c0caef29aEvan Huntperf_datafile_setpipefd(perf_datafile_t *dfile, int pipe_fd)
f3ad877eb05befbc862b0233d985758c0caef29aEvan Huntperf_datafile_setmaxruns(perf_datafile_t *dfile, unsigned int maxruns)
f3ad877eb05befbc862b0233d985758c0caef29aEvan Hunt result = perf_os_waituntilreadable(dfile->fd, dfile->pipe_fd,
f3ad877eb05befbc862b0233d985758c0caef29aEvan Hunt isc_buffer_usedlength(&dfile->data) == dfile->size)
f3ad877eb05befbc862b0233d985758c0caef29aEvan Huntread_one_line(perf_datafile_t *dfile, isc_buffer_t *lines)
f3ad877eb05befbc862b0233d985758c0caef29aEvan Hunt /* Get the current line */
f3ad877eb05befbc862b0233d985758c0caef29aEvan Hunt * If the current line contains the rest of the buffer,
f3ad877eb05befbc862b0233d985758c0caef29aEvan Hunt * we need to read more (unless the full file is cached).
f3ad877eb05befbc862b0233d985758c0caef29aEvan Hunt if (isc_buffer_remaininglength(&dfile->data) == 0) {
f3ad877eb05befbc862b0233d985758c0caef29aEvan Hunt if (isc_buffer_remaininglength(&dfile->data) > nrem)
f3ad877eb05befbc862b0233d985758c0caef29aEvan Hunt /* We now have a line. Advance the buffer past it. */
f3ad877eb05befbc862b0233d985758c0caef29aEvan Hunt /* If the line is empty or a comment, we need to try again. */
f3ad877eb05befbc862b0233d985758c0caef29aEvan Huntperf_datafile_next(perf_datafile_t *dfile, isc_buffer_t *lines,