lib/util: remove the "includes.h" dependeny from util_file.c
[rusty/samba.git] / lib / util / util_file.c
index 7466004e5ce07f175608202d797d23d94f2f2274..e031fc511225563869a93aa537f65550e731dc6a 100644 (file)
  * this program; if not, see <http://www.gnu.org/licenses/>.
  */
 
-#include "includes.h"
+#include "replace.h"
 #include "system/shmem.h"
 #include "system/filesys.h"
-#if _SAMBA_BUILD_ == 3
-#undef malloc
-#undef realloc
-#endif
+#include <talloc.h>
+#include "lib/util/samba_util.h"
+#include "lib/util/debug.h"
 
 /**
  * @file
@@ -235,7 +234,7 @@ _PUBLIC_ void *map_file(const char *fname, size_t size)
        }
 #endif
        if (!p) {
-               p = file_load(fname, &s2, 0, talloc_autofree_context());
+               p = file_load(fname, &s2, 0, NULL);
                if (!p) return NULL;
                if (s2 != size) {
                        DEBUG(1,("incorrect size for %s - got %d expected %d\n",
@@ -435,3 +434,25 @@ _PUBLIC_ bool large_file_support(const char *path)
 }
 
 
+/*
+  compare two files, return true if the two files have the same content
+ */
+bool file_compare(const char *path1, const char *path2)
+{
+       size_t size1, size2;
+       char *p1, *p2;
+       TALLOC_CTX *mem_ctx = talloc_new(NULL);
+
+       p1 = file_load(path1, &size1, 0, mem_ctx);
+       p2 = file_load(path2, &size2, 0, mem_ctx);
+       if (!p1 || !p2 || size1 != size2) {
+               talloc_free(mem_ctx);
+               return false;
+       }
+       if (memcmp(p1, p2, size1) != 0) {
+               talloc_free(mem_ctx);
+               return false;
+       }
+       talloc_free(mem_ctx);
+       return true;
+}