Changeset 87337dc5 in mainline for uspace/lib/c/generic/uuid.c


Ignore:
Timestamp:
2018-07-09T15:00:24Z (6 years ago)
Author:
Jiri Svoboda <jiri@…>
Branches:
lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
Children:
d054ad3
Parents:
914c693
git-author:
Jiri Svoboda <jiri@…> (2018-07-08 19:58:56)
git-committer:
Jiri Svoboda <jiri@…> (2018-07-09 15:00:24)
Message:

Random number generator interface. FAT and exFAT should be created with random volume serial numbers.

File:
1 edited

Legend:

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

    r914c693 r87337dc5  
    3535#include <errno.h>
    3636#include <uuid.h>
     37#include <rndgen.h>
    3738#include <stdlib.h>
    3839#include <stddef.h>
    39 #include <time.h>
    4040#include <str.h>
    4141
     
    4848{
    4949        int i;
    50         struct timeval tv;
     50        rndgen_t *rndgen;
     51        errno_t rc;
    5152
    52         /* XXX This is a rather poor way of generating random numbers */
    53         gettimeofday(&tv, NULL);
    54         srand(tv.tv_sec ^ tv.tv_usec);
     53        rc = rndgen_create(&rndgen);
     54        if (rc != EOK)
     55                return EIO;
    5556
    56         for (i = 0; i < uuid_bytes; i++)
    57                 uuid->b[i] = rand();
     57        for (i = 0; i < uuid_bytes; i++) {
     58                rc = rndgen_uint8(rndgen, &uuid->b[i]);
     59                if (rc != EOK) {
     60                        rc = EIO;
     61                        goto error;
     62                }
     63        }
    5864
    5965        /* Version 4 UUID from random or pseudo-random numbers */
     
    6268
    6369        return EOK;
     70error:
     71        rndgen_destroy(rndgen);
     72        return rc;
    6473}
    6574
Note: See TracChangeset for help on using the changeset viewer.