aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMike Frysinger <vapier@gentoo.org>2016-07-25 00:08:53 +0530
committerMike Frysinger <vapier@gentoo.org>2016-11-12 02:10:03 -0500
commite21ad3cd0055f90cc01f43d7a7357d1fabdbc5fa (patch)
treec3a56d78917cb0bbe614dd4f93cd6d9b1ddde0b8
parentlddtree.py: work around pyelftools API change (diff)
downloadpax-utils-e21ad3cd0055f90cc01f43d7a7357d1fabdbc5fa.tar.gz
pax-utils-e21ad3cd0055f90cc01f43d7a7357d1fabdbc5fa.tar.bz2
pax-utils-e21ad3cd0055f90cc01f43d7a7357d1fabdbc5fa.zip
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.
-rw-r--r--paxinc.c31
-rw-r--r--paxinc.h5
-rw-r--r--scanelf.c29
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)
{