Write the total number of bytes copied by nfs-cp, not just the last block written.
[deb_libnfs.git] / examples / nfs-cp.c
index 53e22d60209db560fa555fc1b1d09c4a1f663741..bedc9bb9ab525be3115ce72bdf1e65ab930e0624 100644 (file)
@@ -29,6 +29,8 @@
 
 #ifdef WIN32
 #include "win32_compat.h"
+#pragma comment(lib, "ws2_32.lib")
+WSADATA wsaData;
 #else
 #include <sys/stat.h>
 #include <string.h>
@@ -96,7 +98,8 @@ static int64_t
 file_pread(struct file_context *fc, char *buf, int64_t count, uint64_t off)
 {
        if (fc->is_nfs == 0) {
-               return pread(fc->fd, buf, count, off);
+               lseek(fc->fd, off, SEEK_SET);
+               return read(fc->fd, buf, count);
        } else {
                return nfs_pread(fc->nfs, fc->nfsfh, off, count, buf);
        }
@@ -106,7 +109,8 @@ static int64_t
 file_pwrite(struct file_context *fc, char *buf, int64_t count, uint64_t off)
 {
        if (fc->is_nfs == 0) {
-               return pwrite(fc->fd, buf, count, off);
+               lseek(fc->fd, off, SEEK_SET);
+               return write(fc->fd, buf, count);
        } else {
                return nfs_pwrite(fc->nfs, fc->nfsfh, off, count, buf);
        }
@@ -293,7 +297,7 @@ int main(int argc, char *argv[])
 
                off += count;
        }
-       printf("copied %d bytes\n", (int)count);
+       printf("copied %d bytes\n", (int)off);
 
        free_file_context(src);
        free_file_context(dst);