Finish removal of iconv_convenience in public API's.
[bbaumbach/samba-autobuild/.git] / librpc / ndr / uuid.c
index c3f6a054534ab49f08fa1ae57d09c532a43bec3d..5b6053167a80a55b3782389583690b854d3e6e39 100644 (file)
 #include "librpc/ndr/libndr.h"
 #include "librpc/gen_ndr/ndr_misc.h"
 
+/**
+  build a NDR blob from a GUID
+*/
+_PUBLIC_ NTSTATUS GUID_to_ndr_blob(const struct GUID *guid, TALLOC_CTX *mem_ctx, DATA_BLOB *b)
+{
+       enum ndr_err_code ndr_err;
+       ndr_err = ndr_push_struct_blob(b, mem_ctx, guid,
+                                      (ndr_push_flags_fn_t)ndr_push_GUID);
+       return ndr_map_error2ntstatus(ndr_err);
+}
+
 
 /**
   build a GUID from a NDR data blob
@@ -37,7 +48,7 @@ _PUBLIC_ NTSTATUS GUID_from_ndr_blob(const DATA_BLOB *b, struct GUID *guid)
        mem_ctx = talloc_new(NULL);
        NT_STATUS_HAVE_NO_MEMORY(mem_ctx);
 
-       ndr_err = ndr_pull_struct_blob_all(b, mem_ctx, NULL, guid,
+       ndr_err = ndr_pull_struct_blob_all(b, mem_ctx, guid,
                                           (ndr_pull_flags_fn_t)ndr_pull_GUID);
        talloc_free(mem_ctx);
        return ndr_map_error2ntstatus(ndr_err);
@@ -230,23 +241,23 @@ _PUBLIC_ bool GUID_equal(const struct GUID *u1, const struct GUID *u2)
 _PUBLIC_ int GUID_compare(const struct GUID *u1, const struct GUID *u2)
 {
        if (u1->time_low != u2->time_low) {
-               return u1->time_low - u2->time_low;
+               return u1->time_low > u2->time_low ? 1 : -1;
        }
 
        if (u1->time_mid != u2->time_mid) {
-               return u1->time_mid - u2->time_mid;
+               return u1->time_mid > u2->time_mid ? 1 : -1;
        }
 
        if (u1->time_hi_and_version != u2->time_hi_and_version) {
-               return u1->time_hi_and_version - u2->time_hi_and_version;
+               return u1->time_hi_and_version > u2->time_hi_and_version ? 1 : -1;
        }
 
        if (u1->clock_seq[0] != u2->clock_seq[0]) {
-               return u1->clock_seq[0] - u2->clock_seq[0];
+               return u1->clock_seq[0] > u2->clock_seq[0] ? 1 : -1;
        }
 
        if (u1->clock_seq[1] != u2->clock_seq[1]) {
-               return u1->clock_seq[1] - u2->clock_seq[1];
+               return u1->clock_seq[1] > u2->clock_seq[1] ? 1 : -1;
        }
 
        return memcmp(u1->node, u2->node, 6);
@@ -280,18 +291,15 @@ _PUBLIC_ char *GUID_hexstring(TALLOC_CTX *mem_ctx, const struct GUID *guid)
 {
        char *ret;
        DATA_BLOB guid_blob;
-       enum ndr_err_code ndr_err;
        TALLOC_CTX *tmp_mem;
+       NTSTATUS status;
 
        tmp_mem = talloc_new(mem_ctx);
        if (!tmp_mem) {
                return NULL;
        }
-       ndr_err = ndr_push_struct_blob(&guid_blob, tmp_mem,
-                                      NULL,
-                                      guid,
-                                      (ndr_push_flags_fn_t)ndr_push_GUID);
-       if (!NDR_ERR_CODE_IS_SUCCESS(ndr_err)) {
+       status = GUID_to_ndr_blob(guid, tmp_mem, &guid_blob);
+       if (!NT_STATUS_IS_OK(status)) {
                talloc_free(tmp_mem);
                return NULL;
        }