diff options
author | Volker Lendecke <vl@samba.org> | 2008-10-23 15:43:36 +0200 |
---|---|---|
committer | Volker Lendecke <vl@samba.org> | 2008-10-23 17:45:52 +0200 |
commit | 3f0406f609899e88f15f90688c0e49beadc72568 (patch) | |
tree | 81d96c45aa71e7980fb9cecdd07c410a5996878c | |
parent | db65c3374ad337135a7bd4d67abced258c01c5bd (diff) | |
download | samba-3f0406f609899e88f15f90688c0e49beadc72568.tar.gz samba-3f0406f609899e88f15f90688c0e49beadc72568.tar.bz2 samba-3f0406f609899e88f15f90688c0e49beadc72568.zip |
Optimize x_fread to speed up the smbclient put command
-rw-r--r-- | lib/util/xfile.c | 25 |
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; } |