ruby-magic 0.0.1 → 0.2.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 39c8d257044d13e7581c09d1a546bf3a53c89721
4
- data.tar.gz: c544dfb6645dff08b837e1f9583238e7e0ecfeb0
3
+ metadata.gz: 2bdbd8e67d4f6fdfcf17101e79003176121482b4
4
+ data.tar.gz: a39c944b6afb2d77087c894ed598a42d872faf5a
5
5
  SHA512:
6
- metadata.gz: 5b272855f23c41b6f6e90d0688ed97309e1880ed35220cdf982e9543a4547307bddf691d338da61f42bbb090e28a112e4db39dbc74172d7ed5080e0e5347b9ba
7
- data.tar.gz: ec5dfa92be79835e0d89ca23a433c55c029e72f5e847ad4931984ab150e9ee2a31dc3ee3e93dc87fbdb41a12bfb387feed952b227246ad9cfe87d91b29b7fe95
6
+ metadata.gz: 8ac4e55c28a4ebb20c276d3e7e8e94566c3267c89a33a36edb2e4c815fe581007980c15594a437cb560fbb3e8a62d869c52fc8462aa081370aa6f2aded32f01f
7
+ data.tar.gz: c5e23e0fd76c60595b75ad368f9841b83922e7796fb1d09797376c8672fd62240bfc8429242f38ec23c609e48feffc569c4fa89155596ebdb3a95f11a211b0e3
data/CHANGES CHANGED
@@ -1,3 +1,48 @@
1
+ ruby-magic (0.2.0)
2
+
3
+ * Fixed formatting and white spaces.
4
+ * Added Gemnasium, plus Coveralls and Code Climate integration (and hence improved
5
+ code test coverage).
6
+ * Fixed Travis CI build against Rubinius.
7
+ * Re-factored the API and cleaned up small portions of code and documentation.
8
+ * Retired support for Ruby 1.8.x (no support for MRI, Ruby Enterprise Edition and Rubinius).
9
+ * Added functionality to handle releasing the GVL for any file and/or I/O operations.
10
+ * Added ability to Magic#flags_array to return name of each flag that is set.
11
+ * Changed Magic#version_array and Magic#version_string methods to be a singleton methods.
12
+ * Renamed the Magic#flags_array method to Magic#flags_to_a.
13
+ * Retired testing with Ruby 1.9.2 and 2.1.0, and added 2.2.0 on Travis CI.
14
+ * Added naïve synchronization via Mutex#lock and Mutex#unlock methods to make interactions
15
+ with libmagic more thread-safe.
16
+ * Changed the Magic::new method, so that it accepts an array of paths from which to load
17
+ the Magic database.
18
+ * Fixed setting of global errno value to avoid race conditions.
19
+ * Added ability for Travis CI test against multiple versions of vanilla libmagic.
20
+ * Added LLVM (clang) compiler to build with to Travis CI, and fixed various issues reported
21
+ by clang compiler during build-time.
22
+ * Added ability for Magic#load to take nil as valid argument.
23
+ * Fixed issue with libmagic's regular expression (regex) library not working with UTF-8 (or
24
+ any other wide-character encoding).
25
+ * Fixed build to make it work with C++ compilers.
26
+ * Added support for the MAGIC_CONTINUE flag so that Magic#file, Magic#buffer and
27
+ Magic#descriptor methods will return an array for multiple results when appropriate.
28
+ * Moved integration with File and String core classes into separate namespace.
29
+ * Removed forward declaration of errno as it's not needed on systems with modern C/C++
30
+ libraries and compilers.
31
+ * Added rudimentary Vagrantfile that can be used to build a development environment.
32
+ * Removed the "-Wl,--no-undefined" option from LDFLAGS, as they might break on some systems.
33
+ * Fixed any C90 standard related build-time warnings.
34
+ * Changed the behaviour not to catch the generic Magic::Error, plus always to raise on errors
35
+ coming from libmagic. This is to make it more aligned with the standard library, where file
36
+ and I/O related errors would raise an appropriate exception.
37
+ * Fixed version number to comply with Semantic Versioning 2 (http://semver.org/).
38
+ * Added the Guard Ruby gem for convenience, with an appropriate Guardfile.
39
+ * Changed behaviour consistent among various versions of libmagic adhering to the POSIX
40
+ standard. This concerns the following IEEE 1003.1 standards:
41
+ - http://pubs.opengroup.org/onlinepubs/007904975/utilities/file.html
42
+ - http://pubs.opengroup.org/onlinepubs/9699919799/utilities/file.html
43
+
44
+ -- Krzysztof Wilczynski <krzysztof.wilczynski@linux.com> Wed, 25 Mar 2015 23:27:00 +0000
45
+
1
46
  ruby-magic (0.0.1)
2
47
 
3
48
  * First version.
@@ -1,3 +1,48 @@
1
+ ruby-magic (0.2.0)
2
+
3
+ * Fixed formatting and white spaces.
4
+ * Added Gemnasium, plus Coveralls and Code Climate integration (and hence improved
5
+ code test coverage).
6
+ * Fixed Travis CI build against Rubinius.
7
+ * Re-factored the API and cleaned up small portions of code and documentation.
8
+ * Retired support for Ruby 1.8.x (no support for MRI, Ruby Enterprise Edition and Rubinius).
9
+ * Added functionality to handle releasing the GVL for any file and/or I/O operations.
10
+ * Added ability to Magic#flags_array to return name of each flag that is set.
11
+ * Changed Magic#version_array and Magic#version_string methods to be a singleton methods.
12
+ * Renamed the Magic#flags_array method to Magic#flags_to_a.
13
+ * Retired testing with Ruby 1.9.2 and 2.1.0, and added 2.2.0 on Travis CI.
14
+ * Added naïve synchronization via Mutex#lock and Mutex#unlock methods to make interactions
15
+ with libmagic more thread-safe.
16
+ * Changed the Magic::new method, so that it accepts an array of paths from which to load
17
+ the Magic database.
18
+ * Fixed setting of global errno value to avoid race conditions.
19
+ * Added ability for Travis CI test against multiple versions of vanilla libmagic.
20
+ * Added LLVM (clang) compiler to build with to Travis CI, and fixed various issues reported
21
+ by clang compiler during build-time.
22
+ * Added ability for Magic#load to take nil as valid argument.
23
+ * Fixed issue with libmagic's regular expression (regex) library not working with UTF-8 (or
24
+ any other wide-character encoding).
25
+ * Fixed build to make it work with C++ compilers.
26
+ * Added support for the MAGIC_CONTINUE flag so that Magic#file, Magic#buffer and
27
+ Magic#descriptor methods will return an array for multiple results when appropriate.
28
+ * Moved integration with File and String core classes into separate namespace.
29
+ * Removed forward declaration of errno as it's not needed on systems with modern C/C++
30
+ libraries and compilers.
31
+ * Added rudimentary Vagrantfile that can be used to build a development environment.
32
+ * Removed the "-Wl,--no-undefined" option from LDFLAGS, as they might break on some systems.
33
+ * Fixed any C90 standard related build-time warnings.
34
+ * Changed the behaviour not to catch the generic Magic::Error, plus always to raise on errors
35
+ coming from libmagic. This is to make it more aligned with the standard library, where file
36
+ and I/O related errors would raise an appropriate exception.
37
+ * Fixed version number to comply with Semantic Versioning 2 (http://semver.org/).
38
+ * Added the Guard Ruby gem for convenience, with an appropriate Guardfile.
39
+ * Changed behaviour consistent among various versions of libmagic adhering to the POSIX
40
+ standard. This concerns the following IEEE 1003.1 standards:
41
+ - http://pubs.opengroup.org/onlinepubs/007904975/utilities/file.html
42
+ - http://pubs.opengroup.org/onlinepubs/9699919799/utilities/file.html
43
+
44
+ -- Krzysztof Wilczynski <krzysztof.wilczynski@linux.com> Wed, 25 Mar 2015 23:27:00 +0000
45
+
1
46
  ruby-magic (0.0.1)
2
47
 
3
48
  * First version.
data/COPYRIGHT CHANGED
@@ -1 +1 @@
1
- Copyright 2013-2014 Krzysztof Wilczynski
1
+ Copyright 2013-2015 Krzysztof Wilczynski
@@ -1,7 +1,8 @@
1
1
  Simple interface to libmagic for Ruby Programming Language
2
2
 
3
3
  {<img src="https://travis-ci.org/kwilczynski/ruby-magic.png?branch=master" alt="Build Status"/>}[https://travis-ci.org/kwilczynski/ruby-magic]
4
+ {<img src="http://inch-ci.org/github/kwilczynski/ruby-magic.svg?branch=master" alt="Documentation Status" />}[http://inch-ci.org/github/kwilczynski/ruby-magic]
5
+ {<img src="https://badge.fury.io/rb/ruby-magic.png" alt="Gem Version" />}[http://badge.fury.io/rb/ruby-magic]
4
6
  {<img src="https://coveralls.io/repos/kwilczynski/ruby-magic/badge.png?branch=master" alt="Coverage Status" />}[https://coveralls.io/r/kwilczynski/ruby-magic?branch=master]
5
- {<img src="https://codeclimate.com/github/kwilczynski/ruby-magic.png" />}[https://codeclimate.com/github/kwilczynski/ruby-magic]
7
+ {<img src="https://codeclimate.com/github/kwilczynski/ruby-magic.png" alt="Code Quality" />}[https://codeclimate.com/github/kwilczynski/ruby-magic]
6
8
  {<img src="https://gemnasium.com/kwilczynski/ruby-magic.png" alt="Dependency Status" />}[https://gemnasium.com/kwilczynski/ruby-magic]
7
- {<img src="https://d2weczhvl823v0.cloudfront.net/kwilczynski/ruby-magic/trend.png" alt="Bitdeli Badge" />}[https://bitdeli.com/free]
data/Rakefile CHANGED
@@ -5,7 +5,7 @@
5
5
  #
6
6
  # Rakefile
7
7
  #
8
- # Copyright 2013-2014 Krzysztof Wilczynski
8
+ # Copyright 2013-2015 Krzysztof Wilczynski
9
9
  #
10
10
  # Licensed under the Apache License, Version 2.0 (the "License");
11
11
  # you may not use this file except in compliance with the License.
@@ -70,6 +70,7 @@ Rake::ExtensionTask.new('magic', gem) do |e|
70
70
  e.lib_dir = 'lib/magic'
71
71
  end
72
72
 
73
+ Rake::Task[:test].prerequisites << :clobber
73
74
  Rake::Task[:test].prerequisites << :compile
74
75
 
75
76
  task :default => :test
data/TODO CHANGED
@@ -1,21 +1,24 @@
1
- ruby-magic (0.0.4)
1
+ ruby-magic (0.5.0)
2
2
 
3
3
  * Vendor libmagic source code?
4
4
 
5
- -- Krzysztof Wilczynski <krzysztof.wilczynski@linux.com> Fri, 21 Mar 2014 18:06:21 +0000
5
+ -- Krzysztof Wilczynski <krzysztof.wilczynski@linux.com> Wed, 25 Mar 2015 23:27:00 +0000
6
6
 
7
- ruby-magic (0.0.3)
7
+ ruby-magic (0.4.0)
8
8
 
9
9
  * Add some examples;
10
10
  * Move to YARD from RDoc (as RDoc is very bad, really);
11
11
  * Improve documentation i.e. source code commenting, README file, etc.
12
12
 
13
- -- Krzysztof Wilczynski <krzysztof.wilczynski@linux.com> Fri, 21 Mar 2014 16:49:26 +0000
13
+ -- Krzysztof Wilczynski <krzysztof.wilczynski@linux.com> Wed, 25 Mar 2015 23:27:00 +0000
14
14
 
15
- ruby-magic (0.0.2)
15
+ ruby-magic (0.3.0)
16
16
 
17
+ * Improve test coverage (if possible to 100%);
17
18
  * Add implementation for the included "binary";
18
19
  * Add Doxygen style comments for other functions in the source code;
19
- * Add RDoc and improve documentation i.e. source code commenting.
20
+ * Add RDoc and improve documentation i.e. source code commenting;
21
+ * Add support for magic_load_buffers(magic_t, void **, size_t *, size_t);
22
+ * Add support for Windows (if possible).
20
23
 
21
- -- Krzysztof Wilczynski <krzysztof.wilczynski@linux.com> Fri, 21 Mar 2014 16:49:26 +0000
24
+ -- Krzysztof Wilczynski <krzysztof.wilczynski@linux.com> Wed, 25 Mar 2015 23:27:00 +0000
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.0.1
1
+ 0.2.0
data/bin/magic CHANGED
@@ -7,7 +7,7 @@
7
7
  #
8
8
  # magic
9
9
  #
10
- # Copyright 2013-2014 Krzysztof Wilczynski
10
+ # Copyright 2013-2015 Krzysztof Wilczynski
11
11
  #
12
12
  # Licensed under the Apache License, Version 2.0 (the "License");
13
13
  # you may not use this file except in compliance with the License.
@@ -3,7 +3,7 @@
3
3
  /*
4
4
  * common.h
5
5
  *
6
- * Copyright 2013-2014 Krzysztof Wilczynski
6
+ * Copyright 2013-2015 Krzysztof Wilczynski
7
7
  *
8
8
  * Licensed under the Apache License, Version 2.0 (the "License");
9
9
  * you may not use this file except in compliance with the License.
@@ -40,13 +40,20 @@ extern "C" {
40
40
  #include <fcntl.h>
41
41
  #include <errno.h>
42
42
  #include <assert.h>
43
- #include <locale.h>
44
43
  #include <sys/stat.h>
45
44
  #include <magic.h>
46
45
  #include <ruby.h>
47
46
 
48
- #if !defined(EPERM)
49
- # define EPERM 1
47
+ #if defined(HAVE_LOCALE_H)
48
+ # include <locale.h>
49
+ #endif
50
+
51
+ #if defined(HAVE_XLOCALE_H)
52
+ # include <xlocale.h>
53
+ #endif
54
+
55
+ #if !defined(ENOMEM)
56
+ # define ENOMEM 12
50
57
  #endif
51
58
 
52
59
  #if !defined(EFAULT)
@@ -75,11 +82,13 @@ extern "C" {
75
82
 
76
83
  #define UNUSED(x) (void)(x)
77
84
 
78
- #if !defined(HAVE_MAGIC_VERSION) || MAGIC_VERSION < 517
85
+ #if !defined(HAVE_MAGIC_VERSION) || MAGIC_VERSION < 518
79
86
  # define HAVE_BROKEN_MAGIC 1
80
87
  #endif
81
88
 
82
- extern int errno;
89
+ #if defined(HAVE_NEWLOCALE) && defined(HAVE_USELOCALE) && defined(HAVE_FREELOCALE)
90
+ # define HAVE_SAFE_LOCALE 1
91
+ #endif
83
92
 
84
93
  #if defined(__cplusplus)
85
94
  }
@@ -5,7 +5,7 @@
5
5
  #
6
6
  # extconf.rb
7
7
  #
8
- # Copyright 2013-2014 Krzysztof Wilczynski
8
+ # Copyright 2013-2015 Krzysztof Wilczynski
9
9
  #
10
10
  # Licensed under the Apache License, Version 2.0 (the "License");
11
11
  # you may not use this file except in compliance with the License.
@@ -24,12 +24,35 @@ require 'mkmf'
24
24
 
25
25
  RbConfig::MAKEFILE_CONFIG['CC'] = ENV['CC'] if ENV['CC']
26
26
 
27
+ $CFLAGS << ' -std=c99 -g -Wall -Wextra -pedantic'
28
+
29
+ unless RbConfig::CONFIG['host_os'][/darwin/]
30
+ $LDFLAGS << ' -Wl,--as-needed'
31
+ end
32
+
27
33
  $LDFLAGS << " %s" % ENV['LDFLAGS'] if ENV['LDFLAGS']
28
34
 
29
- $CFLAGS << " %s" % ENV['CFLAGS'] if ENV['CFLAGS']
30
- $CFLAGS << ' -std=c99 -g -Wall -Wextra -pedantic'
35
+ %w(CFLAGS CXXFLAGS CPPFLAGS).each do |variable|
36
+ $CFLAGS << " %s" % ENV[variable] if ENV[variable]
37
+ end
31
38
 
32
- unless have_header('ruby.h')
39
+ have_header('locale.h')
40
+ have_header('xlocale.h')
41
+ have_header('utime.h')
42
+ have_header('sys/types.h')
43
+ have_header('sys/time.h')
44
+
45
+ have_ruby_h = have_header('ruby.h')
46
+ have_magic_h = have_header('magic.h')
47
+
48
+ have_func('newlocale', ['locale.h', 'xlocale.h'])
49
+ have_func('uselocale', ['locale.h', 'xlocale.h'])
50
+ have_func('freelocale', ['locale.h', 'xlocale.h'])
51
+
52
+ have_func('utime', ['utime.h', 'sys/types.h'])
53
+ have_func('utimes', 'sys/time.h')
54
+
55
+ unless have_ruby_h
33
56
  abort <<-EOS
34
57
 
35
58
  You appear to be missing Ruby development libraries and/or header
@@ -55,7 +78,10 @@ unless have_header('ruby.h')
55
78
  EOS
56
79
  end
57
80
 
58
- unless have_header('magic.h')
81
+ have_func('rb_thread_call_without_gvl')
82
+ have_func('rb_thread_blocking_region')
83
+
84
+ unless have_magic_h
59
85
  abort <<-EOS
60
86
 
61
87
  You appear to be missing libmagic(3) library and/or necessary header
@@ -100,12 +126,6 @@ end
100
126
 
101
127
  have_func('magic_version', 'magic.h')
102
128
 
103
- have_func('utime', ['utime.h', 'sys/types.h'])
104
- have_func('utimes', 'sys/time.h')
105
-
106
- have_func('rb_thread_call_without_gvl')
107
- have_func('rb_thread_blocking_region')
108
-
109
129
  dir_config('magic')
110
130
 
111
131
  create_header
@@ -3,7 +3,7 @@
3
3
  /*
4
4
  * functions.c
5
5
  *
6
- * Copyright 2013-2014 Krzysztof Wilczynski
6
+ * Copyright 2013-2015 Krzysztof Wilczynski
7
7
  *
8
8
  * Licensed under the Apache License, Version 2.0 (the "License");
9
9
  * you may not use this file except in compliance with the License.
@@ -18,6 +18,10 @@
18
18
  * limitations under the License.
19
19
  */
20
20
 
21
+ #if defined(__cplusplus)
22
+ extern "C" {
23
+ #endif
24
+
21
25
  #include "functions.h"
22
26
 
23
27
  int suppress_error_output(void *data);
@@ -116,21 +120,44 @@ out:
116
120
  int
117
121
  override_current_locale(void *data)
118
122
  {
123
+ #if !defined(HAVE_SAFE_LOCALE)
119
124
  char *current_locale = NULL;
125
+ #endif
120
126
 
121
127
  save_t *s = data;
122
128
  assert(s != NULL && "Must be a valid pointer to `save_t' type");
123
129
 
124
130
  s->status = -1;
125
- s->data.locale = NULL;
131
+
132
+ #if defined(HAVE_SAFE_LOCALE)
133
+ s->data.locale.old_locale = NULL;
134
+ s->data.locale.new_locale = NULL;
135
+
136
+ s->data.locale.new_locale = newlocale(LC_ALL_MASK, "C", NULL);
137
+ if (s->data.locale.new_locale == (locale_t)0) {
138
+ goto out;
139
+ }
140
+
141
+ assert(s->data.locale.new_locale != NULL && \
142
+ "Must be a valid pointer to `locale_t' type");
143
+
144
+ s->data.locale.old_locale = uselocale(s->data.locale.new_locale);
145
+ if (s->data.locale.old_locale == (locale_t)0) {
146
+ goto out;
147
+ }
148
+
149
+ assert(s->data.locale.old_locale != NULL && \
150
+ "Must be a valid pointer to `locale_t' type");
151
+ #else
152
+ s->data.locale.old_locale = NULL;
126
153
 
127
154
  current_locale = setlocale(LC_ALL, NULL);
128
155
  if (!current_locale) {
129
156
  goto out;
130
157
  }
131
158
 
132
- s->data.locale = strndup(current_locale, strlen(current_locale));
133
- if (!s->data.locale) {
159
+ s->data.locale.old_locale = strndup(current_locale, strlen(current_locale));
160
+ if (!s->data.locale.old_locale) {
134
161
  goto out;
135
162
  }
136
163
 
@@ -138,7 +165,9 @@ override_current_locale(void *data)
138
165
  goto out;
139
166
  }
140
167
 
141
- assert(s->data.locale != NULL && "Must be a valid pointer to `char' type");
168
+ assert(s->data.locale.old_locale != NULL && \
169
+ "Must be a valid pointer to `char' type");
170
+ #endif
142
171
  s->status = 0;
143
172
 
144
173
  out:
@@ -151,22 +180,44 @@ restore_current_locale(void *data)
151
180
  save_t *s = data;
152
181
  assert(s != NULL && "Must be a valid pointer to `save_t' type");
153
182
 
154
- if (!s->data.locale && s->status != 0) {
183
+ #if defined(HAVE_SAFE_LOCALE)
184
+ if (!s->data.locale.new_locale && !s->data.locale.old_locale && s->status != 0) {
155
185
  return -1;
156
186
  }
157
187
 
158
- if (!setlocale(LC_ALL, s->data.locale)) {
188
+ if (uselocale(s->data.locale.old_locale) == (locale_t)0) {
159
189
  goto out;
160
190
  }
161
191
 
162
- assert(s->data.locale != NULL && "Must be a valid pointer to `char' type");
163
- free(s->data.locale);
192
+ assert(s->data.locale.new_locale != NULL && \
193
+ "Must be a valid pointer to `locale_t' type");
194
+
195
+ freelocale(s->data.locale.new_locale);
196
+ #else
197
+ if (!s->data.locale.old_locale && s->status != 0) {
198
+ return -1;
199
+ }
200
+
201
+ if (!setlocale(LC_ALL, s->data.locale.old_locale)) {
202
+ goto out;
203
+ }
204
+
205
+ assert(s->data.locale.old_locale != NULL && \
206
+ "Must be a valid pointer to `char' type");
207
+
208
+ free(s->data.locale.old_locale);
209
+ #endif
164
210
 
165
211
  return 0;
166
212
 
167
213
  out:
168
- s->data.locale = NULL;
169
214
  s->status = -1;
215
+ #if defined(HAVE_SAFE_LOCALE)
216
+ s->data.locale.old_locale = NULL;
217
+ s->data.locale.new_locale = NULL;
218
+ #else
219
+ s->data.locale.old_locale = NULL;
220
+ #endif
170
221
 
171
222
  return -1;
172
223
  }
@@ -271,4 +322,8 @@ magic_version_wrapper(void)
271
322
  #endif
272
323
  }
273
324
 
325
+ #if defined(__cplusplus)
326
+ }
327
+ #endif
328
+
274
329
  /* vim: set ts=8 sw=4 sts=2 et : */
@@ -3,7 +3,7 @@
3
3
  /*
4
4
  * functions.h
5
5
  *
6
- * Copyright 2013-2014 Krzysztof Wilczynski
6
+ * Copyright 2013-2015 Krzysztof Wilczynski
7
7
  *
8
8
  * Licensed under the Apache License, Version 2.0 (the "License");
9
9
  * you may not use this file except in compliance with the License.
@@ -68,11 +68,22 @@ struct file_data {
68
68
 
69
69
  typedef struct file_data file_data_t;
70
70
 
71
+ struct locale_data {
72
+ #if defined(HAVE_SAFE_LOCALE)
73
+ locale_t old_locale;
74
+ locale_t new_locale;
75
+ #else
76
+ char *old_locale;
77
+ #endif
78
+ };
79
+
80
+ typedef struct locale_data locale_data_t;
81
+
71
82
  struct save {
72
83
  int status;
73
84
  union {
74
85
  file_data_t file;
75
- char *locale;
86
+ locale_data_t locale;
76
87
  } data;
77
88
  };
78
89