util: added sbuf_read() to allow reading from FD straight into sbuf

This commit is contained in:
Adam Sutton 2014-04-10 20:12:25 +01:00
parent e5383315a3
commit 279e7cbfea
2 changed files with 11 additions and 0 deletions

View file

@ -620,6 +620,8 @@ void sbuf_put_be16(sbuf_t *sb, uint16_t u16);
void sbuf_put_byte(sbuf_t *sb, uint8_t u8);
ssize_t sbuf_read(sbuf_t *sb, int fd);
char *md5sum ( const char *str );
int makedirs ( const char *path, int mode );

View file

@ -364,6 +364,15 @@ sbuf_cut(sbuf_t *sb, int off)
memmove(sb->sb_data, sb->sb_data + off, sb->sb_ptr);
}
ssize_t
sbuf_read(sbuf_t *sb, int fd)
{
ssize_t n = read(fd, sb->sb_data + sb->sb_ptr, sb->sb_size - sb->sb_ptr);
if (n > 0)
sb->sb_ptr += n;
return n;
}
char *
md5sum ( const char *str )
{