summaryrefslogtreecommitdiff
path: root/xkbcomp.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 /xkbcomp.c
parenta1551b78e9ac0e2075ca241c0e8ae361758f26b4 (diff)
Use asprintf() if the platform supports it
Signed-off-by: Alan Coopersmith <alan.coopersmith@oracle.com>
Diffstat (limited to 'xkbcomp.c')
-rw-r--r--xkbcomp.c12
1 files changed, 9 insertions, 3 deletions
diff --git a/xkbcomp.c b/xkbcomp.c
index d97220f..c5775fa 100644
--- a/xkbcomp.c
+++ b/xkbcomp.c
@@ -24,6 +24,7 @@
********************************************************/
+#include "utils.h"
#include <stdio.h>
#include <ctype.h>
#include <X11/keysym.h>
@@ -759,15 +760,20 @@ parseArgs(int argc, char *argv[])
}
else if ((!outputFile) && (inputFile) && (strcmp(inputFile, "-") == 0))
{
- int len = strlen("stdin") + strlen(fileTypeExt[outputFormat]) + 2;
+#ifdef HAVE_ASPRINTF
+ if (asprintf(&outputFile, "stdin.%s", fileTypeExt[outputFormat]) < 0)
+#else
+ size_t len = strlen("stdin") + strlen(fileTypeExt[outputFormat]) + 2;
outputFile = calloc(len, sizeof(char));
- if (outputFile == NULL)
+ if (outputFile != NULL)
+ snprintf(outputFile, len, "stdin.%s", fileTypeExt[outputFormat]);
+ else
+#endif
{
WSGO("Cannot allocate space for output file name\n");
ACTION("Exiting\n");
exit(1);
}
- snprintf(outputFile, len, "stdin.%s", fileTypeExt[outputFormat]);
}
else if ((outputFile == NULL) && (inputFile != NULL))
{