rc

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

commit 27e15d138e55da4dbb626b727424d550a1464a69
parent d000dc89db8f65db051a3d870bbc8f4d4edefd8d
Author: tjg <tjg>
Date:   Tue, 30 Sep 2003 10:21:45 +0000

Initial revision

Diffstat:
Aedit-null.c | 72++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
1 file changed, 72 insertions(+), 0 deletions(-)

diff --git a/edit-null.c b/edit-null.c @@ -0,0 +1,72 @@ +#include "rc.h" + +#include <errno.h> + +#include <sys/types.h> + +#include "edit.h" + +bool editing = 0; + +void *edit_init(int fd) { + /* this function deliberately left blank */ + return NULL; +} + +char *edit_alloc(void *cookie, int *count) { + char *buf; + int size, used; + ssize_t r; + + used = 0; + size = 1; + buf = ealloc(size + 1); /* leave room for terminating \0 */ + do { + if (used >= size) { /* >= leaves room for terminating \0 */ + size = size * 2; + buf = erealloc(buf, size); + } + do { + r = rc_read(0, buf + used, size - used); + sigchk(); + if (r == -1) + switch (errno) { + case EAGAIN: + if (!makeblocking(0)) + panic("not O_NONBLOCK"); + errno = EINTR; + break; + case EIO: + if (makesamepgrp(0)) + errno = EINTR; + else + errno = EIO; + break; + } + } while (r < 0 && errno == EINTR); + + if (r == 0) + return NULL; + + used += r; + buf[used] = '\0'; + } while (strchr(buf, '\n') == NULL); + + *count = used; + if (used) + return buf; + else + return NULL; +} + +void edit_prompt(void *cookie, char *prompt) { + fprint(2, "%s", prompt); +} + +void edit_free(void *buffer) { + efree(buffer); +} + +void edit_end(void *cookie) { + /* this function deliberately left blank */ +}