diff options
author | Bruno Haible <bruno@clisp.org> | 2020-06-27 02:39:08 +0200 |
---|---|---|
committer | Bruno Haible <bruno@clisp.org> | 2020-06-27 02:39:54 +0200 |
commit | c7f8c44d9cd5fda98c41a85dc248a4e3d66ea593 (patch) | |
tree | 057d92db63f184cb1fc69fa03e8924f25b560c00 | |
parent | 4ee6e48dc61d5788199b7581ec9004488ba0c208 (diff) | |
download | gnulib-c7f8c44d9cd5fda98c41a85dc248a4e3d66ea593.tar.gz |
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.
-rw-r--r-- | ChangeLog | 7 | ||||
-rw-r--r-- | lib/filenamecat-lgpl.c | 22 | ||||
-rw-r--r-- | modules/filenamecat-lgpl | 1 |
3 files changed, 20 insertions, 10 deletions
@@ -1,5 +1,12 @@ 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. * lib/areadlink-with-size.c (areadlink_with_size): Set errno when malloc fails. 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 |