1/*
2 * Copyright (c) 2000 Silicon Graphics, Inc.  All Rights Reserved.
3 * Author: William Roske
4 * Co-pilot: Dave Fenner
5 *
6 * This program is free software; you can redistribute it and/or modify it
7 * under the terms of version 2 of the GNU General Public License as
8 * published by the Free Software Foundation.
9 *
10 * This program is distributed in the hope that it would be useful, but
11 * WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
13 *
14 * Further, this software is distributed without any warranty that it is
15 * free of the rightful claim of any third person regarding infringement
16 * or the like.  Any license provided herein, whether implied or
17 * otherwise, applies only to this software file.  Patent licenses, if
18 * any, provided herein do not apply to combinations of this program with
19 * other software, or any other product whatsoever.
20 *
21 * You should have received a copy of the GNU General Public License along
22 * with this program; if not, write the Free Software Foundation, Inc.,
23 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
24 *
25 * Contact information: Silicon Graphics, Inc., 1600 Amphitheatre Pkwy,
26 * Mountain View, CA  94043, or:
27 *
28 * http://www.sgi.com
29 *
30 * For further information regarding this notice, see:
31 *
32 * http://oss.sgi.com/projects/GenInfo/NoticeExplan/
33 *
34 */
35
36/*
37 * Testcase to test the basic functionality of fpathconf(2) system call.
38 */
39
40#include <fcntl.h>
41#include <unistd.h>
42#include <errno.h>
43#include <string.h>
44#include <signal.h>
45#include "test.h"
46#include "safe_macros.h"
47
48static void setup(void);
49static void cleanup(void);
50
51static struct pathconf_args {
52	char *name;
53	int value;
54} test_cases[] = {
55	{"_PC_MAX_CANON", _PC_MAX_CANON},
56	{"_PC_MAX_INPUT", _PC_MAX_INPUT},
57	{"_PC_VDISABLE", _PC_VDISABLE},
58	{"_PC_LINK_MAX", _PC_LINK_MAX},
59	{"_PC_NAME_MAX", _PC_NAME_MAX},
60	{"_PC_PATH_MAX", _PC_PATH_MAX},
61	{"_PC_PIPE_BUF", _PC_PIPE_BUF},
62	{"_PC_CHOWN_RESTRICTED", _PC_CHOWN_RESTRICTED},
63	{"_PC_NO_TRUNC", _PC_NO_TRUNC},
64};
65
66char *TCID = "fpathconf01";
67int TST_TOTAL = ARRAY_SIZE(test_cases);
68
69static int fd;
70
71int main(int ac, char **av)
72{
73	int lc;
74	int i;
75
76	tst_parse_opts(ac, av, NULL, NULL);
77
78	setup();
79
80	for (lc = 0; TEST_LOOPING(lc); lc++) {
81
82		tst_count = 0;
83
84		for (i = 0; i < TST_TOTAL; i++) {
85			errno = 0;
86
87			TEST(fpathconf(fd, test_cases[i].value));
88
89			if (TEST_RETURN == -1) {
90				if (TEST_ERRNO == 0) {
91					tst_resm(TINFO,
92						 "fpathconf has NO limit for "
93						 "%s", test_cases[i].name);
94				} else {
95					tst_resm(TFAIL | TTERRNO,
96						 "fpathconf(fd, %s) failed",
97						 test_cases[i].name);
98				}
99			} else {
100				tst_resm(TPASS,
101					 "fpathconf(fd, %s) returned %ld",
102					 test_cases[i].name, TEST_RETURN);
103			}
104		}
105	}
106
107	cleanup();
108
109	tst_exit();
110}
111
112static void setup(void)
113{
114	tst_sig(FORK, DEF_HANDLER, cleanup);
115
116	TEST_PAUSE;
117
118	tst_tmpdir();
119
120	fd = SAFE_OPEN(cleanup, "fpafile01", O_RDWR | O_CREAT, 0700);
121}
122
123static void cleanup(void)
124{
125	if (fd > 0)
126		SAFE_CLOSE(NULL, fd);
127
128	tst_rmdir();
129}
130