From: Bruno Haible Date: Sat, 27 Jun 2020 00:39:08 +0000 (+0200) Subject: filenamecat-lgpl: Set errno upon failure. X-Git-Tag: v1.0~3966 X-Git-Url: https://gitweb.git.savannah.gnu.org/gitweb/?a=commitdiff_plain;h=c7f8c44d9cd5fda98c41a85dc248a4e3d66ea593;p=gnulib.git 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. --- diff --git a/ChangeLog b/ChangeLog index 7372a6b37d..932993a7fc 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,10 @@ +2020-06-26 Bruno Haible + + 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 areadlink-with-size: Set errno upon failure. diff --git a/lib/filenamecat-lgpl.c b/lib/filenamecat-lgpl.c index 6f666f2abb..d97abfa373 100644 --- a/lib/filenamecat-lgpl.c +++ b/lib/filenamecat-lgpl.c @@ -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; } diff --git a/modules/filenamecat-lgpl b/modules/filenamecat-lgpl index 09965a1c6b..a6bf60bf2b 100644 --- a/modules/filenamecat-lgpl +++ b/modules/filenamecat-lgpl @@ -9,6 +9,7 @@ m4/filenamecat.m4 Depends-on: c99 dirname-lgpl +malloc-posix configure.ac: gl_FILE_NAME_CONCAT_LGPL