1 /*
2 * Copyright (c) International Business Machines Corp., 2001
3 * 07/2001 Ported by Wayne Boyer
4 *
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation; either version 2 of the License, or
8 * (at your option) any later version.
9 *
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See
13 * the GNU General Public License for more details.
14 *
15 * You should have received a copy of the GNU General Public License
16 * along with this program; if not, write to the Free Software Foundation,
17 * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
18 */
19
20 /*
21 * Testcase to check whether the sticky bit cleared.
22 * Creat a new file, fstat.st_mode should have the 01000 bit off
23 */
24
25 #include <errno.h>
26 #include <stdio.h>
27 #include <sys/types.h>
28 #include <sys/stat.h>
29 #include <fcntl.h>
30
31 #include "tst_test.h"
32
33 static char pfilname[40];
34 static int fd;
35
verify_creat(void)36 static void verify_creat(void)
37 {
38 struct stat statbuf;
39
40 fd = creat(pfilname, 444);
41
42 if (fd == -1) {
43 tst_res(TFAIL | TERRNO, "creat(%s) failed", pfilname);
44 return;
45 }
46
47 SAFE_FSTAT(fd, &statbuf);
48
49 tst_res(TINFO, "Created file has mode = 0%o", statbuf.st_mode);
50
51 if ((statbuf.st_mode & S_ISVTX) != 0)
52 tst_res(TFAIL, "save text bit not cleared");
53 else
54 tst_res(TPASS, "save text bit cleared");
55
56 SAFE_CLOSE(fd);
57 }
58
setup(void)59 static void setup(void)
60 {
61 sprintf(pfilname, "./creat03.%d", getpid());
62 }
63
cleanup(void)64 static void cleanup(void)
65 {
66 if (fd > 0)
67 SAFE_CLOSE(fd);
68 }
69
70 static struct tst_test test = {
71 .test_all = verify_creat,
72 .needs_tmpdir = 1,
73 .setup = setup,
74 .cleanup = cleanup,
75 };
76