summaryrefslogtreecommitdiff
path: root/libarchive_fe
diff options
context:
space:
mode:
authorTim Kientzle <kientzle@gmail.com>2009-08-23 00:54:32 -0400
committerTim Kientzle <kientzle@gmail.com>2009-08-23 00:54:32 -0400
commit674dbce7bc6b88b0856bb4ab716c552d6edaf049 (patch)
tree8d2227e2ebedb0746961c559fb85646b9f0f8abc /libarchive_fe
parente5be9e3de0e333c9efbe2eb99c661c08a78b78ed (diff)
downloadlibarchive-674dbce7bc6b88b0856bb4ab716c552d6edaf049.tar.gz
Test various line separators in -T input, including CRLF, NL, and null.
Fix tar to pass the test. SVN-Revision: 1385
Diffstat (limited to 'libarchive_fe')
-rw-r--r--libarchive_fe/line_reader.c22
-rw-r--r--libarchive_fe/line_reader.h2
-rw-r--r--libarchive_fe/matching.c5
-rw-r--r--libarchive_fe/matching.h2
4 files changed, 20 insertions, 11 deletions
diff --git a/libarchive_fe/line_reader.c b/libarchive_fe/line_reader.c
index 52757638..21e1c705 100644
--- a/libarchive_fe/line_reader.c
+++ b/libarchive_fe/line_reader.c
@@ -51,12 +51,12 @@ struct lafe_line_reader {
char *buff, *buff_end, *line_start, *line_end, *p;
char *pathname;
size_t buff_length;
- int separator;
+ int nullSeparator; /* Lines separated by null, not CR/CRLF/etc. */
int ret;
};
struct lafe_line_reader *
-lafe_line_reader(const char *pathname, char separator)
+lafe_line_reader(const char *pathname, int nullSeparator)
{
struct lafe_line_reader *lr;
@@ -64,7 +64,7 @@ lafe_line_reader(const char *pathname, char separator)
if (lr == NULL)
lafe_errc(1, ENOMEM, "Can't open %s", pathname);
- lr->separator = separator;
+ lr->nullSeparator = nullSeparator;
lr->pathname = strdup(pathname);
if (strcmp(pathname, "-") == 0)
@@ -91,14 +91,22 @@ lafe_line_reader_next(struct lafe_line_reader *lr)
for (;;) {
/* If there's a line in the buffer, return it immediately. */
while (lr->line_end < lr->buff_end) {
- if (*lr->line_end == lr->separator) {
+ if (lr->nullSeparator) {
+ if (*lr->line_end == '\0') {
+ line_start = lr->line_start;
+ lr->line_start = lr->line_end + 1;
+ lr->line_end = lr->line_start;
+ return (line_start);
+ }
+ } else if (*lr->line_end == '\x0a' || *lr->line_end == '\x0d') {
*lr->line_end = '\0';
line_start = lr->line_start;
lr->line_start = lr->line_end + 1;
lr->line_end = lr->line_start;
- return (line_start);
- } else
- lr->line_end++;
+ if (line_start[0] != '\0')
+ return (line_start);
+ }
+ lr->line_end++;
}
/* If we're at end-of-file, process the final data. */
diff --git a/libarchive_fe/line_reader.h b/libarchive_fe/line_reader.h
index 7bb1742c..d092c051 100644
--- a/libarchive_fe/line_reader.h
+++ b/libarchive_fe/line_reader.h
@@ -28,7 +28,7 @@
struct lafe_line_reader;
-struct lafe_line_reader *lafe_line_reader(const char *, char separator);
+struct lafe_line_reader *lafe_line_reader(const char *, int nullSeparator);
const char *lafe_line_reader_next(struct lafe_line_reader *);
void lafe_line_reader_free(struct lafe_line_reader *);
diff --git a/libarchive_fe/matching.c b/libarchive_fe/matching.c
index af5bde4e..bdfd07b7 100644
--- a/libarchive_fe/matching.c
+++ b/libarchive_fe/matching.c
@@ -111,13 +111,14 @@ lafe_include(struct lafe_matching **matching, const char *pattern)
}
int
-lafe_include_from_file(struct lafe_matching **matching, const char *pathname)
+lafe_include_from_file(struct lafe_matching **matching, const char *pathname,
+ int nullSeparator)
{
struct lafe_line_reader *lr;
const char *p;
int ret = 0;
- lr = lafe_line_reader(pathname, '\n');
+ lr = lafe_line_reader(pathname, nullSeparator);
while ((p = lafe_line_reader_next(lr)) != NULL) {
if (lafe_include(matching, p) != 0)
ret = -1;
diff --git a/libarchive_fe/matching.h b/libarchive_fe/matching.h
index 5cdc0166..f4edebd4 100644
--- a/libarchive_fe/matching.h
+++ b/libarchive_fe/matching.h
@@ -36,7 +36,7 @@ int lafe_exclude_from_file(struct lafe_matching **matching,
const char *pathname);
int lafe_include(struct lafe_matching **matching, const char *pattern);
int lafe_include_from_file(struct lafe_matching **matching,
- const char *pathname);
+ const char *pathname, int nullSeparator);
int lafe_excluded(struct lafe_matching *, const char *pathname);
void lafe_cleanup_exclusions(struct lafe_matching **);