summaryrefslogtreecommitdiff
path: root/Tests/LibC/exec-should-not-search-current-directory.cpp
blob: 57a023a6df45bd18c33e771e4c6861cfbee50a8c (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
#include <stdio.h>
#include <unistd.h>
#include <fcntl.h>

int main()
{
    int fd = open("hax", O_CREAT | O_RDWR, 0755);
    ftruncate(fd, 0);
    close(fd);

    int rc = execlp("hax", "hax", nullptr);
    int saved_errno = errno;
    unlink("hax");
    if (rc == -1 && saved_errno == ENOEXEC) {
        printf("FAIL\n");
        return 1;
    }
    printf("PASS\n");
    return 0;
}