[Win32utils-devel] _mktemp on Windows
Heesob Park
phasis at gmail.com
Tue Jan 17 05:00:18 EST 2012
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
Here is a proper working version:
require 'ffi'
class Win
extend FFI::Library
ffi_lib 'msvcrt'
attach_function :_mktemp, [:pointer], :string
def self.mktemp
5.times {
buf = FFI::MemoryPointer.from_string("rb_file_temp_XXXXXX")
p _mktemp(buf)
}
end
end
Win.mktemp
Regards,
Park Heesob
More information about the win32utils-devel
mailing list