Bruno Haible via GNU coreutils General Discussion <[email protected]>
writes:
> + LC_ALL=C
> + diff -u exp-err err
> --- exp-err 2026-03-23 23:40:31.409487553 +0100
> +++ err 2026-03-23 23:40:31.403746784 +0100
> @@ -1 +1 @@
> -truncate: cannot open '.' for writing: Is a directory
> +truncate: cannot open '.' for writing: Invalid argument
Oh, I probably should have tested that on more systems. When adding the
check I only really wanted to make sure an error is printed. So, I'll
probably push the attached patch later.
This is almost certainly worth documenting in the Gnulib manual, and
perhaps replacing:
$ cat main.c
#include <fcntl.h>
#include <errno.h>
#include <stdio.h>
#include <string.h>
int
main (void)
{
int fd = open (".", O_WRONLY | O_CREAT, 644);
printf ("%d\n", fd);
printf ("%s\n", strerror (errno));
return 0;
}
# GNU/Linux
$ gcc main.c && ./a.out
-1
Is a directory
# Solaris 11.4
$ gcc main.c && ./a.out
-1
Invalid argument
POSIX states:
[EISDIR]
The named file is a directory and oflag includes O_WRONLY or
O_RDWR, or includes O_CREAT without O_DIRECTORY, or includes
O_EXEC when O_EXEC is not the same value as O_SEARCH.
I can send a patch to document it later.
Collin
>From cda6356fbb368373977ebde83bf47aaaf94bfef2 Mon Sep 17 00:00:00 2001
Message-ID: <cda6356fbb368373977ebde83bf47aaaf94bfef2.1774329449.git.collin.fu...@gmail.com>
From: Collin Funk <[email protected]>
Date: Mon, 23 Mar 2026 21:44:05 -0700
Subject: [PATCH] tests: truncate: don't rely on errno being EISDIR
* tests/truncate/multiple-files.sh: Only check that an error is printed
instead of an exact message.
Reported by Bruno Haible.
---
tests/truncate/multiple-files.sh | 6 +-----
1 file changed, 1 insertion(+), 5 deletions(-)
diff --git a/tests/truncate/multiple-files.sh b/tests/truncate/multiple-files.sh
index d7a984c42..a079b66ad 100755
--- a/tests/truncate/multiple-files.sh
+++ b/tests/truncate/multiple-files.sh
@@ -24,10 +24,6 @@ returns_ 1 truncate -s0 a . b > out 2> err || fail=1
test -f a || fail=1
test -f b || fail=1
compare /dev/null out || fail=1
-cat <<EOF > exp-err || framework_failure_
-truncate: cannot open '.' for writing: $EISDIR
-EOF
-compare exp-err err || fail=1
-
+compare /dev/null err && fail=1
Exit $fail
--
2.53.0