X-Git-Url: http://erislabs.net/gitweb/?a=blobdiff_plain;f=tests%2Ftest-read-file.c;h=fff96ecdc46beba829c2d31899b6a57df090805f;hb=1276a2c5f24c0c932426aca9c899fa524d2443f2;hp=392c4f7eaf3962c14a9254c26b6c43f69c44a854;hpb=57fdfd3f8ec62b105c53bcdf6f127c35c7fe7391;p=gnulib.git diff --git a/tests/test-read-file.c b/tests/test-read-file.c index 392c4f7ea..fff96ecdc 100644 --- a/tests/test-read-file.c +++ b/tests/test-read-file.c @@ -1,5 +1,5 @@ /* - * Copyright (C) 2006-2007 Free Software Foundation + * Copyright (C) 2006-2007, 2010-2014 Free Software Foundation, Inc. * Written by Simon Josefsson * * This program is free software: you can redistribute it and/or modify @@ -41,25 +41,37 @@ main (void) if (!out) { - perror ("Could not read file"); - err = 1; - } + perror ("Could not read file"); + err = 1; + } else - { - if (out[len] != '\0') - { - perror ("BAD: out[len] not zero"); - err = 1; - } + { + if (out[len] != '\0') + { + perror ("BAD: out[len] not zero"); + err = 1; + } - /* Assume FILE1 is a regular file or a symlink to a regular file. */ - if (len != statbuf.st_size) - { - fprintf (stderr, "Read %ld from %s...\n", (unsigned long) len, FILE1); - err = 1; - } - free (out); - } + if (S_ISREG (statbuf.st_mode)) + { + /* FILE1 is a regular file or a symlink to a regular file. */ + if (len != statbuf.st_size) + { + fprintf (stderr, "Read %ld from %s...\n", (unsigned long) len, FILE1); + err = 1; + } + } + else + { + /* Assume FILE1 is not empty. */ + if (len == 0) + { + fprintf (stderr, "Read nothing from %s\n", FILE1); + err = 1; + } + } + free (out); + } } /* We can perform the test only if the file exists and is readable. @@ -71,26 +83,26 @@ main (void) if (!out) { - perror ("Could not read file"); - err = 1; - } + perror ("Could not read file"); + err = 1; + } else - { - if (out[len] != '\0') - { - perror ("BAD: out[len] not zero"); - err = 1; - } + { + if (out[len] != '\0') + { + perror ("BAD: out[len] not zero"); + err = 1; + } - /* /dev/null should always be empty. Ignore statbuf.st_size, since it - is not a regular file. */ - if (len != 0) - { - fprintf (stderr, "Read %ld from %s...\n", (unsigned long) len, FILE2); - err = 1; - } - free (out); - } + /* /dev/null should always be empty. Ignore statbuf.st_size, since it + is not a regular file. */ + if (len != 0) + { + fprintf (stderr, "Read %ld from %s...\n", (unsigned long) len, FILE2); + err = 1; + } + free (out); + } } return err;