>From c3dda22534b5d575f167d601ed1d446744008506 Mon Sep 17 00:00:00 2001 From: Bruno Haible Date: Sat, 30 Sep 2023 16:15:44 +0200 Subject: [PATCH 1/3] getcwd-lgpl: Tweaks. * lib/unistd.in.h (getcwd): Mention the module 'getcwd-lgpl'. * lib/getcwd-lgpl.c (rpl_getcwd): Minimize scope of local variables. * tests/test-getcwd-lgpl.c (main): Use GNU coding style. --- ChangeLog | 7 +++++++ lib/getcwd-lgpl.c | 6 +++--- lib/unistd.in.h | 8 ++++---- tests/test-getcwd-lgpl.c | 2 +- 4 files changed, 15 insertions(+), 8 deletions(-) diff --git a/ChangeLog b/ChangeLog index 3cb1e28640..f8082c30a9 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,10 @@ +2023-09-30 Bruno Haible + + getcwd-lgpl: Tweaks. + * lib/unistd.in.h (getcwd): Mention the module 'getcwd-lgpl'. + * lib/getcwd-lgpl.c (rpl_getcwd): Minimize scope of local variables. + * tests/test-getcwd-lgpl.c (main): Use GNU coding style. + 2023-09-29 Bruno Haible Allow different --libtool options from multiple gnulib-tool invocations. diff --git a/lib/getcwd-lgpl.c b/lib/getcwd-lgpl.c index 8a5bde9947..da478e42e4 100644 --- a/lib/getcwd-lgpl.c +++ b/lib/getcwd-lgpl.c @@ -45,12 +45,12 @@ typedef int dummy; char * rpl_getcwd (char *buf, size_t size) { - char *ptr; char *result; /* Handle single size operations. */ if (buf) { + /* Check SIZE argument. */ if (!size) { errno = EINVAL; @@ -79,7 +79,7 @@ rpl_getcwd (char *buf, size_t size) { char tmp[4032]; size = sizeof tmp; - ptr = getcwd (tmp, size); + char *ptr = getcwd (tmp, size); if (ptr) { result = strdup (ptr); @@ -95,7 +95,7 @@ rpl_getcwd (char *buf, size_t size) do { size <<= 1; - ptr = realloc (buf, size); + char *ptr = realloc (buf, size); if (ptr == NULL) { free (buf); diff --git a/lib/unistd.in.h b/lib/unistd.in.h index ac9f50eb3e..96453c90fd 100644 --- a/lib/unistd.in.h +++ b/lib/unistd.in.h @@ -1118,10 +1118,10 @@ _GL_WARN_ON_USE (ftruncate, "ftruncate is unportable - " or SIZE was too small. See the POSIX:2008 specification . - Additionally, the gnulib module 'getcwd' guarantees the following GNU - extension: If BUF is NULL, an array is allocated with 'malloc'; the array - is SIZE bytes long, unless SIZE == 0, in which case it is as big as - necessary. */ + Additionally, the gnulib module 'getcwd' or 'getcwd-lgpl' guarantees the + following GNU extension: If BUF is NULL, an array is allocated with + 'malloc'; the array is SIZE bytes long, unless SIZE == 0, in which case + it is as big as necessary. */ # if @REPLACE_GETCWD@ # if !(defined __cplusplus && defined GNULIB_NAMESPACE) # define getcwd rpl_getcwd diff --git a/tests/test-getcwd-lgpl.c b/tests/test-getcwd-lgpl.c index 821244f3de..26b249c767 100644 --- a/tests/test-getcwd-lgpl.c +++ b/tests/test-getcwd-lgpl.c @@ -92,7 +92,7 @@ main (int argc, char **argv) /* Validate a POSIX requirement on size. */ errno = 0; - ASSERT (getcwd(pwd2, 0) == NULL); + ASSERT (getcwd (pwd2, 0) == NULL); ASSERT (errno == EINVAL); free (pwd1); -- 2.34.1