#include <unistd.h>
#include <sys/mman.h>
#include <stdlib.h>
+#include <linux/limits.h>
#include <wayland-client.h>
static const char template[] =
"/shooter-XXXXXX";
const char *path;
- char *name = NULL;
+ char name[PATH_MAX] = "";
int fd = -1;
int ret = -1;
return -1;
}
- name = malloc(strlen(path) + sizeof(template));
- GOTO_IF_FAIL(name != NULL, fail);
-
- strcpy(name, path);
- strcat(name, template);
+ strncpy(name, path, PATH_MAX);
+ strncat(name, template, PATH_MAX);
fd = mkstemp(name);
if (fd >= 0)
unlink(name);
ret = ftruncate(fd, size);
- GOTO_IF_FAIL(ret >= 0, fail);
-
- free(name);
-
- return fd;
-fail:
- if (fd >= 0)
+ if (ret < 0) {
close(fd);
+ return -1;
+ }
- if (name)
- free(name);
-
- return -1;
+ return fd;
}
static void