>From 2590ea7fe1aebd71ce37e611b5096a160b633344 Mon Sep 17 00:00:00 2001 From: Bruno Haible Date: Tue, 5 Nov 2024 21:10:13 +0100 Subject: [PATCH 06/23] strncpy tests: Verify N3322 functionality. * modules/strncpy: New file. * doc/posix-functions/strncpy.texi: Mention the new module. * tests/test-strncpy.c: New file. * modules/strncpy-tests: New file. --- ChangeLog | 8 ++++++ doc/posix-functions/strncpy.texi | 5 ++-- modules/strncpy | 26 +++++++++++++++++++ modules/strncpy-tests | 11 ++++++++ tests/test-strncpy.c | 44 ++++++++++++++++++++++++++++++++ 5 files changed, 92 insertions(+), 2 deletions(-) create mode 100644 modules/strncpy create mode 100644 modules/strncpy-tests create mode 100644 tests/test-strncpy.c diff --git a/ChangeLog b/ChangeLog index a8fde5dfbc..d0514e69b0 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,11 @@ +2024-11-05 Bruno Haible + + strncpy tests: Verify N3322 functionality. + * modules/strncpy: New file. + * doc/posix-functions/strncpy.texi: Mention the new module. + * tests/test-strncpy.c: New file. + * modules/strncpy-tests: New file. + 2024-11-05 Bruno Haible memmove tests: Verify N3322 functionality. diff --git a/doc/posix-functions/strncpy.texi b/doc/posix-functions/strncpy.texi index 343ff249a9..ea5f41dcce 100644 --- a/doc/posix-functions/strncpy.texi +++ b/doc/posix-functions/strncpy.texi @@ -4,10 +4,11 @@ POSIX specification:@* @url{https://pubs.opengroup.org/onlinepubs/9799919799/functions/strncpy.html} -Gnulib module: string +Gnulib module: string or strncpy @mindex string +@mindex strncpy -Portability problems fixed by Gnulib: +Portability problems fixed by Gnulib module @code{string} or Gnulib module @code{strncpy}: @itemize @item This function cannot be called from plain inline or extern inline functions diff --git a/modules/strncpy b/modules/strncpy new file mode 100644 index 0000000000..de91ffde5e --- /dev/null +++ b/modules/strncpy @@ -0,0 +1,26 @@ +Description: +Copy the initial part of a string. + +Status: +obsolete + +Notice: +This module is obsolete. + +Files: + +Depends-on: +string + +configure.ac: + +Makefile.am: + +Include: + + +License: +LGPLv2+ + +Maintainer: +all diff --git a/modules/strncpy-tests b/modules/strncpy-tests new file mode 100644 index 0000000000..c21d2ac3fd --- /dev/null +++ b/modules/strncpy-tests @@ -0,0 +1,11 @@ +Files: +tests/test-strncpy.c +tests/macros.h + +Depends-on: + +configure.ac: + +Makefile.am: +TESTS += test-strncpy +check_PROGRAMS += test-strncpy diff --git a/tests/test-strncpy.c b/tests/test-strncpy.c new file mode 100644 index 0000000000..518b43d226 --- /dev/null +++ b/tests/test-strncpy.c @@ -0,0 +1,44 @@ +/* Test of strncpy() function. + Copyright (C) 2024 Free Software Foundation, Inc. + + This program is free software: you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation, either version 3 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program. If not, see . */ + +#include + +/* Specification. */ +#include + +#include + +#include "macros.h" + +int +main (void) +{ + int volatile value; + + /* Test zero-length operations on NULL pointers, allowed by + . */ + + value = (strncpy (NULL, "x", 0) == NULL); + ASSERT (value); + + { + char y[1]; + value = (strncpy (y, NULL, 0) == y); + ASSERT (value); + } + + return test_exit_status; +} -- 2.34.1