blob: 8056cd730c840b31a9790ac4755f54fdc4a51cb0 [file] [log] [blame]
plars865695b2001-08-27 22:15:12 +00001/*
2 * Copyright (c) 2000 Silicon Graphics, Inc. All Rights Reserved.
zenglg.jy6ae447c2013-12-04 19:11:33 +08003 * Author: William Roske
4 * Co-pilot: Dave Fenner
plars865695b2001-08-27 22:15:12 +00005 *
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
Wanlong Gaofed96412012-10-24 10:10:29 +080022 * with this program; if not, write the Free Software Foundation, Inc.,
23 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
plars865695b2001-08-27 22:15:12 +000024 *
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 */
zenglg.jy6ae447c2013-12-04 19:11:33 +080035
36/*
37 * Testcase to test the basic functionality of fpathconf(2) system call.
38 */
plars865695b2001-08-27 22:15:12 +000039
40#include <fcntl.h>
41#include <unistd.h>
42#include <errno.h>
43#include <string.h>
44#include <signal.h>
45#include "test.h"
zenglg.jy6ae447c2013-12-04 19:11:33 +080046#include "safe_macros.h"
plars865695b2001-08-27 22:15:12 +000047
zenglg.jy6ae447c2013-12-04 19:11:33 +080048static void setup(void);
49static void cleanup(void);
plars865695b2001-08-27 22:15:12 +000050
zenglg.jy6ae447c2013-12-04 19:11:33 +080051static struct pathconf_args {
52 char *name;
subrata_modak56207ce2009-03-23 13:35:39 +000053 int value;
zenglg.jy6ae447c2013-12-04 19:11:33 +080054} 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},
zenglg.jy1a04a852013-12-04 19:12:27 +080062 {"_PC_CHOWN_RESTRICTED", _PC_CHOWN_RESTRICTED},
63 {"_PC_NO_TRUNC", _PC_NO_TRUNC},
plars865695b2001-08-27 22:15:12 +000064};
65
zenglg.jy6ae447c2013-12-04 19:11:33 +080066char *TCID = "fpathconf01";
67int TST_TOTAL = ARRAY_SIZE(test_cases);
68
69static int fd;
plars865695b2001-08-27 22:15:12 +000070
subrata_modak56207ce2009-03-23 13:35:39 +000071int main(int ac, char **av)
plars865695b2001-08-27 22:15:12 +000072{
Cyril Hrubis89af32a2012-10-24 16:39:11 +020073 int lc;
Cyril Hrubis0b9589f2014-05-27 17:40:33 +020074 const char *msg;
zenglg.jy6ae447c2013-12-04 19:11:33 +080075 int i;
subrata_modak56207ce2009-03-23 13:35:39 +000076
Garrett Cooperccb5d282011-02-21 21:57:37 -080077 if ((msg = parse_opts(ac, av, NULL, NULL)) != NULL)
subrata_modak56207ce2009-03-23 13:35:39 +000078 tst_brkm(TBROK, NULL, "OPTION PARSING ERROR - %s", msg);
plars865695b2001-08-27 22:15:12 +000079
subrata_modak56207ce2009-03-23 13:35:39 +000080 setup();
plars865695b2001-08-27 22:15:12 +000081
subrata_modak56207ce2009-03-23 13:35:39 +000082 for (lc = 0; TEST_LOOPING(lc); lc++) {
subrata_modakbdbaec52009-02-26 12:14:51 +000083
Caspar Zhangd59a6592013-03-07 14:59:12 +080084 tst_count = 0;
subrata_modakbdbaec52009-02-26 12:14:51 +000085
subrata_modak56207ce2009-03-23 13:35:39 +000086 for (i = 0; i < TST_TOTAL; i++) {
zenglg.jy6ae447c2013-12-04 19:11:33 +080087 errno = 0;
Garrett Cooperccb5d282011-02-21 21:57:37 -080088
zenglg.jy6ae447c2013-12-04 19:11:33 +080089 TEST(fpathconf(fd, test_cases[i].value));
subrata_modak56207ce2009-03-23 13:35:39 +000090
zenglg.jy6ae447c2013-12-04 19:11:33 +080091 if (TEST_RETURN == -1) {
92 if (TEST_ERRNO == 0) {
93 tst_resm(TINFO,
94 "fpathconf has NO limit for "
95 "%s", test_cases[i].name);
96 } else {
97 tst_resm(TFAIL | TTERRNO,
98 "fpathconf(fd, %s) failed",
99 test_cases[i].name);
subrata_modak56207ce2009-03-23 13:35:39 +0000100 }
zenglg.jy6ae447c2013-12-04 19:11:33 +0800101 } else {
102 tst_resm(TPASS,
103 "fpathconf(fd, %s) returned %ld",
104 test_cases[i].name, TEST_RETURN);
subrata_modak56207ce2009-03-23 13:35:39 +0000105 }
Garrett Cooper2c282152010-12-16 00:55:50 -0800106 }
107 }
subrata_modak56207ce2009-03-23 13:35:39 +0000108
subrata_modak56207ce2009-03-23 13:35:39 +0000109 cleanup();
plars865695b2001-08-27 22:15:12 +0000110
Garrett Cooper2c282152010-12-16 00:55:50 -0800111 tst_exit();
112}
plars865695b2001-08-27 22:15:12 +0000113
zenglg.jy6ae447c2013-12-04 19:11:33 +0800114static void setup(void)
plars865695b2001-08-27 22:15:12 +0000115{
subrata_modak56207ce2009-03-23 13:35:39 +0000116 tst_sig(FORK, DEF_HANDLER, cleanup);
plars865695b2001-08-27 22:15:12 +0000117
subrata_modak56207ce2009-03-23 13:35:39 +0000118 TEST_PAUSE;
plars865695b2001-08-27 22:15:12 +0000119
subrata_modak56207ce2009-03-23 13:35:39 +0000120 tst_tmpdir();
plars865695b2001-08-27 22:15:12 +0000121
zenglg.jy6ae447c2013-12-04 19:11:33 +0800122 fd = SAFE_OPEN(cleanup, "fpafile01", O_RDWR | O_CREAT, 0700);
Garrett Cooper2c282152010-12-16 00:55:50 -0800123}
plars865695b2001-08-27 22:15:12 +0000124
zenglg.jy6ae447c2013-12-04 19:11:33 +0800125static void cleanup(void)
plars865695b2001-08-27 22:15:12 +0000126{
zenglg.jy6ae447c2013-12-04 19:11:33 +0800127 if (fd > 0)
128 SAFE_CLOSE(NULL, fd);
plars865695b2001-08-27 22:15:12 +0000129
subrata_modak56207ce2009-03-23 13:35:39 +0000130 tst_rmdir();
Garrett Cooperccb5d282011-02-21 21:57:37 -0800131}