file-temp 0.1.0 → 0.1.1

Sign up to get free protection for your applications and to get access to all the features.
data/CHANGES CHANGED
@@ -1,2 +1,6 @@
1
+ = 0.1.1 - 2-Jun-2007
2
+ * Core code and test case now work properly on MS Windows.
3
+ * Now uses MS VC++ 8 functions when available (tmpfile_s, _sopen_s).
4
+
1
5
  = 0.1.0 - 1-Jun-2007
2
- * Initial release
6
+ * Initial release.
data/README CHANGED
@@ -34,7 +34,7 @@
34
34
  not going to waste time with it.
35
35
 
36
36
  = Future Plans
37
- I plan on adding MS Windows support in the next release.
37
+ I plan on adding a pure Ruby version for MS Windows eventually.
38
38
 
39
39
  = License
40
40
  Ruby's
@@ -1,6 +1,9 @@
1
1
  require 'mkmf'
2
2
  dir_config('tmpfile')
3
3
 
4
+ have_func('tmpfile_s')
5
+ have_func('_sopen_s')
6
+
4
7
  unless have_func('tmpfile')
5
8
  raise 'This library is not supported on your platform. Aborting'
6
9
  end
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
- #ifdef HAVE__SOPEN_S
10
- #include <share.h>
13
+ #ifndef P_tmpdir
14
+ #define P_tmpdir "/tmp"
11
15
  #endif
12
16
 
13
- #define VERSION "0.1.0"
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[1];
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(1, v_args);
82
+ return rb_call_super(2, v_args);
72
83
  }
73
84
 
74
85
  /*
@@ -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.0', FileTemp::VERSION)
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
- assert_equal(true, ['/tmp', '/var/tmp/'].include?(FileTemp::TMPDIR))
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 rescue nil # Ignore closed streams
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.0
7
- date: 2007-06-01 00:00:00 -06:00
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