mkhtemp: generalised string concatenation

scatn in strings.c was buggy, so i replaced it; it
concatenates any number of things.

Signed-off-by: Leah Rowe <leah@libreboot.org>
This commit is contained in:
Leah Rowe
2026-03-29 10:32:12 +01:00
parent 1539aff302
commit cec3de5c9e
2 changed files with 30 additions and 41 deletions
+4 -11
View File
@@ -135,19 +135,12 @@ new_tmp_common(int *fd, char **path, int type,
if (slen(templatestr, maxlen, &templatestr_len) < 0)
goto err;
/* sizeof adds an extra byte, useful
* because we also want '.' or '/'
*/
/* may as well calculate in advance */
destlen = dirlen + 1 + templatestr_len;
if (destlen > maxlen - 1) {
errno = EOVERFLOW;
/* full path: */
if (scatn(3, (const char *[]) { tmpdir, "/", templatestr },
maxlen, &dest) < 0)
goto err;
}
memcpy(smalloc(&dest, destlen + 1), tmpdir, dirlen);
*(dest + dirlen) = '/';
memcpy(dest + dirlen + 1, templatestr, templatestr_len);
*(dest + destlen) = '\0';
fname = dest + dirlen + 1;