if (!touch("d1/d2/f3")) return;
if (!touch("d1/d2/f4")) return;
if (!touch("d1/d2/f5")) return;
+ if (!touch("d1/d2/f6")) return;
+ if (!touch("d1/d2/f\x0a")) return;
/* Populate a file list */
f = fopen("filelist", "w+");
if (!assert(f != NULL))
return;
- fprintf(f, "d1/f1\n");
- fprintf(f, "d1/d2/f4\n");
+ /* Use a variety of text line endings. */
+ fprintf(f, "d1/f1\x0d\x0a"); /* CRLF */
+ fprintf(f, "d1/d2/f4\x0a"); /* NL */
+ fprintf(f, "d1/d2/f6"); /* EOF */
fclose(f);
/* Populate a second file list */
f = fopen("filelist2", "w+");
if (!assert(f != NULL))
return;
- fprintf(f, "d1/d2/f3\n");
- fprintf(f, "d1/d2/f5\n");
+ /* Use null-terminated names. */
+ fprintf(f, "d1/d2/f3");
+ fwrite("\0", 1, 1, f);
+ fprintf(f, "d1/d2/f5");
+ fwrite("\0", 1, 1, f);
+ fprintf(f, "d1/d2/f\x0a");
+ fwrite("\0", 1, 1, f);
fclose(f);
/* Use -c -T to archive up the files. */
assertFileNotExists("test1/d1/d2/f3");
assertFileExists("test1/d1/d2/f4");
assertFileNotExists("test1/d1/d2/f5");
+ assertFileExists("test1/d1/d2/f6");
+ assertFileNotExists("test1/d1/d2/f\x0a");
/* Use -r -T to add more files to the archive. */
- systemf("%s -r -f test1.tar -T filelist2 > test2.out 2> test2.err",
+ systemf("%s -r -f test1.tar --null -T filelist2 > test2.out 2> test2.err",
testprog);
assertEmptyFile("test2.out");
assertEmptyFile("test2.err");
assertFileExists("test3/d1/d2/f3");
assertFileExists("test3/d1/d2/f4");
assertFileExists("test3/d1/d2/f5");
+ assertFileExists("test3/d1/d2/f6");
+ assertFileExists("test3/d1/d2/f\x0a");
/* Use -x -T to dearchive the files (verify -x -T together) */
if (!assertEqualInt(0, mkdir("test2", 0755))) return;
assertFileNotExists("test2/d1/d2/f3");
assertFileExists("test2/d1/d2/f4");
assertFileNotExists("test2/d1/d2/f5");
+ assertFileExists("test2/d1/d2/f6");
+ assertFileNotExists("test2/d1/d2/f\x0a");
assertEqualInt(0, mkdir("test4", 0755));
assertEqualInt(0, mkdir("test4_out", 0755));
} else {
skipping("bsdtar does not support -s option on this platform");
}
+
/* TODO: Include some use of -C directory-changing within the filelist. */
/* I'm pretty sure -C within the filelist is broken on extract. */
}
FILE *f;
char *buff, *buff_end, *line_start, *line_end, *p;
size_t buff_length, new_buff_length, bytes_read, bytes_wanted;
- int separator;
int ret;
- separator = bsdtar->option_null ? '\0' : '\n';
ret = 0;
if (strcmp(pathname, "-") == 0)
buff_end += bytes_read;
/* Process all complete lines in the buffer. */
while (line_end < buff_end) {
- if (*line_end == separator) {
+ if (bsdtar->option_null) {
+ if (*line_end == '\0') {
+ if ((*process)(bsdtar, line_start) != 0)
+ ret = -1;
+ line_start = line_end + 1;
+ line_end = line_start;
+ } else
+ line_end++;
+ } else if (*line_end == '\r' || *line_end == '\n') {
*line_end = '\0';
- if ((*process)(bsdtar, line_start) != 0)
- ret = -1;
+ if (line_end - line_start > 1) {
+ if ((*process)(bsdtar, line_start) != 0)
+ ret = -1;
+ }
line_start = line_end + 1;
line_end = line_start;
} else