file-temp 0.1.0 → 0.1.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/CHANGES +5 -1
- data/README +1 -1
- data/ext/extconf.rb +3 -0
- data/ext/temp.c +18 -7
- data/test/tc_file_temp.rb +7 -5
- metadata +2 -2
data/CHANGES
CHANGED
data/README
CHANGED
data/ext/extconf.rb
CHANGED
data/ext/temp.c
CHANGED
@@ -1,16 +1,20 @@
|
|
1
1
|
#include <ruby.h>
|
2
2
|
#include <stdio.h>
|
3
3
|
|
4
|
+
#ifdef HAVE__SOPEN_S
|
5
|
+
#include <share.h>
|
6
|
+
#endif
|
7
|
+
|
4
8
|
#ifndef HAVE_MKSTEMP
|
5
9
|
#include <fcntl.h>
|
6
10
|
#include <temp.h>
|
7
11
|
#endif
|
8
12
|
|
9
|
-
#
|
10
|
-
#
|
13
|
+
#ifndef P_tmpdir
|
14
|
+
#define P_tmpdir "/tmp"
|
11
15
|
#endif
|
12
16
|
|
13
|
-
#define VERSION "0.1.
|
17
|
+
#define VERSION "0.1.1"
|
14
18
|
|
15
19
|
VALUE cFileTemp;
|
16
20
|
|
@@ -35,7 +39,7 @@ VALUE cFileTemp;
|
|
35
39
|
* The +template+ argument is ignored if the +delete+ argument is true.
|
36
40
|
*/
|
37
41
|
static VALUE tempfile_init(int argc, VALUE* argv, VALUE self){
|
38
|
-
VALUE v_args[
|
42
|
+
VALUE v_args[2];
|
39
43
|
VALUE v_delete;
|
40
44
|
VALUE v_template;
|
41
45
|
|
@@ -45,15 +49,21 @@ static VALUE tempfile_init(int argc, VALUE* argv, VALUE self){
|
|
45
49
|
v_delete = Qtrue;
|
46
50
|
|
47
51
|
if(RTEST(v_delete)){
|
52
|
+
#ifdef HAVE_TMPFILE_S
|
53
|
+
FILE* fptr;
|
54
|
+
|
55
|
+
if(tmpfile_s(&fptr))
|
56
|
+
rb_sys_fail("tmpfile_s()");
|
57
|
+
#else
|
48
58
|
FILE* fptr = tmpfile();
|
49
59
|
if(!fptr)
|
50
60
|
rb_sys_fail("tmpfile()");
|
61
|
+
#endif
|
51
62
|
|
52
63
|
v_args[0] = INT2FIX(fileno(fptr));
|
53
64
|
}
|
54
65
|
else{
|
55
66
|
int fd;
|
56
|
-
char buf[L_tmpnam];
|
57
67
|
|
58
68
|
if(NIL_P(v_template))
|
59
69
|
v_template = rb_str_new2("rb_file_temp_XXXXXX");
|
@@ -64,11 +74,12 @@ static VALUE tempfile_init(int argc, VALUE* argv, VALUE self){
|
|
64
74
|
rb_sys_fail("mkstemp()");
|
65
75
|
|
66
76
|
v_args[0] = INT2FIX(fd);
|
67
|
-
v_args[0] = INT2FIX(fd);
|
68
77
|
}
|
69
78
|
|
79
|
+
/* This bit of explicitness is necessary for MS Windows */
|
80
|
+
v_args[1] = rb_str_new2("wb");
|
70
81
|
|
71
|
-
return rb_call_super(
|
82
|
+
return rb_call_super(2, v_args);
|
72
83
|
}
|
73
84
|
|
74
85
|
/*
|
data/test/tc_file_temp.rb
CHANGED
@@ -14,13 +14,15 @@ class TC_File_Temp < Test::Unit::TestCase
|
|
14
14
|
end
|
15
15
|
|
16
16
|
def test_file_temp_version
|
17
|
-
assert_equal('0.1.
|
17
|
+
assert_equal('0.1.1', FileTemp::VERSION)
|
18
18
|
end
|
19
19
|
|
20
20
|
def test_file_temp_tmpdir
|
21
21
|
assert_not_nil(FileTemp::TMPDIR)
|
22
22
|
assert_kind_of(String, FileTemp::TMPDIR)
|
23
|
-
|
23
|
+
unless RUBY_PLATFORM.match('mswin')
|
24
|
+
assert_equal(true, ['/tmp', '/var/tmp/'].include?(FileTemp::TMPDIR))
|
25
|
+
end
|
24
26
|
end
|
25
27
|
|
26
28
|
def test_file_temp_auto_delete
|
@@ -37,17 +39,17 @@ class TC_File_Temp < Test::Unit::TestCase
|
|
37
39
|
end
|
38
40
|
|
39
41
|
def test_file_temp_no_delete_with_template
|
40
|
-
assert_nothing_raised{ FileTemp.new(false, 'temp_foo_XXXXX') }
|
42
|
+
assert_nothing_raised{ @fh = FileTemp.new(false, 'temp_foo_XXXXX') }
|
41
43
|
assert_equal(true, Dir["temp_foo*"].length == 1)
|
42
44
|
end
|
43
45
|
|
44
46
|
def test_file_temp_expected_errors
|
45
|
-
assert_raises(ArgumentError){ FileTemp.new(true, 'temp_bar_XXXXX', 1) }
|
47
|
+
assert_raises(ArgumentError){ @fh = FileTemp.new(true, 'temp_bar_XXXXX', 1) }
|
46
48
|
end
|
47
49
|
|
48
50
|
def teardown
|
49
51
|
@template = nil
|
50
|
-
@fh.close if @fh
|
52
|
+
@fh.close if @fh && !@fh.closed?
|
51
53
|
@fh = nil
|
52
54
|
Dir["temp_*"].each{ |f| File.delete(f) }
|
53
55
|
Dir["rb_file_temp_*"].each{ |f| File.delete(f) }
|
metadata
CHANGED
@@ -3,8 +3,8 @@ rubygems_version: 0.9.4
|
|
3
3
|
specification_version: 1
|
4
4
|
name: file-temp
|
5
5
|
version: !ruby/object:Gem::Version
|
6
|
-
version: 0.1.
|
7
|
-
date: 2007-06-
|
6
|
+
version: 0.1.1
|
7
|
+
date: 2007-06-02 00:00:00 -06:00
|
8
8
|
summary: An alternative way to generate tempfiles
|
9
9
|
require_paths:
|
10
10
|
- lib
|