1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-07-26 07:37:35 +00:00

Userland: Tests: Use mkstemp temporary files in tests

This commit is contained in:
Brendan Coles 2020-11-14 23:18:39 +00:00 committed by Andreas Kling
parent 12d923bb7e
commit d739483ee8
3 changed files with 24 additions and 15 deletions

View file

@ -28,8 +28,10 @@
#include <fcntl.h>
#include <pthread.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <sys/mman.h>
#include <sys/stat.h>
#include <sys/wait.h>
#include <unistd.h>
@ -95,9 +97,15 @@ int main()
header.e_entry = 0;
int fd = open("/tmp/x", O_RDWR | O_CREAT, 0777);
char path[] = "/tmp/x.XXXXXX";
auto fd = mkstemp(path);
if (fd < 0) {
perror("open");
perror("mkstemp");
return 1;
}
if (fchmod(fd, 0777) < 0) {
perror("chmod");
return 1;
}
@ -143,7 +151,7 @@ int main()
if (!fork()) {
try_again:
printf("exec\n");
if (execl("/tmp/x", "x", nullptr) < 0) {
if (execl(path, "x", nullptr) < 0) {
}
goto try_again;
}