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 30#ifndef __UUID_H__ 31#define __UUID_H__ 32 33/* workaround conflicts with system headers */ 34#define uuid_t __vendor_uuid_t 35#define uuid_create __vendor_uuid_create 36#define uuid_compare __vendor_uuid_compare 37#include <sys/types.h> 38#include <unistd.h> 39#undef uuid_t 40#undef uuid_create 41#undef uuid_compare 42 43/* required system headers */ 44#include <string.h> 45 46/* minimum C++ support */ 47#ifdef __cplusplus 48#define DECLARATION_BEGIN extern "C" { 49#define DECLARATION_END } 50#else 51#define DECLARATION_BEGIN 52#define DECLARATION_END 53#endif 54 55DECLARATION_BEGIN 56 57/* OSSP uuid version (compile-time information) */ 58#define UUID_VERSION @UUID_VERSION_HEX@ 59 60/* encoding octet stream lengths */ 61#define UUID_LEN_BIN (128 /*bit*/ / 8 /*bytes*/) 62#define UUID_LEN_STR (128 /*bit*/ / 4 /*nibbles*/ + 4 /*hyphens*/) 63#define UUID_LEN_SIV (39 /*int(log(10,exp(2,128)-1)+1) digits*/) 64 65/* API return codes */ 66typedef enum { 67 UUID_RC_OK = 0, /* everything ok */ 68 UUID_RC_ARG = 1, /* invalid argument */ 69 UUID_RC_MEM = 2, /* out of memory */ 70 UUID_RC_SYS = 3, /* system error */ 71 UUID_RC_INT = 4, /* internal error */ 72 UUID_RC_IMP = 5 /* not implemented */ 73} uuid_rc_t; 74 75/* UUID make modes */ 76enum { 77 UUID_MAKE_V1 = (1 << 0), /* DCE 1.1 v1 UUID */ 78 UUID_MAKE_V3 = (1 << 1), /* DCE 1.1 v3 UUID */ 79 UUID_MAKE_V4 = (1 << 2), /* DCE 1.1 v4 UUID */ 80 UUID_MAKE_V5 = (1 << 3), /* DCE 1.1 v5 UUID */ 81 UUID_MAKE_MC = (1 << 4) /* enforce multi-cast MAC address */ 82}; 83 84/* UUID import/export formats */ 85typedef enum { 86 UUID_FMT_BIN = 0, /* binary representation (import/export) */ 87 UUID_FMT_STR = 1, /* string representation (import/export) */ 88 UUID_FMT_SIV = 2, /* single integer value (import/export) */ 89 UUID_FMT_TXT = 3 /* textual description (export only) */ 90} uuid_fmt_t; 91 92/* UUID abstract data type */ 93struct uuid_st; 94typedef struct uuid_st uuid_t; 95 96/* UUID object handling */ 97extern uuid_rc_t uuid_create ( uuid_t **_uuid); 98extern uuid_rc_t uuid_destroy ( uuid_t *_uuid); 99extern uuid_rc_t uuid_clone (const uuid_t *_uuid, uuid_t **_clone); 100 101/* UUID generation */ 102extern uuid_rc_t uuid_load ( uuid_t *_uuid, const char *_name); 103extern uuid_rc_t uuid_make ( uuid_t *_uuid, unsigned int _mode, ...); 104 105/* UUID comparison */ 106extern uuid_rc_t uuid_isnil (const uuid_t *_uuid, int *_result); 107extern uuid_rc_t uuid_compare (const uuid_t *_uuid, const uuid_t *_uuid2, int *_result); 108 109/* UUID import/export */ 110extern uuid_rc_t uuid_import ( uuid_t *_uuid, uuid_fmt_t _fmt, const void *_data_ptr, size_t _data_len); 111extern uuid_rc_t uuid_export (const uuid_t *_uuid, uuid_fmt_t _fmt, void *_data_ptr, size_t *_data_len); 112 113/* library utilities */ 114extern char *uuid_error (uuid_rc_t _rc); 115extern unsigned long uuid_version (void); 116 117DECLARATION_END 118 119#endif /* __UUID_H__ */ 120 121