s3:utils/smbget improve check of write() result
authorChristian Ambach <ambi@samba.org>
Mon, 8 Feb 2016 22:27:09 +0000 (23:27 +0100)
committerChristian Ambach <ambi@samba.org>
Fri, 26 Feb 2016 10:31:32 +0000 (11:31 +0100)
check that all bytes in the buffer have been written

Signed-off-by: Christian Ambach <ambi@samba.org>
Reviewed-by: Andreas Schneider <asn@samba.org>
source3/utils/smbget.c

index 79574177cf09314b375414333b723fcf0790e665..998761f84821077cf13c16a607c947d8a5c24bcc 100644 (file)
@@ -600,9 +600,10 @@ static bool smb_download_file(const char *base, const char *name,
        /* Now, download all bytes from offset_download to the end */
        for (curpos = offset_download; curpos < remotestat.st_size;
             curpos += opt.blocksize) {
-               ssize_t bytesread = smbc_read(remotehandle,
-                                             readbuf,
-                                             opt.blocksize);
+               ssize_t bytesread;
+               ssize_t byteswritten;
+
+               bytesread = smbc_read(remotehandle, readbuf, opt.blocksize);
                if(bytesread < 0) {
                        fprintf(stderr,
                                "Can't read %zu bytes at offset %jd, file %s\n",
@@ -617,7 +618,8 @@ static bool smb_download_file(const char *base, const char *name,
 
                total_bytes += bytesread;
 
-               if(write(localhandle, readbuf, bytesread) < 0) {
+               byteswritten = write(localhandle, readbuf, bytesread);
+               if (byteswritten != bytesread) {
                        fprintf(stderr,
                                "Can't write %zd bytes to local file %s at "
                                "offset %jd\n", bytesread, path,