]> rtime.felk.cvut.cz Git - frescor/forb.git/blob - uuid.c
Added initial work on inter-ORB communication
[frescor/forb.git] / uuid.c
1 /**
2  * @file   uuid.c
3  * @author Michal Sojka <sojkam1@fel.cvut.cz>
4  * @date   Tue Aug 26 09:17:31 2008
5  * 
6  * @brief  Unix version of UUID generator
7  * 
8  */
9 #include <forb/uuid.h>
10 #include <time.h>
11 #include "sha1.h"
12 #include <sys/types.h>
13 #include <unistd.h>
14
15 /** 
16  * Generates universally unique ID.
17  * 
18  * @param dest Where to store the newly generated UUID.
19  * 
20  * @return Same as @a dest.
21  */
22 forb_uuid_t *forb_uuid_generate(forb_uuid_t *dest)
23 {
24         SHA1_CTX ctx;
25         time_t t = time(0);;
26         pid_t pid = getpid();
27         unsigned char digest[20];
28         
29         SHA1Init(&ctx);
30         SHA1Update(&ctx, (unsigned char*)&t, sizeof(t));
31         SHA1Update(&ctx, (unsigned char*)&pid, sizeof(pid));
32         /* This should be enough for localhost process.
33          * TODO: Add network addresses for distributed operation! */
34         SHA1Final(digest, &ctx);
35         memcpy(dest, digest, sizeof(forb_uuid_t));
36         return dest;
37 }