X-Git-Url: http://git.annexia.org/?a=blobdiff_plain;f=daemon%2Fchecksum.c;h=8533ccc324e0d80b32a66f44b2925ac12b3814ed;hb=ab7f296b63280d183b6574c896cab6d6cafb660a;hp=499d19db9c33857ff74e7c4e9d75dbb1c61a31d9;hpb=9353c6253d5fac1648b13ad9958468a2d9f6ad6f;p=libguestfs.git diff --git a/daemon/checksum.c b/daemon/checksum.c index 499d19d..8533ccc 100644 --- a/daemon/checksum.c +++ b/daemon/checksum.c @@ -27,33 +27,41 @@ #include "daemon.h" #include "actions.h" -char * -do_checksum (const char *csumtype, const char *path) +static const char * +program_of_csum (const char *csumtype) { - const char *program; - char *buf; - char *out, *err; - int r; - int len; - if (STRCASEEQ (csumtype, "crc")) - program = "cksum"; + return "cksum"; else if (STRCASEEQ (csumtype, "md5")) - program = "md5sum"; + return "md5sum"; else if (STRCASEEQ (csumtype, "sha1")) - program = "sha1sum"; + return "sha1sum"; else if (STRCASEEQ (csumtype, "sha224")) - program = "sha224sum"; + return "sha224sum"; else if (STRCASEEQ (csumtype, "sha256")) - program = "sha256sum"; + return "sha256sum"; else if (STRCASEEQ (csumtype, "sha384")) - program = "sha384sum"; + return "sha384sum"; else if (STRCASEEQ (csumtype, "sha512")) - program = "sha512sum"; + return "sha512sum"; else { reply_with_error ("unknown checksum type, expecting crc|md5|sha1|sha224|sha256|sha384|sha512"); return NULL; } +} + +char * +do_checksum (const char *csumtype, const char *path) +{ + const char *program; + char *buf; + char *out, *err; + int r; + int len; + + program = program_of_csum (csumtype); + if (program == NULL) + return NULL; /* Make the path relative to /sysroot. */ buf = sysroot_path (path);