summaryrefslogtreecommitdiffstats
path: root/src/util.c
diff options
context:
space:
mode:
authorLennart Poettering <lennart@poettering.net>2004-07-18 18:47:55 +0000
committerLennart Poettering <lennart@poettering.net>2004-07-18 18:47:55 +0000
commitebf3b3ad1795c877c4164b46aab1397237210417 (patch)
tree28104ccf5c0352a804ef6de3b16bb199d547e1af /src/util.c
parent90c80089c6d6e2d7fe9680e567d8241806d7de9e (diff)
add support for file size accounting in --diff
git-svn-id: file:///home/lennart/svn/public/syrep/trunk@57 07ea20a6-d2c5-0310-9e02-9ef735347d72
Diffstat (limited to 'src/util.c')
-rw-r--r--src/util.c27
1 files changed, 26 insertions, 1 deletions
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;
+
+}