static int journald_entry(struct logger_ctl *ctl, FILE *fp) { struct iovec *iovec; char *buf = NULL; ssize_t sz; int n, lines, vectors = 8, ret = 0; size_t dummy = 0; iovec = xmalloc(vectors * sizeof(struct iovec)); for (lines = 0; /* nothing */ ; lines++) { buf = NULL; sz = getline(&buf, &dummy, fp); if (sz == -1 || (sz = rtrim_whitespace((unsigned char *) buf)) == 0) { free(buf); break; } if (lines == vectors) { vectors *= 2; if (IOV_MAX < vectors) errx(EXIT_FAILURE, _("maximum input lines (%d) exceeded"), IOV_MAX); iovec = xrealloc(iovec, vectors * sizeof(struct iovec)); } iovec[lines].iov_base = buf; iovec[lines].iov_len = sz; } if (!ctl->noact) ret = sd_journal_sendv(iovec, lines); if (ctl->stderr_printout) { for (n = 0; n < lines; n++) fprintf(stderr, "%s\n", (char *) iovec[n].iov_base); } for (n = 0; n < lines; n++) free(iovec[n].iov_base); free(iovec); return ret; }
void assign_without_padding(std::string &dst, const char *src, const size_t len) { rtrim_whitespace(dst.assign(src, len)); }