diff options
author | Jeffrey Armstrong <jeff@approximatrix.com> | 2022-04-28 08:54:49 -0400 |
---|---|---|
committer | Jeffrey Armstrong <jeff@approximatrix.com> | 2022-04-28 08:54:49 -0400 |
commit | e7aaa0256420e8d30dee54e603af60d54434c38e (patch) | |
tree | 908e5d435ea036f8382ed23d7cf30f1c16b04a46 /captain/uuid.f90 | |
parent | 6ae21577802462f38d98dd0e5415166008b1b13f (diff) | |
download | levitating-e7aaa0256420e8d30dee54e603af60d54434c38e.tar.gz levitating-e7aaa0256420e8d30dee54e603af60d54434c38e.zip |
Added module to generate uuids by calling uuidgen utility
Diffstat (limited to 'captain/uuid.f90')
-rw-r--r-- | captain/uuid.f90 | 36 |
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 |