Fix bug 5969: Optimize smbclient put command
authorVolker Lendecke <vl@samba.org>
Mon, 15 Dec 2008 11:46:04 +0000 (12:46 +0100)
committerVolker Lendecke <vl@samba.org>
Mon, 15 Dec 2008 11:46:27 +0000 (12:46 +0100)
This used to be checkin 3f0406f6 to master

source/lib/xfile.c

index e44a92d34dcb79b83f90c6bde687839cc2d90d39..aba49b690bb90dca8f9729df224f14fb5b3d2c32 100644 (file)
@@ -354,12 +354,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;
 }