]> Savannah Git Hosting - gnulib.git/commitdiff
getcwd-lgpl: Tweaks.
authorBruno Haible <bruno@clisp.org>
Sat, 30 Sep 2023 14:15:44 +0000 (16:15 +0200)
committerBruno Haible <bruno@clisp.org>
Sat, 30 Sep 2023 17:31:24 +0000 (19:31 +0200)
* 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
lib/getcwd-lgpl.c
lib/unistd.in.h
tests/test-getcwd-lgpl.c

index 3cb1e2864091a56929a97aae6ccbeb1901ca6bae..f8082c30a9f99460d166f145ea5687916c64909c 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,10 @@
+2023-09-30  Bruno Haible  <bruno@clisp.org>
+
+       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  <bruno@clisp.org>
 
        Allow different --libtool options from multiple gnulib-tool invocations.
index 8a5bde9947f5e26ab4d2c44ec6c8e351cc436087..da478e42e44c0a34236425a5198ce334d3afb7e1 100644 (file)
@@ -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);
index ac9f50eb3e5ad800e4fb0fc34d12c88626dd0a62..96453c90fd133db1c8aade8b6ba2b670bc4c4ce3 100644 (file)
@@ -1118,10 +1118,10 @@ _GL_WARN_ON_USE (ftruncate, "ftruncate is unportable - "
    or SIZE was too small.
    See the POSIX:2008 specification
    <https://pubs.opengroup.org/onlinepubs/9699919799/functions/getcwd.html>.
-   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
index 821244f3de516d35580046dbdcb686a803c184a0..26b249c767d9810345a9a936259cab16ff5e8eef 100644 (file)
@@ -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);