strace/tests/chmod.c
Dmitry V. Levin c6782f144a tests: change the license to GPL-2.0-or-later
strace test suite is now provided under the terms of the GNU General
Public License version 2 or later, see tests/COPYING for more details.
2018-12-10 00:00:00 +00:00

48 lines
941 B
C

/*
* Copyright (c) 2016 Anchit Jain <anchitjain1234@gmail.com>
* Copyright (c) 2016 Dmitry V. Levin <ldv@altlinux.org>
* All rights reserved.
*
* SPDX-License-Identifier: GPL-2.0-or-later
*/
#include "tests.h"
#include <asm/unistd.h>
#if defined __NR_chmod
#include <fcntl.h>
#include <stdio.h>
#include <unistd.h>
#include <errno.h>
int
main(void)
{
static const char fname[] = "chmod_test_file";
if (open(fname, O_CREAT|O_RDONLY, 0400) < 0)
perror_msg_and_fail("open");
long rc = syscall(__NR_chmod, fname, 0600);
printf("chmod(\"%s\", 0600) = %s\n", fname, sprintrc(rc));
if (unlink(fname))
perror_msg_and_fail("unlink");
rc = syscall(__NR_chmod, fname, 051);
printf("chmod(\"%s\", 051) = %s\n", fname, sprintrc(rc));
rc = syscall(__NR_chmod, fname, 004);
printf("chmod(\"%s\", 004) = %s\n", fname, sprintrc(rc));
puts("+++ exited with 0 +++");
return 0;
}
#else
SKIP_MAIN_UNDEFINED("__NR_chmod")
#endif