workbench/classes/zune: Compile fixed for AROS m68k
[AROS.git] / workbench / c / UUIDGen.c
blob99d4cac16263e7c4176c21c0343002af4e5cccdf
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>
55 #include <stdio.h>
57 #define ARG_COUNT 2 /* Number of ReadArgs() arguments */
59 int __nocommandline;
61 int main(void)
63 ULONG amount = 1;
64 /* Array filled by ReadArgs() call */
65 IPTR args[ARG_COUNT] = {0, 0};
67 struct RDArgs *rda; /* ReadArgs standard struct */
69 if((rda = ReadArgs("RANDOM/S,AMOUNT/N", args, NULL)) != NULL)
71 BOOL random = (BOOL)args[0]; /* Random-based UUID? */
73 if (args[1])
74 amount = *(ULONG*)args[1]; /* Amount of uuid's was given. use it */
76 struct Library *UUIDBase = OpenLibrary("uuid.library", 0);
78 if (UUIDBase)
80 char uuidstr[UUID_STRLEN+1];
81 uuid_t uuid;
82 uuidstr[UUID_STRLEN] = 0;
84 while(amount--)
86 /* Generate the uuid identifier */
87 if (random)
88 UUID_Generate(UUID_TYPE_DCE_RANDOM, &uuid);
89 else
90 UUID_Generate(UUID_TYPE_DCE_TIME, &uuid);
92 /* unparse it into human-readable format */
93 UUID_Unparse(&uuid, uuidstr);
95 Printf("%s\n", uuidstr);
98 CloseLibrary(UUIDBase);
102 return RETURN_OK;