uuid.h 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120
  1. /*
  2. ** OSSP uuid - Universally Unique Identifier
  3. ** Copyright (c) 2004-2008 Ralf S. Engelschall <rse@engelschall.com>
  4. ** Copyright (c) 2004-2008 The OSSP Project <http://www.ossp.org/>
  5. **
  6. ** This file is part of OSSP uuid, a library for the generation
  7. ** of UUIDs which can found at http://www.ossp.org/pkg/lib/uuid/
  8. **
  9. ** Permission to use, copy, modify, and distribute this software for
  10. ** any purpose with or without fee is hereby granted, provided that
  11. ** the above copyright notice and this permission notice appear in all
  12. ** copies.
  13. **
  14. ** THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
  15. ** WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
  16. ** MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
  17. ** IN NO EVENT SHALL THE AUTHORS AND COPYRIGHT HOLDERS AND THEIR
  18. ** CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
  19. ** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
  20. ** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
  21. ** USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
  22. ** ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
  23. ** OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
  24. ** OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
  25. ** SUCH DAMAGE.
  26. **
  27. ** uuid.h: library API definition
  28. */
  29. #ifndef __UUID_H__
  30. #define __UUID_H__
  31. /* workaround conflicts with system headers */
  32. #define uuid_t __vendor_uuid_t
  33. #define uuid_create __vendor_uuid_create
  34. #define uuid_compare __vendor_uuid_compare
  35. #include <sys/types.h>
  36. #include <unistd.h>
  37. #undef uuid_t
  38. #undef uuid_create
  39. #undef uuid_compare
  40. /* required system headers */
  41. #include <string.h>
  42. /* minimum C++ support */
  43. #ifdef __cplusplus
  44. #define DECLARATION_BEGIN extern "C" {
  45. #define DECLARATION_END }
  46. #else
  47. #define DECLARATION_BEGIN
  48. #define DECLARATION_END
  49. #endif
  50. DECLARATION_BEGIN
  51. /* OSSP uuid version (compile-time information) */
  52. #define UUID_VERSION 0x106202
  53. /* encoding octet stream lengths */
  54. #define UUID_LEN_BIN (128 /*bit*/ / 8 /*bytes*/)
  55. #define UUID_LEN_STR (128 /*bit*/ / 4 /*nibbles*/ + 4 /*hyphens*/)
  56. #define UUID_LEN_SIV (39 /*int(log(10,exp(2,128)-1)+1) digits*/)
  57. /* API return codes */
  58. typedef enum {
  59. UUID_RC_OK = 0, /* everything ok */
  60. UUID_RC_ARG = 1, /* invalid argument */
  61. UUID_RC_MEM = 2, /* out of memory */
  62. UUID_RC_SYS = 3, /* system error */
  63. UUID_RC_INT = 4, /* internal error */
  64. UUID_RC_IMP = 5 /* not implemented */
  65. } uuid_rc_t;
  66. /* UUID make modes */
  67. enum {
  68. UUID_MAKE_V1 = (1 << 0), /* DCE 1.1 v1 UUID */
  69. UUID_MAKE_V3 = (1 << 1), /* DCE 1.1 v3 UUID */
  70. UUID_MAKE_V4 = (1 << 2), /* DCE 1.1 v4 UUID */
  71. UUID_MAKE_V5 = (1 << 3), /* DCE 1.1 v5 UUID */
  72. UUID_MAKE_MC = (1 << 4) /* enforce multi-cast MAC address */
  73. };
  74. /* UUID import/export formats */
  75. typedef enum {
  76. UUID_FMT_BIN = 0, /* binary representation (import/export) */
  77. UUID_FMT_STR = 1, /* string representation (import/export) */
  78. UUID_FMT_SIV = 2, /* single integer value (import/export) */
  79. UUID_FMT_TXT = 3 /* textual description (export only) */
  80. } uuid_fmt_t;
  81. /* UUID abstract data type */
  82. struct uuid_st;
  83. typedef struct uuid_st uuid_t;
  84. /* UUID object handling */
  85. extern uuid_rc_t uuid_create ( uuid_t **_uuid);
  86. extern uuid_rc_t uuid_destroy ( uuid_t *_uuid);
  87. extern uuid_rc_t uuid_clone (const uuid_t *_uuid, uuid_t **_clone);
  88. /* UUID generation */
  89. extern uuid_rc_t uuid_load ( uuid_t *_uuid, const char *_name);
  90. extern uuid_rc_t uuid_make ( uuid_t *_uuid, unsigned int _mode, ...);
  91. /* UUID comparison */
  92. extern uuid_rc_t uuid_isnil (const uuid_t *_uuid, int *_result);
  93. extern uuid_rc_t uuid_compare (const uuid_t *_uuid, const uuid_t *_uuid2, int *_result);
  94. /* UUID import/export */
  95. extern uuid_rc_t uuid_import ( uuid_t *_uuid, uuid_fmt_t _fmt, const void *_data_ptr, size_t _data_len);
  96. extern uuid_rc_t uuid_export (const uuid_t *_uuid, uuid_fmt_t _fmt, void *_data_ptr, size_t *_data_len);
  97. /* library utilities */
  98. extern char *uuid_error (uuid_rc_t _rc);
  99. extern unsigned long uuid_version (void);
  100. DECLARATION_END
  101. #endif /* __UUID_H__ */