plars | 865695b | 2001-08-27 22:15:12 +0000 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (c) 2000 Silicon Graphics, Inc. All Rights Reserved. |
zenglg.jy | 6ae447c | 2013-12-04 19:11:33 +0800 | [diff] [blame] | 3 | * Author: William Roske |
| 4 | * Co-pilot: Dave Fenner |
plars | 865695b | 2001-08-27 22:15:12 +0000 | [diff] [blame] | 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 |
Wanlong Gao | fed9641 | 2012-10-24 10:10:29 +0800 | [diff] [blame] | 22 | * with this program; if not, write the Free Software Foundation, Inc., |
| 23 | * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. |
plars | 865695b | 2001-08-27 22:15:12 +0000 | [diff] [blame] | 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 | */ |
zenglg.jy | 6ae447c | 2013-12-04 19:11:33 +0800 | [diff] [blame] | 35 | |
| 36 | /* |
| 37 | * Testcase to test the basic functionality of fpathconf(2) system call. |
| 38 | */ |
plars | 865695b | 2001-08-27 22:15:12 +0000 | [diff] [blame] | 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" |
zenglg.jy | 6ae447c | 2013-12-04 19:11:33 +0800 | [diff] [blame] | 46 | #include "safe_macros.h" |
plars | 865695b | 2001-08-27 22:15:12 +0000 | [diff] [blame] | 47 | |
zenglg.jy | 6ae447c | 2013-12-04 19:11:33 +0800 | [diff] [blame] | 48 | static void setup(void); |
| 49 | static void cleanup(void); |
plars | 865695b | 2001-08-27 22:15:12 +0000 | [diff] [blame] | 50 | |
zenglg.jy | 6ae447c | 2013-12-04 19:11:33 +0800 | [diff] [blame] | 51 | static struct pathconf_args { |
| 52 | char *name; |
subrata_modak | 56207ce | 2009-03-23 13:35:39 +0000 | [diff] [blame] | 53 | int value; |
zenglg.jy | 6ae447c | 2013-12-04 19:11:33 +0800 | [diff] [blame] | 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}, |
zenglg.jy | 1a04a85 | 2013-12-04 19:12:27 +0800 | [diff] [blame] | 62 | {"_PC_CHOWN_RESTRICTED", _PC_CHOWN_RESTRICTED}, |
| 63 | {"_PC_NO_TRUNC", _PC_NO_TRUNC}, |
plars | 865695b | 2001-08-27 22:15:12 +0000 | [diff] [blame] | 64 | }; |
| 65 | |
zenglg.jy | 6ae447c | 2013-12-04 19:11:33 +0800 | [diff] [blame] | 66 | char *TCID = "fpathconf01"; |
| 67 | int TST_TOTAL = ARRAY_SIZE(test_cases); |
| 68 | |
| 69 | static int fd; |
plars | 865695b | 2001-08-27 22:15:12 +0000 | [diff] [blame] | 70 | |
subrata_modak | 56207ce | 2009-03-23 13:35:39 +0000 | [diff] [blame] | 71 | int main(int ac, char **av) |
plars | 865695b | 2001-08-27 22:15:12 +0000 | [diff] [blame] | 72 | { |
Cyril Hrubis | 89af32a | 2012-10-24 16:39:11 +0200 | [diff] [blame] | 73 | int lc; |
Cyril Hrubis | 0b9589f | 2014-05-27 17:40:33 +0200 | [diff] [blame] | 74 | const char *msg; |
zenglg.jy | 6ae447c | 2013-12-04 19:11:33 +0800 | [diff] [blame] | 75 | int i; |
subrata_modak | 56207ce | 2009-03-23 13:35:39 +0000 | [diff] [blame] | 76 | |
Garrett Cooper | ccb5d28 | 2011-02-21 21:57:37 -0800 | [diff] [blame] | 77 | if ((msg = parse_opts(ac, av, NULL, NULL)) != NULL) |
subrata_modak | 56207ce | 2009-03-23 13:35:39 +0000 | [diff] [blame] | 78 | tst_brkm(TBROK, NULL, "OPTION PARSING ERROR - %s", msg); |
plars | 865695b | 2001-08-27 22:15:12 +0000 | [diff] [blame] | 79 | |
subrata_modak | 56207ce | 2009-03-23 13:35:39 +0000 | [diff] [blame] | 80 | setup(); |
plars | 865695b | 2001-08-27 22:15:12 +0000 | [diff] [blame] | 81 | |
subrata_modak | 56207ce | 2009-03-23 13:35:39 +0000 | [diff] [blame] | 82 | for (lc = 0; TEST_LOOPING(lc); lc++) { |
subrata_modak | bdbaec5 | 2009-02-26 12:14:51 +0000 | [diff] [blame] | 83 | |
Caspar Zhang | d59a659 | 2013-03-07 14:59:12 +0800 | [diff] [blame] | 84 | tst_count = 0; |
subrata_modak | bdbaec5 | 2009-02-26 12:14:51 +0000 | [diff] [blame] | 85 | |
subrata_modak | 56207ce | 2009-03-23 13:35:39 +0000 | [diff] [blame] | 86 | for (i = 0; i < TST_TOTAL; i++) { |
zenglg.jy | 6ae447c | 2013-12-04 19:11:33 +0800 | [diff] [blame] | 87 | errno = 0; |
Garrett Cooper | ccb5d28 | 2011-02-21 21:57:37 -0800 | [diff] [blame] | 88 | |
zenglg.jy | 6ae447c | 2013-12-04 19:11:33 +0800 | [diff] [blame] | 89 | TEST(fpathconf(fd, test_cases[i].value)); |
subrata_modak | 56207ce | 2009-03-23 13:35:39 +0000 | [diff] [blame] | 90 | |
zenglg.jy | 6ae447c | 2013-12-04 19:11:33 +0800 | [diff] [blame] | 91 | 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_modak | 56207ce | 2009-03-23 13:35:39 +0000 | [diff] [blame] | 100 | } |
zenglg.jy | 6ae447c | 2013-12-04 19:11:33 +0800 | [diff] [blame] | 101 | } else { |
| 102 | tst_resm(TPASS, |
| 103 | "fpathconf(fd, %s) returned %ld", |
| 104 | test_cases[i].name, TEST_RETURN); |
subrata_modak | 56207ce | 2009-03-23 13:35:39 +0000 | [diff] [blame] | 105 | } |
Garrett Cooper | 2c28215 | 2010-12-16 00:55:50 -0800 | [diff] [blame] | 106 | } |
| 107 | } |
subrata_modak | 56207ce | 2009-03-23 13:35:39 +0000 | [diff] [blame] | 108 | |
subrata_modak | 56207ce | 2009-03-23 13:35:39 +0000 | [diff] [blame] | 109 | cleanup(); |
plars | 865695b | 2001-08-27 22:15:12 +0000 | [diff] [blame] | 110 | |
Garrett Cooper | 2c28215 | 2010-12-16 00:55:50 -0800 | [diff] [blame] | 111 | tst_exit(); |
| 112 | } |
plars | 865695b | 2001-08-27 22:15:12 +0000 | [diff] [blame] | 113 | |
zenglg.jy | 6ae447c | 2013-12-04 19:11:33 +0800 | [diff] [blame] | 114 | static void setup(void) |
plars | 865695b | 2001-08-27 22:15:12 +0000 | [diff] [blame] | 115 | { |
subrata_modak | 56207ce | 2009-03-23 13:35:39 +0000 | [diff] [blame] | 116 | tst_sig(FORK, DEF_HANDLER, cleanup); |
plars | 865695b | 2001-08-27 22:15:12 +0000 | [diff] [blame] | 117 | |
subrata_modak | 56207ce | 2009-03-23 13:35:39 +0000 | [diff] [blame] | 118 | TEST_PAUSE; |
plars | 865695b | 2001-08-27 22:15:12 +0000 | [diff] [blame] | 119 | |
subrata_modak | 56207ce | 2009-03-23 13:35:39 +0000 | [diff] [blame] | 120 | tst_tmpdir(); |
plars | 865695b | 2001-08-27 22:15:12 +0000 | [diff] [blame] | 121 | |
zenglg.jy | 6ae447c | 2013-12-04 19:11:33 +0800 | [diff] [blame] | 122 | fd = SAFE_OPEN(cleanup, "fpafile01", O_RDWR | O_CREAT, 0700); |
Garrett Cooper | 2c28215 | 2010-12-16 00:55:50 -0800 | [diff] [blame] | 123 | } |
plars | 865695b | 2001-08-27 22:15:12 +0000 | [diff] [blame] | 124 | |
zenglg.jy | 6ae447c | 2013-12-04 19:11:33 +0800 | [diff] [blame] | 125 | static void cleanup(void) |
plars | 865695b | 2001-08-27 22:15:12 +0000 | [diff] [blame] | 126 | { |
zenglg.jy | 6ae447c | 2013-12-04 19:11:33 +0800 | [diff] [blame] | 127 | if (fd > 0) |
| 128 | SAFE_CLOSE(NULL, fd); |
plars | 865695b | 2001-08-27 22:15:12 +0000 | [diff] [blame] | 129 | |
subrata_modak | 56207ce | 2009-03-23 13:35:39 +0000 | [diff] [blame] | 130 | tst_rmdir(); |
Garrett Cooper | ccb5d28 | 2011-02-21 21:57:37 -0800 | [diff] [blame] | 131 | } |