Changeset 6c707e4 in mainline


Ignore:
Timestamp:
2019-02-18T17:03:03Z (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:
b2dca036
Parents:
ab7d85a
git-author:
Matthieu Riolo <matthieu.riolo@…> (2019-02-09 18:31:41)
git-committer:
Jiří Zárevúcky <zarevucky.jiri@…> (2019-02-18 17:03:03)
Message:

Add an implementation of uuid_format

Location:
uspace/lib/c
Files:
2 edited

Legend:

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

    rab7d85a r6c707e4  
    3939#include <stddef.h>
    4040#include <str.h>
     41#include <stdio.h>
    4142
    4243/** Generate UUID.
     
    176177 * @return EOK on success, ENOMEM if out of memory
    177178 */
    178 errno_t uuid_format(uuid_t *uuid, char **rstr)
    179 {
    180         return ENOTSUP;
     179errno_t uuid_format(uuid_t *uuid, char **rstr, bool uppercase)
     180{
     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;
    181197}
    182198
  • uspace/lib/c/include/uuid.h

    rab7d85a r6c707e4  
    3838#include <stdint.h>
    3939#include <types/uuid.h>
     40#include <stdbool.h>
    4041
    4142extern errno_t uuid_generate(uuid_t *);
     
    4344extern void uuid_decode(uint8_t *, uuid_t *);
    4445extern errno_t uuid_parse(const char *, uuid_t *, const char **);
    45 extern errno_t uuid_format(uuid_t *, char **);
     46extern errno_t uuid_format(uuid_t *, char **, bool);
    4647
    4748#endif
Note: See TracChangeset for help on using the changeset viewer.