libopkg: make MD5 support optional
[oweals/opkg-lede.git] / libopkg / file_util.c
index f5519c85d58a3cb685481e0db757ef39feaa2a8a..c54903c30b66907d126cd6ebb5ed0b58759e0f34 100644 (file)
@@ -1,7 +1,8 @@
 /* file_util.c - convenience routines for common stat operations
 
-   Carl D. Worth
+   Copyright (C) 2009 Ubiq Technologies <graham.gower@gmail.com>
 
+   Carl D. Worth
    Copyright (C) 2001 University of Southern California
 
    This program is free software; you can redistribute it and/or
    General Public License for more details.
 */
 
-#include "includes.h"
+#include "config.h"
+
+#include <stdio.h>
 #include <sys/types.h>
 #include <sys/stat.h>
 #include <dirent.h>
+#include <unistd.h>
 
 #include "sprintf_alloc.h"
 #include "file_util.h"
+#ifdef HAVE_MD5
 #include "md5.h"
+#endif
 #include "libbb/libbb.h"
-#undef strlen
 
 #if defined HAVE_SHA256
 #include "sha256.h"
@@ -132,6 +137,7 @@ file_mkdir_hier(const char *path, long mode)
        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;
@@ -172,11 +178,12 @@ char *file_md5sum_alloc(const char *file_name)
        md5sum_hex[i*2] = bin2hex[md5sum_bin[i] >> 4];
        md5sum_hex[i*2+1] = bin2hex[md5sum_bin[i] & 0xf];
     }
-    
+
     md5sum_hex[md5sum_hex_len] = '\0';
-    
+
     return md5sum_hex;
 }
+#endif
 
 #ifdef HAVE_SHA256
 char *file_sha256sum_alloc(const char *file_name)
@@ -219,9 +226,9 @@ char *file_sha256sum_alloc(const char *file_name)
        sha256sum_hex[i*2] = bin2hex[sha256sum_bin[i] >> 4];
        sha256sum_hex[i*2+1] = bin2hex[sha256sum_bin[i] & 0xf];
     }
-    
+
     sha256sum_hex[sha256sum_hex_len] = '\0';
-    
+
     return sha256sum_hex;
 }
 
@@ -235,6 +242,11 @@ rm_r(const char *path)
        DIR *dir;
        struct dirent *dent;
 
+       if (path == NULL) {
+               opkg_perror(ERROR, "Missing directory parameter");
+               return -1;
+       }
+
        dir = opendir(path);
        if (dir == NULL) {
                opkg_perror(ERROR, "Failed to open dir %s", path);