diff options
Diffstat (limited to 'src/util.c')
-rw-r--r-- | src/util.c | 27 |
1 files changed, 26 insertions, 1 deletions
@@ -200,7 +200,7 @@ off_t filesize(int fd) { struct stat st; if (fstat(fd, &st) < 0) { - fprintf(stderr, "stat(): %s\n", strerror(errno)); +/* fprintf(stderr, "stat(): %s\n", strerror(errno));*/ return (off_t) -1; } @@ -765,3 +765,28 @@ ssize_t loop_write(int fd, void *d, size_t l) { return p-d; } + +char *snprint_off(char *s, size_t l, off_t off) { + assert(s && l); + + if (args.human_readable_flag && off >= 1024*1024*1024) + snprintf(s, l, "%0.1f GB", (double) off/1024/1024/1024); + else if (args.human_readable_flag && off >= 1024*1024) + snprintf(s, l, "%0.1f MB", (double) off/1024/1024); + else if (args.human_readable_flag && off >= 1024) + snprintf(s, l, "%0.1f KB", (double) off/1024); + else + snprintf(s, l, "%llu", (uint64_t) off); + + return s; +} + +off_t filesize2(const char *p) { + struct stat st; + + if (stat(p, &st) < 0) + return (off_t) -1; + + return st.st_size; + +} |