• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 // SPDX-License-Identifier: GPL-2.0-or-later
2 /*
3  * Copyright (c) International Business Machines Corp., 2001
4  * Ported to LTP: Wayne Boyer
5  */
6 
7 /*
8  * Testcase to check whether the sticky bit cleared.
9  * Creat a new file, fstat.st_mode should have the 01000 bit off
10  */
11 
12 #include <errno.h>
13 #include <stdio.h>
14 #include <sys/types.h>
15 #include <sys/stat.h>
16 #include <fcntl.h>
17 
18 #include "tst_test.h"
19 
20 static char pfilname[40];
21 static int fd;
22 
verify_creat(void)23 static void verify_creat(void)
24 {
25 	struct stat statbuf;
26 
27 	fd = creat(pfilname, 444);
28 
29 	if (fd == -1) {
30 		tst_res(TFAIL | TERRNO, "creat(%s) failed", pfilname);
31 		return;
32 	}
33 
34 	SAFE_FSTAT(fd, &statbuf);
35 
36 	tst_res(TINFO, "Created file has mode = 0%o", statbuf.st_mode);
37 
38 	if ((statbuf.st_mode & S_ISVTX) != 0)
39 		tst_res(TFAIL, "save text bit not cleared");
40 	else
41 		tst_res(TPASS, "save text bit cleared");
42 
43 	SAFE_CLOSE(fd);
44 }
45 
setup(void)46 static void setup(void)
47 {
48 	sprintf(pfilname, "./creat03.%d", getpid());
49 }
50 
cleanup(void)51 static void cleanup(void)
52 {
53 	if (fd > 0)
54 		SAFE_CLOSE(fd);
55 }
56 
57 static struct tst_test test = {
58 	.test_all = verify_creat,
59 	.needs_tmpdir = 1,
60 	.setup = setup,
61 	.cleanup = cleanup,
62 };
63