diff options
author | David Oberhollenzer <david.oberhollenzer@sigma-star.at> | 2019-11-06 11:54:56 +0100 |
---|---|---|
committer | David Oberhollenzer <david.oberhollenzer@sigma-star.at> | 2019-11-06 11:56:02 +0100 |
commit | 4d46b361ff1371a6f3f4f89ed8ca81ee23e86de8 (patch) | |
tree | 0705d7c216ea345665cd38345bc21f8931195849 /tests/tar_gnu.c | |
parent | 3afffc2a59cfc3888a84b2b2305b5312393ff4e8 (diff) |
Remove raw file descriptors from tar read path
Signed-off-by: David Oberhollenzer <david.oberhollenzer@sigma-star.at>
Diffstat (limited to 'tests/tar_gnu.c')
-rw-r--r-- | tests/tar_gnu.c | 64 |
1 files changed, 32 insertions, 32 deletions
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; } |