⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 uuid.h

📁 利用C语言实现的人工智能系统
💻 H
字号:
/*
 * Public include file for the UUID library
 * 
 * Copyright (C) 1996, 1997, 1998 Theodore Ts'o.
 *
 * %Begin-Header%
 * Redistribution and use in source and binary forms, with or without
 * modification, are permitted provided that the following conditions
 * are met:
 * 1. Redistributions of source code must retain the above copyright
 *    notice, and the entire permission notice in its entirety,
 *    including the disclaimer of warranties.
 * 2. Redistributions in binary form must reproduce the above copyright
 *    notice, this list of conditions and the following disclaimer in the
 *    documentation and/or other materials provided with the distribution.
 * 3. The name of the author may not be used to endorse or promote
 *    products derived from this software without specific prior
 *    written permission.
 * 
 * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESS OR IMPLIED
 * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE, ALL OF
 * WHICH ARE HEREBY DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR BE
 * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT
 * OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR
 * BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
 * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE
 * USE OF THIS SOFTWARE, EVEN IF NOT ADVISED OF THE POSSIBILITY OF SUCH
 * DAMAGE.
 * %End-Header%
 */

#ifndef HAVE_UUID_H
#define HAVE_UUID_H

#include <string.h>

#define HAVE_UNISTD_H
#ifdef HAVE_UNISTD_H
#include <unistd.h>
#endif
#define HAVE_STDLIB_H
#ifdef HAVE_STDLIB_H
#include <stdlib.h>
#endif
#include <fcntl.h>
#include <errno.h>
#include <sys/types.h>
#include <sys/time.h>
#include <sys/stat.h>
#include <sys/file.h>
#define HAVE_SYS_IOCTL_H
#ifdef HAVE_SYS_IOCTL_H
#include <sys/ioctl.h>
#endif
#define HAVE_SYS_SOCKET_H
#ifdef HAVE_SYS_SOCKET_H
#include <sys/socket.h>
#endif
#ifdef HAVE_SYS_SOCKIO_H
#include <sys/sockio.h>
#endif
#define HAVE_NET_IF_H
#ifdef HAVE_NET_IF_H
#include <net/if.h>
#endif
#define HAVE_NETINET_IN_H
#ifdef HAVE_NETINET_IN_H
#include <netinet/in.h>
#endif
#ifdef HAVE_NET_IF_DL_H
#include <net/if_dl.h>
#endif
#include <stdio.h>
#include <ctype.h>
#include <time.h>

/* 
 * If linux/types.h is already been included, assume it has defined
 * everything we need.  (cross fingers)  Other header files may have 
 * also defined the types that we need.
 */
#if (!defined(_STDINT_H) && !defined(_UUID_STDINT_H))
#define _UUID_STDINT_H

typedef unsigned char uint8_t;
typedef signed char int8_t;

#if (4 == 8)
	typedef int		int64_t;
	typedef unsigned int	uint64_t;
#elif (4 == 8)
	typedef long		int64_t;
	typedef unsigned long	uint64_t;
#elif (8 == 8)
	#if defined(__GNUC__)
		typedef __signed__ long long 	int64_t;
	#else
		typedef signed long long 	int64_t;
	#endif
	typedef unsigned long long	uint64_t;
#endif

#if (4 == 2)
	typedef	int		int16_t;
	typedef	unsigned int	uint16_t;
#elif (2 == 2)
	typedef	short		int16_t;
	typedef	unsigned short	uint16_t;
	#else
	?==error: undefined 16 bit type
#endif

#if (4 == 4)
	typedef	int		int32_t;
	typedef	unsigned int	uint32_t;
#elif (4 == 4)
	typedef	long		int32_t;
	typedef	unsigned long	uint32_t;
	#elif (2 == 4)
		typedef	short		int32_t;
		typedef	unsigned short	uint32_t;
	#else
		?== error: undefined 32 bit type
	#endif
#endif

static const char *fmt_lower = "%08x%04x%04x%02x%02x%02x%02x%02x%02x%02x%02x";
static const char *fmt_upper = "%08X%04X%04X%02X%02X%02X%02X%02X%02X%02X%02X";

struct uuid {
	uint32_t	time_low;
	uint16_t	time_mid;
	uint16_t	time_hi_and_version;
	uint16_t	clock_seq;
	uint8_t	node[6];
};

typedef unsigned char uuid_t[16];

#ifdef UUID_UNPARSE_DEFAULT_UPPER
	#define FMT_DEFAULT fmt_upper
#else
	#define FMT_DEFAULT fmt_lower
#endif

#define UUCMP(u1,u2) if (u1 != u2) return((u1 < u2) ? -1 : 1);

/*
 * Offset between 15-Oct-1582 and 1-Jan-70
 */
#define TIME_OFFSET_HIGH 0x01B21DD2
#define TIME_OFFSET_LOW  0x13814000

/* UUID Variant definitions */
#define UUID_VARIANT_NCS 	0
#define UUID_VARIANT_DCE 	1
#define UUID_VARIANT_MICROSOFT	2
#define UUID_VARIANT_OTHER	3

/* UUID Type definitions */
#define UUID_TYPE_DCE_TIME   1
#define UUID_TYPE_DCE_RANDOM 4

/* Allow UUID constants to be defined */
#define UUID_DEFINE(name,u0,u1,u2,u3,u4,u5,u6,u7,u8,u9,u10,u11,u12,u13,u14,u15) \
static const uuid_t name = {u0,u1,u2,u3,u4,u5,u6,u7,u8,u9,u10,u11,u12,u13,u14,u15}

/* Assume that the gettimeofday() has microsecond granularity */
#define MAX_ADJUSTMENT 10

void uuid_clear(uuid_t uu);
int uuid_compare_binary(const uuid_t uu1, const uuid_t uu2);
void uuid_copy(uuid_t dst, const uuid_t src);

void uuid_generate(uuid_t out);
void uuid_generate_random(uuid_t out);
void uuid_generate_time(uuid_t out);

int uuid_is_null(const uuid_t uu);
int uuid_parse(const char *in, uuid_t uu);

void uuid_unparse(const uuid_t uu, char *out);
void uuid_unparse_lower(const uuid_t uu, char *out);
void uuid_unparse_upper(const uuid_t uu, char *out);

time_t uuid_time(const uuid_t uu, struct timeval *ret_tv);
int uuid_type(const uuid_t uu);
int uuid_variant(const uuid_t uu);

void uuid_pack(const struct uuid *uu, uuid_t ptr);
void uuid_unpack(const uuid_t in, struct uuid *uu);

void uuid_create(char *uuid);
int uuid_compare(char *uuid1, char *uuid2);		

#endif /* HAVE_UUID_H */

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -