summaryrefslogtreecommitdiff
path: root/tests
diff options
context:
space:
mode:
Diffstat (limited to 'tests')
-rw-r--r--tests/tar_fuzz.c15
-rw-r--r--tests/tar_gnu.c64
-rw-r--r--tests/tar_pax.c56
-rw-r--r--tests/tar_sparse_gnu.c22
-rw-r--r--tests/tar_sparse_gnu1.c16
-rw-r--r--tests/tar_sparse_gnu2.c22
-rw-r--r--tests/tar_ustar.c64
-rw-r--r--tests/tar_xattr_bsd.c18
-rw-r--r--tests/tar_xattr_schily.c18
9 files changed, 148 insertions, 147 deletions
diff --git a/tests/tar_fuzz.c b/tests/tar_fuzz.c
index dad3d5a..1a51da4 100644
--- a/tests/tar_fuzz.c
+++ b/tests/tar_fuzz.c
@@ -17,36 +17,37 @@
int main(int argc, char **argv)
{
tar_header_decoded_t hdr;
- int fd, ret;
+ FILE *fp;
+ int ret;
if (argc != 2) {
fputs("usage: tar_fuzz <tarball>\n", stderr);
return EXIT_FAILURE;
}
- fd = open(argv[1], O_RDONLY);
- if (fd < 0) {
+ fp = fopen(argv[1], "rb");
+ if (fp == NULL) {
perror(argv[1]);
return EXIT_FAILURE;
}
for (;;) {
- ret = read_header(fd, &hdr);
+ ret = read_header(fp, &hdr);
if (ret > 0)
break;
if (ret < 0)
goto fail;
- ret = lseek(fd, hdr.sb.st_size, SEEK_CUR);
+ ret = fseek(fp, hdr.sb.st_size, SEEK_CUR);
clear_header(&hdr);
if (ret < 0)
goto fail;
}
- close(fd);
+ fclose(fp);
return EXIT_SUCCESS;
fail:
- close(fd);
+ fclose(fp);
return EXIT_FAILURE;
}
diff --git a/tests/tar_gnu.c b/tests/tar_gnu.c
index b58c9f7..43ebccf 100644
--- a/tests/tar_gnu.c
+++ b/tests/tar_gnu.c
@@ -21,16 +21,16 @@
#define TEST_PATH STRVALUE(TESTPATH)
-static int open_read(const char *path)
+static FILE *open_read(const char *path)
{
- int fd = open(path, O_RDONLY);
+ FILE *fp = fopen(path, "rb");
- if (fd < 0) {
+ if (fp == NULL) {
perror(path);
exit(EXIT_FAILURE);
}
- return fd;
+ return fp;
}
static const char *filename =
@@ -42,12 +42,12 @@ int main(void)
{
tar_header_decoded_t hdr;
char buffer[6];
- int fd;
+ FILE *fp;
assert(chdir(TEST_PATH) == 0);
- fd = open_read("format-acceptance/gnu.tar");
- assert(read_header(fd, &hdr) == 0);
+ fp = open_read("format-acceptance/gnu.tar");
+ assert(read_header(fp, &hdr) == 0);
assert(hdr.sb.st_mode == (S_IFREG | 0644));
assert(hdr.sb.st_uid == 01750);
assert(hdr.sb.st_gid == 01750);
@@ -56,14 +56,14 @@ int main(void)
assert(hdr.mtime == 1542905892);
assert(strcmp(hdr.name, "input.txt") == 0);
assert(!hdr.unknown_record);
- assert(read_retry("data0", fd, buffer, 5) == 0);
+ assert(read_retry("data0", fp, buffer, 5) == 0);
buffer[5] = '\0';
assert(strcmp(buffer, "test\n") == 0);
clear_header(&hdr);
- close(fd);
+ fclose(fp);
- fd = open_read("format-acceptance/gnu-g.tar");
- assert(read_header(fd, &hdr) == 0);
+ fp = open_read("format-acceptance/gnu-g.tar");
+ assert(read_header(fp, &hdr) == 0);
assert(hdr.sb.st_mode == (S_IFREG | 0644));
assert(hdr.sb.st_uid == 01750);
assert(hdr.sb.st_gid == 01750);
@@ -72,14 +72,14 @@ int main(void)
assert(hdr.mtime == 013375560044);
assert(strcmp(hdr.name, "input.txt") == 0);
assert(!hdr.unknown_record);
- assert(read_retry("data1", fd, buffer, 5) == 0);
+ assert(read_retry("data1", fp, buffer, 5) == 0);
buffer[5] = '\0';
assert(strcmp(buffer, "test\n") == 0);
clear_header(&hdr);
- close(fd);
+ fclose(fp);
- fd = open_read("file-size/gnu.tar");
- assert(read_header(fd, &hdr) == 0);
+ fp = open_read("file-size/gnu.tar");
+ assert(read_header(fp, &hdr) == 0);
assert(hdr.sb.st_mode == (S_IFREG | 0644));
assert(hdr.sb.st_uid == 01750);
assert(hdr.sb.st_gid == 01750);
@@ -89,10 +89,10 @@ int main(void)
assert(strcmp(hdr.name, "big-file.bin") == 0);
assert(!hdr.unknown_record);
clear_header(&hdr);
- close(fd);
+ fclose(fp);
- fd = open_read("user-group-largenum/gnu.tar");
- assert(read_header(fd, &hdr) == 0);
+ fp = open_read("user-group-largenum/gnu.tar");
+ assert(read_header(fp, &hdr) == 0);
assert(hdr.sb.st_mode == (S_IFREG | 0644));
assert(hdr.sb.st_uid == 0x80000000);
assert(hdr.sb.st_gid == 0x80000000);
@@ -101,14 +101,14 @@ int main(void)
assert(hdr.mtime == 013376036700);
assert(strcmp(hdr.name, "input.txt") == 0);
assert(!hdr.unknown_record);
- assert(read_retry("data2", fd, buffer, 5) == 0);
+ assert(read_retry("data2", fp, buffer, 5) == 0);
buffer[5] = '\0';
assert(strcmp(buffer, "test\n") == 0);
clear_header(&hdr);
- close(fd);
+ fclose(fp);
- fd = open_read("large-mtime/gnu.tar");
- assert(read_header(fd, &hdr) == 0);
+ fp = open_read("large-mtime/gnu.tar");
+ assert(read_header(fp, &hdr) == 0);
assert(hdr.sb.st_mode == (S_IFREG | 0644));
assert(hdr.sb.st_uid == 01750);
assert(hdr.sb.st_gid == 01750);
@@ -121,14 +121,14 @@ int main(void)
assert(hdr.mtime == 8589934592L);
assert(strcmp(hdr.name, "input.txt") == 0);
assert(!hdr.unknown_record);
- assert(read_retry("data3", fd, buffer, 5) == 0);
+ assert(read_retry("data3", fp, buffer, 5) == 0);
buffer[5] = '\0';
assert(strcmp(buffer, "test\n") == 0);
clear_header(&hdr);
- close(fd);
+ fclose(fp);
- fd = open_read("negative-mtime/gnu.tar");
- assert(read_header(fd, &hdr) == 0);
+ fp = open_read("negative-mtime/gnu.tar");
+ assert(read_header(fp, &hdr) == 0);
assert(hdr.sb.st_mode == (S_IFREG | 0644));
assert(hdr.sb.st_uid == 01750);
assert(hdr.sb.st_gid == 01750);
@@ -137,14 +137,14 @@ int main(void)
assert(hdr.mtime == -315622800);
assert(strcmp(hdr.name, "input.txt") == 0);
assert(!hdr.unknown_record);
- assert(read_retry("data4", fd, buffer, 5) == 0);
+ assert(read_retry("data4", fp, buffer, 5) == 0);
buffer[5] = '\0';
assert(strcmp(buffer, "test\n") == 0);
clear_header(&hdr);
- close(fd);
+ fclose(fp);
- fd = open_read("long-paths/gnu.tar");
- assert(read_header(fd, &hdr) == 0);
+ fp = open_read("long-paths/gnu.tar");
+ assert(read_header(fp, &hdr) == 0);
assert(hdr.sb.st_mode == (S_IFREG | 0644));
assert(hdr.sb.st_uid == 01750);
assert(hdr.sb.st_gid == 01750);
@@ -153,11 +153,11 @@ int main(void)
assert(hdr.mtime == 1542909670);
assert(strcmp(hdr.name, filename) == 0);
assert(!hdr.unknown_record);
- assert(read_retry("data5", fd, buffer, 5) == 0);
+ assert(read_retry("data5", fp, buffer, 5) == 0);
buffer[5] = '\0';
assert(strcmp(buffer, "test\n") == 0);
clear_header(&hdr);
- close(fd);
+ fclose(fp);
return EXIT_SUCCESS;
}
diff --git a/tests/tar_pax.c b/tests/tar_pax.c
index f0fdef0..475a7f1 100644
--- a/tests/tar_pax.c
+++ b/tests/tar_pax.c
@@ -21,16 +21,16 @@
#define TEST_PATH STRVALUE(TESTPATH)
-static int open_read(const char *path)
+static FILE *open_read(const char *path)
{
- int fd = open(path, O_RDONLY);
+ FILE *fp = fopen(path, "rb");
- if (fd < 0) {
+ if (fp == NULL) {
perror(path);
exit(EXIT_FAILURE);
}
- return fd;
+ return fp;
}
static const char *filename =
@@ -42,12 +42,12 @@ int main(void)
{
tar_header_decoded_t hdr;
char buffer[6];
- int fd;
+ FILE *fp;
assert(chdir(TEST_PATH) == 0);
- fd = open_read("format-acceptance/pax.tar");
- assert(read_header(fd, &hdr) == 0);
+ fp = open_read("format-acceptance/pax.tar");
+ assert(read_header(fp, &hdr) == 0);
assert(hdr.sb.st_mode == (S_IFREG | 0644));
assert(hdr.sb.st_uid == 01750);
assert(hdr.sb.st_gid == 01750);
@@ -56,14 +56,14 @@ int main(void)
assert(hdr.mtime == 1542905892);
assert(strcmp(hdr.name, "input.txt") == 0);
assert(!hdr.unknown_record);
- assert(read_retry("data0", fd, buffer, 5) == 0);
+ assert(read_retry("data0", fp, buffer, 5) == 0);
buffer[5] = '\0';
assert(strcmp(buffer, "test\n") == 0);
clear_header(&hdr);
- close(fd);
+ fclose(fp);
- fd = open_read("file-size/pax.tar");
- assert(read_header(fd, &hdr) == 0);
+ fp = open_read("file-size/pax.tar");
+ assert(read_header(fp, &hdr) == 0);
assert(hdr.sb.st_mode == (S_IFREG | 0644));
assert(hdr.sb.st_uid == 01750);
assert(hdr.sb.st_gid == 01750);
@@ -73,10 +73,10 @@ int main(void)
assert(strcmp(hdr.name, "big-file.bin") == 0);
assert(!hdr.unknown_record);
clear_header(&hdr);
- close(fd);
+ fclose(fp);
- fd = open_read("user-group-largenum/pax.tar");
- assert(read_header(fd, &hdr) == 0);
+ fp = open_read("user-group-largenum/pax.tar");
+ assert(read_header(fp, &hdr) == 0);
assert(hdr.sb.st_mode == (S_IFREG | 0644));
assert(hdr.sb.st_uid == 2147483648);
assert(hdr.sb.st_gid == 2147483648);
@@ -85,14 +85,14 @@ int main(void)
assert(hdr.mtime == 013376036700);
assert(strcmp(hdr.name, "input.txt") == 0);
assert(!hdr.unknown_record);
- assert(read_retry("data1", fd, buffer, 5) == 0);
+ assert(read_retry("data1", fp, buffer, 5) == 0);
buffer[5] = '\0';
assert(strcmp(buffer, "test\n") == 0);
clear_header(&hdr);
- close(fd);
+ fclose(fp);
- fd = open_read("large-mtime/pax.tar");
- assert(read_header(fd, &hdr) == 0);
+ fp = open_read("large-mtime/pax.tar");
+ assert(read_header(fp, &hdr) == 0);
assert(hdr.sb.st_mode == (S_IFREG | 0644));
assert(hdr.sb.st_uid == 01750);
assert(hdr.sb.st_gid == 01750);
@@ -105,14 +105,14 @@ int main(void)
assert(hdr.mtime == 8589934592L);
assert(strcmp(hdr.name, "input.txt") == 0);
assert(!hdr.unknown_record);
- assert(read_retry("data2", fd, buffer, 5) == 0);
+ assert(read_retry("data2", fp, buffer, 5) == 0);
buffer[5] = '\0';
assert(strcmp(buffer, "test\n") == 0);
clear_header(&hdr);
- close(fd);
+ fclose(fp);
- fd = open_read("negative-mtime/pax.tar");
- assert(read_header(fd, &hdr) == 0);
+ fp = open_read("negative-mtime/pax.tar");
+ assert(read_header(fp, &hdr) == 0);
assert(hdr.sb.st_mode == (S_IFREG | 0644));
assert(hdr.sb.st_uid == 01750);
assert(hdr.sb.st_gid == 01750);
@@ -121,14 +121,14 @@ int main(void)
assert(hdr.mtime == -315622800);
assert(strcmp(hdr.name, "input.txt") == 0);
assert(!hdr.unknown_record);
- assert(read_retry("data3", fd, buffer, 5) == 0);
+ assert(read_retry("data3", fp, buffer, 5) == 0);
buffer[5] = '\0';
assert(strcmp(buffer, "test\n") == 0);
clear_header(&hdr);
- close(fd);
+ fclose(fp);
- fd = open_read("long-paths/pax.tar");
- assert(read_header(fd, &hdr) == 0);
+ fp = open_read("long-paths/pax.tar");
+ assert(read_header(fp, &hdr) == 0);
assert(hdr.sb.st_mode == (S_IFREG | 0644));
assert(hdr.sb.st_uid == 01750);
assert(hdr.sb.st_gid == 01750);
@@ -137,11 +137,11 @@ int main(void)
assert(hdr.mtime == 1542909670);
assert(strcmp(hdr.name, filename) == 0);
assert(!hdr.unknown_record);
- assert(read_retry("data4", fd, buffer, 5) == 0);
+ assert(read_retry("data4", fp, buffer, 5) == 0);
buffer[5] = '\0';
assert(strcmp(buffer, "test\n") == 0);
clear_header(&hdr);
- close(fd);
+ fclose(fp);
return EXIT_SUCCESS;
}
diff --git a/tests/tar_sparse_gnu.c b/tests/tar_sparse_gnu.c
index 3546571..b67171d 100644
--- a/tests/tar_sparse_gnu.c
+++ b/tests/tar_sparse_gnu.c
@@ -21,28 +21,28 @@
#define TEST_PATH STRVALUE(TESTPATH)
-static int open_read(const char *path)
+static FILE *open_read(const char *path)
{
- int fd = open(path, O_RDONLY);
+ FILE *fp = fopen(path, "rb");
- if (fd < 0) {
+ if (fp == NULL) {
perror(path);
exit(EXIT_FAILURE);
}
- return fd;
+ return fp;
}
int main(void)
{
tar_header_decoded_t hdr;
sparse_map_t *sparse;
- int fd;
+ FILE *fp;
assert(chdir(TEST_PATH) == 0);
- fd = open_read("sparse-files/gnu-small.tar");
- assert(read_header(fd, &hdr) == 0);
+ fp = open_read("sparse-files/gnu-small.tar");
+ assert(read_header(fp, &hdr) == 0);
assert(hdr.sb.st_mode == (S_IFREG | 0644));
assert(hdr.sb.st_uid == 01750);
assert(hdr.sb.st_gid == 01750);
@@ -70,10 +70,10 @@ int main(void)
assert(sparse->next == NULL);
clear_header(&hdr);
- close(fd);
+ fclose(fp);
- fd = open_read("sparse-files/gnu.tar");
- assert(read_header(fd, &hdr) == 0);
+ fp = open_read("sparse-files/gnu.tar");
+ assert(read_header(fp, &hdr) == 0);
assert(hdr.sb.st_mode == (S_IFREG | 0644));
assert(hdr.sb.st_uid == 01750);
assert(hdr.sb.st_gid == 01750);
@@ -132,7 +132,7 @@ int main(void)
assert(sparse == NULL);
clear_header(&hdr);
- close(fd);
+ fclose(fp);
return EXIT_SUCCESS;
}
diff --git a/tests/tar_sparse_gnu1.c b/tests/tar_sparse_gnu1.c
index 19106cd..a9d90d4 100644
--- a/tests/tar_sparse_gnu1.c
+++ b/tests/tar_sparse_gnu1.c
@@ -21,28 +21,28 @@
#define TEST_PATH STRVALUE(TESTPATH)
-static int open_read(const char *path)
+static FILE *open_read(const char *path)
{
- int fd = open(path, O_RDONLY);
+ FILE *fp = fopen(path, "rb");
- if (fd < 0) {
+ if (fp == NULL) {
perror(path);
exit(EXIT_FAILURE);
}
- return fd;
+ return fp;
}
int main(void)
{
tar_header_decoded_t hdr;
sparse_map_t *sparse;
- int fd;
+ FILE *fp;
assert(chdir(TEST_PATH) == 0);
- fd = open_read("sparse-files/pax-gnu0-0.tar");
- assert(read_header(fd, &hdr) == 0);
+ fp = open_read("sparse-files/pax-gnu0-0.tar");
+ assert(read_header(fp, &hdr) == 0);
assert(hdr.sb.st_mode == (S_IFREG | 0644));
assert(hdr.sb.st_uid == 01750);
assert(hdr.sb.st_gid == 01750);
@@ -101,7 +101,7 @@ int main(void)
assert(sparse == NULL);
clear_header(&hdr);
- close(fd);
+ fclose(fp);
return EXIT_SUCCESS;
}
diff --git a/tests/tar_sparse_gnu2.c b/tests/tar_sparse_gnu2.c
index 2171850..6402c87 100644
--- a/tests/tar_sparse_gnu2.c
+++ b/tests/tar_sparse_gnu2.c
@@ -21,28 +21,28 @@
#define TEST_PATH STRVALUE(TESTPATH)
-static int open_read(const char *path)
+static FILE *open_read(const char *path)
{
- int fd = open(path, O_RDONLY);
+ FILE *fp = open(path, O_RDONLY);
- if (fd < 0) {
+ if (fp == NULL) {
perror(path);
exit(EXIT_FAILURE);
}
- return fd;
+ return fp;
}
int main(void)
{
tar_header_decoded_t hdr;
sparse_map_t *sparse;
- int fd;
+ FILE *fp;
assert(chdir(TEST_PATH) == 0);
- fd = open_read("sparse-files/pax-gnu0-1.tar");
- assert(read_header(fd, &hdr) == 0);
+ fp = open_read("sparse-files/pax-gnu0-1.tar");
+ assert(read_header(fp, &hdr) == 0);
assert(hdr.sb.st_mode == (S_IFREG | 0644));
assert(hdr.sb.st_uid == 01750);
assert(hdr.sb.st_gid == 01750);
@@ -101,10 +101,10 @@ int main(void)
assert(sparse == NULL);
clear_header(&hdr);
- close(fd);
+ fclose(fp);
- fd = open_read("sparse-files/pax-gnu1-0.tar");
- assert(read_header(fd, &hdr) == 0);
+ fp = open_read("sparse-files/pax-gnu1-0.tar");
+ assert(read_header(fp, &hdr) == 0);
assert(hdr.sb.st_mode == (S_IFREG | 0644));
assert(hdr.sb.st_uid == 01750);
assert(hdr.sb.st_gid == 01750);
@@ -163,7 +163,7 @@ int main(void)
assert(sparse == NULL);
clear_header(&hdr);
- close(fd);
+ fclose(fp);
return EXIT_SUCCESS;
}
diff --git a/tests/tar_ustar.c b/tests/tar_ustar.c
index 20a0bd0..8b9b453 100644
--- a/tests/tar_ustar.c
+++ b/tests/tar_ustar.c
@@ -21,16 +21,16 @@
#define TEST_PATH STRVALUE(TESTPATH)
-static int open_read(const char *path)
+static FILE *open_read(const char *path)
{
- int fd = open(path, O_RDONLY);
+ FILE *fp = fopen(path, "rb");
- if (fd < 0) {
+ if (fp == NULL) {
perror(path);
exit(EXIT_FAILURE);
}
- return fd;
+ return fp;
}
static const char *filename =
@@ -42,12 +42,12 @@ int main(void)
{
tar_header_decoded_t hdr;
char buffer[6];
- int fd;
+ FILE *fp;
assert(chdir(TEST_PATH) == 0);
- fd = open_read("format-acceptance/ustar.tar");
- assert(read_header(fd, &hdr) == 0);
+ fp = open_read("format-acceptance/ustar.tar");
+ assert(read_header(fp, &hdr) == 0);
assert(hdr.sb.st_mode == (S_IFREG | 0644));
assert(hdr.sb.st_uid == 01750);
assert(hdr.sb.st_gid == 01750);
@@ -56,14 +56,14 @@ int main(void)
assert(hdr.mtime == 1542905892);
assert(strcmp(hdr.name, "input.txt") == 0);
assert(!hdr.unknown_record);
- assert(read_retry("data0", fd, buffer, 5) == 0);
+ assert(read_retry("data0", fp, buffer, 5) == 0);
buffer[5] = '\0';
assert(strcmp(buffer, "test\n") == 0);
clear_header(&hdr);
- close(fd);
+ fclose(fp);
- fd = open_read("format-acceptance/ustar-pre-posix.tar");
- assert(read_header(fd, &hdr) == 0);
+ fp = open_read("format-acceptance/ustar-pre-posix.tar");
+ assert(read_header(fp, &hdr) == 0);
assert(hdr.sb.st_mode == (S_IFREG | 0644));
assert(hdr.sb.st_uid == 01750);
assert(hdr.sb.st_gid == 01750);
@@ -72,14 +72,14 @@ int main(void)
assert(hdr.mtime == 1542905892);
assert(strcmp(hdr.name, "input.txt") == 0);
assert(!hdr.unknown_record);
- assert(read_retry("data1", fd, buffer, 5) == 0);
+ assert(read_retry("data1", fp, buffer, 5) == 0);
buffer[5] = '\0';
assert(strcmp(buffer, "test\n") == 0);
clear_header(&hdr);
- close(fd);
+ fclose(fp);
- fd = open_read("format-acceptance/v7.tar");
- assert(read_header(fd, &hdr) == 0);
+ fp = open_read("format-acceptance/v7.tar");
+ assert(read_header(fp, &hdr) == 0);
assert(hdr.sb.st_mode == (S_IFREG | 0644));
assert(hdr.sb.st_uid == 01750);
assert(hdr.sb.st_gid == 01750);
@@ -88,14 +88,14 @@ int main(void)
assert(hdr.mtime == 1542905892);
assert(strcmp(hdr.name, "input.txt") == 0);
assert(!hdr.unknown_record);
- assert(read_retry("data2", fd, buffer, 5) == 0);
+ assert(read_retry("data2", fp, buffer, 5) == 0);
buffer[5] = '\0';
assert(strcmp(buffer, "test\n") == 0);
clear_header(&hdr);
- close(fd);
+ fclose(fp);
- fd = open_read("file-size/12-digit.tar");
- assert(read_header(fd, &hdr) == 0);
+ fp = open_read("file-size/12-digit.tar");
+ assert(read_header(fp, &hdr) == 0);
assert(hdr.sb.st_mode == (S_IFREG | 0644));
assert(hdr.sb.st_uid == 01750);
assert(hdr.sb.st_gid == 01750);
@@ -105,10 +105,10 @@ int main(void)
assert(strcmp(hdr.name, "big-file.bin") == 0);
assert(!hdr.unknown_record);
clear_header(&hdr);
- close(fd);
+ fclose(fp);
- fd = open_read("user-group-largenum/8-digit.tar");
- assert(read_header(fd, &hdr) == 0);
+ fp = open_read("user-group-largenum/8-digit.tar");
+ assert(read_header(fp, &hdr) == 0);
assert(hdr.sb.st_mode == (S_IFREG | 0644));
assert(hdr.sb.st_uid == 8388608);
assert(hdr.sb.st_gid == 8388608);
@@ -117,14 +117,14 @@ int main(void)
assert(hdr.mtime == 013376036700);
assert(strcmp(hdr.name, "input.txt") == 0);
assert(!hdr.unknown_record);
- assert(read_retry("data3", fd, buffer, 5) == 0);
+ assert(read_retry("data3", fp, buffer, 5) == 0);
buffer[5] = '\0';
assert(strcmp(buffer, "test\n") == 0);
clear_header(&hdr);
- close(fd);
+ fclose(fp);
- fd = open_read("large-mtime/12-digit.tar");
- assert(read_header(fd, &hdr) == 0);
+ fp = open_read("large-mtime/12-digit.tar");
+ assert(read_header(fp, &hdr) == 0);
assert(hdr.sb.st_mode == (S_IFREG | 0644));
assert(hdr.sb.st_uid == 01750);
assert(hdr.sb.st_gid == 01750);
@@ -137,14 +137,14 @@ int main(void)
assert(hdr.mtime == 8589934592L);
assert(strcmp(hdr.name, "input.txt") == 0);
assert(!hdr.unknown_record);
- assert(read_retry("data4", fd, buffer, 5) == 0);
+ assert(read_retry("data4", fp, buffer, 5) == 0);
buffer[5] = '\0';
assert(strcmp(buffer, "test\n") == 0);
clear_header(&hdr);
- close(fd);
+ fclose(fp);
- fd = open_read("long-paths/ustar.tar");
- assert(read_header(fd, &hdr) == 0);
+ fp = open_read("long-paths/ustar.tar");
+ assert(read_header(fp, &hdr) == 0);
assert(hdr.sb.st_mode == (S_IFREG | 0644));
assert(hdr.sb.st_uid == 01750);
assert(hdr.sb.st_gid == 01750);
@@ -153,11 +153,11 @@ int main(void)
assert(hdr.mtime == 1542909670);
assert(strcmp(hdr.name, filename) == 0);
assert(!hdr.unknown_record);
- assert(read_retry("data5", fd, buffer, 5) == 0);
+ assert(read_retry("data5", fp, buffer, 5) == 0);
buffer[5] = '\0';
assert(strcmp(buffer, "test\n") == 0);
clear_header(&hdr);
- close(fd);
+ fclose(fp);
return EXIT_SUCCESS;
}
diff --git a/tests/tar_xattr_bsd.c b/tests/tar_xattr_bsd.c
index 36d8ac1..9a7eab2 100644
--- a/tests/tar_xattr_bsd.c
+++ b/tests/tar_xattr_bsd.c
@@ -21,28 +21,28 @@
#define TEST_PATH STRVALUE(TESTPATH)
-static int open_read(const char *path)
+static FILE *open_read(const char *path)
{
- int fd = open(path, O_RDONLY);
+ FILE *fp = fopen(path, "rb");
- if (fd < 0) {
+ if (fp == NULL) {
perror(path);
exit(EXIT_FAILURE);
}
- return fd;
+ return fp;
}
int main(void)
{
tar_header_decoded_t hdr;
char buffer[6];
- int fd;
+ FILE *fp;
assert(chdir(TEST_PATH) == 0);
- fd = open_read("xattr/xattr-libarchive.tar");
- assert(read_header(fd, &hdr) == 0);
+ fp = open_read("xattr/xattr-libarchive.tar");
+ assert(read_header(fp, &hdr) == 0);
assert(hdr.sb.st_mode == (S_IFREG | 0644));
assert(hdr.sb.st_uid == 01750);
assert(hdr.sb.st_gid == 01750);
@@ -51,7 +51,7 @@ int main(void)
assert(hdr.mtime == 1543094477);
assert(strcmp(hdr.name, "input.txt") == 0);
assert(!hdr.unknown_record);
- assert(read_retry("data0", fd, buffer, 5) == 0);
+ assert(read_retry("data0", fp, buffer, 5) == 0);
buffer[5] = '\0';
assert(strcmp(buffer, "test\n") == 0);
@@ -61,6 +61,6 @@ int main(void)
assert(hdr.xattr->next == NULL);
clear_header(&hdr);
- close(fd);
+ fclose(fp);
return EXIT_SUCCESS;
}
diff --git a/tests/tar_xattr_schily.c b/tests/tar_xattr_schily.c
index e543351..7434a41 100644
--- a/tests/tar_xattr_schily.c
+++ b/tests/tar_xattr_schily.c
@@ -21,28 +21,28 @@
#define TEST_PATH STRVALUE(TESTPATH)
-static int open_read(const char *path)
+static FILE *open_read(const char *path)
{
- int fd = open(path, O_RDONLY);
+ FILE *fp = fopen(path, "rb");
- if (fd < 0) {
+ if (fp == NULL) {
perror(path);
exit(EXIT_FAILURE);
}
- return fd;
+ return fp;
}
int main(void)
{
tar_header_decoded_t hdr;
char buffer[6];
- int fd;
+ FILE *fp;
assert(chdir(TEST_PATH) == 0);
- fd = open_read("xattr/xattr-schily.tar");
- assert(read_header(fd, &hdr) == 0);
+ fp = open_read("xattr/xattr-schily.tar");
+ assert(read_header(fp, &hdr) == 0);
assert(hdr.sb.st_mode == (S_IFREG | 0644));
assert(hdr.sb.st_uid == 01750);
assert(hdr.sb.st_gid == 01750);
@@ -51,7 +51,7 @@ int main(void)
assert(hdr.mtime == 1543094477);
assert(strcmp(hdr.name, "input.txt") == 0);
assert(!hdr.unknown_record);
- assert(read_retry("data0", fd, buffer, 5) == 0);
+ assert(read_retry("data0", fp, buffer, 5) == 0);
buffer[5] = '\0';
assert(strcmp(buffer, "test\n") == 0);
@@ -61,6 +61,6 @@ int main(void)
assert(hdr.xattr->next == NULL);
clear_header(&hdr);
- close(fd);
+ fclose(fp);
return EXIT_SUCCESS;
}