xref: /aosp_15_r20/external/e2fsprogs/contrib/python-uuid/uuid.c (revision 6a54128f25917bfc36a8a6e9d722c04a0b4641b6)
1*6a54128fSAndroid Build Coastguard Worker #include <Python.h>
2*6a54128fSAndroid Build Coastguard Worker #include <time.h>
3*6a54128fSAndroid Build Coastguard Worker #include <uuid/uuid.h>
4*6a54128fSAndroid Build Coastguard Worker 
_uuid_generate(PyObject * self,PyObject * args)5*6a54128fSAndroid Build Coastguard Worker static PyObject * _uuid_generate(PyObject *self, PyObject *args)
6*6a54128fSAndroid Build Coastguard Worker {
7*6a54128fSAndroid Build Coastguard Worker   uuid_t u;
8*6a54128fSAndroid Build Coastguard Worker   char uuid[37];
9*6a54128fSAndroid Build Coastguard Worker   if (!PyArg_ParseTuple(args, "")) return NULL;
10*6a54128fSAndroid Build Coastguard Worker   uuid_generate(u);
11*6a54128fSAndroid Build Coastguard Worker   uuid_unparse(u, uuid);
12*6a54128fSAndroid Build Coastguard Worker   return Py_BuildValue("s", uuid);
13*6a54128fSAndroid Build Coastguard Worker }
14*6a54128fSAndroid Build Coastguard Worker 
15*6a54128fSAndroid Build Coastguard Worker static PyMethodDef _uuid_methods[] = {
16*6a54128fSAndroid Build Coastguard Worker   {"generate", _uuid_generate, METH_VARARGS, "Generate UUID"},
17*6a54128fSAndroid Build Coastguard Worker   {NULL, NULL, 0, NULL}
18*6a54128fSAndroid Build Coastguard Worker };
19*6a54128fSAndroid Build Coastguard Worker 
inite2fsprogs_uuid(void)20*6a54128fSAndroid Build Coastguard Worker void inite2fsprogs_uuid(void)
21*6a54128fSAndroid Build Coastguard Worker {
22*6a54128fSAndroid Build Coastguard Worker   (void) Py_InitModule("e2fsprogs_uuid", _uuid_methods);
23*6a54128fSAndroid Build Coastguard Worker }
24