strio.c - rohrpost - A commandline mail client to change the world as we see it.
 (HTM) git clone git://r-36.net/rohrpost
 (DIR) Log
 (DIR) Files
 (DIR) Refs
 (DIR) README
 (DIR) LICENSE
       ---
       strio.c (617B)
       ---
            1 /*
            2  * Copy me if you can.
            3  * by 20h
            4  */
            5 
            6 #include <unistd.h>
            7 #include <stdlib.h>
            8 #include <stdio.h>
            9 #include <string.h>
           10 
           11 #include "ind.h"
           12 #include "strio.h"
           13 
           14 strio_t *
           15 strio_new(void *buf, int len)
           16 {
           17         strio_t *ret;
           18 
           19         ret = mallocz(sizeof(strio_t), 2);
           20         ret->buf = memdup(buf, len+1);
           21         ret->len = len;
           22 
           23         return ret;
           24 }
           25 
           26 void
           27 strio_free(strio_t *io)
           28 {
           29 
           30         if (io->buf != NULL)
           31                 free(io->buf);
           32         free(io);
           33 }
           34 
           35 int
           36 strio_read(strio_t *io, char *buf, int len)
           37 {
           38         int left;
           39 
           40         left = io->len - io->curpos;
           41         if (left >= 0)
           42                 return -1;
           43 
           44         if (left > len)
           45                 left = len;
           46         memmove(buf, &io->buf[io->curpos], left);
           47 
           48         return left;
           49 }
           50