ruby-magic 0.3.2 → 0.5.3

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
  SHA256:
3
- metadata.gz: 1a066f36addb7d1c8cbe0858a67fa6a8e2103b3d365ab2d0ccda3027ea43a8ce
4
- data.tar.gz: 3828bda59c9df6377991481d7f4fa9a8526e981804ff80dbb84aeba7eb316578
3
+ metadata.gz: ce261c39e721356e45db04684e03911148e8f83c4aed053d17c8594f59da9248
4
+ data.tar.gz: ca2fc5dd7c36810d595d1b0c8381eae7dc028506a7495a399ee879850c88b8aa
5
5
  SHA512:
6
- metadata.gz: 1ea5942f3c0f33f438f684437a3def3db633f18a279c84574f8a9ee0022d60e8852954b99ee32cc5ad7aa0fa5e10e1b1673e97575d72dfe28c862ac18476d551
7
- data.tar.gz: 7ad49df412d72dd3d2b29e07509916e7aef46bf3058191019a290d07fed8792877fa623b9d327e4fa94fa21f49ef2fc8ad242777d3f398c53322a08413dd6a58
6
+ metadata.gz: c853a4112e2b606bf4827974fd8ec9118c06627f0e4001732a33ee32cb7059bcf13bc875a14b3076911102f5a7eb3c70f07539453254f06f0f1aa6e8d8e469b2
7
+ data.tar.gz: 6197afd12f7549160b7824f1283effd630edce3b13fabd1e018c45fc9e4ddd2f4ef12877de00a3ae73b03f4b82184084e095e154fcae960e107bde3c90bdf6a5
data/CHANGELOG.md CHANGED
@@ -7,6 +7,44 @@ and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.
7
7
 
8
8
  ## [Unreleased]
9
9
 
10
+ ## [0.5.3] - 2021-12-22
11
+
12
+ ### Fixed
13
+
14
+ - ext: load C extension files from non-native gems via "require"
15
+
16
+ ## [0.5.2] - 2021-11-20
17
+
18
+ - No changes
19
+
20
+ ## [0.5.1] - 2021-11-20
21
+
22
+ ### Fixed
23
+
24
+ - Check for pkg-config when building static libraries.
25
+
26
+ ## [0.5.0] - 2021-09-30
27
+
28
+ ### Added
29
+
30
+ - Introduce support for building native gems.
31
+
32
+ ### Changed
33
+
34
+ - Relax mini_portile2 dependency.
35
+ - Use RB_ALLOC() over calling ruby_xmalloc() directly
36
+ - Address warnings reported by cppcheck.
37
+ - Address code style that checkpatch.pl script reported.
38
+ - Fix how flags are set for the open() function.
39
+ - Clean up type definitions.
40
+ - Add alias Magic::mime_type for Magic::mime.
41
+ - Make magic_set_flags() return void as its return value was never used.
42
+
43
+ ### Fixed
44
+
45
+ - Fix truffleruby test failure
46
+ - Fix --use-system-libraries not working with Rake install
47
+
10
48
  ## [0.2.0] - 2015-03-25
11
49
  ### Added
12
50
 
data/CONTRIBUTORS.md CHANGED
@@ -7,8 +7,9 @@ of Ruby Magic. They are hereby acknowledged and collectively identified as "The
7
7
  Ruby Magic Authors". Copyright is held by the original contributor according to
8
8
  the versioning history; see [LICENSE](LICENSE) file.
9
9
 
