aboutsummaryrefslogtreecommitdiff
path: root/captain/uuid.f90
diff options
context:
space:
mode:
Diffstat (limited to 'captain/uuid.f90')
-rw-r--r--captain/uuid.f9036
1 files changed, 36 insertions, 0 deletions
diff --git a/captain/uuid.f90 b/captain/uuid.f90
new file mode 100644
index 0000000..1b2d882
--- /dev/null
+++ b/captain/uuid.f90
@@ -0,0 +1,36 @@
+module m_uuid
+implicit none
+
+ integer, parameter::UUID_LENGTH = 36
+
+ character(len=*), parameter::UUID_GENERATOR = "uuidgen"
+
+contains
+
+ function generate_uuid4() result(uuid)
+ use utilities
+ implicit none
+
+ character(len=:), pointer::tempfile
+ character(len=UUID_LENGTH)::uuid
+
+ character(len=5)::fmt
+
+ integer::unum
+
+ tempfile => generate_temporary_filename()
+
+ call execute_command_line(UUID_GENERATOR//" > "//trim(tempfile), wait=.true.)
+
+ open(newunit=unum, action="read", file=tempfile, status="old")
+ write(fmt, '(I3)') UUID_LENGTH
+ fmt = "(A"//trim(adjustl(fmt))//")"
+ read(unum, fmt) uuid
+ close(unum)
+ call unlink(tempfile)
+
+ deallocate(tempfile)
+
+ end function generate_uuid4
+
+end module m_uuid \ No newline at end of file