diff --git a/src/bin/tyalpha.c b/src/bin/tyalpha.c index 63cdfaa4..ce22792a 100644 --- a/src/bin/tyalpha.c +++ b/src/bin/tyalpha.c @@ -45,7 +45,8 @@ main(int argc, char **argv) snprintf(tbuf, sizeof(tbuf), "%c}ap%s", 0x1b, argv[i]); else snprintf(tbuf, sizeof(tbuf), "%c}at%s", 0x1b, argv[i]); - if (write(1, tbuf, strlen(tbuf) + 1) != (signed)(strlen(tbuf) + 1)) perror("write"); + if (ty_write(1, tbuf, strlen(tbuf) + 1) != (signed)(strlen(tbuf) + 1)) + perror("write"); } return 0; } diff --git a/src/bin/tybg.c b/src/bin/tybg.c index 53c9b023..e797466d 100644 --- a/src/bin/tybg.c +++ b/src/bin/tybg.c @@ -29,7 +29,8 @@ main(int argc, char **argv) { char tbuf[32]; snprintf(tbuf, sizeof(tbuf), "%c}bt", 0x1b); - if (write(1, tbuf, strlen(tbuf) + 1) != (signed)(strlen(tbuf) + 1)) perror("write"); + if (ty_write(1, tbuf, strlen(tbuf) + 1) != (signed)(strlen(tbuf) + 1)) + perror("write"); return 0; } for (i = 1; i < argc; i++) @@ -48,7 +49,8 @@ main(int argc, char **argv) snprintf(tbuf, sizeof(tbuf), "%c}bp%s", 0x1b, path); else snprintf(tbuf, sizeof(tbuf), "%c}bt%s", 0x1b, path); - if (write(1, tbuf, strlen(tbuf) + 1) != (signed)(strlen(tbuf) + 1)) perror("write"); + if (ty_write(1, tbuf, strlen(tbuf) + 1) != (signed)(strlen(tbuf) + 1)) + perror("write"); } return 0; } diff --git a/src/bin/tycat.c b/src/bin/tycat.c index 43444271..1a618c0d 100644 --- a/src/bin/tycat.c +++ b/src/bin/tycat.c @@ -96,7 +96,8 @@ prnt(const char *path, int w, int h, int mode) snprintf(buf, sizeof(buf), "%c}if#%i;%i;%s", 0x1b, w, h, path); else snprintf(buf, sizeof(buf), "%c}is#%i;%i;%s", 0x1b, w, h, path); - if (write(1, buf, strlen(buf) + 1) < 0) perror("write"); + if (ty_write(1, buf, strlen(buf) + 1) < 0) + perror("write"); i = 0; line[i++] = 0x1b; line[i++] = '}'; @@ -112,7 +113,8 @@ prnt(const char *path, int w, int h, int mode) line[i++] = '\n'; for (y = 0; y < h; y++) { - if (write(1, line, i) < 0) perror("write"); + if (ty_write(1, line, i) < 0) + perror("write"); } free(line); } @@ -329,11 +331,13 @@ main(int argc, char **argv) emotion_init(); ee = ecore_evas_buffer_new(1, 1); - if (!ee) goto shutdown; + if (!ee) + goto shutdown; evas = ecore_evas_get(ee); echo_off(); snprintf(buf, sizeof(buf), "%c}qs", 0x1b); - if (write(1, buf, strlen(buf) + 1) < 0) perror("write"); + if (ty_write(1, buf, strlen(buf) + 1) < 0) + perror("write"); if (scanf("%i;%i;%i;%i", &tw, &th, &cw, &ch) != 4 || ((tw <= 0) || (th <= 0) || (cw <= 1) || (ch <= 1))) { diff --git a/src/bin/tycommon.c b/src/bin/tycommon.c index aef8a659..0c34503d 100644 --- a/src/bin/tycommon.c +++ b/src/bin/tycommon.c @@ -1,5 +1,7 @@ #include "private.h" +#include #include +#include #include "tycommon.h" @@ -14,3 +16,25 @@ is_running_in_terminology(void) return 1; } + +ssize_t +ty_write(int fd, const void *buf, size_t count) +{ + const char *data = buf; + ssize_t len = count; + + while (len > 0) + { + ssize_t res = write(fd, data, len); + + if (res < 0) + { + if (errno == EINTR || errno == EAGAIN) + continue; + return res; + } + data += res; + len -= res; + } + return len; +} diff --git a/src/bin/tycommon.h b/src/bin/tycommon.h index 2d7cabdd..d5bf90e6 100644 --- a/src/bin/tycommon.h +++ b/src/bin/tycommon.h @@ -2,6 +2,7 @@ #define _TY_COMMON_H__ 1 int is_running_in_terminology(void); +ssize_t ty_write(int fd, const void *buf, size_t count); #define ON_NOT_RUNNING_IN_TERMINOLOGY_EXIT_1() \ do \ diff --git a/src/bin/tyls.c b/src/bin/tyls.c index 86331c30..a9267e36 100644 --- a/src/bin/tyls.c +++ b/src/bin/tyls.c @@ -763,7 +763,8 @@ main(int argc, char **argv) echo_off(); snprintf(buf, sizeof(buf), "%c}qs", 0x1b); len = strlen(buf); - if (write(1, buf, len + 1) < (signed)len + 1) perror("write"); + if (ty_write(1, buf, len + 1) < (signed)len + 1) + perror("write"); if ((scanf("%i;%i;%i;%i", &tw, &th, &cw, &ch) != 4) || (tw <= 0) || (th <= 0) || (cw <= 1) || (ch <= 1)) { diff --git a/src/bin/typop.c b/src/bin/typop.c index 8a9e1597..6485a69b 100644 --- a/src/bin/typop.c +++ b/src/bin/typop.c @@ -39,7 +39,8 @@ main(int argc, char **argv) if (realpath(path, buf)) path = buf; snprintf(tbuf, sizeof(tbuf), "%c}p%c%s", 0x1b, (i == 1) ? 'n': 'q', path); - if (write(1, tbuf, strlen(tbuf) + 1) != (signed)(strlen(tbuf) + 1)) perror("write"); + if (ty_write(1, tbuf, strlen(tbuf) + 1) != (signed)(strlen(tbuf) + 1)) + perror("write"); } return 0; } diff --git a/src/bin/tyq.c b/src/bin/tyq.c index 1d6167f2..2bcac24b 100644 --- a/src/bin/tyq.c +++ b/src/bin/tyq.c @@ -38,7 +38,8 @@ main(int argc, char **argv) path = argv[i]; if (realpath(path, buf)) path = buf; snprintf(tbuf, sizeof(tbuf), "%c}pq%s", 0x1b, path); - if (write(1, tbuf, strlen(tbuf) + 1) != (signed)(strlen(tbuf) + 1)) perror("write"); + if (ty_write(1, tbuf, strlen(tbuf) + 1) != (signed)(strlen(tbuf) + 1)) + perror("write"); } return 0; } diff --git a/src/bin/tysend.c b/src/bin/tysend.c index 33ff5f06..ea8b291f 100644 --- a/src/bin/tysend.c +++ b/src/bin/tysend.c @@ -69,7 +69,7 @@ main(int argc, char **argv) path = argv[i]; snprintf(tbuf, sizeof(tbuf), "%c}fr%s", 0x1b, path); - if (write(1, tbuf, strlen(tbuf) + 1) != (signed)(strlen(tbuf) + 1)) + if (ty_write(1, tbuf, strlen(tbuf) + 1) != (signed)(strlen(tbuf) + 1)) goto err; file_fd = open(path, O_RDONLY); if (file_fd >= 0) @@ -79,7 +79,7 @@ main(int argc, char **argv) off = lseek(file_fd, 0, SEEK_END); lseek(file_fd, 0, SEEK_SET); snprintf(tbuf, sizeof(tbuf), "%c}fs%llu", 0x1b, (unsigned long long)off); - if (write(1, tbuf, strlen(tbuf) + 1) != (signed)(strlen(tbuf) + 1)) + if (ty_write(1, tbuf, strlen(tbuf) + 1) != (signed)(strlen(tbuf) + 1)) goto err; for (;;) { @@ -104,9 +104,9 @@ main(int argc, char **argv) pksum += rawbuf2[bin]; } snprintf(tbuf, sizeof(tbuf), "%c}fd%i ", 0x1b, pksum); - if (write(1, tbuf, strlen(tbuf)) != (signed)(strlen(tbuf))) + if (ty_write(1, tbuf, strlen(tbuf)) != (signed)(strlen(tbuf))) goto err; - if (write(1, rawbuf2, bout + 1) != bout + 1) + if (ty_write(1, rawbuf2, bout + 1) != bout + 1) goto err; } else break; @@ -123,10 +123,10 @@ main(int argc, char **argv) close(file_fd); } snprintf(tbuf, sizeof(tbuf), "%c}fx", 0x1b); - if (write(1, tbuf, strlen(tbuf) + 1) != (signed)(strlen(tbuf) + 1)) + if (ty_write(1, tbuf, strlen(tbuf) + 1) != (signed)(strlen(tbuf) + 1)) goto err; tbuf[0] = 0; - if (write(1, tbuf, 1) != 1) + if (ty_write(1, tbuf, 1) != 1) goto err; } echo_on();