mkdtemp 1.0 → 1.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (3) hide show
  1. data/ext/mkdtemp.c +20 -4
  2. data/lib/mkdtemp/version.rb +2 -2
  3. metadata +7 -6
data/ext/mkdtemp.c CHANGED
@@ -1,5 +1,5 @@
1
- /*
2
- Copyright 2007-2008 Wincent Colaiuta
1
+ /*
2
+ Copyright 2007-2009 Wincent Colaiuta
3
3
  This program is free software: you can redistribute it and/or modify
4
4
  it under the terms of the GNU General Public License as published by
5
5
  the Free Software Foundation, either version 3 of the License, or
@@ -17,6 +17,7 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
17
17
  #include <ruby.h>
18
18
  #include <errno.h>
19
19
  #include <unistd.h>
20
+ #include "ruby_compat.h"
20
21
 
21
22
  /*
22
23
 
@@ -35,16 +36,31 @@ Enterprise Linux it states that the template suffix "must be XXXXXX".
35
36
  static VALUE dir_mkdtemp_m(int argc, VALUE *argv, VALUE self)
36
37
  {
37
38
  VALUE template;
39
+ char *c_template;
38
40
  char *path;
41
+
42
+ /* process argument */
39
43
  if (rb_scan_args(argc, argv, "01", &template) == 0) /* check for 0 mandatory arguments, 1 optional argument */
40
44
  template = Qnil; /* default to nil if no argument passed */
41
45
  if (NIL_P(template))
42
46
  template = rb_str_new2("/tmp/temp.XXXXXX"); /* fallback to this template if passed nil */
43
47
  SafeStringValue(template); /* raises if template is tainted and SAFE level > 0 */
44
48
  template = StringValue(template); /* duck typing support */
45
- path = mkdtemp(RSTRING(template)->ptr);
49
+
50
+ /* create temporary storage */
51
+ c_template = malloc(RSTRING_LEN(template) + 1);
52
+ if (!c_template)
53
+ rb_raise(rb_eNoMemError, "failed to allocate %ld bytes of template storage", RSTRING_LEN(template) + 1);
54
+ strncpy(c_template, RSTRING_PTR(template), RSTRING_LEN(template));
55
+ c_template[RSTRING_LEN(template)] = 0; /* NUL-terminate */
56
+
57
+ /* fill out template */
58
+ path = mkdtemp(c_template);
59
+ if (path)
60
+ template = rb_str_new2(path);
61
+ free(c_template);
46
62
  if (path == NULL)
47
- rb_raise(rb_eSystemCallError, "mkdtemp failed (error: %d)", errno);
63
+ rb_raise(rb_eSystemCallError, "mkdtemp failed (error #%d: %s)", errno, strerror(errno));
48
64
  return template;
49
65
  }
50
66
 
@@ -1,4 +1,4 @@
1
- # Copyright 2008 Wincent Colaiuta
1
+ # Copyright 2008-2009 Wincent Colaiuta
2
2
  # This program is free software: you can redistribute it and/or modify
3
3
  # it under the terms of the GNU General Public License as published by
4
4
  # the Free Software Foundation, either version 3 of the License, or
@@ -14,6 +14,6 @@
14
14
 
15
15
  class Dir
16
16
  module Mkdtemp
17
- VERSION = '1.0'
17
+ VERSION = '1.1'
18
18
  end # module Mkdtemp
19
19
  end # class Dir
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: mkdtemp
3
3
  version: !ruby/object:Gem::Version
4
- version: "1.0"
4
+ version: "1.1"
5
5
  platform: ruby
6
6
  authors:
7
7
  - Wincent Colaiuta
@@ -9,11 +9,11 @@ autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
11
 
12
- date: 2009-03-18 00:00:00 +01:00
12
+ date: 2009-12-06 00:00:00 +01:00
13
13
  default_executable:
14
14
  dependencies: []
15
15
 
16
- description: mkdtemp is a C extension that wraps the Standard C Library function of the same name to make secure creation of temporary directories easily available from within Ruby.
16
+ description: " mkdtemp is a C extension that wraps the Standard C Library function\n of the same name to make secure creation of temporary directories\n easily available from within Ruby.\n"
17
17
  email: win@wincent.com
18
18
  executables: []
19
19
 
@@ -22,7 +22,6 @@ extensions:
22
22
  extra_rdoc_files: []
23
23
 
24
24
  files:
25
- - lib/mkdtemp
26
25
  - lib/mkdtemp/version.rb
27
26
  - spec/mkdtemp_spec.rb
28
27
  - spec/spec_helper.rb
@@ -30,6 +29,8 @@ files:
30
29
  - ext/extconf.rb
31
30
  has_rdoc: true
32
31
  homepage: http://mkdtemp.rubyforge.org/
32
+ licenses: []
33
+
33
34
  post_install_message:
34
35
  rdoc_options: []
35
36
 
@@ -51,9 +52,9 @@ required_rubygems_version: !ruby/object:Gem::Requirement
51
52
  requirements: []
52
53
 
53
54
  rubyforge_project: mkdtemp
54
- rubygems_version: 1.3.1
55
+ rubygems_version: 1.3.5
55
56
  signing_key:
56
- specification_version: 2
57
+ specification_version: 3
57
58
  summary: Secure creation of temporary directories
58
59
  test_files: []
59
60