From: Dmitry V. Levin Date: Sat, 10 Sep 2016 22:58:40 +0000 (+0000) Subject: tests: use sprintrc in tests/chmod.c X-Git-Tag: v4.14~86 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=961a541ab4352652951fff1bdd177b5b7c61d743;p=strace tests: use sprintrc in tests/chmod.c * tests/chmod.c (main): Use sprintrc. Add more chmod decoding tests. --- diff --git a/tests/chmod.c b/tests/chmod.c index 936acc95..f6f98ece 100644 --- a/tests/chmod.c +++ b/tests/chmod.c @@ -1,5 +1,6 @@ /* * Copyright (c) 2016 Anchit Jain + * Copyright (c) 2016 Dmitry V. Levin * All rights reserved. * * Redistribution and use in source and binary forms, with or without @@ -40,30 +41,20 @@ main(void) { static const char fname[] = "chmod_test_file"; - if (open(fname, O_CREAT|O_RDONLY, 0400) == -1) + if (open(fname, O_CREAT|O_RDONLY, 0400) < 0) perror_msg_and_fail("open"); - int chmod_res = syscall(__NR_chmod, fname, 0600); + long rc = syscall(__NR_chmod, fname, 0600); + printf("chmod(\"%s\", 0600) = %s\n", fname, sprintrc(rc)); - if (chmod_res == 0) { - printf("chmod(\"%s\", 0600) = 0\n", fname); - } else { - if (errno == ENOSYS) { - printf("chmod(\"%s\", 0600) = -1 ENOSYS (%m)\n", fname); - } else { - perror_msg_and_fail("chmod"); - } - } - - if (unlink(fname) == -1) + if (unlink(fname)) perror_msg_and_fail("unlink"); - if (chmod_res == 0) { - if (syscall(__NR_chmod, fname, 0600) != -1) - perror_msg_and_fail("chmod"); + rc = syscall(__NR_chmod, fname, 051); + printf("chmod(\"%s\", 051) = %s\n", fname, sprintrc(rc)); - printf("chmod(\"%s\", 0600) = -1 ENOENT (%m)\n", fname); - } + rc = syscall(__NR_chmod, fname, 004); + printf("chmod(\"%s\", 004) = %s\n", fname, sprintrc(rc)); puts("+++ exited with 0 +++"); return 0;