1 /*
2 *
3 * Copyright (c) International Business Machines Corp., 2001
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
17 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
18 */
19
20 /*
21 * NAME
22 * umask02.c
23 *
24 * DESCRIPTION
25 * Check that umask changes the mask, and that the previous
26 * value of the mask is returned correctly for each value.
27 *
28 * ALGORITHM
29 * For each mask value (9 bits) set mask, and check that the return
30 * corresponds to the previous value set.
31 *
32 * USAGE: <for command-line>
33 * umask02 [-c n] [-e] [-i n] [-I x] [-P x] [-t]
34 * where, -c n : Run n copies concurrently.
35 * -e : Turn on errno logging.
36 * -i n : Execute test n times.
37 * -I x : Execute test for x seconds.
38 * -P x : Pause for x seconds between iterations.
39 * -t : Turn on syscall timing.
40 *
41 * History
42 * 07/2001 John George
43 * -Ported
44 *
45 * Restrictions
46 * None
47 */
48
49 #include <sys/types.h>
50 #include <sys/stat.h>
51 #include <fcntl.h>
52 #include <stdio.h>
53 #include "test.h"
54
55 char *TCID = "umask02";
56 int TST_TOTAL = 1;
57
58 void setup(void);
59 void cleanup(void);
60
main(int argc,char ** argv)61 int main(int argc, char **argv)
62 {
63 int lc;
64
65 int uret = 0, i, mskval = 0000;
66 int failcnt = 0;
67
68 tst_parse_opts(argc, argv, NULL, NULL);
69
70 setup();
71
72 /* Check for looping state if -i option is given */
73 for (lc = 0; TEST_LOOPING(lc); lc++) {
74
75 /* reset tst_count in case we are looping */
76 tst_count = 0;
77
78 for (umask(++mskval), i = 1; mskval < 01000;
79 uret = umask(++mskval), i++) {
80 if ((uret != mskval - 1) && (mskval != 0000)) {
81 failcnt = 1;
82 tst_resm(TFAIL, "umask(%d) returned bad mask "
83 "value %d.", mskval, uret);
84 }
85 }
86 if (!failcnt)
87 tst_resm(TPASS, "All umask values return correct "
88 "values");
89 }
90 cleanup();
91 tst_exit();
92
93 }
94
95 /*
96 * setup()
97 * performs all ONE TIME setup for this test
98 */
setup(void)99 void setup(void)
100 {
101
102 tst_sig(FORK, DEF_HANDLER, cleanup);
103
104 /* Pause if that option was specified
105 * TEST_PAUSE contains the code to fork the test with the -c option.
106 */
107 TEST_PAUSE;
108 }
109
110 /*
111 * cleanup()
112 * performs all ONE TIME cleanup for this test at
113 * completion or premature exit
114 */
cleanup(void)115 void cleanup(void)
116 {
117
118 }
119