mirror of
https://github.com/mauiaaron/apple2.git
synced 2024-10-02 11:55:00 +00:00
deal with short writes
This commit is contained in:
parent
0bb0df0960
commit
0b7f3a75b5
@ -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;
|
||||||
|
do {
|
||||||
|
if (TEMP_FAILURE_RETRY(outlen = write(STDOUT_FILENO, outbuf, outmax)) == -1) {
|
||||||
errWrt = "error writing to stdout";
|
errWrt = "error writing to stdout";
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
outbuf += outlen;
|
||||||
|
outmax -= outlen;
|
||||||
|
} while (outmax > 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (sawCR) {
|
if (sawCR) {
|
||||||
|
Loading…
Reference in New Issue
Block a user