casper-unique-file 0.1.3

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: c6f40e1bb9c655ef5d48ab596e80fcaf50113700
4
+ data.tar.gz: 3b08d72f017cce1e66b78b27e751af54291baa57
5
+ SHA512:
6
+ metadata.gz: 727465c523206dcde4d55cdcb89a892ae3695e98803f57acebaa167d9b7f509078468c1c08658aa2afcba4e5d06c085555e2b3bea7c4356e43b74bc464c8a820
7
+ data.tar.gz: 99856eb3d572e39d6f701d0d93b94b8ed94c607ab22c7ef1ac4cd350bc5ac402e5de135db4d0a4bbe5f317afbe6c22f1add66c96d65f9e6585be6904800d490d
data/README.md ADDED
@@ -0,0 +1,40 @@
1
+ # Casper::Unique::File
2
+
3
+ Helper to use mkstemp on MRI ruby. This gem provides the create module method that creates a uniquely named file inside the specified folder.
4
+ The filename has six characters and the created file is empty.
5
+
6
+ ## Installation
7
+
8
+ Add this line to your application's Gemfile:
9
+
10
+ ```ruby
11
+ gem 'casper-unique-file'
12
+ ```
13
+
14
+ And then execute:
15
+
16
+ $ bundle
17
+
18
+ Or install it yourself as:
19
+
20
+ $ gem install casper-unique-file
21
+
22
+ ## Usage
23
+
24
+ Just call Casper::Unique::File::create passing the name of the folder where the file should be created and the extension if needed. Returns the unique file name. On failure returns nil.
25
+ ```sh
26
+ [ casper-unique-file ⇣⇡ master ᚶ ] $ ./bin/console
27
+ 2.1.5 :001 > Casper::Unique::File::create('/tmp', '.pdf')
28
+ => "/tmp/ZtkM4u.pdf"
29
+ 2.1.5 :002 >
30
+ ```
31
+
32
+ ## Development
33
+
34
+ After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake clean compile` compile the C code. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
35
+
36
+ To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).
37
+
38
+ ## Contributing
39
+
40
+ Bug reports and pull requests are welcome on GitHub at https://github.com/casper2020/casper-unique-file.
data/Rakefile ADDED
@@ -0,0 +1,30 @@
1
+ #
2
+ # Copyright (c) 2018 Cloudware S.A. All rights reserved.
3
+ #
4
+ # This file is part of casper-unique-file.
5
+ #
6
+ # casper-unique-file is free software: you can redistribute it and/or modify
7
+ # it under the terms of the GNU Affero General Public License as published by
8
+ # the Free Software Foundation, either version 3 of the License, or
9
+ # (at your option) any later version.
10
+ #
11
+ # casper-unique-file is distributed in the hope that it will be useful,
12
+ # but WITHOUT ANY WARRANTY; without even the implied warranty of
13
+ # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14
+ # GNU General Public License for more details.
15
+ #
16
+ # You should have received a copy of the GNU Affero General Public License
17
+ # along with casper-unique-file. If not, see <http://www.gnu.org/licenses/>.
18
+ #
19
+ require 'bundler/gem_tasks'
20
+ require 'rake/extensiontask'
21
+
22
+ gemspec = Gem::Specification.load('casper_unique_file.gemspec')
23
+
24
+ Rake::ExtensionTask.new('casper_unique_file') do |ext|
25
+ ext.name = 'casper_unique_file'
26
+ ext.source_pattern = "*.{c,h}"
27
+ ext.ext_dir = 'ext/casper_unique_file'
28
+ ext.lib_dir = 'lib/casper_unique_file'
29
+ ext.gem_spec = gemspec
30
+ end
@@ -0,0 +1,54 @@
1
+ #
2
+ # Copyright (c) 2018 Cloudware S.A. All rights reserved.
3
+ #
4
+ # This file is part of casper-unique-file.
5
+ #
6
+ # casper-unique-file is free software: you can redistribute it and/or modify
7
+ # it under the terms of the GNU Affero General Public License as published by
8
+ # the Free Software Foundation, either version 3 of the License, or
9
+ # (at your option) any later version.
10
+ #
11
+ # casper-unique-file is distributed in the hope that it will be useful,
12
+ # but WITHOUT ANY WARRANTY; without even the implied warranty of
13
+ # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14
+ # GNU General Public License for more details.
15
+ #
16
+ # You should have received a copy of the GNU Affero General Public License
17
+ # along with casper-unique-file. If not, see <http://www.gnu.org/licenses/>.
18
+ #
19
+
20
+ lib = File.expand_path("../lib", __FILE__)
21
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
22
+ require "casper/unique/file/version"
23
+
24
+ Gem::Specification.new do |spec|
25
+ spec.name = "casper-unique-file"
26
+ spec.version = Casper::Unique::File::VERSION
27
+ spec.authors = ["Eurico Inocencio"]
28
+ spec.email = ["eurico.inocencio@gmail.com"]
29
+
30
+ spec.summary = %q{Helper to make safe unique filenames in ruby}
31
+ spec.homepage = "https://github.com/casper2020/casper-unique-file"
32
+
33
+ # this tells RubyGems to build an extension upon install
34
+ spec.extensions = %w[ext/casper_unique_file/extconf.rb]
35
+
36
+ #spec.files = `git ls-files -z`.split("\x0").reject do |f|
37
+ # f.match(%r{^(ext|test|spec|features)/})
38
+ #end
39
+ spec.files = Dir.glob("ext/**/*") + Dir.glob("lib/**/*") + %w[
40
+ README.md
41
+ Rakefile
42
+ casper-unique-file.gemspec
43
+ ]
44
+
45
+ spec.bindir = "exe"
46
+ spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
47
+ spec.require_paths = ["lib"]
48
+
49
+ spec.add_development_dependency "bundler", "~> 1.16"
50
+ spec.add_development_dependency "rake", "~> 10.0"
51
+ spec.add_development_dependency "rspec"
52
+ spec.add_development_dependency 'rake-compiler'
53
+
54
+ end
@@ -0,0 +1,239 @@
1
+
2
+ SHELL = /bin/sh
3
+
4
+ # V=0 quiet, V=1 verbose. other values don't work.
5
+ V = 0
6
+ Q1 = $(V:1=)
7
+ Q = $(Q1:0=@)
8
+ ECHO1 = $(V:1=@:)
9
+ ECHO = $(ECHO1:0=@echo)
10
+
11
+ #### Start of system configuration section. ####
12
+
13
+ srcdir = .
14
+ topdir = /Users/emi/.rvm/rubies/ruby-2.1.5/include/ruby-2.1.0
15
+ hdrdir = $(topdir)
16
+ arch_hdrdir = /Users/emi/.rvm/rubies/ruby-2.1.5/include/ruby-2.1.0/x86_64-darwin16.0
17
+ PATH_SEPARATOR = :
18
+ VPATH = $(srcdir):$(arch_hdrdir)/ruby:$(hdrdir)/ruby
19
+ prefix = $(DESTDIR)/Users/emi/.rvm/rubies/ruby-2.1.5
20
+ rubysitearchprefix = $(rubylibprefix)/$(sitearch)
21
+ rubyarchprefix = $(rubylibprefix)/$(arch)
22
+ rubylibprefix = $(libdir)/$(RUBY_BASE_NAME)
23
+ exec_prefix = $(prefix)
24
+ vendorarchhdrdir = $(vendorhdrdir)/$(sitearch)
25
+ sitearchhdrdir = $(sitehdrdir)/$(sitearch)
26
+ rubyarchhdrdir = $(rubyhdrdir)/$(arch)
27
+ vendorhdrdir = $(rubyhdrdir)/vendor_ruby
28
+ sitehdrdir = $(rubyhdrdir)/site_ruby
29
+ rubyhdrdir = $(includedir)/$(RUBY_VERSION_NAME)
30
+ vendorarchdir = $(vendorlibdir)/$(sitearch)
31
+ vendorlibdir = $(vendordir)/$(ruby_version)
32
+ vendordir = $(rubylibprefix)/vendor_ruby
33
+ sitearchdir = $(sitelibdir)/$(sitearch)
34
+ sitelibdir = $(sitedir)/$(ruby_version)
35
+ sitedir = $(rubylibprefix)/site_ruby
36
+ rubyarchdir = $(rubylibdir)/$(arch)
37
+ rubylibdir = $(rubylibprefix)/$(ruby_version)
38
+ sitearchincludedir = $(includedir)/$(sitearch)
39
+ archincludedir = $(includedir)/$(arch)
40
+ sitearchlibdir = $(libdir)/$(sitearch)
41
+ archlibdir = $(libdir)/$(arch)
42
+ ridir = $(datarootdir)/$(RI_BASE_NAME)
43
+ mandir = $(datarootdir)/man
44
+ localedir = $(datarootdir)/locale
45
+ libdir = $(exec_prefix)/lib
46
+ psdir = $(docdir)
47
+ pdfdir = $(docdir)
48
+ dvidir = $(docdir)
49
+ htmldir = $(docdir)
50
+ infodir = $(datarootdir)/info
51
+ docdir = $(datarootdir)/doc/$(PACKAGE)
52
+ oldincludedir = $(DESTDIR)/usr/include
53
+ includedir = $(prefix)/include
54
+ localstatedir = $(prefix)/var
55
+ sharedstatedir = $(prefix)/com
56
+ sysconfdir = $(prefix)/etc
57
+ datadir = $(datarootdir)
58
+ datarootdir = $(prefix)/share
59
+ libexecdir = $(exec_prefix)/libexec
60
+ sbindir = $(exec_prefix)/sbin
61
+ bindir = $(exec_prefix)/bin
62
+ archdir = $(rubyarchdir)
63
+
64
+
65
+ CC = gcc
66
+ CXX = g++
67
+ LIBRUBY = $(LIBRUBY_SO)
68
+ LIBRUBY_A = lib$(RUBY_SO_NAME)-static.a
69
+ LIBRUBYARG_SHARED = -l$(RUBY_SO_NAME)
70
+ LIBRUBYARG_STATIC = -l$(RUBY_SO_NAME)-static -framework CoreFoundation
71
+ empty =
72
+ OUTFLAG = -o $(empty)
73
+ COUTFLAG = -o $(empty)
74
+
75
+ RUBY_EXTCONF_H =
76
+ cflags = $(optflags) $(debugflags) $(warnflags)
77
+ optflags = -O3 -fno-fast-math
78
+ debugflags = -ggdb3
79
+ warnflags = -Wall -Wextra -Wno-unused-parameter -Wno-parentheses -Wno-long-long -Wno-missing-field-initializers -Wunused-variable -Wpointer-arith -Wwrite-strings -Wdeclaration-after-statement -Wshorten-64-to-32 -Wimplicit-function-declaration -Wdivision-by-zero -Wextra-tokens
80
+ CCDLFLAGS = -fno-common
81
+ CFLAGS = $(CCDLFLAGS) $(cflags) -fno-common -pipe $(ARCH_FLAG)
82
+ INCFLAGS = -I. -I$(arch_hdrdir) -I$(hdrdir)/ruby/backward -I$(hdrdir) -I$(srcdir)
83
+ DEFS =
84
+ CPPFLAGS = -DHAVE_MKSTEMP -O2 -g -I/usr/local/opt/libyaml/include -I/usr/local/opt/readline/include -I/usr/local/opt/libksba/include -I/usr/local/opt/openssl/include -I/usr/local/opt/libyaml/include -I/usr/local/opt/readline/include -I/usr/local/opt/libksba/include -I/usr/local/opt/openssl/include -D_XOPEN_SOURCE -D_DARWIN_C_SOURCE -D_DARWIN_UNLIMITED_SELECT -D_REENTRANT $(DEFS) $(cppflags)
85
+ CXXFLAGS = $(CCDLFLAGS) $(cxxflags) $(ARCH_FLAG)
86
+ ldflags = -L. -fstack-protector -L/usr/local/opt/libyaml/lib -L/usr/local/opt/readline/lib -L/usr/local/opt/libksba/lib -L/usr/local/opt/openssl/lib -L/usr/local/opt/libyaml/lib -L/usr/local/opt/readline/lib -L/usr/local/opt/libksba/lib -L/usr/local/opt/openssl/lib
87
+ dldflags = -Wl,-undefined,dynamic_lookup -Wl,-multiply_defined,suppress -L/usr/local/opt/libyaml/lib -L/usr/local/opt/readline/lib -L/usr/local/opt/libksba/lib -L/usr/local/opt/openssl/lib -L/usr/local/opt/libyaml/lib -L/usr/local/opt/readline/lib -L/usr/local/opt/libksba/lib -L/usr/local/opt/openssl/lib
88
+ ARCH_FLAG =
89
+ DLDFLAGS = $(ldflags) $(dldflags) $(ARCH_FLAG)
90
+ LDSHARED = $(CC) -dynamic -bundle
91
+ LDSHAREDXX = $(CXX) -dynamic -bundle
92
+ AR = ar
93
+ EXEEXT =
94
+
95
+ RUBY_INSTALL_NAME = ruby
96
+ RUBY_SO_NAME = ruby.2.1.0
97
+ RUBYW_INSTALL_NAME =
98
+ RUBY_VERSION_NAME = $(RUBY_BASE_NAME)-$(ruby_version)
99
+ RUBYW_BASE_NAME = rubyw
100
+ RUBY_BASE_NAME = ruby
101
+
102
+ arch = x86_64-darwin16.0
103
+ sitearch = $(arch)
104
+ ruby_version = 2.1.0
105
+ ruby = $(bindir)/ruby
106
+ RUBY = $(ruby)
107
+ ruby_headers = $(hdrdir)/ruby.h $(hdrdir)/ruby/ruby.h $(hdrdir)/ruby/defines.h $(hdrdir)/ruby/missing.h $(hdrdir)/ruby/intern.h $(hdrdir)/ruby/st.h $(hdrdir)/ruby/subst.h $(arch_hdrdir)/ruby/config.h
108
+
109
+ RM = rm -f
110
+ RM_RF = $(RUBY) -run -e rm -- -rf
111
+ RMDIRS = rmdir -p
112
+ MAKEDIRS = mkdir -p
113
+ INSTALL = /usr/bin/install -c
114
+ INSTALL_PROG = $(INSTALL) -m 0755
115
+ INSTALL_DATA = $(INSTALL) -m 644
116
+ COPY = cp
117
+ TOUCH = exit >
118
+
119
+ #### End of system configuration section. ####
120
+
121
+ preload =
122
+
123
+ libpath = . $(libdir) /usr/local/opt/libyaml/lib /usr/local/opt/readline/lib /usr/local/opt/libksba/lib /usr/local/opt/openssl/lib
124
+ LIBPATH = -L. -L$(libdir) -L/usr/local/opt/libyaml/lib -L/usr/local/opt/readline/lib -L/usr/local/opt/libksba/lib -L/usr/local/opt/openssl/lib
125
+ DEFFILE =
126
+
127
+ CLEANFILES = mkmf.log
128
+ DISTCLEANFILES =
129
+ DISTCLEANDIRS =
130
+
131
+ extout =
132
+ extout_prefix =
133
+ target_prefix = /casper_unique_file
134
+ LOCAL_LIBS =
135
+ LIBS = $(LIBRUBYARG_SHARED) -lpthread -ldl -lobjc
136
+ ORIG_SRCS = casper_unique_file.c
137
+ SRCS = $(ORIG_SRCS) casper_unique_file.c
138
+ OBJS = casper_unique_file.o
139
+ HDRS =
140
+ TARGET = casper_unique_file
141
+ TARGET_NAME = casper_unique_file
142
+ TARGET_ENTRY = Init_$(TARGET_NAME)
143
+ DLLIB = $(TARGET).bundle
144
+ EXTSTATIC =
145
+ STATIC_LIB =
146
+
147
+ TIMESTAMP_DIR = .
148
+ BINDIR = $(bindir)
149
+ RUBYCOMMONDIR = $(sitedir)$(target_prefix)
150
+ RUBYLIBDIR = $(sitelibdir)$(target_prefix)
151
+ RUBYARCHDIR = $(sitearchdir)$(target_prefix)
152
+ HDRDIR = $(rubyhdrdir)/ruby$(target_prefix)
153
+ ARCHHDRDIR = $(rubyhdrdir)/$(arch)/ruby$(target_prefix)
154
+
155
+ TARGET_SO = $(DLLIB)
156
+ CLEANLIBS = $(TARGET).bundle
157
+ CLEANOBJS = *.o *.bak
158
+
159
+ all: $(DLLIB)
160
+ static: $(STATIC_LIB)
161
+ .PHONY: all install static install-so install-rb
162
+ .PHONY: clean clean-so clean-static clean-rb
163
+
164
+ clean-static::
165
+ clean-rb-default::
166
+ clean-rb::
167
+ clean-so::
168
+ clean: clean-so clean-static clean-rb-default clean-rb
169
+ -$(Q)$(RM) $(CLEANLIBS) $(CLEANOBJS) $(CLEANFILES) .*.time
170
+
171
+ distclean-rb-default::
172
+ distclean-rb::
173
+ distclean-so::
174
+ distclean-static::
175
+ distclean: clean distclean-so distclean-static distclean-rb-default distclean-rb
176
+ -$(Q)$(RM) Makefile $(RUBY_EXTCONF_H) conftest.* mkmf.log
177
+ -$(Q)$(RM) core ruby$(EXEEXT) *~ $(DISTCLEANFILES)
178
+ -$(Q)$(RMDIRS) $(DISTCLEANDIRS) 2> /dev/null || true
179
+
180
+ realclean: distclean
181
+ install: install-so install-rb
182
+
183
+ install-so: $(DLLIB) $(TIMESTAMP_DIR)/.RUBYARCHDIR.-.casper_unique_file.time
184
+ $(INSTALL_PROG) $(DLLIB) $(RUBYARCHDIR)
185
+ clean-static::
186
+ -$(Q)$(RM) $(STATIC_LIB)
187
+ install-rb: pre-install-rb install-rb-default
188
+ install-rb-default: pre-install-rb-default
189
+ pre-install-rb: Makefile
190
+ pre-install-rb-default: Makefile
191
+ pre-install-rb-default:
192
+ $(ECHO) installing default casper_unique_file libraries
193
+ $(TIMESTAMP_DIR)/.RUBYARCHDIR.-.casper_unique_file.time:
194
+ $(Q) $(MAKEDIRS) $(@D) $(RUBYARCHDIR)
195
+ $(Q) $(TOUCH) $@
196
+
197
+ site-install: site-install-so site-install-rb
198
+ site-install-so: install-so
199
+ site-install-rb: install-rb
200
+
201
+ .SUFFIXES: .c .m .cc .mm .cxx .cpp .C .o
202
+
203
+ .cc.o:
204
+ $(ECHO) compiling $(<)
205
+ $(Q) $(CXX) $(INCFLAGS) $(CPPFLAGS) $(CXXFLAGS) $(COUTFLAG)$@ -c $<
206
+
207
+ .mm.o:
208
+ $(ECHO) compiling $(<)
209
+ $(Q) $(CXX) $(INCFLAGS) $(CPPFLAGS) $(CXXFLAGS) $(COUTFLAG)$@ -c $<
210
+
211
+ .cxx.o:
212
+ $(ECHO) compiling $(<)
213
+ $(Q) $(CXX) $(INCFLAGS) $(CPPFLAGS) $(CXXFLAGS) $(COUTFLAG)$@ -c $<
214
+
215
+ .cpp.o:
216
+ $(ECHO) compiling $(<)
217
+ $(Q) $(CXX) $(INCFLAGS) $(CPPFLAGS) $(CXXFLAGS) $(COUTFLAG)$@ -c $<
218
+
219
+ .C.o:
220
+ $(ECHO) compiling $(<)
221
+ $(Q) $(CXX) $(INCFLAGS) $(CPPFLAGS) $(CXXFLAGS) $(COUTFLAG)$@ -c $<
222
+
223
+ .c.o:
224
+ $(ECHO) compiling $(<)
225
+ $(Q) $(CC) $(INCFLAGS) $(CPPFLAGS) $(CFLAGS) $(COUTFLAG)$@ -c $<
226
+
227
+ .m.o:
228
+ $(ECHO) compiling $(<)
229
+ $(Q) $(CC) $(INCFLAGS) $(CPPFLAGS) $(CFLAGS) $(COUTFLAG)$@ -c $<
230
+
231
+ $(DLLIB): $(OBJS) Makefile
232
+ $(ECHO) linking shared-object casper_unique_file/$(DLLIB)
233
+ -$(Q)$(RM) $(@)
234
+ $(Q) $(LDSHARED) -o $@ $(OBJS) $(LIBPATH) $(DLDFLAGS) $(LOCAL_LIBS) $(LIBS)
235
+ $(Q) $(POSTLINK)
236
+
237
+
238
+
239
+ $(OBJS): $(HDRS) $(ruby_headers)
@@ -0,0 +1,88 @@
1
+ /*
2
+ * Copyright (c) 2018 Cloudware S.A. All rights reserved.
3
+ *
4
+ * This file is part of casper-unique-file.
5
+ *
6
+ * casper-unique-file is free software: you can redistribute it and/or modify
7
+ * it under the terms of the GNU Affero General Public License as published by
8
+ * the Free Software Foundation, either version 3 of the License, or
9
+ * (at your option) any later version.
10
+ *
11
+ * casper-unique-file is distributed in the hope that it will be useful,
12
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
13
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14
+ * GNU General Public License for more details.
15
+ *
16
+ * You should have received a copy of the GNU Affero General Public License
17
+ * along with casper-unique-file. If not, see <http://www.gnu.org/licenses/>.
18
+ */
19
+ #include <ruby.h>
20
+ #include <ruby/intern.h>
21
+ #include <ruby/encoding.h>
22
+ #include <stdio.h>
23
+ #include <unistd.h>
24
+ #include <fcntl.h>
25
+ #include <string.h>
26
+
27
+ /**
28
+ * @brief Creates a uniquely named file inside the specified folder. The created file is empty
29
+ *
30
+ * @param a_self Object handle, ignored
31
+ * @param a_folder Folder where the file will be created
32
+ * @param a_suffix file suffix, warning must include the .
33
+ * @return Absolute file path
34
+ */
35
+ VALUE _casper_unique_filename (VALUE a_self, VALUE a_folder, VALUE a_suffix)
36
+ {
37
+ const char* template = "XXXXXX"; /* file template */
38
+ char fname[PATH_MAX]; /* path to be created */
39
+ char fpath[PATH_MAX]; /* full file path */
40
+ int fd; /* file descriptor */
41
+ char* folder; /* base folder where we'll create the file */
42
+ char* suffix; /* base folder where we'll create the file */
43
+ VALUE rv; /* Return value to ruby */
44
+
45
+ if ( NIL_P(a_folder) || TYPE(a_folder) != T_STRING ) {
46
+ rb_raise(rb_eArgError, "expecting a string as a_folder argument");
47
+ }
48
+ folder = StringValueCStr(a_folder);
49
+
50
+ if ( NIL_P(a_suffix) || TYPE(a_suffix) != T_STRING ) {
51
+ rb_raise(rb_eArgError, "expecting a string as a_suffix argument");
52
+ }
53
+ suffix = StringValueCStr(a_suffix);
54
+
55
+ /* concats argument path with file template */
56
+ snprintf(fname, sizeof(fname) - 1, "%s/%s%s", folder, template, suffix);
57
+
58
+ /* create file */
59
+ fd = mkstemps(fname, (int) strlen(suffix));
60
+
61
+ /* get file full name */
62
+ if (fcntl(fd, F_GETPATH, fpath) != -1) {
63
+ close(fd);
64
+ rv = rb_enc_str_new_cstr(fpath, rb_enc_find("UTF-8"));
65
+ /* exit with success */
66
+ return rv;
67
+
68
+ } else {
69
+ close(fd);
70
+ /* exit with error */
71
+ return Qnil;
72
+ }
73
+ }
74
+
75
+ /**
76
+ * @brief This defines the C functions as extensions.
77
+ *
78
+ * @note The name of the Init_ function is important. What follows Init_ must match
79
+ * the file name (including case) so ruby knows what method to call to define
80
+ * the extensions.
81
+ */
82
+ void Init_casper_unique_file ()
83
+ {
84
+ VALUE rb_mCasper = rb_const_get(rb_cObject, rb_intern("Casper"));
85
+ VALUE rb_mUnique = rb_const_get(rb_mCasper, rb_intern("Unique"));
86
+ VALUE rb_mFile = rb_const_get(rb_mUnique, rb_intern("File"));
87
+ rb_define_module_function(rb_mFile, "create", _casper_unique_filename, 2);
88
+ }
@@ -0,0 +1,41 @@
1
+ #
2
+ # Copyright (c) 2018 Cloudware S.A. All rights reserved.
3
+ #
4
+ # This file is part of casper-unique-file.
5
+ #
6
+ # casper-unique-file is free software: you can redistribute it and/or modify
7
+ # it under the terms of the GNU Affero General Public License as published by
8
+ # the Free Software Foundation, either version 3 of the License, or
9
+ # (at your option) any later version.
10
+ #
11
+ # casper-unique-file is distributed in the hope that it will be useful,
12
+ # but WITHOUT ANY WARRANTY; without even the implied warranty of
13
+ # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14
+ # GNU General Public License for more details.
15
+ #
16
+ # You should have received a copy of the GNU Affero General Public License
17
+ # along with casper-unique-file. If not, see <http://www.gnu.org/licenses/>.
18
+ #
19
+ require 'mkmf'
20
+
21
+ # have_func returns false if a C function cannot be found. Sometimes this
22
+ # will be OK (the function changed names between versions) and sometimes it is
23
+ # not so you need to exit without creating the Makefile.
24
+
25
+ abort 'missing mkstemp()' unless have_func 'mkstemp'
26
+ abort 'missing snprintf()' unless have_func 'snprintf'
27
+ abort 'missing fcntl()' unless have_func 'fcntl'
28
+
29
+ $defs.push('-O2 -g')
30
+
31
+ $objs = %w[
32
+ casper_unique_file.o
33
+ ]
34
+
35
+ extension_name = 'casper_unique_file'
36
+
37
+ # Now we create the Makefile that will install the extension as
38
+ # lib/casper_unique_file/casper_unique_file.so.
39
+
40
+ create_makefile('casper_unique_file/casper_unique_file')
41
+
@@ -0,0 +1,33 @@
1
+ have_func: checking for mkstemp()... -------------------- yes
2
+
3
+ "gcc -o conftest -I/Users/emi/.rvm/rubies/ruby-2.1.5/include/ruby-2.1.0/x86_64-darwin16.0 -I/Users/emi/.rvm/rubies/ruby-2.1.5/include/ruby-2.1.0/ruby/backward -I/Users/emi/.rvm/rubies/ruby-2.1.5/include/ruby-2.1.0 -I. -I/usr/local/opt/libyaml/include -I/usr/local/opt/readline/include -I/usr/local/opt/libksba/include -I/usr/local/opt/openssl/include -I/usr/local/opt/libyaml/include -I/usr/local/opt/readline/include -I/usr/local/opt/libksba/include -I/usr/local/opt/openssl/include -D_XOPEN_SOURCE -D_DARWIN_C_SOURCE -D_DARWIN_UNLIMITED_SELECT -D_REENTRANT -O3 -fno-fast-math -ggdb3 -Wall -Wextra -Wno-unused-parameter -Wno-parentheses -Wno-long-long -Wno-missing-field-initializers -Wunused-variable -Wpointer-arith -Wwrite-strings -Wdeclaration-after-statement -Wshorten-64-to-32 -Wimplicit-function-declaration -Wdivision-by-zero -Wextra-tokens -fno-common -pipe conftest.c -L. -L/Users/emi/.rvm/rubies/ruby-2.1.5/lib -L/usr/local/opt/libyaml/lib -L/usr/local/opt/readline/lib -L/usr/local/opt/libksba/lib -L/usr/local/opt/openssl/lib -L. -fstack-protector -L/usr/local/opt/libyaml/lib -L/usr/local/opt/readline/lib -L/usr/local/opt/libksba/lib -L/usr/local/opt/openssl/lib -L/usr/local/opt/libyaml/lib -L/usr/local/opt/readline/lib -L/usr/local/opt/libksba/lib -L/usr/local/opt/openssl/lib -lruby.2.1.0 -lpthread -ldl -lobjc "
4
+ checked program was:
5
+ /* begin */
6
+ 1: #include "ruby.h"
7
+ 2:
8
+ 3: int main(int argc, char **argv)
9
+ 4: {
10
+ 5: return 0;
11
+ 6: }
12
+ /* end */
13
+
14
+ "gcc -o conftest -I/Users/emi/.rvm/rubies/ruby-2.1.5/include/ruby-2.1.0/x86_64-darwin16.0 -I/Users/emi/.rvm/rubies/ruby-2.1.5/include/ruby-2.1.0/ruby/backward -I/Users/emi/.rvm/rubies/ruby-2.1.5/include/ruby-2.1.0 -I. -I/usr/local/opt/libyaml/include -I/usr/local/opt/readline/include -I/usr/local/opt/libksba/include -I/usr/local/opt/openssl/include -I/usr/local/opt/libyaml/include -I/usr/local/opt/readline/include -I/usr/local/opt/libksba/include -I/usr/local/opt/openssl/include -D_XOPEN_SOURCE -D_DARWIN_C_SOURCE -D_DARWIN_UNLIMITED_SELECT -D_REENTRANT -O3 -fno-fast-math -ggdb3 -Wall -Wextra -Wno-unused-parameter -Wno-parentheses -Wno-long-long -Wno-missing-field-initializers -Wunused-variable -Wpointer-arith -Wwrite-strings -Wdeclaration-after-statement -Wshorten-64-to-32 -Wimplicit-function-declaration -Wdivision-by-zero -Wextra-tokens -fno-common -pipe conftest.c -L. -L/Users/emi/.rvm/rubies/ruby-2.1.5/lib -L/usr/local/opt/libyaml/lib -L/usr/local/opt/readline/lib -L/usr/local/opt/libksba/lib -L/usr/local/opt/openssl/lib -L. -fstack-protector -L/usr/local/opt/libyaml/lib -L/usr/local/opt/readline/lib -L/usr/local/opt/libksba/lib -L/usr/local/opt/openssl/lib -L/usr/local/opt/libyaml/lib -L/usr/local/opt/readline/lib -L/usr/local/opt/libksba/lib -L/usr/local/opt/openssl/lib -lruby.2.1.0 -lpthread -ldl -lobjc "
15
+ checked program was:
16
+ /* begin */
17
+ 1: #include "ruby.h"
18
+ 2:
19
+ 3: /*top*/
20
+ 4: extern int t(void);
21
+ 5: int main(int argc, char **argv)
22
+ 6: {
23
+ 7: if (argc > 1000000) {
24
+ 8: printf("%p", &t);
25
+ 9: }
26
+ 10:
27
+ 11: return 0;
28
+ 12: }
29
+ 13: int t(void) { void ((*volatile p)()); p = (void ((*)()))mkstemp; return 0; }
30
+ /* end */
31
+
32
+ --------------------
33
+
@@ -0,0 +1,20 @@
1
+ #
2
+ # Copyright (c) 2018 Cloudware S.A. All rights reserved.
3
+ #
4
+ # This file is part of casper-unique-file.
5
+ #
6
+ # casper-unique-file is free software: you can redistribute it and/or modify
7
+ # it under the terms of the GNU Affero General Public License as published by
8
+ # the Free Software Foundation, either version 3 of the License, or
9
+ # (at your option) any later version.
10
+ #
11
+ # casper-unique-file is distributed in the hope that it will be useful,
12
+ # but WITHOUT ANY WARRANTY; without even the implied warranty of
13
+ # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14
+ # GNU General Public License for more details.
15
+ #
16
+ # You should have received a copy of the GNU Affero General Public License
17
+ # along with casper-unique-file. If not, see <http://www.gnu.org/licenses/>.
18
+ #
19
+ require 'casper/unique/file/version'
20
+ require 'casper_unique_file/casper_unique_file'
@@ -0,0 +1,27 @@
1
+ #
2
+ # Copyright (c) 2018 Cloudware S.A. All rights reserved.
3
+ #
4
+ # This file is part of casper-unique-file.
5
+ #
6
+ # casper-unique-file is free software: you can redistribute it and/or modify
7
+ # it under the terms of the GNU Affero General Public License as published by
8
+ # the Free Software Foundation, either version 3 of the License, or
9
+ # (at your option) any later version.
10
+ #
11
+ # casper-unique-file is distributed in the hope that it will be useful,
12
+ # but WITHOUT ANY WARRANTY; without even the implied warranty of
13
+ # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14
+ # GNU General Public License for more details.
15
+ #
16
+ # You should have received a copy of the GNU Affero General Public License
17
+ # along with casper-unique-file. If not, see <http://www.gnu.org/licenses/>.
18
+ #
19
+ require "casper/unique/file/version"
20
+
21
+ module Casper
22
+ module Unique
23
+ module File
24
+ # Your code goes here...
25
+ end
26
+ end
27
+ end
@@ -0,0 +1,25 @@
1
+ #
2
+ # Copyright (c) 2018 Cloudware S.A. All rights reserved.
3
+ #
4
+ # This file is part of casper-unique-file.
5
+ #
6
+ # casper-unique-file is free software: you can redistribute it and/or modify
7
+ # it under the terms of the GNU Affero General Public License as published by
8
+ # the Free Software Foundation, either version 3 of the License, or
9
+ # (at your option) any later version.
10
+ #
11
+ # casper-unique-file is distributed in the hope that it will be useful,
12
+ # but WITHOUT ANY WARRANTY; without even the implied warranty of
13
+ # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14
+ # GNU General Public License for more details.
15
+ #
16
+ # You should have received a copy of the GNU Affero General Public License
17
+ # along with casper-unique-file. If not, see <http://www.gnu.org/licenses/>.
18
+ #
19
+ module Casper
20
+ module Unique
21
+ module File
22
+ VERSION = "0.1.3"
23
+ end
24
+ end
25
+ end
metadata ADDED
@@ -0,0 +1,111 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: casper-unique-file
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.3
5
+ platform: ruby
6
+ authors:
7
+ - Eurico Inocencio
8
+ autorequire:
9
+ bindir: exe
10
+ cert_chain: []
11
+ date: 2018-02-07 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: bundler
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '1.16'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '1.16'
27
+ - !ruby/object:Gem::Dependency
28
+ name: rake
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '10.0'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '10.0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: rspec
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - ">="
46
+ - !ruby/object:Gem::Version
47
+ version: '0'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - ">="
53
+ - !ruby/object:Gem::Version
54
+ version: '0'
55
+ - !ruby/object:Gem::Dependency
56
+ name: rake-compiler
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - ">="
60
+ - !ruby/object:Gem::Version
61
+ version: '0'
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - ">="
67
+ - !ruby/object:Gem::Version
68
+ version: '0'
69
+ description:
70
+ email:
71
+ - eurico.inocencio@gmail.com
72
+ executables: []
73
+ extensions:
74
+ - ext/casper_unique_file/extconf.rb
75
+ extra_rdoc_files: []
76
+ files:
77
+ - README.md
78
+ - Rakefile
79
+ - casper-unique-file.gemspec
80
+ - ext/casper_unique_file/Makefile
81
+ - ext/casper_unique_file/casper_unique_file.c
82
+ - ext/casper_unique_file/extconf.rb
83
+ - ext/casper_unique_file/mkmf.log
84
+ - lib/casper-unique-file.rb
85
+ - lib/casper/unique/file.rb
86
+ - lib/casper/unique/file/version.rb
87
+ - lib/casper_unique_file/casper_unique_file.bundle
88
+ homepage: https://github.com/casper2020/casper-unique-file
89
+ licenses: []
90
+ metadata: {}
91
+ post_install_message:
92
+ rdoc_options: []
93
+ require_paths:
94
+ - lib
95
+ required_ruby_version: !ruby/object:Gem::Requirement
96
+ requirements:
97
+ - - ">="
98
+ - !ruby/object:Gem::Version
99
+ version: '0'
100
+ required_rubygems_version: !ruby/object:Gem::Requirement
101
+ requirements:
102
+ - - ">="
103
+ - !ruby/object:Gem::Version
104
+ version: '0'
105
+ requirements: []
106
+ rubyforge_project:
107
+ rubygems_version: 2.4.8
108
+ signing_key:
109
+ specification_version: 4
110
+ summary: Helper to make safe unique filenames in ruby
111
+ test_files: []