]> Savannah Git Hosting - gnulib.git/commitdiff
filenamecat-lgpl: Set errno upon failure.
authorBruno Haible <bruno@clisp.org>
Sat, 27 Jun 2020 00:39:08 +0000 (02:39 +0200)
committerBruno Haible <bruno@clisp.org>
Sat, 27 Jun 2020 00:39:54 +0000 (02:39 +0200)
* lib/filenamecat-lgpl.c (mfile_name_concat): Document the failure
return convention.
* modules/filenamecat-lgpl (Depends-on): Add malloc-posix.

ChangeLog
lib/filenamecat-lgpl.c
modules/filenamecat-lgpl

index 7372a6b37d76a96103cc05eb900ef78c05a113b8..932993a7fcce4adff73d230eafc1ac627fd2aa08 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,10 @@
+2020-06-26  Bruno Haible  <bruno@clisp.org>
+
+       filenamecat-lgpl: Set errno upon failure.
+       * lib/filenamecat-lgpl.c (mfile_name_concat): Document the failure
+       return convention.
+       * modules/filenamecat-lgpl (Depends-on): Add malloc-posix.
+
 2020-06-26  Bruno Haible  <bruno@clisp.org>
 
        areadlink-with-size: Set errno upon failure.
index 6f666f2abb00ac001528756d6ad1f75005b354aa..d97abfa373f27b0b61b17881e8acdbd84b2c8479 100644 (file)
@@ -41,7 +41,7 @@
    *BASE_IN_RESULT to point to the copy of BASE at the end of the
    returned concatenation.
 
-   Return NULL if malloc fails.  */
+   If malloc fails, return NULL with errno set.  */
 
 char *
 mfile_name_concat (char const *dir, char const *base, char **base_in_result)
@@ -68,20 +68,22 @@ mfile_name_concat (char const *dir, char const *base, char **base_in_result)
     }
 
   char *p_concat = malloc (dirlen + (sep != '\0')  + baselen + 1);
-  char *p;
-
   if (p_concat == NULL)
     return NULL;
 
-  p = mempcpy (p_concat, dir, dirlen);
-  *p = sep;
-  p += sep != '\0';
+  {
+    char *p;
+
+    p = mempcpy (p_concat, dir, dirlen);
+    *p = sep;
+    p += sep != '\0';
 
-  if (base_in_result)
-    *base_in_result = p;
+    if (base_in_result)
+      *base_in_result = p;
 
-  p = mempcpy (p, base, baselen);
-  *p = '\0';
+    p = mempcpy (p, base, baselen);
+    *p = '\0';
+  }
 
   return p_concat;
 }
index 09965a1c6b78b453951c564e8f9a91aa1905468c..a6bf60bf2b15bd2ebbacbbb8f660d68992c3d8ba 100644 (file)
@@ -9,6 +9,7 @@ m4/filenamecat.m4
 Depends-on:
 c99
 dirname-lgpl
+malloc-posix
 
 configure.ac:
 gl_FILE_NAME_CONCAT_LGPL