summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorcinap_lenrek <cinap_lenrek@centraldogma>2011-10-06 00:39:05 +0200
committercinap_lenrek <cinap_lenrek@centraldogma>2011-10-06 00:39:05 +0200
commitc0c9a9927f413e70f59158a10c460b1927985f44 (patch)
tree8455dbc351cf7c3536f21027a1ab56c407d585cc
parent7e744bda2bfe0c664890b0f844591793fb08c976 (diff)
libbio: add Breadn
-rw-r--r--sys/include/bio.h1
-rw-r--r--sys/man/2/bio12
-rw-r--r--sys/src/libbio/breadn.c26
-rw-r--r--sys/src/libbio/mkfile1
4 files changed, 39 insertions, 1 deletions
diff --git a/sys/include/bio.h b/sys/include/bio.h
index f358c962c..fabc2b7c8 100644
--- a/sys/include/bio.h
+++ b/sys/include/bio.h
@@ -66,6 +66,7 @@ int Bputrune(Biobufhdr*, long);
void* Brdline(Biobufhdr*, int);
char* Brdstr(Biobufhdr*, int, int);
long Bread(Biobufhdr*, void*, long);
+long Breadn(Biobufhdr*, void*, long);
vlong Bseek(Biobufhdr*, vlong, int);
int Bterm(Biobufhdr*);
int Bungetc(Biobufhdr*);
diff --git a/sys/man/2/bio b/sys/man/2/bio
index a059f1cf4..ebb17c840 100644
--- a/sys/man/2/bio
+++ b/sys/man/2/bio
@@ -1,6 +1,6 @@
.TH BIO 2
.SH NAME
-Bopen, Binit, Binits, Brdline, Brdstr, Bgetc, Bgetrune, Bgetd, Bungetc, Bungetrune, Bread, Bseek, Boffset, Bfildes, Blinelen, Bputc, Bputrune, Bprint, Bvprint, Bwrite, Bflush, Bterm, Bbuffered, Blethal \- buffered input/output
+Bopen, Binit, Binits, Brdline, Brdstr, Bgetc, Bgetrune, Bgetd, Bungetc, Bungetrune, Bread, Breadn, Bseek, Boffset, Bfildes, Blinelen, Bputc, Bputrune, Bprint, Bvprint, Bwrite, Bflush, Bterm, Bbuffered, Blethal \- buffered input/output
.SH SYNOPSIS
.ta \w'Biobuf* 'u
.B #include <u.h>
@@ -70,6 +70,9 @@ int Bputrune(Biobufhdr *bp, long c)
long Bread(Biobufhdr *bp, void *addr, long nbytes)
.PP
.B
+long Breadn(Biobufhdr *bp, void *addr, long nbytes)
+.PP
+.B
long Bwrite(Biobufhdr *bp, void *addr, long nbytes)
.PP
.B
@@ -236,6 +239,13 @@ into memory starting at
The number of bytes read is returned on success
and a negative value is returned if a read error occurred.
.PP
+.I Breadn
+is like
+.I Bread
+but continues reading until
+.I nbytes
+have been read into the buffer.
+.PP
.I Bseek
applies
.IR seek (2)
diff --git a/sys/src/libbio/breadn.c b/sys/src/libbio/breadn.c
new file mode 100644
index 000000000..fa335873f
--- /dev/null
+++ b/sys/src/libbio/breadn.c
@@ -0,0 +1,26 @@
+#include <u.h>
+#include <libc.h>
+#include <bio.h>
+
+long
+Breadn(Biobufhdr *bp, void *data, long len)
+{
+ char *e, *p;
+ int n;
+
+ p = data;
+ e = p + len;
+ if(e < p){
+ Berror(bp, "invalid read length");
+ return -1;
+ }
+ while(p < e){
+ if((n = Bread(bp, p, e - p)) <= 0){
+ if(n < 0 && p == data)
+ return -1;
+ break;
+ }
+ p += n;
+ }
+ return p - (char*)data;
+}
diff --git a/sys/src/libbio/mkfile b/sys/src/libbio/mkfile
index 3b40fd25c..cae6e4850 100644
--- a/sys/src/libbio/mkfile
+++ b/sys/src/libbio/mkfile
@@ -17,6 +17,7 @@ OFILES=\
brdline.$O\
brdstr.$O\
bread.$O\
+ breadn.$O\
bseek.$O\
bwrite.$O\
bvprint.$O\