3
0

compare.c 2.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455
  1. /* vi: set sw=4 ts=4: */
  2. /*
  3. * compare.c --- compare whether or not two UUID's are the same
  4. *
  5. * Returns 0 if the two UUID's are different, and 1 if they are the same.
  6. *
  7. * Copyright (C) 1996, 1997 Theodore Ts'o.
  8. *
  9. * %Begin-Header%
  10. * Redistribution and use in source and binary forms, with or without
  11. * modification, are permitted provided that the following conditions
  12. * are met:
  13. * 1. Redistributions of source code must retain the above copyright
  14. * notice, and the entire permission notice in its entirety,
  15. * including the disclaimer of warranties.
  16. * 2. Redistributions in binary form must reproduce the above copyright
  17. * notice, this list of conditions and the following disclaimer in the
  18. * documentation and/or other materials provided with the distribution.
  19. * 3. The name of the author may not be used to endorse or promote
  20. * products derived from this software without specific prior
  21. * written permission.
  22. *
  23. * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESS OR IMPLIED
  24. * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
  25. * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE, ALL OF
  26. * WHICH ARE HEREBY DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE
  27. * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
  28. * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT
  29. * OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR
  30. * BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
  31. * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
  32. * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE
  33. * USE OF THIS SOFTWARE, EVEN IF NOT ADVISED OF THE POSSIBILITY OF SUCH
  34. * DAMAGE.
  35. * %End-Header%
  36. */
  37. #include "uuidP.h"
  38. #include <string.h>
  39. #define UUCMP(u1,u2) if (u1 != u2) return (u1 < u2) ? -1 : 1;
  40. int uuid_compare(const uuid_t uu1, const uuid_t uu2)
  41. {
  42. struct uuid uuid1, uuid2;
  43. uuid_unpack(uu1, &uuid1);
  44. uuid_unpack(uu2, &uuid2);
  45. UUCMP(uuid1.time_low, uuid2.time_low);
  46. UUCMP(uuid1.time_mid, uuid2.time_mid);
  47. UUCMP(uuid1.time_hi_and_version, uuid2.time_hi_and_version);
  48. UUCMP(uuid1.clock_seq, uuid2.clock_seq);
  49. return memcmp(uuid1.node, uuid2.node, 6);
  50. }