summaryrefslogtreecommitdiff
path: root/lib/util/xfile.c
diff options
context:
space:
mode:
authorJelmer Vernooij <jelmer@samba.org>2008-10-23 18:04:16 +0200
committerJelmer Vernooij <jelmer@samba.org>2008-10-23 18:04:16 +0200
commitd70efa57ceae1011a6a55d57d0152fd1bc2bb192 (patch)
tree92ee7a3f33ea51f34a33fee094eaed651215a3d3 /lib/util/xfile.c
parent2f265feb174de1f743e8102ad34b3bdbcd2897cc (diff)
parentd805c714bb79a709716ec0373670283bfcd23c3c (diff)
downloadsamba-d70efa57ceae1011a6a55d57d0152fd1bc2bb192.tar.gz
samba-d70efa57ceae1011a6a55d57d0152fd1bc2bb192.tar.bz2
samba-d70efa57ceae1011a6a55d57d0152fd1bc2bb192.zip
Merge branch 'master' of git://git.samba.org/samba
Conflicts: lib/util/asn1_proto.h
Diffstat (limited to 'lib/util/xfile.c')
-rw-r--r--lib/util/xfile.c25
1 files changed, 20 insertions, 5 deletions
diff --git a/lib/util/xfile.c b/lib/util/xfile.c
index 94b0ee9b18..cf195706db 100644
--- a/lib/util/xfile.c
+++ b/lib/util/xfile.c
@@ -329,12 +329,27 @@ int x_fgetc(XFILE *f)
/** simulate fread */
size_t x_fread(void *p, size_t size, size_t nmemb, XFILE *f)
{
+ size_t remaining = size * nmemb;
size_t total = 0;
- while (total < size*nmemb) {
- int c = x_fgetc(f);
- if (c == EOF) break;
- (total+(char *)p)[0] = (char)c;
- total++;
+
+ while (remaining > 0) {
+ size_t thistime;
+
+ x_fillbuf(f);
+
+ if (f->bufused == 0) {
+ f->flags |= X_FLAG_EOF;
+ break;
+ }
+
+ thistime = MIN(f->bufused, remaining);
+
+ memcpy((char *)p+total, f->next, thistime);
+
+ f->next += thistime;
+ f->bufused -= thistime;
+ remaining -= thistime;
+ total += thistime;
}
return total/size;
}