diff options
author | Jeffrey Armstrong <jeff@approximatrix.com> | 2021-03-29 16:38:00 -0400 |
---|---|---|
committer | Jeffrey Armstrong <jeff@approximatrix.com> | 2021-03-29 16:38:00 -0400 |
commit | be976a38f1d95258f19d94f4cf5dc4c677041ed9 (patch) | |
tree | df8557c3d44c6dc41a29f34646d5d231d6075270 /common | |
parent | 7614a6244d080b8c0f82da8c34ccf7a4a88fe72a (diff) | |
download | levitating-be976a38f1d95258f19d94f4cf5dc4c677041ed9.tar.gz levitating-be976a38f1d95258f19d94f4cf5dc4c677041ed9.zip |
Changed how temp files work on UNIX-y stuff. Fixed templates, which were quite broken.
Diffstat (limited to 'common')
-rw-r--r-- | common/utilities.F90 | 32 |
1 files changed, 17 insertions, 15 deletions
diff --git a/common/utilities.F90 b/common/utilities.F90 index 2e19031..3ce3363 100644 --- a/common/utilities.F90 +++ b/common/utilities.F90 @@ -122,6 +122,7 @@ contains function generate_temporary_filename() result(fullpath) use iso_c_binding + use logging implicit none character(len=:), pointer::fullpath @@ -177,24 +178,13 @@ contains res = GetTempFileName(tmp_path, c_null_ptr, 0, tmp_name) call c_free(tmp_path) -#else - interface - function tmpnam(p) bind(c, name='tmpnam') - use iso_c_binding - type(c_ptr), value::p - type(c_ptr)::tmpnam - end function tmpnam - end interface - type(c_ptr)::ignored - - tmp_name = c_malloc(int(1024, kind=c_size_t)) - - ignored = tmpnam(tmp_name) -#endif - ! Convert the C Ptr to a Fortran object clength = c_strlen(tmp_name) + if(clength == 0) then + call write_log("temp name is zero length") + stop + end if call c_f_pointer(tmp_name, cfullpath, (/ clength /)) allocate(character(len=clength)::fullpath) do i = 1, clength @@ -204,6 +194,18 @@ contains cfullpath => null() call c_free(tmp_name) +#else + character(32)::num_text + real::rnum + + allocate(character(len=1024) :: fullpath) + + call random_number(rnum) + write(num_text, *) abs(rnum) + fullpath = "/tmp/lv."//trim(adjustl(num_text))//".tmp" + +#endif + end function generate_temporary_filename subroutine delete_file(filename) |