From ebf3b3ad1795c877c4164b46aab1397237210417 Mon Sep 17 00:00:00 2001 From: Lennart Poettering Date: Sun, 18 Jul 2004 18:47:55 +0000 Subject: add support for file size accounting in --diff git-svn-id: file:///home/lennart/svn/public/syrep/trunk@57 07ea20a6-d2c5-0310-9e02-9ef735347d72 --- src/util.c | 27 ++++++++++++++++++++++++++- 1 file changed, 26 insertions(+), 1 deletion(-) (limited to 'src/util.c') diff --git a/src/util.c b/src/util.c index 97e470f..2d010a0 100644 --- a/src/util.c +++ b/src/util.c @@ -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; + +} -- cgit