static bool read_and_detect_pdu(w_jbuffer_t *jr, w_stm_t stm, json_error_t *jerr) { enum w_pdu_type pdu; shunt_down(jr); pdu = detect_pdu(jr); if (pdu == need_data) { if (!fill_buffer(jr, stm)) { if (errno != EAGAIN) { snprintf(jerr->text, sizeof(jerr->text), "fill_buffer: %s", errno ? strerror(errno) : "EOF"); } return false; } pdu = detect_pdu(jr); } if (pdu == is_json_compact && stm == w_stm_stdin()) { // Minor hack for the `-j` option for reading pretty printed // json from stdin pdu = is_json_pretty; } jr->pdu_type = pdu; return true; }
static bool read_and_detect_pdu(w_jbuffer_t *jr, int fd, json_error_t *jerr) { enum w_pdu_type pdu; shunt_down(jr); pdu = detect_pdu(jr); if (pdu == need_data) { if (!fill_buffer(jr, fd)) { if (errno != EAGAIN) { snprintf(jerr->text, sizeof(jerr->text), "fill_buffer: %s", strerror(errno)); } return false; } pdu = detect_pdu(jr); } jr->pdu_type = pdu; return true; }