From 39d47d5934a7401320a0c98095cad11e5c8abe52 Mon Sep 17 00:00:00 2001 From: Michael Vrable Date: Wed, 13 Dec 2006 08:44:21 -0800 Subject: [PATCH] Read contents of all regular files processed. --- scandir.cc | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/scandir.cc b/scandir.cc index 64aec8a..4b8f27f 100644 --- a/scandir.cc +++ b/scandir.cc @@ -4,6 +4,7 @@ #include #include #include +#include #include #include #include @@ -22,11 +23,30 @@ void dumpfile(int fd) { struct stat stat_buf; fstat(fd, &stat_buf); + int64_t size = 0; + + char buf[4096]; if ((stat_buf.st_mode & S_IFMT) != S_IFREG) { printf("file is no longer a regular file!\n"); return; } + + while (true) { + ssize_t res = read(fd, buf, sizeof(buf)); + if (res < 0) { + if (errno == EINTR) + continue; + printf("Error while reading: %m\n"); + return; + } else if (res == 0) { + break; + } else { + size += res; + } + } + + printf("Bytes read: %Ld\n", size); } void scanfile(const string& path) -- 2.20.1