]> git.saurik.com Git - apple/hfs.git/blob - tests/cases/test-symlinks.c
hfs-556.100.11.tar.gz
[apple/hfs.git] / tests / cases / test-symlinks.c
1 /*
2 * Copyright (c) 2020 Apple Inc. All rights reserved.
3 *
4 * <rdar://problem/65693863> UNIX Conformance | hfs_vnop_symlink should not validate empty path.
5 */
6 #include <unistd.h>
7 #include <sys/stat.h>
8
9
10 #include "hfs-tests.h"
11 #include "test-utils.h"
12 #include "disk-image.h"
13
14 #define SYMPLINK_TEST_DIR "symlink.testdir"
15 #define SYMLINK_EMPTYSTR "symlink.emptystr"
16 TEST(symlinks)
17
18 int run_symlinks(__unused test_ctx_t *ctx)
19 {
20 disk_image_t *di;
21 struct stat statb;
22 char *parent_dir, *slink;
23 char buf;
24
25 di = disk_image_get();
26
27 //
28 // Create a parent directory to host our test.
29 //
30 asprintf(&parent_dir, "%s/"SYMPLINK_TEST_DIR, di->mount_point);
31 assert(!mkdir(parent_dir, 0777) || errno == EEXIST);
32
33 //
34 // Now check to make sure we support creating a symlink with an empty
35 // target required for UNIX Conformance.
36 //
37 asprintf(&slink, "%s/"SYMLINK_EMPTYSTR, parent_dir);
38 assert_no_err(symlink("", slink));
39
40 //
41 // Test that symlink has "l" as the S_ISLNK flag using lstat
42 //
43 memset(&statb, 0, sizeof(statb));
44 assert(!(lstat(slink, &statb) < 0 ));
45 assert(S_ISLNK(statb.st_mode));
46
47 //
48 // Test that readlink returns zero.
49 //
50 assert(!readlink(slink, &buf, 1));
51
52 //
53 // Delete test symlink, test directory and release all resources.
54 //
55 unlink(slink);
56 unlink(parent_dir);
57 free(slink);
58 free(parent_dir);
59 return 0;
60 }