Changes in uspace/lib/c/generic/uuid.c [f52ce72:09ab0a9a] in mainline
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
uspace/lib/c/generic/uuid.c
rf52ce72 r09ab0a9a 39 39 #include <stddef.h> 40 40 #include <str.h> 41 #include <stdio.h>42 41 43 42 /** Generate UUID. … … 65 64 66 65 /* Version 4 UUID from random or pseudo-random numbers */ 67 uuid->b[ 6] = (uuid->b[6] & 0x4F) | 0x40;68 uuid->b[ 8] = (uuid->b[8] & 0xBF) | 0xB0;69 70 r c =EOK;66 uuid->b[8] = (uuid->b[8] & ~0xc0) | 0x40; 67 uuid->b[6] = (uuid->b[6] & 0xf0) | 0x40; 68 69 return EOK; 71 70 error: 72 71 rndgen_destroy(rndgen); … … 140 139 141 140 rc = str_uint64_t(str + 24, &eptr, 16, false, &node); 142 if (rc != EOK || eptr != str + 36 )141 if (rc != EOK || eptr != str + 36 || *eptr != '\0') 143 142 return EINVAL; 144 143 … … 177 176 * @return EOK on success, ENOMEM if out of memory 178 177 */ 179 errno_t uuid_format(uuid_t *uuid, char **rstr , bool uppercase)178 errno_t uuid_format(uuid_t *uuid, char **rstr) 180 179 { 181 size_t size = 37; 182 char *str = malloc(sizeof(char) * size); 183 if (str == NULL) 184 return ENOMEM; 185 186 const char *format = "%02x%02x%02x%02x-%02x%02x-%02x%02x-%02x%02x-%02x%02x%02x%02x%02x%02x"; 187 if (uppercase) 188 format = "%02X%02X%02X%02X-%02X%02X-%02X%02X-%02X%02X-%02X%02X%02X%02X%02X%02X"; 189 190 int ret = snprintf(str, size, format, uuid->b[0], uuid->b[1], uuid->b[2], uuid->b[3], uuid->b[4], uuid->b[5], uuid->b[6], uuid->b[7], uuid->b[8], uuid->b[9], uuid->b[10], uuid->b[11], uuid->b[12], uuid->b[13], uuid->b[14], uuid->b[15]); 191 192 if (ret != 36) 193 return EINVAL; 194 195 *rstr = str; 196 return EOK; 180 return ENOTSUP; 197 181 } 198 182
Note:
See TracChangeset
for help on using the changeset viewer.