Changeset 3716
- Timestamp:
- 02/21/06 23:10:09 (3 years ago)
- Files:
-
- libwired/trunk/libwired/data/wi-uuid.c (modified) (11 diffs)
- libwired/trunk/libwired/data/wi-uuid.h (modified) (1 diff)
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
libwired/trunk/libwired/data/wi-uuid.c
r3696 r3716 68 68 #include <netinet/in.h> 69 69 #include <net/if.h> 70 #include <inttypes.h> 70 71 71 72 #ifdef HAVE_NET_IF_DL_H … … 109 110 wi_string_t *string; 110 111 111 u nsigned inttime_low;112 u nsigned shorttime_mid;113 u nsigned shorttime_hi_and_version;114 u nsigned shortclock_seq;115 u nsigned charnode[_WI_UUID_NODE_SIZE];112 uint32_t time_low; 113 uint16_t time_mid; 114 uint16_t time_hi_and_version; 115 uint16_t clock_seq; 116 uint8_t node[_WI_UUID_NODE_SIZE]; 116 117 }; 117 118 … … 127 128 static void _wi_uuid_get_random_buffer(void *, size_t); 128 129 static wi_boolean_t _wi_uuid_get_node(unsigned char *); 129 static void _wi_uuid_get_clock(u nsigned int *, unsigned int *, unsigned short *);130 static void _wi_uuid_get_clock(uint32_t *, uint32_t *, uint16_t *); 130 131 131 132 … … 154 155 void wi_uuid_initialize(void) { 155 156 struct timeval tv; 156 u nsigned inti;157 uint32_t i; 157 158 158 159 _wi_uuid_clock_lock = wi_lock_init(wi_lock_alloc()), … … 222 223 223 224 wi_uuid_t * wi_uuid_init_from_time(wi_uuid_t *uuid) { 224 u nsigned int clock_mid, clock_low;225 u nsigned shortclock_seq;226 227 _wi_uuid_get_clock(& clock_mid, &clock_low, &clock_seq);228 229 uuid->time_low = clock_low;230 uuid->time_mid = (u nsigned short) clock_mid;231 uuid->time_hi_and_version = (( clock_mid >> 16) & 0x0FFFF) | 0x1000;225 uint32_t time_mid, time_low; 226 uint16_t clock_seq; 227 228 _wi_uuid_get_clock(&time_mid, &time_low, &clock_seq); 229 230 uuid->time_low = time_low; 231 uuid->time_mid = (uint16_t) time_mid; 232 uuid->time_hi_and_version = ((time_mid >> 16) & 0x0FFFF) | 0x1000; 232 233 uuid->clock_seq = clock_seq | 0x8000; 233 234 … … 236 237 _wi_uuid_pack_buffer(uuid); 237 238 239 return uuid; 240 } 241 242 243 244 wi_uuid_t * wi_uuid_init_with_string(wi_uuid_t *uuid, wi_string_t *string) { 245 uint32_t time_low, time_mid, time_hi_and_version, clock_seq_high, clock_seq_low; 246 uint32_t node[6]; 247 248 if(sscanf(wi_string_cstring(string), "%08X-%04X-%04X-%02X%02X-%02X%02X%02X%02X%02X%02X", 249 &time_low, 250 &time_mid, 251 &time_hi_and_version, 252 &clock_seq_high, 253 &clock_seq_low, 254 &node[0], 255 &node[1], 256 &node[2], 257 &node[3], 258 &node[4], 259 &node[5]) != 11) { 260 wi_release(uuid); 261 262 return NULL; 263 } 264 265 uuid->time_low = time_low; 266 uuid->time_mid = (uint16_t) time_mid; 267 uuid->time_hi_and_version = (uint16_t) time_hi_and_version; 268 uuid->clock_seq = (clock_seq_high << 8) + (clock_seq_low & 0xFF); 269 uuid->node[0] = (uint8_t) node[0]; 270 uuid->node[1] = (uint8_t) node[1]; 271 uuid->node[2] = (uint8_t) node[2]; 272 uuid->node[3] = (uint8_t) node[3]; 273 uuid->node[4] = (uint8_t) node[4]; 274 uuid->node[5] = (uint8_t) node[5]; 275 276 _wi_uuid_pack_buffer(uuid); 277 238 278 return uuid; 239 279 } … … 243 283 wi_uuid_t * wi_uuid_init_with_buffer(wi_uuid_t *uuid, const void *buffer) { 244 284 const unsigned char *p; 245 u nsigned inti;285 uint32_t i; 246 286 247 287 memcpy(uuid->buffer, buffer, WI_UUID_BUFFER_SIZE); … … 343 383 static void _wi_uuid_pack_buffer(wi_uuid_t *uuid) { 344 384 unsigned char *p; 345 u nsigned inti;385 uint32_t i; 346 386 347 387 p = uuid->buffer; … … 378 418 static void _wi_uuid_get_random_buffer(void *buffer, size_t size) { 379 419 unsigned char *p = buffer; 380 u nsigned inti;420 uint32_t i; 381 421 382 422 if(_wi_uuid_random_fd >= 0) … … 459 499 460 500 461 static void _wi_uuid_get_clock(u nsigned int *clock_high, unsigned int *clock_low, unsigned short *clock_seq) {501 static void _wi_uuid_get_clock(uint32_t *clock_high, uint32_t *clock_low, uint16_t *clock_seq) { 462 502 static struct timeval lasttv; 463 static u nsigned intadjustment;464 static u nsigned shortsequence;465 u nsigned long longclock_reg;503 static uint32_t adjustment; 504 static uint16_t sequence; 505 uint64_t clock_reg; 466 506 struct timeval tv; 467 507 wi_boolean_t tryagain; … … 503 543 504 544 clock_reg = (tv.tv_usec * 10) + adjustment; 505 clock_reg += ((u nsigned long long) tv.tv_sec) * 10000000;506 clock_reg += (((u nsigned long long) 0x01B21DD2) << 32) + 0x13814000;545 clock_reg += ((uint64_t) tv.tv_sec) * 10000000; 546 clock_reg += (((uint64_t) 0x01B21DD2) << 32) + 0x13814000; 507 547 508 548 *clock_high = clock_reg >> 32; libwired/trunk/libwired/data/wi-uuid.h
r3696 r3716 48 48 WI_EXPORT wi_uuid_t * wi_uuid_init_from_random_data(wi_uuid_t *); 49 49 WI_EXPORT wi_uuid_t * wi_uuid_init_from_time(wi_uuid_t *); 50 WI_EXPORT wi_uuid_t * wi_uuid_init_with_string(wi_uuid_t *, wi_string_t *); 50 51 WI_EXPORT wi_uuid_t * wi_uuid_init_with_buffer(wi_uuid_t *, const void *); 51 52
