Пример реализации
D.1 Описание файлов
Данная реализация состоит из шести файлов: copyrt.h, uuid.h, uuid.c, sysdep.h, sysdep.c и utest.c. Файлы uuid.* являются системно независимой реализацией алгоритмов генерации УУИд, описанных в разделах 13, 14 и 15, со всеми оптимизациями, описанными в приложении А (за исключением эффективного состояния, совместно используемого процессами). Код подразумевает поддержку 64-битового целого, что делает его более ясным.
Примечание - Код был протестирован в системах Linux (Red Hat 4.0) с GCC (2.7.2) и Windows NT 4.0 c VC + + 5.0.
D.2 Файл copyrt.h
Все последующие исходные файлы должны рассматриваться как имеющие следующее заявление об авторских правах:
/*
** Copyright (с) 1990 - 1993, 1996 Open Software Foundation, Inc.
** Copyright (с) 1989 by Hewlett-Packard Company, Palo Alto, Ca. &
** Digital Equipment Corporation, Maynard, Mass.
** Copyright (c) 1998 Microsoft.
** To anyone who acknowledges that this file is provided "AS IS"
** without any express or implied warranty: permission to use, copy,
** modify, and distribute this file for any purpose is hereby
** granted without fee, provided that the above copyright notices and
** this notice appears in all source code copies, and that none of
** the names of Open Software Foundation, Inc., Hewlett-Packard
** Company, or Digital Equipment Corporation be used in advertising
** or publicity pertaining to distribution of the software without
** specific, written prior permission. Neither Open Software
** Foundation, Inc., Hewlett-Packard Company, Microsoft, nor Digital
** Equipment Corporation makes any representations about the
** suitability
** of this software for any purpose.
*/
D.3 Файл uuid.h
#include "copyrt.h" | ||||||
#undef uuid_t | ||||||
typedef struct { | ||||||
unsigned32 time_low; | ||||||
unsigned16 time_mid; | ||||||
unsigned16 time_hi_and_version; | ||||||
unsigned8 clock_seq_hi_and_reserved; | ||||||
unsigned8 clock_seq_low; | ||||||
byte node[6]; | ||||||
} uuid_t; | ||||||
/* uuid_create -- сгенерировать УУИд */ | ||||||
int uuid_create(uuid_t * uuid); | ||||||
/* uuid_create_from_name -- создать УУИд, используя "имя" | ||||||
из "пространства имен" */ | ||||||
void uuid_create_from_name( | ||||||
uuid_t *uuid, | /* результирующий УУИд */ | |||||
uuid_t nsid, | /* УУИд пространства имен */ | |||||
void *name, | /* имя, из которого генерируется УУИд */ | |||||
int namelen | /* длина имени*/ | |||||
); | ||||||
/* uuid_compare -- Сравнить два УУИд "лексически" и вернуть | ||||||
-1 | u1 лексически до u2 | |||||
0 | u1 лексически равен u2 | |||||
1 | u1 лексически после u2 | |||||
Лексическое упорядочение не является временным! | ||||||
*/ | ||||||
int uuid_compare(uuid_t *u1, uuid_t *u2); |