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