* tests/test-fstat.c: Include <fcntl.h>.
(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 <bruno@clisp.org>
+
+ stat, lstat, fstat tests: Enhance tests regarding /dev/null or NUL.
+ * tests/test-fstat.c: Include <fcntl.h>.
+ (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 <bruno@clisp.org>
stat: Document mingw bug.
SIGNATURE_CHECK (fstat, int, (int, struct stat *));
#include <errno.h>
+#include <fcntl.h>
#include <unistd.h>
#include "macros.h"
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;
}
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
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