summaryrefslogtreecommitdiffstats
path: root/libtar
diff options
context:
space:
mode:
Diffstat (limited to 'libtar')
-rw-r--r--libtar/libtar.h2
-rw-r--r--libtar/wrapper.c30
2 files changed, 32 insertions, 0 deletions
diff --git a/libtar/libtar.h b/libtar/libtar.h
index f2f423b9b..1d6c1dfc8 100644
--- a/libtar/libtar.h
+++ b/libtar/libtar.h
@@ -291,6 +291,8 @@ int tar_extract_all(TAR *t, char *prefix);
/* add a whole tree of files */
int tar_append_tree(TAR *t, char *realdir, char *savedir);
+/* find an entry */
+int tar_find(TAR *t, char *searchstr);
#ifdef __cplusplus
}
diff --git a/libtar/wrapper.c b/libtar/wrapper.c
index 116dc28cc..7f65375a0 100644
--- a/libtar/wrapper.c
+++ b/libtar/wrapper.c
@@ -153,3 +153,33 @@ tar_append_tree(TAR *t, char *realdir, char *savedir)
return 0;
}
+
+
+int
+tar_find(TAR *t, char *searchstr)
+{
+ if (!searchstr)
+ return 0;
+
+ char *filename;
+ int i, entryfound = 0;
+#ifdef DEBUG
+ printf("==> tar_find(0x%lx, %s)\n", (long unsigned int)t, searchstr);
+#endif
+ while ((i = th_read(t)) == 0) {
+ filename = th_get_pathname(t);
+ if (fnmatch(searchstr, filename, FNM_FILE_NAME | FNM_PERIOD) == 0) {
+ entryfound++;
+#ifdef DEBUG
+ printf("Found matching entry: %s\n", filename);
+#endif
+ break;
+ }
+ }
+#ifdef DEBUG
+ if (!entryfound)
+ printf("No matching entry found.\n");
+#endif
+
+ return entryfound;
+}