|
| 1 | +/* |
| 2 | + * Copyright 2024 The Emscripten Authors. All rights reserved. |
| 3 | + * Emscripten is available under two separate licenses, the MIT license and the |
| 4 | + * University of Illinois/NCSA Open Source License. Both these licenses can be |
| 5 | + * found in the LICENSE file. |
| 6 | + */ |
| 7 | + |
| 8 | +#define _GNU_SOURCE |
| 9 | + |
| 10 | +#include <assert.h> |
| 11 | +#include <fcntl.h> |
| 12 | +#include <stdio.h> |
| 13 | +#include <string.h> |
| 14 | +#include <sys/stat.h> |
| 15 | +#include <unistd.h> |
| 16 | + |
| 17 | +void create_file(const char *path, const char *buffer, int mode) { |
| 18 | + int fd = open(path, O_WRONLY | O_CREAT | O_EXCL, mode); |
| 19 | + assert(fd >= 0); |
| 20 | + |
| 21 | + int err = write(fd, buffer, sizeof(char) * strlen(buffer)); |
| 22 | + assert(err == (sizeof(char) * strlen(buffer))); |
| 23 | + |
| 24 | + close(fd); |
| 25 | +} |
| 26 | + |
| 27 | +void setup() { |
| 28 | + mkdir("folder", 0777); |
| 29 | + create_file("folder/file", "abcdef", 0777); |
| 30 | + symlink("file", "folder/file-link"); |
| 31 | +} |
| 32 | + |
| 33 | +int main() { |
| 34 | + setup(); |
| 35 | + |
| 36 | + int rc; |
| 37 | + struct statx buf; |
| 38 | + |
| 39 | + rc = statx(AT_FDCWD, "folder", 0, STATX_ALL, &buf); |
| 40 | + assert(rc == 0); |
| 41 | + assert(S_ISDIR(buf.stx_mode)); |
| 42 | + |
| 43 | + rc = statx(AT_FDCWD, "folder/file", 0, STATX_ALL, &buf); |
| 44 | + assert(rc == 0); |
| 45 | + assert(S_ISREG(buf.stx_mode)); |
| 46 | + |
| 47 | + rc = statx(AT_FDCWD, "folder/file-link", 0, STATX_ALL, &buf); |
| 48 | + assert(rc == 0); |
| 49 | + assert(S_ISREG(buf.stx_mode)); |
| 50 | + |
| 51 | + rc = statx(AT_FDCWD, "folder/file-link", AT_SYMLINK_NOFOLLOW, STATX_ALL, &buf); |
| 52 | + assert(rc == 0); |
| 53 | + assert(S_ISLNK(buf.stx_mode)); |
| 54 | + |
| 55 | + printf("success\n"); |
| 56 | + return 0; |
| 57 | +} |
0 commit comments