tools: add progress implementation

Signed-off-by: Patrick Venture <venture@google.com>
Change-Id: I9da1674d6cbc688efc7bab0e033788d6ee4694f7
diff --git a/internal/sys.cpp b/internal/sys.cpp
index 46c6642..2e040ae 100644
--- a/internal/sys.cpp
+++ b/internal/sys.cpp
@@ -19,11 +19,27 @@
 #include <fcntl.h>
 #include <sys/ioctl.h>
 #include <sys/mman.h>
+#include <sys/stat.h>
+#include <sys/types.h>
 #include <unistd.h>
 
+#include <cstdint>
+
 namespace internal
 {
 
+std::int64_t SysImpl::getSize(const char* pathname) const
+{
+    struct stat results;
+    int rc = ::stat(pathname, &results);
+    if (rc)
+    {
+        return 0;
+    }
+
+    return static_cast<std::int64_t>(results.st_size);
+}
+
 int SysImpl::open(const char* pathname, int flags) const
 {
     return ::open(pathname, flags);
diff --git a/internal/sys.hpp b/internal/sys.hpp
index 2975b8c..265d251 100644
--- a/internal/sys.hpp
+++ b/internal/sys.hpp
@@ -12,6 +12,7 @@
 
 #include <cinttypes>
 #include <cstddef>
+#include <cstdint>
 
 namespace internal
 {
@@ -34,6 +35,7 @@
     virtual int getpagesize() const = 0;
     virtual int ioctl(int fd, unsigned long request, void* param) const = 0;
     virtual int poll(struct pollfd* fds, nfds_t nfds, int timeout) const = 0;
+    virtual std::int64_t getSize(const char* pathname) const = 0;
 };
 
 /**
@@ -53,6 +55,8 @@
     int getpagesize() const override;
     int ioctl(int fd, unsigned long request, void* param) const override;
     int poll(struct pollfd* fds, nfds_t nfds, int timeout) const override;
+    /* returns 0 on failure, or if the file is zero bytes. */
+    std::int64_t getSize(const char* pathname) const override;
 };
 
 /** @brief Default instantiation of sys */