[Win32utils-devel] _mktemp on Windows
Daniel Berger
djberg96 at gmail.com
Mon Jan 16 09:00:50 EST 2012
On Sun, Jan 15, 2012 at 8:44 PM, Heesob Park <phasis at gmail.com> wrote:
> Hi,
>
> 2012/1/14 Daniel Berger <djberg96 at gmail.com>:
>> Is it odd that calling _mktemp more than once in the same process doesn't work?
>>
>> require 'ffi'
>>
>> class Win
>> extend FFI::Library
>>
>> ffi_lib 'msvcrt'
>> attach_function :_mktemp, [:string], :string
>>
>> def self.mktemp
>> 5.times{ p _mktemp("rb_file_temp_XXXXXX") }
>> end
>> end
>>
>> Win.mktemp
>>
>> # Output
>> "rb_file_temp_a03680"
>> nil
>> nil
>> nil
>> nil
> It is odd indeed.
> _mktemp not working in the loop.
>
> require 'ffi'
>
> class Win
> extend FFI::Library
>
> ffi_lib 'msvcrt'
> attach_function :_mktemp, [:string], :string
>
> def self.mktemp
> p _mktemp("rb_file_temp_XXXXXX")
> p _mktemp("rb_file_temp_XXXXXX")
> p _mktemp("rb_file_temp_XXXXXX")
> p _mktemp("rb_file_temp_XXXXXX")
> p _mktemp("rb_file_temp_XXXXXX")
> 5.times {
> p _mktemp("rb_loop_temp_XXXXXX")
> }
> end
> end
>
> Win.mktemp
>
> # Output
> "rb_file_temp_a05972"
> "rb_file_temp_a05972"
> "rb_file_temp_a05972"
> "rb_file_temp_a05972"
> "rb_file_temp_a05972"
> "rb_loop_temp_a05972"
> nil
> nil
> nil
> nil
I noticed that in the example of the bottom of the _mktemp
documentation that they don't use the char* string directly, but
instead strcpy it to an array of chars and use that. I guess there's a
limit of 26 names.
Regards,
Dan
More information about the win32utils-devel
mailing list