summaryrefslogtreecommitdiff
path: root/lib/libalpm/util.c
diff options
context:
space:
mode:
authorAndrew Fyfe <andrew@neptune-one.net>2007-07-25 22:49:32 +0100
committerDan McGee <dan@archlinux.org>2007-08-16 13:17:33 -0400
commit1cb6d80631359306d70bbe5fbcbbca1474594ada (patch)
tree61348cf98beac7febbe0558a353f2cec46930315 /lib/libalpm/util.c
parentba67fdae63122b40d8fb4abf9c1c7695999f143d (diff)
downloadpacman-1cb6d80631359306d70bbe5fbcbbca1474594ada.tar.xz
Clean up MD5 code.
* Move alpm md5 functions to lib/libalpm/util.c * Remove unneeded includes for md5.h * Replace md5 implementation with one from http://www.xyssl.org Dan: clean up XySSL code by removing parts we don't use, and add a note saying what changed. Dan: fix alpm_get_md5sum, off by one error on the malloc call and other small things. Signed-off-by: Andrew Fyfe <andrew@neptune-one.net> Signed-off-by: Dan McGee <dan@archlinux.org>
Diffstat (limited to 'lib/libalpm/util.c')
-rw-r--r--lib/libalpm/util.c42
1 files changed, 42 insertions, 0 deletions
diff --git a/lib/libalpm/util.c b/lib/libalpm/util.c
index ddc3edcc..5f431171 100644
--- a/lib/libalpm/util.c
+++ b/lib/libalpm/util.c
@@ -48,6 +48,7 @@
#include "error.h"
#include "package.h"
#include "alpm.h"
+#include "md5.h"
#ifndef HAVE_STRVERSCMP
/* GNU's strverscmp() function, taken from glibc 2.3.2 sources
@@ -541,5 +542,46 @@ int _alpm_str_cmp(const void *s1, const void *s2)
return(strcmp(s1, s2));
}
+/** Get the md5 sum of file.
+ * @param filename name of the file
+ * @return the checksum on success, NULL on error
+ * @addtogroup alpm_misc
+ */
+char SYMEXPORT *alpm_get_md5sum(char *filename)
+{
+ unsigned char output[16];
+ char *md5sum;
+ int ret, i;
+
+ ALPM_LOG_FUNC;
+
+ ASSERT(filename != NULL, return(NULL));
+
+ /* allocate 32 chars plus 1 for null */
+ md5sum = calloc(33, sizeof(char));
+ ret = md5_file(filename, output);
+
+ if (ret > 0) {
+ if (ret == 1) {
+ _alpm_log(PM_LOG_ERROR, _("md5: %s can't be opened\n"), filename);
+ } else if (ret == 2) {
+ _alpm_log(PM_LOG_ERROR, _("md5: %s can't be read\n"), filename);
+ }
+
+ return(NULL);
+ }
+
+ /* Convert the result to something readable */
+ for (i = 0; i < 16; i++) {
+ /* sprintf is acceptable here because we know our output */
+ sprintf(md5sum +(i * 2), "%02x", output[i]);
+ }
+ md5sum[32] = '\0';
+
+ _alpm_log(PM_LOG_DEBUG, "md5(%s) = %s", filename, md5sum);
+ return(md5sum);
+}
+
+
/* vim: set ts=2 sw=2 noet: */