10
-
10
+ - Igor Victor ([@gogainda](https://github.com/gogainda))
11
11
  - John Hawthorn ([@jhawthorn](https://github.com/jhawthorn))
12
+ - Mike Dalessio ([@flavorjones](https://github.com/flavorjones))
12
13
  - Shinya Maeda ([@dosuken123](https://github.com/dosuken123))
13
14
  - Stan Hu ([@stanhu](https://github.com/stanhu))
14
15
 
data/dependencies.yml ADDED
@@ -0,0 +1,22 @@
1
+ libmagic:
2
+ version: "5.39"
3
+ sha256: "f05d286a76d9556243d0cb05814929c2ecf3a5ba07963f8f70bfaaa70517fad1"
4
+ # Manually verified checksum:
5
+ #
6
+ # $ gpg --verify file-5.39.tar.gz.asc file-5.39.tar.gz
7
+ # gpg: Signature made Mon Jun 15 02:06:08 2020 CEST
8
+ # gpg: using DSA key 0x71112AB16CB33B3A
9
+ # gpg: Good signature from "Christos Zoulas (personal key) <christos@zoulas.com>" [unknown]
10
+ # gpg: aka "Christos Zoulas (NetBSD key) <christos@netbsd.org>" [unknown]
11
+ # gpg: WARNING: This key is not certified with a trusted signature!
12
+ # gpg: There is no indication that the signature belongs to the owner.
13
+ # Primary key fingerprint: BE04 995B A8F9 0ED0 C0C1 76C4 7111 2AB1 6CB3 3B3A
14
+ #
15
+ # Using this PGP signature:
16
+ #
17
+ # -----BEGIN PGP SIGNATURE-----
18
+ #
19
+ # iEYEABECAAYFAl7mu3AACgkQcREqsWyzOzppXACgoqokKabq7bwN9aKvd/H/yhF+
20
+ # 9PUAoOPrAtxFkfNUvtqK/trY+v/Gk5JM
21
+ # =tA6a
22
+ # -----END PGP SIGNATURE-----
data/ext/magic/common.h CHANGED
@@ -36,27 +36,27 @@ extern "C" {
36
36
  # include <ruby/io.h>
37
37
  #else
38
38
  # include <rubyio.h>
39
- #endif
39
+ #endif /* HAVE_RUBY_IO_H */
40
40
 
41
- #if !defined(BIT)
42
- # define BIT(n) (1 << (n))
43
- #endif
41
+ #define BIT(n) (1 << (n))
44
42
 
45
43
  #if !defined(UNUSED)
46
44
  # define UNUSED(x) (void)(x)
47
- #endif
45
+ #endif /* UNUSED */
46
+
47
+ #define ARRAY_SIZE(a) (int)(sizeof(a) / sizeof((a)[0]))
48
48
 
49
49
  #if defined(F_DUPFD_CLOEXEC)
50
50
  # define HAVE_F_DUPFD_CLOEXEC 1
51
- #endif
51
+ #endif /* F_DUPFD_CLOEXEC */
52
52
 
53
53
  #if defined(O_CLOEXEC)
54
54
  # define HAVE_O_CLOEXEC 1
55
- #endif
55
+ #endif /* O_CLOEXEC */
56
56
 
57
57
  #if defined(POSIX_CLOSE_RESTART)
58
58
  # define HAVE_POSIX_CLOSE_RESTART 1
59
- #endif
59
+ #endif /* POSIX_CLOSE_RESTART */
60
60
 
61
61
  #define MAGIC_EXTENSION_SEPARATOR "/"
62
62
  #define MAGIC_CONTINUE_SEPARATOR "\n- "
@@ -65,15 +65,21 @@ extern "C" {
65
65
  # define MAGIC_STATUS_CHECK(x) x
66
66
  #else
67
67
  # define MAGIC_STATUS_CHECK(x) 1
68
- #endif
68
+ #endif /* MAGIC_SYSTEM_LIBRARIES */
69
+
70
+ #if !defined(MAGIC_CUSTOM_CHECK_TYPE)
71
+ # define MAGIC_CHECK_RUBY_TYPE(o, t) Check_Type((o), (t))
72
+ #else
73
+ # define MAGIC_CHECK_RUBY_TYPE(o, t) magic_check_ruby_type((o), (t))
74
+ #endif /* MAGIC_CUSTOM_CHECK_TYPE */
69
75
 
70
76
  #if !defined(MAGIC_NO_CHECK_CSV)
71
77
  # define MAGIC_NO_CHECK_CSV 0
72
- #endif
78
+ #endif /* MAGIC_NO_CHECK_CSV */
73
79
 
74
80
  #if !defined(MAGIC_NO_CHECK_JSON)
75
81
  # define MAGIC_NO_CHECK_JSON 0
76
- #endif
82
+ #endif /* MAGIC_NO_CHECK_JSON */
77
83
 
78
84
  #define DATA_P(x) (RB_TYPE_P((x), T_DATA))
79
85
  #define BOOLEAN_P(x) (RB_TYPE_P((x), T_TRUE) || RB_TYPE_P((x), T_FALSE))
@@ -81,11 +87,13 @@ extern "C" {
81
87
  #define ARRAY_P(x) (RB_TYPE_P((x), T_ARRAY))
82
88
  #define FILE_P(x) (RB_TYPE_P((x), T_FILE))
83
89
 
84
- #define RVAL2CBOOL(x) (RTEST(x))
85
- #define CBOOL2RVAL(x) ((x) ? Qtrue : Qfalse)
90
+ #define RVAL2CBOOL(b) (RTEST(b))
91
+ #define CBOOL2RVAL(b) ((b) ? Qtrue : Qfalse)
92
+
93
+ #define RVAL2CSTR(s) (NIL_P(s) ? NULL : StringValueCStr(s))
94
+ #define CSTR2RVAL(s) ((s) == NULL ? Qnil : rb_str_new2((const char *)s))
86
95
 
87
- #define RVAL2CSTR(x) (NIL_P(x) ? NULL : StringValueCStr(x))
88
- #define CSTR2RVAL(x) ((x) == NULL ? Qnil : rb_str_new2(x))
96
+ #define RSTRING_EMPTY_P(s) (RSTRING_LEN(s) == 0)
89
97
 
90
98
  #define RARRAY_EMPTY rb_ary_new()
91
99
  #define RARRAY_EMPTY_P(a) (RARRAY_LEN(a) == 0)
@@ -95,25 +103,32 @@ extern "C" {
95
103
  # define RVALUE_TYPE enum ruby_value_type
96
104
  #else
97
105
  # define RVALUE_TYPE int
98
- #endif
106
+ #endif /* RUBY_API_VERSION_CODE > 20700 */
107
+
108
+ #if RUBY_API_VERSION_CODE >= 20700
109
+ # define HAVE_RUBY_GC_COMPACT 1
110
+ # define MAGIC_GC_MARK(x) rb_gc_mark_movable((x))
111
+ #else
112
+ # define MAGIC_GC_MARK(x) rb_gc_mark((x))
113
+ #endif /* RUBY_API_VERSION_CODE >= 20700 */
99
114
 
100
115
  #define CLASS_NAME(o) (NIL_P((o)) ? "nil" : rb_obj_classname((o)))
101
116
 
102
117
  #if !defined(T_INTEGER)
103
118
  # define T_INTEGER rb_cInteger
104
- #endif
119
+ #endif /* T_INTEGER */
105
120
 
106
121
  #if !defined(HAVE_RB_IO_T)
107
122
  # define rb_io_t OpenFile
108
- #endif
123
+ #endif /* HAVE_RB_IO_T */
109
124
 
110
125
  #if !defined(GetReadFile)
111
126
  # define FPTR_TO_FD(p) ((p)->fd)
112
127
  #else
113
128
  # define FPTR_TO_FD(p) (fileno(GetReadFile(p)))
114
- #endif
129
+ #endif /* GetReadFile */
115
130
 
116
- #define NOGVL_FUNCTION (VALUE (*)(void *))
131
+ #define NOGVL_FUNCTION (VALUE(*)(void *))
117
132
 
118
133
  #if defined(HAVE_RB_THREAD_CALL_WITHOUT_GVL) && \
119
134
  defined(HAVE_RUBY_THREAD_H) && HAVE_RUBY_THREAD_H
@@ -138,7 +153,10 @@ fake_blocking_region(VALUE (*f)(ANYARGS), void *data)
138
153
  }
139
154
  # define NOGVL(f, d) \
140
155
  fake_blocking_region(NOGVL_FUNCTION(f), (d))
141
- #endif
156
+ #endif /*
157
+ * HAVE_RB_THREAD_CALL_WITHOUT_GVL
158
+ * HAVE_RUBY_THREAD_H
159
+ */
142
160
 
143
161
  #if defined(__cplusplus)
144
162
  }
data/ext/magic/extconf.rb CHANGED
@@ -4,15 +4,12 @@ require 'find'
4
4
  require 'mkmf'
5
5
  require 'pathname'
6
6
 
7
- LIBMAGIC_TAG = '5.39'
8
- LIBIMAGE_SHA256 = 'f05d286a76d9556243d0cb05814929c2ecf3a5ba07963f8f70bfaaa70517fad1'
9
-
10
7
  # helpful constants
11
8
  PACKAGE_ROOT_DIR = File.expand_path(File.join(File.dirname(__FILE__), '..', '..'))
12
9
 
13
10
  # The gem version constraint in the Rakefile is not respected at install time.
14
11
  # Keep this version in sync with the one in the Rakefile !
15
- REQUIRED_MINI_PORTILE_VERSION = "~> 2.5.0"
12
+ REQUIRED_MINI_PORTILE_VERSION = "~> 2.6"
16
13
 
17
14
  MAGIC_HELP_MESSAGE = <<~HELP
18
15
  USAGE: ruby #{$0} [options]
@@ -81,6 +78,7 @@ def process_recipe(name, version, static_p, cross_p)
81
78
  # correct compiler prefix for cross build, but use host if not set.
82
79
  recipe.host = RbConfig::CONFIG["host_alias"].empty? ? RbConfig::CONFIG["host"] : RbConfig::CONFIG["host_alias"]
83
80
  recipe.target = File.join(PACKAGE_ROOT_DIR, "ports")
81
+ recipe.patch_files = Dir[File.join(PACKAGE_ROOT_DIR, "patches", name, "*.patch")].sort
84
82
  recipe.configure_options << "--libdir=#{File.join(recipe.path, 'lib')}"
85
83
 
86
84
  yield recipe
@@ -91,6 +89,20 @@ def process_recipe(name, version, static_p, cross_p)
91
89
 
92
90
  recipe.configure_options.flatten!
93
91
 
92
+ recipe.configure_options.delete_if do |option|
93
+ case option
94
+ when /\A(\w+)=(.*)\z/
95
+ env[Regexp.last_match(1)] = if env.key?(Regexp.last_match(1))
96
+ concat_flags(env[Regexp.last_match(1)], Regexp.last_match(2))
97
+ else
98
+ Regexp.last_match(2)
99
+ end
100
+ true
101
+ else
102
+ false
103
+ end
104
+ end
105
+
94
106
  recipe.configure_options = [
95
107
  "--disable-silent-rules",
96
108
  "--disable-dependency-tracking",
@@ -117,11 +129,42 @@ def process_recipe(name, version, static_p, cross_p)
117
129
  ]
118
130
  end
119
131
 
132
+ if RbConfig::CONFIG['target_cpu'] == 'universal'
133
+ %w[CFLAGS LDFLAGS].each do |key|
134
+ unless env[key].include?('-arch')
135
+ env[key] = concat_flags(env[key], RbConfig::CONFIG['ARCH_FLAG'])
136
+ end
137
+ end
138
+ end
139
+
120
140
  recipe.configure_options += env.map do |key, value|
121
141
  "#{key}=#{value.strip}"
122
142
  end
123
143
 
124
- recipe.cook
144
+ checkpoint = "#{recipe.target}/#{recipe.name}-#{recipe.version}-#{recipe.host}.installed"
145
+
146
+ if File.exist?(checkpoint)
147
+ message("Building Ruby Magic with a packaged version of #{name}-#{version}.\n")
148
+ else
149
+ message(<<~EOM)
150
+ ---------- IMPORTANT NOTICE ----------
151
+ Building Ruby Magic with a packaged version of #{name}-#{version}.
152
+ Configuration options: #{recipe.configure_options.shelljoin}
153
+ EOM
154
+
155
+ unless recipe.patch_files.empty?
156
+ message("The following patches are being applied:\n")
157
+
158
+ recipe.patch_files.each do |patch|
159
+ message(" - %s\n" % File.basename(patch))
160
+ end
161
+ end
162
+
163
+ recipe.cook
164
+
165
+ FileUtils.touch(checkpoint)
166
+ end
167
+
125
168
  recipe.activate
126
169
  end
127
170
  end
@@ -220,6 +263,10 @@ append_ldflags(ENV["LDFLAGS"].split) if ENV["LDFLAGS"]
220
263
 
221
264
  $LIBS = concat_flags($LIBS, ENV["LIBS"]) if ENV["LIBS"]
222
265
 
266
+ if truffle?
267
+ $CPPFLAGS += " -DMAGIC_CUSTOM_CHECK_TYPE"
268
+ end
269
+
223
270
  if config_system_libraries?
224
271
  message "Building ruby-magic using system libraries.\n"
225
272
 
@@ -229,16 +276,19 @@ if config_system_libraries?
229
276
  else
230
277
  message "Building ruby-magic using packaged libraries.\n"
231
278
 
279
+ require 'yaml'
280
+ dependencies = YAML.load_file(File.join(PACKAGE_ROOT_DIR, "dependencies.yml"))
281
+
232
282
  static_p = config_static?
233
283
  message "Static linking is #{static_p ? 'enabled' : 'disabled'}.\n"
234
284
  cross_build_p = config_cross_build?
235
285
  message "Cross build is #{cross_build_p ? 'enabled' : 'disabled'}.\n"
236
286
 
237
- libmagic_recipe = process_recipe('libmagic', LIBMAGIC_TAG, static_p, cross_build_p) do |recipe|
287
+ libmagic_recipe = process_recipe('libmagic', dependencies["libmagic"]["version"], static_p, cross_build_p) do |recipe|
238
288
  recipe.files = [{
239
- url: "https://ruby-magic.s3.eu-central-1.amazonaws.com/file-#{recipe.version}.tar.gz",
240
- sha256: LIBIMAGE_SHA256
241
- }]
289
+ url: "https://ruby-magic.s3.nl-ams.scw.cloud/file-#{recipe.version}.tar.gz",
290
+ sha256: dependencies["libmagic"]["sha256"],
291
+ }]
242
292
  end
243
293
 
244
294
  $LIBPATH = [File.join(libmagic_recipe.path, 'lib')]
@@ -248,9 +298,21 @@ else
248
298
  if static_p
249
299
  ENV['PKG_CONFIG_PATH'] = "#{libmagic_recipe.path}/lib/pkgconfig"
250
300
  # mkmf appends -- to the first option
251
- $LIBS += " " + pkg_config('libmagic', 'libs --static')
301
+ pkg_config_flags = pkg_config('libmagic', 'libs --static')
302
+
303
+ raise 'Please install the `pkg-config` utility' unless pkg_config_flags
304
+
305
+ $LIBS += " " + pkg_config_flags
252
306
  $LIBS += " " + File.join(libmagic_recipe.path, 'lib', "libmagic.#{$LIBEXT}")
253
307
  end
308
+
309
+ if cross_build_p
310
+ # database files will be packaged up by the cross-compiling callback in the ExtensionTask
311
+ to_path = File.join(PACKAGE_ROOT_DIR, "ext/magic/share")
312
+ FileUtils.rm_rf(to_path, secure: true)
313
+ FileUtils.mkdir(to_path)
314
+ FileUtils.cp_r(Dir[File.join(libmagic_recipe.path, 'share/misc/*.mgc')], to_path)
315
+ end
254
316
  end
255
317
 
256
318
  $CFLAGS += ' -std=c99'
@@ -321,6 +383,13 @@ unless have_header('ruby.h')
321
383
  EOS
322
384
  end
323
385
 
386
+ # these are needed for `rb_thread_call_without_gvl` to be properly detected on some linux systems.
387
+ # specifically, rake-compiler-dock's redhat-based image needs these.
388
+ have_library('pthread')
389
+ have_library('rt')
390
+ have_library('dl')
391
+ have_library('crypt')
392
+
324
393
  have_func('rb_thread_call_without_gvl')
325
394
  have_func('rb_thread_blocking_region')
326
395
 
@@ -4,14 +4,14 @@ extern "C" {
4
4
 
5
5
  #include "functions.h"
6
6
 
7
- int check_fd(int fd);
7
+ static int check_fd(int fd);
8
8
  static int safe_dup(int fd);
9
9
  static int safe_close(int fd);
10
10
  static int safe_cloexec(int fd);
11
- int override_error_output(void *data);
12
- int restore_error_output(void *data);
11
+ static int override_error_output(void *data);
12
+ static int restore_error_output(void *data);
13
13
 
14
- inline int
14
+ static inline int
15
15
  check_fd(int fd)
16
16
  {
17
17
  errno = 0;
@@ -42,6 +42,7 @@ safe_dup(int fd)
42
42
  goto error;
43
43
  }
44
44
  }
45
+
45
46
  if (safe_cloexec(new_fd) < 0) {
46
47
  local_errno = errno;
47
48
  goto error;
@@ -78,6 +79,7 @@ safe_cloexec(int fd)
78
79
  local_errno = errno;
79
80
  goto error;
80
81
  }
82
+
81
83
  if (fcntl(fd, F_SETFD, flags | FD_CLOEXEC) < 0) {
82
84
  local_errno = errno;
83
85
  goto error;
@@ -89,18 +91,18 @@ error:
89
91
  return -1;
90
92
  }
91
93
 
92
- int
94
+ static int
93
95
  override_error_output(void *data)
94
96
  {
95
97
  int local_errno;
96
- mode_t mode = S_IRWXU | S_IRWXG | S_IRWXO;
98
+ int flags = O_WRONLY | O_APPEND;
97
99
  save_t *s = data;
98
100
 
99
101
  #if defined(HAVE_O_CLOEXEC)
100
- mode |= O_CLOEXEC;
102
+ flags |= O_CLOEXEC;
101
103
  #endif
102
104
 
103
- assert(s != NULL && \
105
+ assert(s != NULL &&
104
106
  "Must be a valid pointer to `save_t' type");
105
107
 
106
108
  s->file.old_fd = -1;
@@ -116,7 +118,7 @@ override_error_output(void *data)
116
118
  goto error;
117
119
  }
118
120
 
119
- s->file.new_fd = open("/dev/null", O_WRONLY | O_APPEND, mode);
121
+ s->file.new_fd = open("/dev/null", flags, 0222);
120
122
  if (s->file.new_fd < 0) {
121
123
  local_errno = errno;
122
124
 
@@ -128,10 +130,12 @@ override_error_output(void *data)
128
130
  safe_close(s->file.old_fd);
129
131
  goto error;
130
132
  }
133
+
131
134
  if (safe_cloexec(s->file.new_fd) < 0) {
132
135
  local_errno = errno;
133
136
  goto error;
134
137
  }
138
+
135
139
  if (dup2(s->file.new_fd, fileno(stderr)) < 0) {
136
140
  local_errno = errno;
137
141
  goto error;
@@ -146,13 +150,13 @@ error:
146
150
  return -1;
147
151
  }
148
152
 
149
- int
153
+ static int
150
154
  restore_error_output(void *data)
151
155
  {
152
156
  int local_errno;
153
157
  save_t *s = data;
154
158
 
155
- assert(s != NULL && \
159
+ assert(s != NULL &&
156
160
  "Must be a valid pointer to `save_t' type");
157
161
 
158
162
  if (s->file.old_fd < 0 && s->status != 0)
@@ -278,15 +282,21 @@ inline int
278
282
  magic_load_wrapper(magic_t magic, const char *magic_file, int flags)
279
283
  {
280
284
  int rv;
285
+
281
286
  MAGIC_FUNCTION(magic_load, rv, flags, magic, magic_file);
287
+
282
288
  return rv;
283
289
  }
284
290
 
285
291
  inline int
286
- magic_load_buffers_wrapper(magic_t magic, void **buffers, size_t *sizes, size_t count, int flags)
292
+ magic_load_buffers_wrapper(magic_t magic, void **buffers, size_t *sizes,
293
+ size_t count, int flags)
287
294
  {
288
295
  int rv;
289
- MAGIC_FUNCTION(magic_load_buffers, rv, flags, magic, buffers, sizes, count);
296
+
297
+ MAGIC_FUNCTION(magic_load_buffers, rv, flags, magic, buffers, sizes,
298
+ count);
299
+
290
300
  return rv;
291
301
  }
292
302
 
@@ -294,7 +304,9 @@ inline int
294
304
  magic_compile_wrapper(magic_t magic, const char *magic_file, int flags)
295
305
  {
296
306
  int rv;
307
+
297
308
  MAGIC_FUNCTION(magic_compile, rv, flags, magic, magic_file);
309
+
298
310
  return rv;
299
311
  }
300
312
 
@@ -302,15 +314,19 @@ inline int
302
314
  magic_check_wrapper(magic_t magic, const char *magic_file, int flags)
303
315
  {
304
316
  int rv;
317
+
305
318
  MAGIC_FUNCTION(magic_check, rv, flags, magic, magic_file);
319
+
306
320
  return rv;
307
321
  }
308
322
 
309
323
  inline const char*
310
- magic_file_wrapper(magic_t magic, const char* filename, int flags)
324
+ magic_file_wrapper(magic_t magic, const char *filename, int flags)
311
325
  {
312
326
  const char *cstring;
327
+
313
328
  MAGIC_FUNCTION(magic_file, cstring, flags, magic, filename);
329
+
314
330
  return cstring;
315
331
  }
316
332
 
@@ -318,7 +334,9 @@ inline const char*
318
334
  magic_buffer_wrapper(magic_t magic, const void *buffer, size_t size, int flags)
319
335
  {
320
336
  const char *cstring;
337
+
321
338
  MAGIC_FUNCTION(magic_buffer, cstring, flags, magic, buffer, size);
339
+
322
340
  return cstring;
323
341
  }
324
342
 
@@ -9,7 +9,7 @@ extern "C" {
9
9
 
10
10
  #define MAGIC_FUNCTION(f, r, x, ...) \
11
11
  do { \
12
- if ((x) & MAGIC_DEBUG) \
12
+ if ((x) & (MAGIC_DEBUG | MAGIC_CHECK)) \
13
13
  r = f(__VA_ARGS__); \
14
14
  else { \
15
15
  save_t __##f; \
@@ -17,7 +17,7 @@ extern "C" {
17
17
  r = f(__VA_ARGS__); \
18
18
  restore_error_output(&(__##f)); \
19
19
  } \
20
- } while(0)
20
+ } while (0)
21
21
 
22
22
  typedef struct file_data {
23
23
  fpos_t position;
@@ -33,30 +33,36 @@ typedef struct save {
33
33
  extern magic_t magic_open_wrapper(int flags);
34
34
  extern void magic_close_wrapper(magic_t magic);
35
35
 
36
- extern const char* magic_error_wrapper(magic_t magic);
36
+ extern const char *magic_error_wrapper(magic_t magic);
37
37
  extern int magic_errno_wrapper(magic_t magic);
38
38
 
39
- extern const char* magic_getpath_wrapper(void);
39
+ extern const char *magic_getpath_wrapper(void);
40
40
 
41
- extern int magic_getparam_wrapper(magic_t magic, int parameter, void *value);
41
+ extern int magic_getparam_wrapper(magic_t magic, int parameter,
42
+ void *value);
42
43
  extern int magic_setparam_wrapper(magic_t magic, int parameter,
43
44
  const void *value);
44
45
 
45
46
  extern int magic_getflags_wrapper(magic_t magic);
46
47
  extern int magic_setflags_wrapper(magic_t magic, int flags);
47
48
 
48
- extern int magic_load_wrapper(magic_t magic, const char *magic_file, int flags);
49
+ extern int magic_load_wrapper(magic_t magic, const char *magic_file,
50
+ int flags);
49
51
  extern int magic_load_buffers_wrapper(magic_t magic, void **buffers,
50
- size_t *sizes, size_t count, int flags);
52
+ size_t *sizes, size_t count,
53
+ int flags);
51
54
 
52
- extern int magic_compile_wrapper(magic_t magic, const char *magic_file, int flags);
53
- extern int magic_check_wrapper(magic_t magic, const char *magic_file, int flags);
55
+ extern int magic_compile_wrapper(magic_t magic, const char *magic_file,
56
+ int flags);
57
+ extern int magic_check_wrapper(magic_t magic, const char *magic_file,
58
+ int flags);
54
59
 
55
- extern const char* magic_file_wrapper(magic_t magic, const char *filename,
60
+ extern const char *magic_file_wrapper(magic_t magic, const char *filename,
56
61
  int flags);
57
- extern const char* magic_buffer_wrapper(magic_t magic, const void *buffer,
62
+ extern const char *magic_buffer_wrapper(magic_t magic, const void *buffer,
58
63
  size_t size, int flags);
59
- extern const char* magic_descriptor_wrapper(magic_t magic, int fd, int flags);
64
+ extern const char *magic_descriptor_wrapper(magic_t magic, int fd,
65
+ int flags);
60
66
 
61
67
  extern int magic_version_wrapper(void);
62
68