32 #include <sys/types.h>
36 #ifdef USE_PROC_FOR_UUID
38 #elif defined HAVE_UUID_UUID_H
40 # include <uuid/uuid.h>
41 #elif defined HAVE_UUID_H
43 # include <arpa/inet.h>
46 #elif defined USE_WIN32_UUID_API
53 # include <arpa/inet.h>
65 #ifdef USE_PROC_FOR_UUID
66 char buf[STRING_SIZE];
67 int fd =
open(
"/proc/sys/kernel/random/uuid", O_RDONLY);
71 bool failed = (read(fd, buf, STRING_SIZE) != STRING_SIZE);
77 #elif defined HAVE_UUID_UUID_H
80 memcpy(uuid_data, &uu, BINARY_SIZE);
81 #elif defined HAVE_UUID_H
84 uuid_create(&uu, &status);
85 if (status != uuid_s_ok) {
87 throw std::bad_alloc();
89 uu.time_low = htonl(uu.time_low);
90 uu.time_mid = htons(uu.time_mid);
91 uu.time_hi_and_version = htons(uu.time_hi_and_version);
92 memcpy(uuid_data, &uu, BINARY_SIZE);
93 #elif defined USE_WIN32_UUID_API
95 if (
rare(UuidCreate(&uuid) != RPC_S_OK)) {
101 uuid.Data1 = htonl(uuid.Data1);
102 uuid.Data2 = htons(uuid.Data2);
103 uuid.Data3 = htons(uuid.Data3);
104 memcpy(uuid_data, &uuid, BINARY_SIZE);
106 # error Do not know how to generate UUIDs
113 for (
unsigned i = 0; i != BINARY_SIZE; ++i) {
123 result.reserve(STRING_SIZE);
124 for (
unsigned i = 0; i != BINARY_SIZE; ++i) {
125 unsigned char ch = uuid_data[i];
126 result +=
"0123456789abcdef"[ch >> 4];
127 result +=
"0123456789abcdef"[ch & 0x0f];
std::string to_string() const
void parse(const char *in)
DatabaseCreateError indicates a failure to create a database.
Hierarchy of classes which Xapian can throw as exceptions.
WritableDatabase open()
Construct a WritableDatabase object for a new, empty InMemory database.
include <fcntl.h>, but working around broken platforms.
include <sys/stat.h> with portability enhancements
<unistd.h>, but with compat.
include <windows.h> without all the bloat and damage.
include <winsock2.h> but working around problems.
Various handy helpers which std::string really should provide.
char hex_decode(char ch1, char ch2)
Decode a pair of ASCII hex digits.
static constexpr unsigned UUID_GAP_MASK
Bit-mask to determine where to put hyphens in the string representation.
Class for handling UUIDs.