diff options
author | Alan Coopersmith <alan.coopersmith@oracle.com> | 2022-12-10 16:10:01 -0800 |
---|---|---|
committer | Alan Coopersmith <alan.coopersmith@oracle.com> | 2023-01-03 11:02:06 -0800 |
commit | 81e46cab5f4bdd69fa0a644dba86f6902cece175 (patch) | |
tree | 3f664cb6d78c4a2cccbe9ef2be153e3df9633fc9 /listing.c | |
parent | a1551b78e9ac0e2075ca241c0e8ae361758f26b4 (diff) |
Use asprintf() if the platform supports it
Signed-off-by: Alan Coopersmith <alan.coopersmith@oracle.com>
Diffstat (limited to 'listing.c')
-rw-r--r-- | listing.c | 10 |
1 files changed, 8 insertions, 2 deletions
@@ -70,6 +70,7 @@ SOFTWARE. ******************************************************************/ +#include "utils.h" #include <stdio.h> #include <ctype.h> #include <sys/types.h> @@ -303,19 +304,24 @@ AddDirectory(char *head, char *ptrn, char *rest, char *map) { char *tmp, *filename; struct stat sbuf; - size_t tmpsize; filename = FileName(file); if (!filename || filename[0] == '.') continue; if (ptrn && (!XkbNameMatchesPattern(filename, ptrn))) continue; - tmpsize = (head ? strlen(head) : 0) + strlen(filename) + 2; +#ifdef HAVE_ASPRINTF + if (asprintf(&tmp, "%s%s%s", + (head ? head : ""), (head ? "/" : ""), filename) < 0) + continue; +#else + size_t tmpsize = (head ? strlen(head) : 0) + strlen(filename) + 2; tmp = malloc(tmpsize); if (!tmp) continue; snprintf(tmp, tmpsize, "%s%s%s", (head ? head : ""), (head ? "/" : ""), filename); +#endif if (stat(tmp, &sbuf) < 0) { free(tmp); |