Re: [PATCH] tests: set executable bit in test-trim[1-3].sh

2023-04-03 Thread Bruno Haible
Jim Meyering wrote:
> I tried latest gnulib with grep and saw three easily-fixed failures

Ah, some packages execute the tests without $(SHELL). Then we need to
make all the tests/*.sh executable.


2023-04-03  Bruno Haible  

tests: Set executable bit on more tests.
* tests/test-c-dtoastr.sh: Make executable.
* tests/test-c-ldtoastr.sh: Likewise.
* tests/test-immutable.sh: Likewise.
* tests/test-vasnwprintf-posix2.sh: Likewise.







[PATCH] tests: set executable bit in test-trim[1-3].sh

2023-04-03 Thread Jim Meyering
I tried latest gnulib with grep and saw three easily-fixed failures, so
I've pushed this:

>From d7e034a02c4ede22045be9165e68cea1990cfd6a Mon Sep 17 00:00:00 2001
From: Jim Meyering 
Date: Mon, 3 Apr 2023 12:27:46 -0700
Subject: [PATCH] tests: set executable bit in test-trim[1-3].sh

This avoids a test failure for each new file.
* tests/test-trim1.sh: Make this file executable.
* tests/test-trim2.sh: Likewise.
* tests/test-trim1.sh: Likewise.
---
 ChangeLog   | 8 
 tests/test-trim1.sh | 0
 tests/test-trim2.sh | 0
 3 files changed, 8 insertions(+)
 mode change 100644 => 100755 tests/test-trim1.sh
 mode change 100644 => 100755 tests/test-trim2.sh

diff --git a/ChangeLog b/ChangeLog
index e9a8688988..41a8197227 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,11 @@
+2023-04-03  Jim Meyering  
+
+	tests: set executable bit in test-trim[1-3].sh
+	This avoids a test failure for each new file.
+	* tests/test-trim1.sh: Make this file executable.
+	* tests/test-trim2.sh: Likewise.
+	* tests/test-trim1.sh: Likewise.
+
 2023-04-03  Bruno Haible  

 	Use the 'extern-inline' module explicitly where needed.
diff --git a/tests/test-trim1.sh b/tests/test-trim1.sh
old mode 100644
new mode 100755
diff --git a/tests/test-trim2.sh b/tests/test-trim2.sh
old mode 100644
new mode 100755
-- 
2.40.0.166.g140b9478da



Re: Use the 'extern-inline' module explicitly where needed

2023-04-03 Thread Bruno Haible
Paul Eggert wrote:
> Perhaps something like the attached as well?

Feel free to push it.

Bruno






Re: Use the 'extern-inline' module explicitly where needed

2023-04-03 Thread Paul Eggert

Thanks for doing that. Perhaps something like the attached as well?From 9fce35022cc3dfa516059062ead881bf787404a9 Mon Sep 17 00:00:00 2001
From: Paul Eggert 
Date: Mon, 3 Apr 2023 11:30:08 -0700
Subject: [PATCH] Document extern-inline find

---
 ChangeLog | 5 +
 1 file changed, 5 insertions(+)

diff --git a/ChangeLog b/ChangeLog
index e9a8688988..8829004554 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,6 +1,11 @@
 2023-04-03  Bruno Haible  
 
 	Use the 'extern-inline' module explicitly where needed.
+	I found the list of affected modules through this command:
+	  for m in $(for f in `grep -Fl _GL_INLINE_HEADER_BEGIN lib/*.h | sort`
+	 do ./gnulib-tool --find $f; done)
+	  do grep '^extern-inline' modules/$m > /dev/null || echo $m
+	  done
 	* modules/fdutimensat (Depends-on): Add extern-inline.
 	* modules/file-has-acl (Depends-on): Likewise.
 	* modules/hamt (Depends-on): Likewise.
-- 
2.37.2



Use the 'extern-inline' module explicitly where needed

2023-04-03 Thread Bruno Haible
When a .h file uses _GL_INLINE_HEADER_BEGIN / _GL_INLINE_HEADER_END,
it needs a dependency towards the 'extern-inline' module.

Some modules had this dependency only accidentally; it's better to
have it explicitly, for maintenance.

I found the list of affected modules through
$ for m in $(for f in `fgrep -l _GL_INLINE_HEADER_BEGIN lib/*.h | sort`; do 
./gnulib-tool --find $f; done); do
if grep '^extern-inline' modules/$m > /dev/null; then :; else echo $m; fi;
  done


2023-04-03  Bruno Haible  

Use the 'extern-inline' module explicitly where needed.
* modules/fdutimensat (Depends-on): Add extern-inline.
* modules/file-has-acl (Depends-on): Likewise.
* modules/hamt (Depends-on): Likewise.
* modules/relocatable-prog-wrapper (Depends-on): Likewise.
* modules/safe-alloc (Depends-on): Likewise.
* modules/string-desc (Depends-on): Likewise.
* modules/string-desc-quotearg (Depends-on): Likewise.
* modules/xstring-desc (Depends-on): Likewise.
* modules/xvasprintf (Depends-on): Likewise.

diff --git a/modules/fdutimensat b/modules/fdutimensat
index 21d656f1a5..e2cf553466 100644
--- a/modules/fdutimensat
+++ b/modules/fdutimensat
@@ -6,6 +6,7 @@ lib/fdutimensat.c
 lib/utimens.h
 
 Depends-on:
+extern-inline
 futimens
 utimensat
 
diff --git a/modules/file-has-acl b/modules/file-has-acl
index fa2ea4ca22..be1048dfe1 100644
--- a/modules/file-has-acl
+++ b/modules/file-has-acl
@@ -8,6 +8,7 @@ m4/acl.m4
 
 Depends-on:
 acl-permissions
+extern-inline
 free-posix
 stat
 stdbool
diff --git a/modules/hamt b/modules/hamt
index d73f09c2db..d8b0d7207a 100644
--- a/modules/hamt
+++ b/modules/hamt
@@ -7,6 +7,7 @@ lib/hamt.c
 
 Depends-on:
 count-one-bits
+extern-inline
 flexmember
 inttypes-incomplete
 stdbool
diff --git a/modules/relocatable-prog-wrapper b/modules/relocatable-prog-wrapper
index c885ce2759..e1a14d0448 100644
--- a/modules/relocatable-prog-wrapper
+++ b/modules/relocatable-prog-wrapper
@@ -57,6 +57,7 @@ double-slash-root
 eloop-threshold
 environ
 errno
+extern-inline
 fcntl-h
 filename
 idx
diff --git a/modules/safe-alloc b/modules/safe-alloc
index 180aa8a2de..370b30f625 100644
--- a/modules/safe-alloc
+++ b/modules/safe-alloc
@@ -8,6 +8,7 @@ m4/safe-alloc.m4
 
 Depends-on:
 calloc-gnu
+extern-inline
 reallocarray
 
 configure.ac:
diff --git a/modules/string-desc b/modules/string-desc
index 044ee266e4..047e2d390c 100644
--- a/modules/string-desc
+++ b/modules/string-desc
@@ -10,6 +10,7 @@ Depends-on:
 stdbool
 idx
 ialloc
+extern-inline
 memchr
 memrchr
 memmem
diff --git a/modules/string-desc-quotearg b/modules/string-desc-quotearg
index 42472b0774..17e0fa5abf 100644
--- a/modules/string-desc-quotearg
+++ b/modules/string-desc-quotearg
@@ -8,6 +8,7 @@ lib/string-desc-quotearg.c
 Depends-on:
 string-desc
 quotearg
+extern-inline
 
 configure.ac:
 
diff --git a/modules/xstring-desc b/modules/xstring-desc
index d0cda2d23e..5653853686 100644
--- a/modules/xstring-desc
+++ b/modules/xstring-desc
@@ -8,6 +8,7 @@ lib/xstring-desc.c
 Depends-on:
 string-desc
 xalloc-die
+extern-inline
 
 configure.ac:
 
diff --git a/modules/xvasprintf b/modules/xvasprintf
index 4ebbba470a..b322890876 100644
--- a/modules/xvasprintf
+++ b/modules/xvasprintf
@@ -13,6 +13,7 @@ stdio
 vasprintf
 xalloc
 xalloc-die
+extern-inline
 xsize
 stdarg
 errno






Re: bug#62607: cp --recursive --backup broken in 9.2

2023-04-03 Thread Pádraig Brady

On 02/04/2023 13:40, Pádraig Brady wrote:

On 01/04/2023 23:40, Kristian Klausen via GNU coreutils Bug Reports wrote:

Hi

After upgrading to coreutils 9.2-2 on Arch Linux the following:
mkdir -p src dst
touch {src,dst}/bar
cp --recursive --backup src/* dst
fails with:
cp: cannot create regular file 'dst/foo/bar': File exists

Running strace on cp I noticed:
renameat2(4, "foo/bar", 4, "foo/bar~", 0) = -1 ENOENT (No such file or
directory)

In coreutils 9.1-3 the syscall succeeds:
renameat2(4, "bar", 4, "bar~", 0)   = 0

I assume renameat2 is called with the wrong oldpath and newpath in 9.2
and that it should just be the basename and not the full relative path.

Cheers
Kristian Klausen


Your analysis is correct wrt the wrong paths being given to the renameat2().
This is related to https://bugs.gnu.org/55029

For completeness the correct repro is:

mkdir -p {src,dst}/foo
touch {src,dst}/foo/bar
cp --recursive --backup src/* dst


The attached two patches should address this.
The first fixes the bug in gnulib (cc'd),
while the second adds a test to coreutils.

thanks,
Pádraig
From 418aa564ebff70c1d118a5d3307a6d0b147ff7a2 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?P=C3=A1draig=20Brady?= 
Date: Mon, 3 Apr 2023 18:06:22 +0100
Subject: [PATCH] backupfile: fix bug when renaming from subdirectory

* lib/backupfile.c (backup_internal): Ensure we use the
appropriate offset if operating on a subdirectory,
i.e., on an updated sdir.
Fixes https://bugs.gnu.org/62607
---
 ChangeLog| 8 
 lib/backupfile.c | 7 ---
 2 files changed, 12 insertions(+), 3 deletions(-)

diff --git a/ChangeLog b/ChangeLog
index ae851ed8aa..69c19b3ebe 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,11 @@
+2023-04-03  Pádraig Brady  
+
+	backupfile: fix bug when renaming from subdirectory
+	* lib/backupfile.c (backup_internal): Ensure we use the
+	appropriate offset if operating on a subdirectory,
+	i.e., on an updated sdir.
+	Fixes https://bugs.gnu.org/62607
+
 2023-04-03  Bruno Haible  
 
 	vasnprintf-posix: Fix harmless mistake (regression 2023-03-24).
diff --git a/lib/backupfile.c b/lib/backupfile.c
index 9cca271343..5bcf924414 100644
--- a/lib/backupfile.c
+++ b/lib/backupfile.c
@@ -331,7 +331,7 @@ backupfile_internal (int dir_fd, char const *file,
 return s;
 
   DIR *dirp = NULL;
-  int sdir = dir_fd;
+  int sdir = -1;
   idx_t base_max = 0;
   while (true)
 {
@@ -370,9 +370,10 @@ backupfile_internal (int dir_fd, char const *file,
   if (! rename)
 break;
 
-  idx_t offset = backup_type == simple_backups ? 0 : base_offset;
+  dir_fd = sdir < 0 ? dir_fd : sdir;
+  idx_t offset = sdir < 0 ? 0 : base_offset;
   unsigned flags = backup_type == simple_backups ? 0 : RENAME_NOREPLACE;
-  if (renameatu (sdir, file + offset, sdir, s + offset, flags) == 0)
+  if (renameatu (dir_fd, file + offset, dir_fd, s + offset, flags) == 0)
 break;
   int e = errno;
   if (! (e == EEXIST && extended))
-- 
2.26.2

From 1a80fab339d52db7e284b4f2f41068d5d8dd7e4e Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?P=C3=A1draig=20Brady?= 
Date: Mon, 3 Apr 2023 18:12:33 +0100
Subject: [PATCH] tests: cp: test --backup with subdirectories

* tests/cp/backup-dir.sh: Add a test to ensure
we rename appropriately when backing up through subdirs.
* NEWS: Mention the bug fix.
Addresses https://bugs.gnu.org/62607
---
 NEWS   | 5 +
 tests/cp/backup-dir.sh | 8 +++-
 2 files changed, 12 insertions(+), 1 deletion(-)

diff --git a/NEWS b/NEWS
index f53adab6f..59c6da5a7 100644
--- a/NEWS
+++ b/NEWS
@@ -10,6 +10,11 @@ GNU coreutils NEWS-*- outline -*-
   more restricted systems like android or containers etc.
   [bug introduced in coreutils-9.2]
 
+  cp --recursive --backup will again operate correctly.
+  Previousy it may have hit "File exists" errors when
+  it failed to appropriately rename files being replaced.
+  [bug introduced in coreutils-9.2]
+
   date --file and dircolors will now diagnose a failure to read a file.
   Previously they would have silently ignored the failure.
   [This bug was present in "the beginning".]
diff --git a/tests/cp/backup-dir.sh b/tests/cp/backup-dir.sh
index 6573d58e0..5c17498cf 100755
--- a/tests/cp/backup-dir.sh
+++ b/tests/cp/backup-dir.sh
@@ -1,5 +1,5 @@
 #!/bin/sh
-# Ensure that cp -b doesn't back up directories.
+# Ensure that cp -b handles directories appropriately
 
 # Copyright (C) 2006-2023 Free Software Foundation, Inc.
 
@@ -29,4 +29,10 @@ cp -ab x y || fail=1
 test -d y/x || fail=1
 test -d y/x~ && fail=1
 
+# Bug 62607.
+# This would fail to backup using rename, and thus fail to replace the file
+mkdir -p {src,dst}/foo || framework_failure_
+touch {src,dst}/foo/bar || framework_failure_
+cp --recursive --backup src/* dst || fail=1
+
 Exit $fail
-- 
2.26.2



Re: *printf-posix: ISO C 23: Support size specifiers 'wN' and 'wfN'

2023-04-03 Thread Bruno Haible
Oops, there was a mistake here. Fortunately a harmless one.

> @@ -1633,24 +1633,155 @@ MAX_ROOM_NEEDED (const arguments *ap, size_t 
> arg_index, FCHAR_T conversion,
>switch (conversion)
>  {
>  case 'd': case 'i': case 'u':
> -  if (type == TYPE_LONGLONGINT || type == TYPE_ULONGLONGINT)
> -tmp_length =
> -  (unsigned int) (sizeof (unsigned long long) * CHAR_BIT
> -  * 0.30103 /* binary -> decimal */
> - )
> -  + 1; /* turn floor into ceil */
> -  else if (type == TYPE_LONGINT || type == TYPE_ULONGINT)
> -tmp_length =
> -  (unsigned int) (sizeof (unsigned long) * CHAR_BIT
> -  * 0.30103 /* binary -> decimal */
> - )
> -  + 1; /* turn floor into ceil */
> -  else
> -tmp_length =
> -  (unsigned int) (sizeof (unsigned int) * CHAR_BIT
> -  * 0.30103 /* binary -> decimal */
> - )
> -  + 1; /* turn floor into ceil */
> +  switch (type)
> +{
> +default:
> +  tmp_length =
> +(unsigned int) (sizeof (unsigned int) * CHAR_BIT
> +* 0.30103 /* binary -> decimal */
> +   )
> ++ 1; /* turn floor into ceil */
> +case TYPE_LONGINT:
> +  tmp_length =
> +(unsigned int) (sizeof (long int) * CHAR_BIT
> +* 0.30103 /* binary -> decimal */
> +   )
> ++ 1; /* turn floor into ceil */
> +  break;


2023-04-03  Bruno Haible  

vasnprintf-posix: Fix harmless mistake (regression 2023-03-24).
Found by Coverity.
* lib/vasnprintf.c (MAX_ROOM_NEEDED): Insert 'break;' statement.

diff --git a/lib/vasnprintf.c b/lib/vasnprintf.c
index 111d898a94..6eb056d0e9 100644
--- a/lib/vasnprintf.c
+++ b/lib/vasnprintf.c
@@ -1641,6 +1641,7 @@ MAX_ROOM_NEEDED (const arguments *ap, size_t arg_index, 
FCHAR_T conversion,
 * 0.30103 /* binary -> decimal */
)
 + 1; /* turn floor into ceil */
+  break;
 case TYPE_LONGINT:
   tmp_length =
 (unsigned int) (sizeof (long int) * CHAR_BIT






more tests against glibc C locale bug

2023-04-03 Thread Bruno Haible
For robustness, let me add tests against the glibc bug
https://sourceware.org/bugzilla/show_bug.cgi?id=19932
also to the mb*c32* unit tests.

Here, no fixes are needed, since the fixes are already in the mb*wc*
and mbrtoc32 modules.


2023-04-03  Bruno Haible  

mbstoc32s tests: Check behaviour in the C locale.
* tests/test-mbstoc32s.c (main): Test behaviour in the C locale. Based
on tests/test-mbstowcs.c.
* tests/test-mbstoc32s-5.sh: New file, based on tests/test-mbstowcs5.sh.
* modules/mbstoc32s-tests (Files): Add it.
(Depends-on): Add btoc32.
(Makefile.am): Run test-mbstoc32s-5.sh.

2023-04-03  Bruno Haible  

mbsnrtoc32s tests: Check behaviour in the C locale.
* tests/test-mbsnrtoc32s.c (main): Test behaviour in the C locale. Based
on tests/test-mbsnrtowcs.c.
* tests/test-mbsnrtoc32s-5.sh: New file, based on
tests/test-mbsrtowcs5.sh.
* modules/mbsnrtoc32s-tests (Files): Add it.
(Depends-on): Add btoc32.
(Makefile.am): Run test-mbsnrtoc32s-5.sh.

2023-04-03  Bruno Haible  

mbsrtoc32s tests: Check behaviour in the C locale.
* tests/test-mbsrtoc32s.c (main): Test behaviour in the C locale. Based
on tests/test-mbsrtowcs.c.
* tests/test-mbsrtoc32s-5.sh: New file, based on
tests/test-mbsrtowcs5.sh.
* modules/mbsrtoc32s-tests (Files): Add it.
(Depends-on): Add btoc32.
(Makefile.am): Run test-mbsrtoc32s-5.sh.

2023-04-03  Bruno Haible  

btoc32 tests: Check behaviour in the C locale.
* tests/test-btoc32.c (main): Test behaviour in the C locale. Based on
tests/test-btowc.c.
* tests/test-btoc32-3.sh: New file, based on tests/test-btowc3.sh.
* modules/btoc32-tests (Files): Add it.
(Makefile.am): Test it.

2023-04-03  Bruno Haible  

mbrtoc32 tests: Prefer *c32* functions.
* tests/test-mbrtoc32.c (main): Use btoc32 instead of btowc.
* modules/mbrtoc32-tests (Depends-on): Add btoc32.

2023-04-03  Bruno Haible  

mbrtoc32 tests: Add comment.
* m4/mbrtowc.m4 (gl_MBRTOWC_C_LOCALE): Add comment.
* m4/mbrtoc32.m4 (gl_MBRTOC32_C_LOCALE): Add comment.
* tests/test-mbrtoc32.c: Add comment.
* tests/test-mbrtoc32-5.sh: Use symmetric coding style.
* doc/posix-functions/mbrtoc32.texi: Update.

>From 09a9ccc95ddd3e4ffbf386cca440b944c91d3412 Mon Sep 17 00:00:00 2001
From: Bruno Haible 
Date: Mon, 3 Apr 2023 14:24:37 +0200
Subject: [PATCH 1/6] mbrtoc32 tests: Add comment.

* m4/mbrtowc.m4 (gl_MBRTOWC_C_LOCALE): Add comment.
* m4/mbrtoc32.m4 (gl_MBRTOC32_C_LOCALE): Add comment.
* tests/test-mbrtoc32.c: Add comment.
* tests/test-mbrtoc32-5.sh: Use symmetric coding style.
* doc/posix-functions/mbrtoc32.texi: Update.
---
 ChangeLog | 9 +
 doc/posix-functions/mbrtoc32.texi | 2 +-
 m4/mbrtoc32.m4| 7 ++-
 m4/mbrtowc.m4 | 4 
 tests/test-mbrtoc32-5.sh  | 7 +--
 tests/test-mbrtoc32.c | 4 
 6 files changed, 29 insertions(+), 4 deletions(-)

diff --git a/ChangeLog b/ChangeLog
index 2993b1561f..7bc1a008f1 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,12 @@
+2023-04-03  Bruno Haible  
+
+	mbrtoc32 tests: Add comment.
+	* m4/mbrtowc.m4 (gl_MBRTOWC_C_LOCALE): Add comment.
+	* m4/mbrtoc32.m4 (gl_MBRTOC32_C_LOCALE): Add comment.
+	* tests/test-mbrtoc32.c: Add comment.
+	* tests/test-mbrtoc32-5.sh: Use symmetric coding style.
+	* doc/posix-functions/mbrtoc32.texi: Update.
+
 2023-04-02  Bruno Haible  
 
 	trim: Fix trim_trailing result in multibyte locales.
diff --git a/doc/posix-functions/mbrtoc32.texi b/doc/posix-functions/mbrtoc32.texi
index d95c670200..7c3d6c294a 100644
--- a/doc/posix-functions/mbrtoc32.texi
+++ b/doc/posix-functions/mbrtoc32.texi
@@ -12,7 +12,7 @@
 @item
 In the C or POSIX locales, this function can return @code{(size_t) -1}
 and set @code{errno} to @code{EILSEQ}:
-glibc 2.23.
+glibc 2.35.
 @item
 This function returns 0 instead of @code{(size_t) -2} when the input
 is empty:
diff --git a/m4/mbrtoc32.m4 b/m4/mbrtoc32.m4
index f2de33aff6..d6401fe2e4 100644
--- a/m4/mbrtoc32.m4
+++ b/m4/mbrtoc32.m4
@@ -1,4 +1,4 @@
-# mbrtoc32.m4 serial 10
+# mbrtoc32.m4 serial 11
 dnl Copyright (C) 2014-2023 Free Software Foundation, Inc.
 dnl This file is free software; the Free Software Foundation
 dnl gives unlimited permission to copy and/or distribute it,
@@ -101,6 +101,11 @@ AC_DEFUN([gl_MBRTOC32_EMPTY_INPUT]
 ])
 ])
 
+dnl 
+dnl POSIX:2018 says regarding mbrtowc: "In the POSIX locale an [EILSEQ] error
+dnl cannot occur since all byte values are valid characters."  It is reasonable
+dnl to expect mbrtoc32 to behave in the same way.
+
 AC_DEFUN([gl_MBRTOC32_C_LOCALE],
 [
   AC_REQUIRE([AC_CANONICAL_HOST]) dnl for cross-compiles
diff --git a/m4/mbrtowc.m4