revert between 56095 -> 55830 in arch
[AROS.git] / workbench / c / UUIDGen.c
blob051f6dce871103918577009a539e4afe8d374389
1 /*
2 Copyright © 1995-2001, The AROS Development Team. All rights reserved.
3 $Id$
5 Desc: Generate UUIDs
6 Lang: English
7 */
9 /******************************************************************************
11 NAME
13 UUIDGen
15 SYNOPSIS
17 RANDOM/S, AMOUNT/N
19 LOCATION
23 FUNCTION
25 Generates one or more universally unique identifiers. They may be either
26 time-based or random. Please note that the quality of random generated
27 uuid's may be poor, due to the lack of high-quality noise generators on AROS.
29 INPUTS
31 RANDOM -- Generate randob-based UUID instead of time based
32 AMOUNT -- Amount of UUID's to generate. Defaults to 1.
34 RESULT
36 NOTES
38 EXAMPLE
40 BUGS
42 SEE ALSO
44 INTERNALS
46 HISTORY
48 ******************************************************************************/
50 #include <aros/debug.h>
51 #include <proto/exec.h>
52 #include <proto/dos.h>
53 #include <proto/uuid.h>
54 #include <libraries/uuid.h>
56 #define ARG_COUNT 2 /* Number of ReadArgs() arguments */
58 int __nocommandline;
60 int main(void)
62 ULONG amount = 1;
63 /* Array filled by ReadArgs() call */
64 IPTR args[ARG_COUNT] = {0, 0};
66 struct RDArgs *rda; /* ReadArgs standard struct */
68 if((rda = ReadArgs("RANDOM/S,AMOUNT/N", args, NULL)) != NULL)
70 BOOL random = (BOOL)args[0]; /* Random-based UUID? */
72 if (args[1])
73 amount = *(ULONG*)args[1]; /* Amount of uuid's was given. use it */
75 struct Library *UUIDBase = OpenLibrary("uuid.library", 0);
77 if (UUIDBase)
79 char uuidstr[UUID_STRLEN+1];
80 uuid_t uuid;
81 uuidstr[UUID_STRLEN] = 0;
83 while(amount--)
85 /* Generate the uuid identifier */
86 if (random)
87 UUID_Generate(UUID_TYPE_DCE_RANDOM, &uuid);
88 else
89 UUID_Generate(UUID_TYPE_DCE_TIME, &uuid);
91 /* unparse it into human-readable format */
92 UUID_Unparse(&uuid, uuidstr);
94 Printf("%s\n", uuidstr);
97 CloseLibrary(UUIDBase);
101 return RETURN_OK;