rc

[fork] interactive rc shell
Log | Files | Refs | README | LICENSE

commit 2af5bbbb5355e9fcf311673f8051952c6b9b2509
parent 943fd3314e3955c9f6094ffeaef81f0fe5ab16f8
Author: tgoodwin <tgoodwin>
Date:   Tue, 17 Feb 1998 13:48:31 +0000

Initial revision

Diffstat:
Asystem-bsd.c | 50++++++++++++++++++++++++++++++++++++++++++++++++++
Asystem.c | 14++++++++++++++
2 files changed, 64 insertions(+), 0 deletions(-)

diff --git a/system-bsd.c b/system-bsd.c @@ -0,0 +1,50 @@ +/* signal-safe read and write (for BSD slow devices). writeall() also +allows partial writes */ + +#include <errno.h> + +#include "rc.h" +#include "jbwrap.h" + +static char *safe_buf; +static size_t safe_remain; + +extern void writeall(int fd, char *buf, size_t remain) { + int i; + + safe_buf = buf; + safe_remain = remain; + for (i = 0; safe_remain > 0; buf += i, safe_remain -= i) { + interrupt_happened = FALSE; + if (!sigsetjmp(slowbuf.j, 1)) { + slow = TRUE; + if (interrupt_happened) + break; + else if ((i = write(fd, safe_buf, safe_remain)) <= 0) + break; /* abort silently on errors in write() */ + } else + break; + slow = FALSE; + } + slow = FALSE; + sigchk(); +} + +extern int rc_read(int fd, char *buf, size_t n) { + long /*ssize_t*/ r; + interrupt_happened = FALSE; + if (!sigsetjmp(slowbuf.j, 1)) { + slow = TRUE; + if (!interrupt_happened) + r = read(fd, buf, n); + else + r = -2; + } else + r = -2; + slow = FALSE; + if (r == -2) { + errno = EINTR; + r = -1; + } + return r; +} diff --git a/system.c b/system.c @@ -0,0 +1,14 @@ +#include "rc.h" + +extern void writeall(int fd, char *buf, size_t remain) { + int i; + + for (i = 0; remain > 0; buf += i, remain -= i) + if ((i = write(fd, buf, remain)) <= 0) + break; /* abort silently on errors in write() */ + sigchk(); +} + +extern int rc_read(int fd, char *buf, size_t n) { + return read(fd, buf, n); +}