Changeset f57ccb5 in mainline for uspace/lib/c/generic/uuid.c
- Timestamp:
- 2015-08-11T16:03:59Z (9 years ago)
- Branches:
- lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
- Children:
- 0bde8523
- Parents:
- 1b23e33
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
uspace/lib/c/generic/uuid.c
r1b23e33 rf57ccb5 36 36 #include <uuid.h> 37 37 #include <stdlib.h> 38 #include <str.h> 38 39 39 40 /** Generate UUID. … … 87 88 } 88 89 90 /** Parse string UUID. 91 * 92 * If @a endptr is not NULL, it is set to point to the first character 93 * following the UUID. If @a endptr is NULL, the string must not contain 94 * any characters following the UUID, otherwise an error is returned. 95 * 96 * @param str String beginning with UUID string representation 97 * @param uuid Place to store UUID 98 * @param endptr Place to store pointer to end of UUID or @c NULL 99 * 100 * @return EOK on success or negative error code 101 */ 102 int uuid_parse(const char *str, uuid_t *uuid, const char **endptr) 103 { 104 int rc; 105 const char *eptr; 106 uint32_t time_low; 107 uint16_t time_mid; 108 uint16_t time_ver; 109 uint16_t clock; 110 uint64_t node; 111 int i; 112 113 rc = str_uint32_t(str, &eptr, 16, false, &time_low); 114 if (rc != EOK || eptr != str + 8 || *eptr != '-') 115 return EINVAL; 116 117 rc = str_uint16_t(str + 9, &eptr, 16, false, &time_mid); 118 if (rc != EOK || eptr != str + 13 || *eptr != '-') 119 return EINVAL; 120 121 rc = str_uint16_t(str + 14, &eptr, 16, false, &time_ver); 122 if (rc != EOK || eptr != str + 18 || *eptr != '-') 123 return EINVAL; 124 125 rc = str_uint16_t(str + 19, &eptr, 16, false, &clock); 126 if (rc != EOK || eptr != str + 23 || *eptr != '-') 127 return EINVAL; 128 129 rc = str_uint64_t(str + 24, &eptr, 16, false, &node); 130 if (rc != EOK || eptr != str + 36 || *eptr != '\0') 131 return EINVAL; 132 133 uuid->b[0] = time_low >> 24; 134 uuid->b[1] = (time_low >> 16) & 0xff; 135 uuid->b[2] = (time_low >> 8) & 0xff; 136 uuid->b[3] = time_low & 0xff; 137 138 uuid->b[4] = time_mid >> 8; 139 uuid->b[5] = time_mid & 0xff; 140 141 uuid->b[6] = time_ver >> 8; 142 uuid->b[7] = time_ver & 0xff; 143 144 uuid->b[8] = clock >> 8; 145 uuid->b[9] = clock & 0xff; 146 147 for (i = 0; i < 6; i++) 148 uuid->b[10 + i] = (node >> 8 * (5 - i)) & 0xff; 149 150 if (endptr != NULL) { 151 *endptr = str + 36; 152 } else { 153 if (*(str + 36) != '\0') 154 return EINVAL; 155 } 156 157 return EOK; 158 } 159 160 /** Format UUID into string representation. 161 * 162 * @param uuid UUID 163 * @param rstr Place to store pointer to newly allocated string 164 * 165 * @return EOK on success, ENOMEM if out of memory 166 */ 167 int uuid_format(uuid_t *uuid, char **rstr) 168 { 169 return ENOTSUP; 170 } 171 172 89 173 /** @} 90 174 */
Note:
See TracChangeset
for help on using the changeset viewer.