[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
filenamecat-lgpl: set errno upon failure
From: |
Bruno Haible |
Subject: |
filenamecat-lgpl: set errno upon failure |
Date: |
Sat, 27 Jun 2020 02:41:25 +0200 |
User-agent: |
KMail/5.1.3 (Linux/4.4.0-179-generic; KDE/5.18.0; x86_64; ; ) |
POSIX <https://pubs.opengroup.org/onlinepubs/9699919799/functions/opendir.html>
says that when opendir() fails, it return NULL with errno set.
To implement this in gnulib for native Windows,
- the function _gl_register_fd must set errno upon failure,
- therefore get_name must set errno upon failure,
- therefore mfile_name_concat must set errno upon failure.
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.
diff --git a/lib/filenamecat-lgpl.c b/lib/filenamecat-lgpl.c
index 6f666f2..d97abfa 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 09965a1..a6bf60b 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
- filenamecat-lgpl: set errno upon failure,
Bruno Haible <=