View Issue Details

IDProjectCategoryView StatusLast Update
0000615filegeneralpublic2017-05-23 21:54
ReporterKrzysztof Wilczynski 
Assigned ToChristos Zoulas 
PrioritynormalSeverityfeatureReproducibilityN/A
Status resolvedResolutionfixed 
Product Version 
Target VersionFixed in VersionHEAD 
Summary0000615: Add magic_getflags() which returns a value representing current flags.
DescriptionThe attached patch adds a simple magic_getflags() function alongside the magic_setflags() which can be used to retrieve a value representing current flags set.

I would like to be able to retrieve the value from the opened libmagic directly, so that one does not need to maintain an extra variable (global, thread-local, or otherwise) to track which flags are currently set. This helps a little bit when writing language bindings and/or wrapping libmagic.
Tagsfeature

Relationships

Activities

Krzysztof Wilczynski

Krzysztof Wilczynski

2017-05-14 21:25

reporter  

0001-Add-magic_getflags-function-alongside-magic_setflags.patch (2,101 bytes)
From de085094944880e4507a6889423d007180a4974d Mon Sep 17 00:00:00 2001
From: Krzysztof Wilczynski <kw@linux.com>
Date: Sun, 14 May 2017 22:18:53 +0100
Subject: [PATCH] Add magic_getflags() function alongside magic_setflags().

This commit adds a new function magic_getflags() which can be used to retrieve
a value (bitmask) of current flags set. This is to be used alongside the
magic_setflags() function.

Signed-off-by: Krzysztof Wilczynski <kw@linux.com>
---
 doc/libmagic.man | 9 +++++++++
 src/magic.c      | 9 +++++++++
 src/magic.h.in   | 1 +
 3 files changed, 19 insertions(+)

diff --git a/doc/libmagic.man b/doc/libmagic.man
index 638890af..d42dfcf9 100644
--- a/doc/libmagic.man
+++ b/doc/libmagic.man
@@ -35,6 +35,7 @@
 .Nm magic_errno ,
 .Nm magic_descriptor ,
 .Nm magic_buffer ,
+.Nm magic_getflags ,
 .Nm magic_setflags ,
 .Nm magic_check ,
 .Nm magic_compile ,
@@ -64,6 +65,8 @@
 .Ft const char *
 .Fn magic_buffer "magic_t cookie" "const void *buffer" "size_t length"
 .Ft int
+.Fn magic_getflags "magic_t cookie"
+.Ft int
 .Fn magic_setflags "magic_t cookie" "int flags"
 .Ft int
 .Fn magic_check "magic_t cookie" "const char *filename"
@@ -206,6 +209,12 @@ argument with
 bytes size.
 .Pp
 The
+.Fn magic_getflags
+functions returns a value representing current
+.Ar flags
+set.
+.Pp
+The
 .Fn magic_setflags
 function sets the
 .Ar flags
diff --git a/src/magic.c b/src/magic.c
index a9b7e32a..56b5fea6 100644
--- a/src/magic.c
+++ b/src/magic.c
@@ -568,6 +568,15 @@ magic_errno(struct magic_set *ms)
 }
 
 public int
+magic_getflags(struct magic_set *ms)
+{
+	if (ms == NULL)
+		return -1;
+
+	return ms->flags;
+}
+
+public int
 magic_setflags(struct magic_set *ms, int flags)
 {
 	if (ms == NULL)
diff --git a/src/magic.h.in b/src/magic.h.in
index 3d6954a2..fcfa381d 100644
--- a/src/magic.h.in
+++ b/src/magic.h.in
@@ -97,6 +97,7 @@ const char *magic_descriptor(magic_t, int);
 const char *magic_buffer(magic_t, const void *, size_t);
 
 const char *magic_error(magic_t);
+int magic_getflags(magic_t);
 int magic_setflags(magic_t, int);
 
 int magic_version(void);
-- 
2.13.0

Christos Zoulas

Christos Zoulas

2017-05-23 21:54

manager   ~0001520

Added, thanks!

Issue History

Date Modified Username Field Change
2017-05-14 21:25 Krzysztof Wilczynski New Issue
2017-05-14 21:25 Krzysztof Wilczynski File Added: 0001-Add-magic_getflags-function-alongside-magic_setflags.patch
2017-05-14 21:25 Krzysztof Wilczynski Tag Attached: feature
2017-05-23 21:54 Christos Zoulas Assigned To => Christos Zoulas
2017-05-23 21:54 Christos Zoulas Status new => assigned
2017-05-23 21:54 Christos Zoulas Status assigned => resolved
2017-05-23 21:54 Christos Zoulas Resolution open => fixed
2017-05-23 21:54 Christos Zoulas Fixed in Version => HEAD
2017-05-23 21:54 Christos Zoulas Note Added: 0001520