diff options
Diffstat (limited to 'sys/src/cmd/webfs/buf.c')
-rw-r--r-- | sys/src/cmd/webfs/buf.c | 89 |
1 files changed, 0 insertions, 89 deletions
diff --git a/sys/src/cmd/webfs/buf.c b/sys/src/cmd/webfs/buf.c deleted file mode 100644 index ffd249407..000000000 --- a/sys/src/cmd/webfs/buf.c +++ /dev/null @@ -1,89 +0,0 @@ -#include <u.h> -#include <libc.h> -#include <bio.h> -#include <ip.h> -#include <plumb.h> -#include <thread.h> -#include <fcall.h> -#include <9p.h> -#include "dat.h" -#include "fns.h" - -void -initibuf(Ibuf *b, Ioproc *io, int fd) -{ - b->fd = fd; - b->io = io; - b->rp = b->wp = b->buf; -} - -int -readibuf(Ibuf *b, char *buf, int len) -{ - int n; - - n = b->wp - b->rp; - if(n > 0){ - if(n > len) - n = len; - memmove(buf, b->rp, n); - b->rp += n; - return n; - } - return ioreadn(b->io, b->fd, buf, len); -} - -void -unreadline(Ibuf *b, char *line) -{ - int i, n; - - i = strlen(line); - n = b->wp - b->rp; - memmove(&b->buf[i+1], b->rp, n); - memmove(b->buf, line, i); - b->buf[i] = '\n'; - b->rp = b->buf; - b->wp = b->rp+i+1+n; -} - -int -readline(Ibuf *b, char *buf, int len) -{ - int n; - char *p; - - len--; - - for(p = buf;;){ - if(b->rp >= b->wp){ - n = ioread(b->io, b->fd, b->wp, sizeof(b->buf)/2); - if(n < 0) - return -1; - if(n == 0) - break; - b->wp += n; - } - n = *b->rp++; - if(len > 0){ - *p++ = n; - len--; - } - if(n == '\n') - break; - } - - /* drop trailing white */ - for(;;){ - if(p <= buf) - break; - n = *(p-1); - if(n != ' ' && n != '\t' && n != '\r' && n != '\n') - break; - p--; - } - - *p = 0; - return p-buf; -} - |