]> git.saurik.com Git - apple/hfs.git/blob - tests/cases/test-renamex.c
hfs-407.1.3.tar.gz
[apple/hfs.git] / tests / cases / test-renamex.c
1 #include <TargetConditionals.h>
2
3 #include <fcntl.h>
4 #include <unistd.h>
5 #include <stdio.h>
6 #include <sys/stat.h>
7
8 #include "hfs-tests.h"
9 #include "test-utils.h"
10 #include "disk-image.h"
11
12 TEST(renamex_test)
13
14 static disk_image_t *di;
15 extern int errno;
16
17 int run_renamex_test (__unused test_ctx_t *ctx) {
18
19 di = disk_image_get();
20 char* dst_file;
21 int dst_file_fd;
22 char* src_file;
23 int src_file_fd;
24 asprintf (&dst_file, "%s/renamex_dst", di->mount_point);
25 asprintf (&src_file, "%s/renamex_src", di->mount_point);
26
27 /* create the files */
28
29 src_file_fd = open (src_file, O_RDWR | O_CREAT | O_TRUNC, 0666);
30 assert (src_file_fd >= 0);
31
32 dst_file_fd = open (dst_file, O_RDWR | O_CREAT | O_TRUNC, 0666);
33 assert (src_file_fd >= 0);
34
35 /* attempt the renamex calls...*/
36
37 //first verify non-supported flags error out
38 int error = renamex_np (src_file, dst_file, (RENAME_SWAP));
39 assert (error != 0);
40
41 //now try both flags
42 error = renamex_np (src_file, dst_file, (RENAME_SWAP | RENAME_EXCL));
43 assert (error != 0);
44
45 //now verify it errors out because destination exists.
46 error = renamex_np (src_file, dst_file, (RENAME_EXCL));
47 assert ((error != 0) && (errno == EEXIST));
48
49 /* now delete dst and try again */
50 error = unlink (dst_file);
51 assert (error == 0);
52
53 error = renamex_np (src_file, dst_file, (RENAME_EXCL));
54 assert (error == 0);
55
56 error = unlink(dst_file);
57 assert (error == 0);
58
59 assert_no_err(close(src_file_fd));
60 assert_no_err(close(dst_file_fd));
61
62 return 0;
63 }
64
65