]> git.ipfire.org Git - thirdparty/libarchive.git/commitdiff
Convert most open()/read()/write()/close() to use assertMakeFile(), stdio, and slurpf...
authorTim Kientzle <kientzle@gmail.com>
Tue, 4 Aug 2009 05:24:31 +0000 (01:24 -0400)
committerTim Kientzle <kientzle@gmail.com>
Tue, 4 Aug 2009 05:24:31 +0000 (01:24 -0400)
SVN-Revision: 1337

cpio/test/test_option_a.c
cpio/test/test_option_l.c
cpio/test/test_option_lzma.c
cpio/test/test_option_u.c
cpio/test/test_option_y.c
cpio/test/test_option_z.c
cpio/test/test_passthrough_dotdot.c
cpio/test/test_passthrough_reverse.c

index d1fe5ff0abc05a0947c524d5a63c795ca41b972c..a597bd8d6bd3b164295b91d2dfbc04e8b361875c 100644 (file)
@@ -57,19 +57,15 @@ test_create(void)
        struct utimbuf times;
        static const int numfiles = sizeof(files) / sizeof(files[0]);
        int i;
-       int fd;
 
        for (i = 0; i < numfiles; ++i) {
-               fd = open(files[i].name, O_CREAT | O_WRONLY, 0644);
-               assert(fd >= 0);
                /*
                 * Note: Have to write at least one byte to the file.
                 * cpio doesn't bother reading the file if it's zero length,
                 * so the atime never gets changed in that case, which
                 * makes the tests below rather pointless.
                 */
-               assertEqualInt(1, write(fd, "a", 1));
-               close(fd);
+               assertMakeFile(files[i].name, 0644, "a");
 
                /* If utime() isn't supported on your platform, just
                 * #ifdef this section out.  Most of the test below is
@@ -97,16 +93,14 @@ DEFINE_TEST(test_option_a)
 {
        struct stat st;
        int r;
-       int f;
-       char buff[64];
+       char *p;
 
        /* Create all of the test files. */
        test_create();
 
        /* Sanity check; verify that atimes really do get modified. */
-       f = open(files[0].name, O_RDONLY);
-       assertEqualInt(1, read(f,buff, 1));
-       assertEqualInt(0, close(f));
+       assert((p = slurpfile(NULL, "f0")) != NULL);
+       free(p);
        assertEqualInt(0, stat("f0", &st));
        if (st.st_atime == files[0].atime_sec) {
                skipping("Cannot verify -a option\n"
index c6110fa025627f28bfa023779045f3e54e2ee15f..81135d58d196e8e306213a42cf8afa3e640f0a78 100644 (file)
@@ -28,14 +28,10 @@ __FBSDID("$FreeBSD$");
 DEFINE_TEST(test_option_l)
 {
        struct stat st, st2;
-       int fd;
        int r;
 
        /* Create a file. */
-       fd = open("f", O_CREAT | O_WRONLY, 0644);
-       assert(fd >= 0);
-       assertEqualInt(1, write(fd, "a", 1));
-       close(fd);
+       assertMakeFile("f", 0644, "a");
 
        /* Stat it. */
        assertEqualInt(0, stat("f", &st));
index 132cba1da8a0b85b2f2afd387274c6cd54114f33..c6e33530150580eb855f1924efd0f4f18803b362 100644 (file)
@@ -28,15 +28,11 @@ __FBSDID("$FreeBSD$");
 DEFINE_TEST(test_option_lzma)
 {
        char *p;
-       int fd;
        int r;
        size_t s;
 
        /* Create a file. */
-       fd = open("f", O_CREAT | O_WRONLY, 0644);
-       assert(fd >= 0);
-       assertEqualInt(1, write(fd, "a", 1));
-       close(fd);
+       assertMakeFile("f", 0644, "a");
 
        /* Archive it with lzma compression. */
        r = systemf("echo f | %s -o --lzma >archive.out 2>archive.err",
index 7d2edfff564f3cfb049dc792673a3ae6bac5b191..769134cbde58ac2930bb0c4db75439c3988ec893 100644 (file)
@@ -35,14 +35,10 @@ DEFINE_TEST(test_option_u)
        struct utimbuf times;
        char *p;
        size_t s;
-       int fd;
        int r;
 
        /* Create a file. */
-       fd = open("f", O_CREAT | O_WRONLY, 0644);
-       assert(fd >= 0);
-       assertEqualInt(1, write(fd, "a", 1));
-       close(fd);
+       assertMakeFile("f", 0644, "a");
 
        /* Copy the file to the "copy" dir. */
        r = systemf("echo f | %s -pd copy >copy.out 2>copy.err",
@@ -55,10 +51,7 @@ DEFINE_TEST(test_option_u)
        assertEqualMem(p, "a", 1);
 
        /* Recreate the file with a single "b" */
-       fd = open("f", O_CREAT | O_TRUNC | O_WRONLY, 0644);
-       assert(fd >= 0);
-       assertEqualInt(1, write(fd, "b", 1));
-       close(fd);
+       assertMakeFile("f", 0644, "b");
 
        /* Set the mtime to the distant past. */
        memset(&times, 0, sizeof(times));
index a8a5936dcc3bff72ab4d416f6e75cd1012671193..58734966ce6ab3ef0193e4f1dd73c3231a621a9d 100644 (file)
@@ -28,15 +28,11 @@ __FBSDID("$FreeBSD: src/usr.bin/cpio/test/test_option_y.c,v 1.2 2008/08/24 06:21
 DEFINE_TEST(test_option_y)
 {
        char *p;
-       int fd;
        int r;
        size_t s;
 
        /* Create a file. */
-       fd = open("f", O_CREAT | O_WRONLY, 0644);
-       assert(fd >= 0);
-       assertEqualInt(1, write(fd, "a", 1));
-       close(fd);
+       assertMakeFile("f", 0644, "a");
 
        /* Archive it with bzip2 compression. */
        r = systemf("echo f | %s -oy >archive.out 2>archive.err",
index c4bc480e980e5799a487e6fbeffd5ab18208736d..91d37ac1983a4c626e7af2ecc94af443824a0b9b 100644 (file)
@@ -28,15 +28,11 @@ __FBSDID("$FreeBSD$");
 DEFINE_TEST(test_option_z)
 {
        char *p;
-       int fd;
        int r;
        size_t s;
 
        /* Create a file. */
-       fd = open("f", O_CREAT | O_WRONLY, 0644);
-       assert(fd >= 0);
-       assertEqualInt(1, write(fd, "a", 1));
-       close(fd);
+       assertMakeFile("f", 0644, "a");
 
        /* Archive it with gzip compression. */
        r = systemf("echo f | %s -oz >archive.out 2>archive.err",
index 9dc8dbb0d08e90b6762b6abdf188333619b6fb9c..72f8562e39554095bc1e59d51a963db8adb913b4 100644 (file)
@@ -32,31 +32,28 @@ __FBSDID("$FreeBSD: src/usr.bin/cpio/test/test_passthrough_dotdot.c,v 1.4 2008/0
 DEFINE_TEST(test_passthrough_dotdot)
 {
        struct stat st;
-       int fd, r;
-       int filelist;
+       int r;
+       FILE *filelist;
 
        assertUmask(0);
 
        /*
         * Create an assortment of files on disk.
         */
-       filelist = open("filelist", O_CREAT | O_WRONLY, 0644);
+       filelist = fopen("filelist", "w");
 
        /* Directory. */
        assertMakeDir("dir", 0755);
        assertChdir("dir");
 
-       write(filelist, ".\n", 2);
+       fprintf(filelist, ".\n");
 
        /* File with 10 bytes content. */
-       fd = open("file", O_CREAT | O_WRONLY, 0642);
-       assert(fd >= 0);
-       assertEqualInt(10, write(fd, "123456789", 10));
-       close(fd);
-       write(filelist, "file\n", 5);
+       assertMakeFile("file", 0642, "1234567890");
+       fprintf(filelist, "file\n");
 
        /* All done. */
-       close(filelist);
+       fclose(filelist);
 
 
        /*
index 25ba73b563a1d9e9b49d2fecf28c12d1e08c10fd..8a4a5193e8b7cb48fa592b4124754a0dfda31f09 100644 (file)
@@ -37,31 +37,28 @@ __FBSDID("$FreeBSD: src/usr.bin/cpio/test/test_passthrough_reverse.c,v 1.2 2008/
 DEFINE_TEST(test_passthrough_reverse)
 {
        struct stat st;
-       int fd, r;
-       int filelist;
+       int r;
+       FILE *filelist;
 
        assertUmask(0);
 
        /*
         * Create an assortment of files on disk.
         */
-       filelist = open("filelist", O_CREAT | O_WRONLY, 0644);
+       filelist = fopen("filelist", "w");
 
        /* Directory. */
        assertMakeDir("dir", 0743);
 
        /* File with 10 bytes content. */
-       fd = open("dir/file", O_CREAT | O_WRONLY, 0644);
-       assert(fd >= 0);
-       assertEqualInt(10, write(fd, "123456789", 10));
-       close(fd);
-       write(filelist, "dir/file\n", 9);
+       assertMakeFile("dir/file", 0644, "1234567890");
+       fprintf(filelist, "dir/file\n");
 
        /* Write dir last. */
-       write(filelist, "dir\n", 4);
+       fprintf(filelist, "dir\n");
 
        /* All done. */
-       close(filelist);
+       fclose(filelist);
 
 
        /*