1
// test using absolute paths, so cde-exec should redirect all of these
2
// calls within the package
9
#define PWD "/home/pgbovine/CDE/tests/at_syscalls_test/"
12
// extracted from fcntl.h
14
# define AT_FDCWD -100 /* Special value used to indicate
15
the *at functions should use the
16
current working directory. */
17
# define AT_SYMLINK_NOFOLLOW 0x100 /* Do not follow symbolic links. */
18
# define AT_REMOVEDIR 0x200 /* Remove directory instead of
20
# define AT_SYMLINK_FOLLOW 0x400 /* Follow symbolic links. */
21
# define AT_EACCESS 0x200 /* Test access permitted for
22
effective IDs, not real IDs. */
28
// - use absolute paths to make *at syscalls
29
// - use relative paths to do assertion checks
32
// then flip it around and use relative paths to make syscalls and
33
// absolute paths to do assertion checks (TODO: implement this!)
39
openat(AT_FDCWD, PWD "openat.txt", O_CREAT | O_WRONLY, 0644);
40
assert(stat("openat.txt", &st) == 0); // relative path
42
assert(faccessat(AT_FDCWD, PWD "openat.txt", F_OK, 0) == 0);
43
assert(fstatat(AT_FDCWD, PWD "openat.txt", &st2, 0) == 0);
44
assert(fchmodat(AT_FDCWD, PWD "openat.txt", 0777, 0) == 0);
46
struct timeval my_times[2];
47
my_times[0].tv_sec = 0;
48
my_times[0].tv_usec = 0;
49
my_times[1].tv_sec = 0;
50
my_times[1].tv_usec = 0;
51
assert(futimesat(AT_FDCWD, PWD "openat.txt", my_times, 0) == 0);
53
// see /etc/passwd, user 'pgbovine' is 508:100
54
assert(fchownat(AT_FDCWD, PWD "openat.txt", 508, 100, 0) == 0);
56
assert(linkat(AT_FDCWD, PWD "openat.txt", AT_FDCWD, PWD "openat_hardlink.txt", 0) == 0);
57
assert(stat("openat_hardlink.txt", &st) == 0); // relative path
59
assert(symlinkat(PWD "openat.txt", AT_FDCWD, PWD "openat_symlink.txt") == 0);
60
assert(lstat("openat_symlink.txt", &st) == 0); // relative path
63
assert(readlinkat(AT_FDCWD, PWD "openat_symlink.txt", res, sizeof(res)) > 0);
65
assert(renameat(AT_FDCWD, PWD "openat.txt", AT_FDCWD, PWD "openat_newname.txt", 0) == 0);
66
assert(stat("openat.txt", &st) != 0); // should not exist anymore
67
assert(stat("openat_newname.txt", &st) == 0); // relative path
69
unlinkat(AT_FDCWD, PWD "openat_newname.txt", 0);
70
unlinkat(AT_FDCWD, PWD "openat_hardlink.txt", 0);
71
unlinkat(AT_FDCWD, PWD "openat_symlink.txt", 0);
74
mknodat(AT_FDCWD, PWD "mknodat.fifo", S_IFIFO);
75
assert(stat("mknodat.fifo", &st) == 0); // relative path
76
unlinkat(AT_FDCWD, PWD "mknodat.fifo", 0);
78
mkdirat(AT_FDCWD, PWD "mkdirat_dir", 0);
79
assert(stat("mkdirat_dir", &st) == 0); // relative path
80
unlinkat(AT_FDCWD, PWD "mkdirat_dir", AT_REMOVEDIR); // like 'rmdir'