From: Bruno Haible Date: Thu, 12 Jun 2025 17:45:19 +0000 (+0200) Subject: stat, lstat, fstat tests: Enhance tests regarding /dev/null or NUL. X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=fab078415a9789b8f74aae37d2cf94f103f7261d;p=thirdparty%2Fgnulib.git stat, lstat, fstat tests: Enhance tests regarding /dev/null or NUL. * tests/test-fstat.c: Include . (main): Check that fstat reports /dev/null or NUL as a character device. * tests/test-stat.h (test_stat_func): Likewise for stat. * tests/test-lstat.h (test_lstat_func): Likewise for lstat. --- diff --git a/ChangeLog b/ChangeLog index cb4853e4b3..da241662d7 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,11 @@ +2025-06-12 Bruno Haible + + stat, lstat, fstat tests: Enhance tests regarding /dev/null or NUL. + * tests/test-fstat.c: Include . + (main): Check that fstat reports /dev/null or NUL as a character device. + * tests/test-stat.h (test_stat_func): Likewise for stat. + * tests/test-lstat.h (test_lstat_func): Likewise for lstat. + 2025-06-12 Bruno Haible stat: Document mingw bug. diff --git a/tests/test-fstat.c b/tests/test-fstat.c index 474e262077..7e65ee2f23 100644 --- a/tests/test-fstat.c +++ b/tests/test-fstat.c @@ -22,6 +22,7 @@ SIGNATURE_CHECK (fstat, int, (int, struct stat *)); #include +#include #include #include "macros.h" @@ -46,5 +47,21 @@ main () ASSERT (errno == EBADF); } + /* /dev/null is a character device. */ + { + int fd; + struct stat statbuf; + +#if defined _WIN32 && !defined __CYGWIN__ + fd = open ("NUL", O_RDWR); +#else + fd = open ("/dev/null", O_RDWR); +#endif + ASSERT (fstat (fd, &statbuf) == 0); + close (fd); + ASSERT (!S_ISREG (statbuf.st_mode)); + ASSERT (S_ISCHR (statbuf.st_mode)); + } + return test_exit_status; } diff --git a/tests/test-lstat.h b/tests/test-lstat.h index b9846df710..fb9a808a76 100644 --- a/tests/test-lstat.h +++ b/tests/test-lstat.h @@ -64,6 +64,15 @@ test_lstat_func (int (*func) (char const *, struct stat *), bool print) ASSERT (func (BASE "file/", &st1) == -1); ASSERT (errno == ENOTDIR); + /* /dev/null is a character device. */ +#if defined _WIN32 && !defined __CYGWIN__ + ASSERT (func ("NUL", &st1) == 0); +#else + ASSERT (func ("/dev/null", &st1) == 0); +#endif + ASSERT (!S_ISREG (st1.st_mode)); + ASSERT (S_ISCHR (st1.st_mode)); + /* Now for some symlink tests, where supported. We set up: link1 -> directory link2 -> file diff --git a/tests/test-stat.h b/tests/test-stat.h index fc0a9d4dd5..3d2b912e8f 100644 --- a/tests/test-stat.h +++ b/tests/test-stat.h @@ -61,6 +61,15 @@ test_stat_func (int (*func) (char const *, struct stat *), bool print) ASSERT (func (BASE "file/", &st1) == -1); ASSERT (errno == ENOTDIR); + /* /dev/null is a character device. */ +#if defined _WIN32 && !defined __CYGWIN__ + ASSERT (func ("NUL", &st1) == 0); +#else + ASSERT (func ("/dev/null", &st1) == 0); +#endif + ASSERT (!S_ISREG (st1.st_mode)); + ASSERT (S_ISCHR (st1.st_mode)); + /* Now for some symlink tests, where supported. We set up: link1 -> directory link2 -> file