3 * The Regents of the University of California. All rights reserved.
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
8 * 1. Redistributions of source code must retain the above copyright
9 * notice, this list of conditions and the following disclaimer.
10 * 2. Redistributions in binary form must reproduce the above copyright
11 * notice, this list of conditions and the following disclaimer in the
12 * documentation and/or other materials provided with the distribution.
13 * 3. All advertising materials mentioning features or use of this software
14 * must display the following acknowledgement:
15 * This product includes software developed by the University of
16 * California, Berkeley and its contributors.
17 * 4. Neither the name of the University nor the names of its contributors
18 * may be used to endorse or promote products derived from this software
19 * without specific prior written permission.
21 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
22 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
23 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
24 * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
25 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
26 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
27 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
28 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
29 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
30 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
35 static const char copyright[] =
36 "@(#) Copyright (c) 1993\n\
37 The Regents of the University of California. All rights reserved.\n";
42 static char sccsid[] = "@(#)pathconf.c 8.1 (Berkeley) 6/6/93";
44 static const char rcsid[] =
45 "$FreeBSD: src/sbin/sysctl/pathconf.c,v 1.4 1999/08/28 00:14:30 peter Exp $";
48 #include <sys/param.h>
49 #include <sys/sysctl.h>
50 #include <sys/unistd.h>
61 { "link_max", CTLTYPE_INT }, \
62 { "max_canon", CTLTYPE_INT }, \
63 { "max_input", CTLTYPE_INT }, \
64 { "name_max", CTLTYPE_INT }, \
65 { "path_max", CTLTYPE_INT }, \
66 { "pipe_buf", CTLTYPE_INT }, \
67 { "chown_restricted", CTLTYPE_INT }, \
68 { "no_trunc", CTLTYPE_INT }, \
69 { "vdisable", CTLTYPE_INT }, \
73 struct ctlname pcnames[] = PC_NAMES;
80 struct list pclist = { pcnames, PC_MAXID };
82 int Aflag, aflag, nflag, wflag, stdinflag;
84 int findname __P((char *, char *, char**, struct list *));
85 void listall __P((char *, struct list *));
86 void parse __P((char *, char *, int));
87 static void usage __P((void));
97 while ((ch = getopt(argc, argv, "Aan")) != -1) {
122 if (strcmp(path, "-") == 0)
125 if (Aflag || aflag) {
126 listall(path, &pclist);
132 parse(path, *argv, 1);
137 * List all variables known to the system.
148 for (lvl2 = 0; lvl2 < lp->size; lvl2++) {
149 if (lp->list[lvl2].ctl_name == 0)
151 parse(path, lp->list[lvl2].ctl_name, Aflag);
156 * Parse a name into an index.
157 * Lookup and print out the attribute if it exists.
160 parse(pathname, string, flags)
166 char *bufp, buf[BUFSIZ];
169 snprintf(buf, BUFSIZ, "%s", string);
170 if ((indx = findname(string, "top", &bufp, &pclist)) == -1)
173 warnx("name %s in %s is unknown", *bufp, string);
177 value = fpathconf(0, indx);
179 value = pathconf(pathname, indx);
185 warnx("%s: value is not available", string);
188 warnx("%s: specification is incomplete", string);
191 warnx("%s: type is unknown to this program", string);
199 fprintf(stdout, "%s = ", string);
200 fprintf(stdout, "%d\n", value);
204 * Scan a list of names searching for a particular name.
207 findname(string, level, bufp, namelist)
211 struct list *namelist;
216 if (namelist->list == 0 || (name = strsep(bufp, ".")) == NULL) {
217 warnx("%s: incomplete specification", string);
220 for (i = 0; i < namelist->size; i++)
221 if (namelist->list[i].ctl_name != NULL &&
222 strcmp(name, namelist->list[i].ctl_name) == 0)
224 if (i == namelist->size) {
225 warnx("%s level name %s in %s is invalid", level, name, string);
235 (void)fprintf(stderr, "%s\n%s\n%s\n",
236 "usage: pathname [-n] variable ...",
238 " pathname [-n] -A");