aboutsummaryrefslogtreecommitdiffstats
path: root/test/test-fstat.c
blob: 78f7013ef47fd73c4cd5a867c5b5fb9f6310c3ac (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
/*
 * Test that stat'ing a file descriptor of a symlink does not dereference the symlink
 * SPDX-License-Identifier: LGPL-2.1-only
 *
 */
#define _GNU_SOURCE

#include <sys/stat.h>
#include <sys/types.h>
#include <fcntl.h>
#include <stdio.h>

int main(void) {
    struct stat buf;
    int fd = open("symlink", O_NOFOLLOW | O_PATH);
    if (fd == -1) {
        perror("open symlink");
        return 1;
    }
    if (fstatat(fd, "", &buf, AT_EMPTY_PATH) == -1) {
        perror("stat symlink");
        return 1;
    }
    if (S_ISLNK(buf.st_mode) != 1) {
        fprintf(stderr, "path is not a symlink\n");
        return 1;
    }
    return 0;
}