#include "sprintf_alloc.h"
#include "file_util.h"
-#ifdef HAVE_MD5
-#include "md5.h"
-#endif
+#include <libubox/md5.h>
#include "libbb/libbb.h"
-#if defined HAVE_SHA256
#include "sha256.h"
-#endif
int file_exists(const char *file_name)
{
return make_directory(path, mode, FILEUTILS_RECUR);
}
-#ifdef HAVE_MD5
char *file_md5sum_alloc(const char *file_name)
{
static const int md5sum_bin_len = 16;
'c', 'd', 'e', 'f'
};
- int i, err;
- FILE *file;
+ int i, len;
char *md5sum_hex;
unsigned char md5sum_bin[md5sum_bin_len];
- md5sum_hex = xcalloc(1, md5sum_hex_len + 1);
-
- file = fopen(file_name, "r");
- if (file == NULL) {
- opkg_perror(ERROR, "Failed to open file %s", file_name);
- free(md5sum_hex);
- return NULL;
- }
+ len = md5sum(file_name, md5sum_bin);
- err = md5_stream(file, md5sum_bin);
- if (err) {
+ if (len) {
opkg_msg(ERROR, "Could't compute md5sum for %s.\n", file_name);
- fclose(file);
- free(md5sum_hex);
return NULL;
}
- fclose(file);
+ md5sum_hex = xcalloc(1, md5sum_hex_len + 1);
for (i = 0; i < md5sum_bin_len; i++) {
md5sum_hex[i * 2] = bin2hex[md5sum_bin[i] >> 4];
return md5sum_hex;
}
-#endif
-#ifdef HAVE_SHA256
char *file_sha256sum_alloc(const char *file_name)
{
static const int sha256sum_bin_len = 32;
return sha256sum_hex;
}
-#endif
-
char *checksum_bin2hex(const char *src, size_t len)
{
unsigned char *p;