file-temp 1.2.1 → 1.7.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +5 -5
- checksums.yaml.gz.sig +1 -0
- data.tar.gz.sig +0 -0
- data/{CHANGES → CHANGES.rdoc} +33 -0
- data/LICENSE +177 -0
- data/MANIFEST.rdoc +13 -0
- data/README.rdoc +66 -0
- data/Rakefile +8 -47
- data/certs/djberg96_pub.pem +26 -0
- data/file-temp.gemspec +22 -14
- data/lib/file-temp.rb +1 -0
- data/lib/file/{temp_java.rb → java/temp.rb} +14 -16
- data/lib/file/temp.rb +11 -2
- data/lib/file/unix/temp.rb +106 -0
- data/lib/file/windows/temp.rb +217 -0
- data/spec/file_temp_spec.rb +159 -0
- metadata +75 -32
- metadata.gz.sig +0 -0
- data/MANIFEST +0 -9
- data/README +0 -61
- data/lib/file/temp_c.rb +0 -254
- data/test/test_file_temp.rb +0 -135
metadata
CHANGED
@@ -1,55 +1,82 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: file-temp
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.
|
4
|
+
version: 1.7.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Daniel J. Berger
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
|
-
cert_chain:
|
11
|
-
|
10
|
+
cert_chain:
|
11
|
+
- |
|
12
|
+
-----BEGIN CERTIFICATE-----
|
13
|
+
MIIEcDCCAtigAwIBAgIBATANBgkqhkiG9w0BAQsFADA/MREwDwYDVQQDDAhkamJl
|
14
|
+
cmc5NjEVMBMGCgmSJomT8ixkARkWBWdtYWlsMRMwEQYKCZImiZPyLGQBGRYDY29t
|
15
|
+
MB4XDTE4MDMxODE1MjIwN1oXDTI4MDMxNTE1MjIwN1owPzERMA8GA1UEAwwIZGpi
|
16
|
+
ZXJnOTYxFTATBgoJkiaJk/IsZAEZFgVnbWFpbDETMBEGCgmSJomT8ixkARkWA2Nv
|
17
|
+
bTCCAaIwDQYJKoZIhvcNAQEBBQADggGPADCCAYoCggGBALgfaroVM6CI06cxr0/h
|
18
|
+
A+j+pc8fgpRgBVmHFaFunq28GPC3IvW7Nvc3Y8SnAW7pP1EQIbhlwRIaQzJ93/yj
|
19
|
+
u95KpkP7tA9erypnV7dpzBkzNlX14ACaFD/6pHoXoe2ltBxk3CCyyzx70mTqJpph
|
20
|
+
75IB03ni9a8yqn8pmse+s83bFJOAqddSj009sGPcQO+QOWiNxqYv1n5EHcvj2ebO
|
21
|
+
6hN7YTmhx7aSia4qL/quc4DlIaGMWoAhvML7u1fmo53CYxkKskfN8MOecq2vfEmL
|
22
|
+
iLu+SsVVEAufMDDFMXMJlvDsviolUSGMSNRTujkyCcJoXKYYxZSNtIiyd9etI0X3
|
23
|
+
ctu0uhrFyrMZXCedutvXNjUolD5r9KGBFSWH1R9u2I3n3SAyFF2yzv/7idQHLJJq
|
24
|
+
74BMnx0FIq6fCpu5slAipvxZ3ZkZpEXZFr3cIBtO1gFvQWW7E/Y3ijliWJS1GQFq
|
25
|
+
058qERadHGu1yu1dojmFRo6W2KZvY9al2yIlbkpDrD5MYQIDAQABo3cwdTAJBgNV
|
26
|
+
HRMEAjAAMAsGA1UdDwQEAwIEsDAdBgNVHQ4EFgQUFZsMapgzJimzsbaBG2Tm8j5e
|
27
|
+
AzgwHQYDVR0RBBYwFIESZGpiZXJnOTZAZ21haWwuY29tMB0GA1UdEgQWMBSBEmRq
|
28
|
+
YmVyZzk2QGdtYWlsLmNvbTANBgkqhkiG9w0BAQsFAAOCAYEAW2tnYixXQtKxgGXq
|
29
|
+
/3iSWG2bLwvxS4go3srO+aRXZHrFUMlJ5W0mCxl03aazxxKTsVVpZD8QZxvK91OQ
|
30
|
+
h9zr9JBYqCLcCVbr8SkmYCi/laxIZxsNE5YI8cC8vvlLI7AMgSfPSnn/Epq1GjGY
|
31
|
+
6L1iRcEDtanGCIvjqlCXO9+BmsnCfEVehqZkQHeYczA03tpOWb6pon2wzvMKSsKH
|
32
|
+
ks0ApVdstSLz1kzzAqem/uHdG9FyXdbTAwH1G4ZPv69sQAFAOCgAqYmdnzedsQtE
|
33
|
+
1LQfaQrx0twO+CZJPcRLEESjq8ScQxWRRkfuh2VeR7cEU7L7KqT10mtUwrvw7APf
|
34
|
+
DYoeCY9KyjIBjQXfbj2ke5u1hZj94Fsq9FfbEQg8ygCgwThnmkTrrKEiMSs3alYR
|
35
|
+
ORVCZpRuCPpmC8qmqxUnARDArzucjaclkxjLWvCVHeFa9UP7K3Nl9oTjJNv+7/jM
|
36
|
+
WZs4eecIcUc4tKdHxcAJ0MO/Dkqq7hGaiHpwKY76wQ1+8xAh
|
37
|
+
-----END CERTIFICATE-----
|
38
|
+
date:
|
12
39
|
dependencies:
|
13
40
|
- !ruby/object:Gem::Dependency
|
14
41
|
name: ffi
|
15
42
|
requirement: !ruby/object:Gem::Requirement
|
16
43
|
requirements:
|
17
|
-
- -
|
44
|
+
- - "~>"
|
18
45
|
- !ruby/object:Gem::Version
|
19
|
-
version: 1.
|
46
|
+
version: '1.1'
|
20
47
|
type: :runtime
|
21
48
|
prerelease: false
|
22
49
|
version_requirements: !ruby/object:Gem::Requirement
|
23
50
|
requirements:
|
24
|
-
- -
|
51
|
+
- - "~>"
|
25
52
|
- !ruby/object:Gem::Version
|
26
|
-
version: 1.
|
53
|
+
version: '1.1'
|
27
54
|
- !ruby/object:Gem::Dependency
|
28
|
-
name:
|
55
|
+
name: rspec
|
29
56
|
requirement: !ruby/object:Gem::Requirement
|
30
57
|
requirements:
|
31
|
-
- -
|
58
|
+
- - "~>"
|
32
59
|
- !ruby/object:Gem::Version
|
33
|
-
version: '
|
60
|
+
version: '3.9'
|
34
61
|
type: :development
|
35
62
|
prerelease: false
|
36
63
|
version_requirements: !ruby/object:Gem::Requirement
|
37
64
|
requirements:
|
38
|
-
- -
|
65
|
+
- - "~>"
|
39
66
|
- !ruby/object:Gem::Version
|
40
|
-
version: '
|
67
|
+
version: '3.9'
|
41
68
|
- !ruby/object:Gem::Dependency
|
42
69
|
name: rake
|
43
70
|
requirement: !ruby/object:Gem::Requirement
|
44
71
|
requirements:
|
45
|
-
- -
|
72
|
+
- - ">="
|
46
73
|
- !ruby/object:Gem::Version
|
47
74
|
version: '0'
|
48
75
|
type: :development
|
49
76
|
prerelease: false
|
50
77
|
version_requirements: !ruby/object:Gem::Requirement
|
51
78
|
requirements:
|
52
|
-
- -
|
79
|
+
- - ">="
|
53
80
|
- !ruby/object:Gem::Version
|
54
81
|
version: '0'
|
55
82
|
description: |2
|
@@ -60,42 +87,58 @@ email: djberg96@gmail.com
|
|
60
87
|
executables: []
|
61
88
|
extensions: []
|
62
89
|
extra_rdoc_files:
|
63
|
-
- CHANGES
|
64
|
-
- README
|
65
|
-
- MANIFEST
|
90
|
+
- CHANGES.rdoc
|
91
|
+
- README.rdoc
|
92
|
+
- MANIFEST.rdoc
|
66
93
|
files:
|
67
|
-
-
|
68
|
-
- MANIFEST
|
69
|
-
- README
|
70
|
-
- Rakefile
|
94
|
+
- LICENSE
|
71
95
|
- file-temp.gemspec
|
96
|
+
- spec
|
97
|
+
- spec/file_temp_spec.rb
|
98
|
+
- Rakefile
|
99
|
+
- certs
|
100
|
+
- certs/djberg96_pub.pem
|
101
|
+
- lib
|
102
|
+
- lib/file-temp.rb
|
103
|
+
- lib/file
|
72
104
|
- lib/file/temp.rb
|
73
|
-
- lib/file/
|
74
|
-
- lib/file/
|
75
|
-
-
|
105
|
+
- lib/file/java
|
106
|
+
- lib/file/java/temp.rb
|
107
|
+
- lib/file/unix
|
108
|
+
- lib/file/unix/temp.rb
|
109
|
+
- lib/file/windows
|
110
|
+
- lib/file/windows/temp.rb
|
111
|
+
- CHANGES.rdoc
|
112
|
+
- MANIFEST.rdoc
|
113
|
+
- README.rdoc
|
76
114
|
homepage: http://github.com/djberg96/file-temp
|
77
115
|
licenses:
|
78
|
-
-
|
79
|
-
metadata:
|
116
|
+
- Apache-2.0
|
117
|
+
metadata:
|
118
|
+
homepage_uri: https://github.com/djberg96/file-temp
|
119
|
+
bug_tracker_uri: https://github.com/djberg96/file-temp/issues
|
120
|
+
changelog_uri: https://github.com/djberg96/file-temp/blob/master/CHANGES
|
121
|
+
documentation_uri: https://github.com/djberg96/file-temp/wiki
|
122
|
+
source_code_uri: https://github.com/djberg96/file-temp
|
123
|
+
wiki_uri: https://github.com/djberg96/file-temp/wiki
|
80
124
|
post_install_message:
|
81
125
|
rdoc_options: []
|
82
126
|
require_paths:
|
83
127
|
- lib
|
84
128
|
required_ruby_version: !ruby/object:Gem::Requirement
|
85
129
|
requirements:
|
86
|
-
- -
|
130
|
+
- - ">="
|
87
131
|
- !ruby/object:Gem::Version
|
88
|
-
version:
|
132
|
+
version: '0'
|
89
133
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
90
134
|
requirements:
|
91
|
-
- -
|
135
|
+
- - ">="
|
92
136
|
- !ruby/object:Gem::Version
|
93
137
|
version: '0'
|
94
138
|
requirements: []
|
95
|
-
|
96
|
-
rubygems_version: 2.2.2
|
139
|
+
rubygems_version: 3.0.3
|
97
140
|
signing_key:
|
98
141
|
specification_version: 4
|
99
142
|
summary: An alternative way to generate temp files
|
100
143
|
test_files:
|
101
|
-
-
|
144
|
+
- spec/file_temp_spec.rb
|
metadata.gz.sig
ADDED
Binary file
|
data/MANIFEST
DELETED
data/README
DELETED
@@ -1,61 +0,0 @@
|
|
1
|
-
== Description
|
2
|
-
The file-temp library is an alternate way to handle tempfile generation.
|
3
|
-
|
4
|
-
== Requirements
|
5
|
-
ffi 1.0.0 or later
|
6
|
-
|
7
|
-
== Installation
|
8
|
-
gem install file-temp
|
9
|
-
|
10
|
-
== Synopsis
|
11
|
-
require 'file/temp'
|
12
|
-
|
13
|
-
fh = File::Temp.new
|
14
|
-
fh.puts "hello"
|
15
|
-
fh.close # => Tempfile automatically deleted
|
16
|
-
|
17
|
-
fh = File::Temp.new(false)
|
18
|
-
fh.puts "world"
|
19
|
-
fh.close # => Tempfile still on your filesystem
|
20
|
-
|
21
|
-
== Motivation
|
22
|
-
Ruby's tempfile.rb is overwrought and susceptible to race conditions.
|
23
|
-
This library uses your system's native tmpfile() or mkstemp() functions
|
24
|
-
instead of trying to handle race conditions manually via pure Ruby.
|
25
|
-
|
26
|
-
This library is also more secure because it restricts file permission via
|
27
|
-
umask() for files created with mkstemp().
|
28
|
-
|
29
|
-
Finally, this library subclasses the File class. This means you get almost
|
30
|
-
exactly the same interface as the File class. The only difference is the
|
31
|
-
constructor.
|
32
|
-
|
33
|
-
== JRuby
|
34
|
-
The implementation for JRuby uses the Java API, not the C API. The
|
35
|
-
temporary file name generated by Java is different than the C version,
|
36
|
-
since it uses a GUID instead of the 'XXXXXX' template, but the
|
37
|
-
interface is otherwise identical.
|
38
|
-
|
39
|
-
There is one test failure with JRuby (threaded tempfile creation). I am
|
40
|
-
not sure why, as sample code seems to work fine. Help wanted.
|
41
|
-
|
42
|
-
== MS Windows
|
43
|
-
You may need to use the mingw build in order to use this library.
|
44
|
-
|
45
|
-
== License
|
46
|
-
Artistic 2.0
|
47
|
-
|
48
|
-
== Copyright
|
49
|
-
(C) 2007-2014 Daniel J. Berger
|
50
|
-
All Rights Reserved
|
51
|
-
|
52
|
-
== Warranty
|
53
|
-
This library is provided "as is" and without any express or
|
54
|
-
implied warranties, including, without limitation, the implied
|
55
|
-
warranties of merchantability and fitness for a particular purpose.
|
56
|
-
|
57
|
-
== Author
|
58
|
-
Daniel J. Berger
|
59
|
-
|
60
|
-
== See also
|
61
|
-
tmpfile(), mkstemp(), tmpnam()
|
data/lib/file/temp_c.rb
DELETED
@@ -1,254 +0,0 @@
|
|
1
|
-
require 'ffi'
|
2
|
-
require 'tmpdir'
|
3
|
-
|
4
|
-
class File::Temp < File
|
5
|
-
extend FFI::Library
|
6
|
-
ffi_lib FFI::Library::LIBC
|
7
|
-
|
8
|
-
# :stopdoc:
|
9
|
-
|
10
|
-
private
|
11
|
-
|
12
|
-
if File::ALT_SEPARATOR
|
13
|
-
attach_function :_close, [:int], :int
|
14
|
-
attach_function :fclose, [:pointer], :int
|
15
|
-
attach_function :_fdopen, [:int, :string], :pointer
|
16
|
-
attach_function :_fileno, [:pointer], :int
|
17
|
-
attach_function :_get_errno, [:pointer], :int
|
18
|
-
attach_function :_open, [:string, :int, :int], :int
|
19
|
-
attach_function :_open_osfhandle, [:long, :int], :int
|
20
|
-
attach_function :tmpnam_s, [:pointer, :size_t], :int
|
21
|
-
attach_function :mktemp_s, :_mktemp_s, [:pointer, :size_t], :int
|
22
|
-
|
23
|
-
private_class_method :_close, :_fdopen, :_get_errno, :_open
|
24
|
-
private_class_method :_open_osfhandle, :mktemp_s, :tmpnam_s
|
25
|
-
|
26
|
-
ffi_lib :kernel32
|
27
|
-
|
28
|
-
attach_function :CloseHandle, [:long], :bool
|
29
|
-
attach_function :CreateFileW, [:buffer_in, :ulong, :ulong, :pointer, :ulong, :ulong, :ulong], :long
|
30
|
-
attach_function :DeleteFileW, [:string], :bool
|
31
|
-
attach_function :GetTempPathW, [:ulong, :buffer_out], :ulong
|
32
|
-
attach_function :GetTempFileNameW, [:buffer_in, :string, :uint, :buffer_out], :uint
|
33
|
-
|
34
|
-
private_class_method :_close, :_fdopen, :_open, :_open_osfhandle
|
35
|
-
private_class_method :CloseHandle, :CreateFileW, :DeleteFileW
|
36
|
-
private_class_method :GetTempPathW, :GetTempFileNameW
|
37
|
-
|
38
|
-
S_IWRITE = 128
|
39
|
-
S_IREAD = 256
|
40
|
-
BINARY = 0x8000
|
41
|
-
SHORT_LIVED = 0x1000
|
42
|
-
GENERIC_READ = 0x80000000
|
43
|
-
GENERIC_WRITE = 0x40000000
|
44
|
-
CREATE_ALWAYS = 2
|
45
|
-
|
46
|
-
FORMAT_MESSAGE_FROM_SYSTEM = 0x00001000
|
47
|
-
FORMAT_MESSAGE_ARGUMENT_ARRAY = 0x00002000
|
48
|
-
|
49
|
-
FILE_ATTRIBUTE_NORMAL = 0x00000080
|
50
|
-
FILE_FLAG_DELETE_ON_CLOSE = 0x04000000
|
51
|
-
INVALID_HANDLE_VALUE = -1
|
52
|
-
else
|
53
|
-
attach_function :fclose, [:pointer], :int
|
54
|
-
attach_function :_fileno, :fileno, [:pointer], :int
|
55
|
-
attach_function :strerror, [:int], :string
|
56
|
-
attach_function :tmpfile, [], :pointer
|
57
|
-
attach_function :tmpnam, [:pointer], :string
|
58
|
-
attach_function :mktemp, [:pointer], :string
|
59
|
-
|
60
|
-
private_class_method :mktemp, :strerror, :tmpfile, :tmpnam
|
61
|
-
end
|
62
|
-
|
63
|
-
private_class_method :fclose, :_fileno
|
64
|
-
|
65
|
-
public
|
66
|
-
|
67
|
-
# :startdoc:
|
68
|
-
|
69
|
-
# The version of the file-temp library.
|
70
|
-
VERSION = '1.2.1'
|
71
|
-
|
72
|
-
# The temporary directory used on MS Windows or Unix.
|
73
|
-
if File::ALT_SEPARATOR
|
74
|
-
TMPDIR = ENV['TEMP'] || ENV['TMP'] || ENV['USERPROFILE'] || Dir.tmpdir
|
75
|
-
else
|
76
|
-
TMPDIR = ENV['TEMP'] || ENV['TMP'] || ENV['TMPDIR'] || Dir.tmpdir
|
77
|
-
end
|
78
|
-
|
79
|
-
# The name of the temporary file. Set to nil if the +delete+ option to the
|
80
|
-
# constructor is true.
|
81
|
-
attr_reader :path
|
82
|
-
|
83
|
-
# Creates a new, anonymous, temporary file in your File::Temp::TMPDIR
|
84
|
-
# directory
|
85
|
-
#
|
86
|
-
# If the +delete+ option is set to true (the default) then the temporary file
|
87
|
-
# will be deleted automatically as soon as all references to it are closed.
|
88
|
-
# Otherwise, the file will live on in your File::Temp::TMPDIR path.
|
89
|
-
#
|
90
|
-
# If the +delete+ option is set to false, then the file is not deleted. In
|
91
|
-
# addition, you can supply a string +template+ that the system replaces with
|
92
|
-
# a unique filename. This template should end with 3 to 6 'X' characters.
|
93
|
-
# The default template is 'rb_file_temp_XXXXXX'. In this case the temporary
|
94
|
-
# file lives in the directory where it was created.
|
95
|
-
#
|
96
|
-
# The +template+ argument is ignored if the +delete+ argument is true.
|
97
|
-
#
|
98
|
-
# Example:
|
99
|
-
#
|
100
|
-
# fh = File::Temp.new(true, 'rb_file_temp_XXXXXX') => file
|
101
|
-
# fh.puts 'hello world'
|
102
|
-
# fh.close
|
103
|
-
#
|
104
|
-
def initialize(delete = true, template = 'rb_file_temp_XXXXXX')
|
105
|
-
@fptr = nil
|
106
|
-
|
107
|
-
if delete
|
108
|
-
@fptr = tmpfile()
|
109
|
-
fd = _fileno(@fptr)
|
110
|
-
else
|
111
|
-
begin
|
112
|
-
omask = File.umask(077)
|
113
|
-
|
114
|
-
ptr = FFI::MemoryPointer.from_string(template)
|
115
|
-
|
116
|
-
if File::ALT_SEPARATOR
|
117
|
-
errno = mktemp_s(ptr, ptr.size)
|
118
|
-
|
119
|
-
raise SystemCallError.new('mktemp_s', errno) if errno != 0
|
120
|
-
else
|
121
|
-
str = mktemp(ptr)
|
122
|
-
|
123
|
-
if str.nil? || str.empty?
|
124
|
-
raise SystemCallError.new('mktemp', FFI.errno)
|
125
|
-
end
|
126
|
-
end
|
127
|
-
|
128
|
-
@path = File.join(TMPDIR, ptr.read_string)
|
129
|
-
@path.tr!(File::SEPARATOR, File::ALT_SEPARATOR) if File::ALT_SEPARATOR
|
130
|
-
ensure
|
131
|
-
File.umask(omask)
|
132
|
-
end
|
133
|
-
end
|
134
|
-
|
135
|
-
if delete
|
136
|
-
super(fd, 'wb+')
|
137
|
-
else
|
138
|
-
super(@path, 'wb+')
|
139
|
-
end
|
140
|
-
end
|
141
|
-
|
142
|
-
# The close method was overridden to ensure the internal file pointer we
|
143
|
-
# created in the constructor is closed. It is otherwise identical to the
|
144
|
-
# File#close method.
|
145
|
-
#
|
146
|
-
def close
|
147
|
-
super
|
148
|
-
fclose(@fptr) if @fptr
|
149
|
-
end
|
150
|
-
|
151
|
-
# Generates a unique file name.
|
152
|
-
#
|
153
|
-
# Note that a file is not actually generated on the filesystem.
|
154
|
-
#--
|
155
|
-
# NOTE: One quirk of the Windows function is that, after the first call, it
|
156
|
-
# adds a file extension of sequential numbers in base 32, e.g. .1-.1vvvvvu.
|
157
|
-
#
|
158
|
-
def self.temp_name
|
159
|
-
if File::ALT_SEPARATOR
|
160
|
-
ptr = FFI::MemoryPointer.new(:char, 1024)
|
161
|
-
errno = tmpnam_s(ptr, ptr.size)
|
162
|
-
|
163
|
-
raise SystemCallError.new('tmpnam_s', errno) if errno != 0
|
164
|
-
|
165
|
-
TMPDIR + ptr.read_string + 'tmp'
|
166
|
-
else
|
167
|
-
tmpnam(nil) << '.tmp'
|
168
|
-
end
|
169
|
-
end
|
170
|
-
|
171
|
-
private
|
172
|
-
|
173
|
-
# For those times when we want the posix errno rather than a formatted string.
|
174
|
-
# This is necessary because FFI.errno appears to be using GetLastError() which
|
175
|
-
# does not always match what _get_errno() returns.
|
176
|
-
#
|
177
|
-
def get_posix_errno
|
178
|
-
if File::ALT_SEPARATOR
|
179
|
-
ptr = FFI::MemoryPointer.new(:int)
|
180
|
-
_get_errno(ptr)
|
181
|
-
ptr.read_int
|
182
|
-
else
|
183
|
-
FFI.errno
|
184
|
-
end
|
185
|
-
end
|
186
|
-
|
187
|
-
if File::ALT_SEPARATOR
|
188
|
-
# Simple wrapper around the GetTempPath function.
|
189
|
-
#
|
190
|
-
def get_temp_path
|
191
|
-
buf = 0.chr * 1024
|
192
|
-
buf.encode!("UTF-16LE")
|
193
|
-
|
194
|
-
if GetTempPathW(buf.size, buf) == 0
|
195
|
-
raise SystemCallError, FFI.errno, 'GetTempPathW'
|
196
|
-
end
|
197
|
-
|
198
|
-
buf.strip.chop # remove trailing slash
|
199
|
-
end
|
200
|
-
|
201
|
-
# The version of tmpfile() implemented by Microsoft is unacceptable.
|
202
|
-
# It attempts to write to C:\ (root) instead of a temporary directory.
|
203
|
-
# This is not only bad behavior, it won't work on Windows 7 and later
|
204
|
-
# without admin rights due to security restrictions.
|
205
|
-
#
|
206
|
-
# This is a custom implementation based on some code from the Cairo
|
207
|
-
# project.
|
208
|
-
#
|
209
|
-
def tmpfile
|
210
|
-
file_name = get_temp_path()
|
211
|
-
buf = 0.chr * 1024
|
212
|
-
buf.encode!("UTF-16LE")
|
213
|
-
|
214
|
-
if GetTempFileNameW(file_name, 'rb_', 0, buf) == 0
|
215
|
-
raise SystemCallError, FFI.errno, 'GetTempFileNameW'
|
216
|
-
end
|
217
|
-
|
218
|
-
file_name = buf.strip
|
219
|
-
|
220
|
-
handle = CreateFileW(
|
221
|
-
file_name,
|
222
|
-
GENERIC_READ | GENERIC_WRITE,
|
223
|
-
0,
|
224
|
-
nil,
|
225
|
-
CREATE_ALWAYS,
|
226
|
-
FILE_ATTRIBUTE_NORMAL | FILE_FLAG_DELETE_ON_CLOSE,
|
227
|
-
0
|
228
|
-
)
|
229
|
-
|
230
|
-
if handle == INVALID_HANDLE_VALUE
|
231
|
-
error = FFI.errno
|
232
|
-
DeleteFileW(file_name)
|
233
|
-
raise SystemCallError.new('CreateFileW', error)
|
234
|
-
end
|
235
|
-
|
236
|
-
fd = _open_osfhandle(handle, 0)
|
237
|
-
|
238
|
-
if fd < 0
|
239
|
-
CloseHandle(handle)
|
240
|
-
raise SystemCallError, get_posix_errno, '_open_osfhandle'
|
241
|
-
end
|
242
|
-
|
243
|
-
fp = _fdopen(fd, 'w+b')
|
244
|
-
|
245
|
-
if fp.nil?
|
246
|
-
_close(fd)
|
247
|
-
CloseHandle(handle)
|
248
|
-
raise SystemCallError, get_posix_errno, 'fdopen'
|
249
|
-
end
|
250
|
-
|
251
|
-
fp
|
252
|
-
end
|
253
|
-
end
|
254
|
-
end
|