commit:     e21ad3cd0055f90cc01f43d7a7357d1fabdbc5fa
Author:     Mike Frysinger <vapier <AT> gentoo <DOT> org>
AuthorDate: Sun Jul 24 18:38:53 2016 +0000
Commit:     Mike Frysinger <vapier <AT> gentoo <DOT> org>
CommitDate: Sat Nov 12 07:10:03 2016 +0000
URL:        https://gitweb.gentoo.org/proj/pax-utils.git/commit/?id=e21ad3cd

split out fs related helper funcs as lib code

This way we can use the funcs in other modules.  It makes scanelf
a little bigger (~1k), but shouldn't be a big deal overall.

 paxinc.c  | 31 +++++++++++++++++++++++++++++++
 paxinc.h  |  5 +++++
 scanelf.c | 29 -----------------------------
 3 files changed, 36 insertions(+), 29 deletions(-)

diff --git a/paxinc.c b/paxinc.c
index 068aa60..64a3069 100644
--- a/paxinc.c
+++ b/paxinc.c
@@ -167,3 +167,34 @@ void color_init(bool disable)
        if (disable)
                NORM = RED = YELLOW = "";
 }
+
+/* File system helpers. */
+int root_fd = AT_FDCWD;
+
+FILE *fopenat_r(int dir_fd, const char *path)
+{
+       int fd = openat(dir_fd, path, O_RDONLY|O_CLOEXEC);
+       if (fd == -1)
+               return NULL;
+       return fdopen(fd, "re");
+}
+
+const char *root_rel_path(const char *path)
+{
+       /*
+        * openat() will ignore the dirfd if path starts with
+        * a /, so consume all of that noise
+        *
+        * XXX: we don't handle relative paths like ../ that
+        * break out of the --root option, but for now, just
+        * don't do that :P.
+        */
+       if (root_fd != AT_FDCWD) {
+               while (*path == '/')
+                       ++path;
+               if (*path == '\0')
+                       path = ".";
+       }
+
+       return path;
+}

diff --git a/paxinc.h b/paxinc.h
index e687b3a..f761b2e 100644
--- a/paxinc.h
+++ b/paxinc.h
@@ -123,4 +123,9 @@ extern const char argv0[];
 #define errf(fmt, args...) _err(warnf, fmt, ## args)
 #define errp(fmt, args...) _err(warnp, fmt , ## args)
 
+/* File system helper functions. */
+extern int root_fd;
+FILE *fopenat_r(int dir_fd, const char *path);
+const char *root_rel_path(const char *path);
+
 #endif /* _PAX_INC_H */

diff --git a/scanelf.c b/scanelf.c
index 5a765b5..89c9695 100644
--- a/scanelf.c
+++ b/scanelf.c
@@ -60,7 +60,6 @@ static char use_ldpath = 0;
 static char **qa_textrels = NULL;
 static char **qa_execstack = NULL;
 static char **qa_wx_load = NULL;
-static int root_fd = AT_FDCWD;
 
 static int match_bits = 0;
 static unsigned int match_perms = 0;
@@ -131,34 +130,6 @@ static const char *which(const char *fname, const char 
*envvar)
        return NULL;
 }
 
-static FILE *fopenat_r(int dir_fd, const char *path)
-{
-       int fd = openat(dir_fd, path, O_RDONLY|O_CLOEXEC);
-       if (fd == -1)
-               return NULL;
-       return fdopen(fd, "re");
-}
-
-static const char *root_rel_path(const char *path)
-{
-       /*
-        * openat() will ignore the dirfd if path starts with
-        * a /, so consume all of that noise
-        *
-        * XXX: we don't handle relative paths like ../ that
-        * break out of the --root option, but for now, just
-        * don't do that :P.
-        */
-       if (root_fd != AT_FDCWD) {
-               while (*path == '/')
-                       ++path;
-               if (*path == '\0')
-                       path = ".";
-       }
-
-       return path;
-}
-
 /* sub-funcs for scanelf_fileat() */
 static void scanelf_file_get_symtabs(elfobj *elf, void **sym, void **str)
 {

Reply via email to