summaryrefslogtreecommitdiff
path: root/listing.c
diff options
context:
space:
mode:
authorAlan Coopersmith <alan.coopersmith@oracle.com>2022-12-10 16:10:01 -0800
committerAlan Coopersmith <alan.coopersmith@oracle.com>2023-01-03 11:02:06 -0800
commit81e46cab5f4bdd69fa0a644dba86f6902cece175 (patch)
tree3f664cb6d78c4a2cccbe9ef2be153e3df9633fc9 /listing.c
parenta1551b78e9ac0e2075ca241c0e8ae361758f26b4 (diff)
downloadxorg-app-xkbcomp-81e46cab5f4bdd69fa0a644dba86f6902cece175.tar.gz
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.c10
1 files changed, 8 insertions, 2 deletions
diff --git a/listing.c b/listing.c
index f8b1186..d367e3f 100644
--- a/listing.c
+++ b/listing.c
@@ -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);