X-Git-Url: http://git.annexia.org/?a=blobdiff_plain;f=daemon%2Ffile.c;h=839713f66bf418737f0a761fbfff21f0f399d6ba;hb=09d988e8f1cfa42ef9a5abe5c9c151962aa1d2cc;hp=7854adef9d2b58643df49e60de3cde243a70879f;hpb=90cf7fc904fca42665fe04cdd90a4c547d23b00c;p=libguestfs.git diff --git a/daemon/file.c b/daemon/file.c index 7854ade..839713f 100644 --- a/daemon/file.c +++ b/daemon/file.c @@ -44,11 +44,7 @@ do_touch (const char *path) return -1; } -#ifdef HAVE_FUTIMENS r = futimens (fd, NULL); -#else - r = futimes (fd, NULL); -#endif if (r == -1) { reply_with_perror ("futimens: %s", path); close (fd); @@ -430,7 +426,7 @@ do_file (const char *path) char *buf; int len; - if (strncmp (path, "/dev/", 5) == 0) + if (STREQLEN (path, "/dev/", 5)) buf = (char *) path; else { buf = sysroot_path (path); @@ -481,9 +477,9 @@ do_zfile (const char *method, const char *path) FILE *fp; char line[256]; - if (strcmp (method, "gzip") == 0 || strcmp (method, "compress") == 0) + if (STREQ (method, "gzip") || STREQ (method, "compress")) zcat = "zcat"; - else if (strcmp (method, "bzip2") == 0) + else if (STREQ (method, "bzip2")) zcat = "bzcat"; else { reply_with_error ("zfile: unknown method"); @@ -524,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; +}