summaryrefslogtreecommitdiffstats
path: root/daemon/file.c
diff options
context:
space:
mode:
authorRichard Jones <rjones@redhat.com>2010-01-25 11:34:56 +0000
committerRichard Jones <rjones@redhat.com>2010-01-25 11:37:12 +0000
commit306077ac965cde0a5605782921d33a72bb77c382 (patch)
tree45a64c587a1cf76b44f686f9aa1b039de939fae2 /daemon/file.c
parentc9324c2025b2636cda243b71debcb6c6457c6001 (diff)
downloadlibguestfs-306077ac965cde0a5605782921d33a72bb77c382.tar.gz
libguestfs-306077ac965cde0a5605782921d33a72bb77c382.tar.xz
libguestfs-306077ac965cde0a5605782921d33a72bb77c382.zip
Add 'filesize' call.
Returns the size of a file. You can already do this with 'stat', but this call is good for scripting.
Diffstat (limited to 'daemon/file.c')
-rw-r--r--daemon/file.c18
1 files changed, 18 insertions, 0 deletions
diff --git a/daemon/file.c b/daemon/file.c
index 0b50eebd..839713f6 100644
--- a/daemon/file.c
+++ b/daemon/file.c
@@ -520,3 +520,21 @@ do_zfile (const char *method, const char *path)
return strdup (line);
}
+
+int64_t
+do_filesize (const char *path)
+{
+ int r;
+ struct stat buf;
+
+ CHROOT_IN;
+ r = stat (path, &buf); /* follow symlinks */
+ CHROOT_OUT;
+
+ if (r == -1) {
+ reply_with_perror ("filesize: %s", path);
+ return -1;
+ }
+
+ return buf.st_size;
+}