deal with short writes

This commit is contained in:
Aaron Culliney 2015-12-04 20:10:31 -08:00
parent 0bb0df0960
commit 0b7f3a75b5

View File

@ -56,26 +56,31 @@ static int _convert_crlf_to_lf(void) {
// convert CRLF -> LF // convert CRLF -> LF
ssize_t outlen=0; ssize_t outmax=0;
for (ssize_t i=0; i<inlen; i++) { for (ssize_t i=0; i<inlen; i++) {
char c = inbuf[i]; char c = inbuf[i];
if (sawCR && (c != LF)) { if (sawCR && (c != LF)) {
outbuf[outlen++] = CR; outbuf[outmax++] = CR;
} }
sawCR = false; sawCR = false;
if (c == CR) { if (c == CR) {
sawCR = true; sawCR = true;
} else { } else {
outbuf[outlen++] = c; outbuf[outmax++] = c;
} }
} }
if (TEMP_FAILURE_RETRY(write(STDOUT_FILENO, outbuf, outlen)) == -1) { ssize_t outlen = 0;
errWrt = "error writing to stdout"; do {
break; if (TEMP_FAILURE_RETRY(outlen = write(STDOUT_FILENO, outbuf, outmax)) == -1) {
} errWrt = "error writing to stdout";
break;
}
outbuf += outlen;
outmax -= outlen;
} while (outmax > 0);
} }
if (sawCR) { if (sawCR) {