Changeset bc417660 in mainline for uspace/lib/c/generic/uuid.c


Ignore:
Timestamp:
2019-02-23T16:28:16Z (6 years ago)
Author:
Jiří Zárevúcky <zarevucky.jiri@…>
Branches:
lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
Children:
ab87db5
Parents:
098e16a5 (diff), 76ec309b (diff)
Note: this is a merge changeset, the changes displayed below correspond to the merge itself.
Use the (diff) links above to see all the changes relative to each parent.
Message:

Merge pcut tests and corrections by matthieuriolo

File:
1 edited

Legend:

Unmodified
Added
Removed
  • uspace/lib/c/generic/uuid.c

    r098e16a5 rbc417660  
    3939#include <stddef.h>
    4040#include <str.h>
     41#include <stdio.h>
    4142
    4243/** Generate UUID.
     
    6768        uuid->b[8] = (uuid->b[8] & 0x3f) | 0x80;
    6869
    69         return EOK;
    7070error:
    7171        rndgen_destroy(rndgen);
     
    139139
    140140        rc = str_uint64_t(str + 24, &eptr, 16, false, &node);
    141         if (rc != EOK || eptr != str + 36 || *eptr != '\0')
     141        if (rc != EOK || eptr != str + 36)
    142142                return EINVAL;
    143143
     
    176176 * @return EOK on success, ENOMEM if out of memory
    177177 */
    178 errno_t uuid_format(uuid_t *uuid, char **rstr)
     178errno_t uuid_format(uuid_t *uuid, char **rstr, bool uppercase)
    179179{
    180         return ENOTSUP;
     180        size_t size = 37;
     181        char *str = malloc(sizeof(char) * size);
     182        if (str == NULL)
     183                return ENOMEM;
     184
     185        const char *format = "%02x%02x%02x%02x-%02x%02x-%02x%02x-%02x%02x-%02x%02x%02x%02x%02x%02x";
     186        if (uppercase)
     187                format = "%02X%02X%02X%02X-%02X%02X-%02X%02X-%02X%02X-%02X%02X%02X%02X%02X%02X";
     188
     189        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]);
     190
     191        if (ret != 36)
     192                return EINVAL;
     193
     194        *rstr = str;
     195        return EOK;
    181196}
    182197
Note: See TracChangeset for help on using the changeset viewer.