From: Michael Vrable Date: Wed, 13 Dec 2006 16:44:21 +0000 (-0800) Subject: Read contents of all regular files processed. X-Git-Url: https://git.vrable.net/?a=commitdiff_plain;h=39d47d5934a7401320a0c98095cad11e5c8abe52;p=cumulus.git Read contents of all regular files processed. --- 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)