Print this page
10120 smatch indenting fixes for usr/src/cmd
Reviewed by: Gergő Doma <domag02@gmail.com>
Portions contributed by: Joyce McIntosh <joyce.mcintosh@nexenta.com>
Split |
Close |
Expand all |
Collapse all |
--- old/usr/src/cmd/pathchk/pathchk.c
+++ new/usr/src/cmd/pathchk/pathchk.c
1 1 /*
2 2 * CDDL HEADER START
3 3 *
4 4 * The contents of this file are subject to the terms of the
5 5 * Common Development and Distribution License, Version 1.0 only
6 6 * (the "License"). You may not use this file except in compliance
7 7 * with the License.
8 8 *
9 9 * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
10 10 * or http://www.opensolaris.org/os/licensing.
11 11 * See the License for the specific language governing permissions
12 12 * and limitations under the License.
↓ open down ↓ |
12 lines elided |
↑ open up ↑ |
13 13 *
14 14 * When distributing Covered Code, include this CDDL HEADER in each
15 15 * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
16 16 * If applicable, add the following below this CDDL HEADER, with the
17 17 * fields enclosed by brackets "[]" replaced with your own identifying
18 18 * information: Portions Copyright [yyyy] [name of copyright owner]
19 19 *
20 20 * CDDL HEADER END
21 21 */
22 22 /*
23 - *
24 - * Copyright (c) 1994 by Sun Microsystems, Inc.
23 + * Copyright (c) 1994 by Sun Microsystems, Inc.
24 + * Copyright (c) 2018, Joyent, Inc.
25 25 */
26 26
27 27 /*
28 28 * Copyright 1991, 1992 by Mortice Kern Systems Inc. All rights reserved.
29 29 *
30 30 * Standards Conformance :
31 31 * P1003.2/D11.2
32 32 *
33 33 */
34 -#pragma ident "%Z%%M% %I% %E% SMI"
35 34 /*
36 35 * Original ident string for reference
37 36 * ident "$Id: pathchk.c,v 1.29 1994/05/24 15:51:19 mark Exp $"
38 37 */
39 38
40 39 #include <locale.h>
41 40 #include <libintl.h>
42 41 #include <limits.h>
43 42 #include <sys/stat.h>
44 43 #include <fcntl.h> /* for creat() prototype */
45 44 #include <string.h>
46 45 #include <errno.h>
47 46 #include <stdlib.h>
48 47 #include <stdio.h>
49 48 #include <ctype.h>
50 49 #include <unistd.h>
51 50 #include <stdlib.h>
52 51
53 52 /*
54 53 * These are the characters in the portable filename character set defined
55 54 * in POSIX P1003.2.
56 55 */
57 56 static char portfsset[] = \
58 57 "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789._-";
59 58
60 59
61 60 #ifndef M_FSDELIM
62 61 #define M_FSDELIM(c) ((c) == '/')
63 62 #endif
64 63
65 64 static char *nametoolong = "%s: component too long.\n";
66 65 static char *pathtoolong = "%s: pathname too long.\n";
67 66 static char *notsrch = "%s: Not searchable.\n";
68 67 static char *badchar = "%s: Nonportable character '%c' (%#02X) found.\n";
69 68 static char *badbyte = "%s: Nonportable byte %#02X found.\n";
70 69
71 70 static char *pathconfprob = "pathchk: warning: \
72 71 pathconf(\"%s\", %s) returns '%s'. Using %s = %d\n";
73 72
74 73
75 74 static int printWarnings = 1;
76 75
77 76 static int checkpathname(char *, int);
78 77 static void usage(void);
79 78
80 79 /*
81 80 * mainline for pathchk
82 81 */
83 82 int
84 83 main(int argc, char **argv)
85 84 {
86 85 int c;
87 86 int errors;
88 87 int pflag = 0;
89 88
90 89 (void) setlocale(LC_ALL, "");
91 90 #if !defined(TEXT_DOMAIN)
92 91 #define TEXT_DOMAIN "SYS_TEST"
93 92 #endif
94 93 (void) textdomain(TEXT_DOMAIN);
95 94
96 95
97 96 while ((c = getopt(argc, argv, "pw")) != EOF) {
98 97 switch (c) {
99 98 case 'p':
100 99 pflag = 1;
101 100 break;
102 101
103 102 case 'w':
104 103 /* turn off warning messages */
105 104 printWarnings = 0;
106 105 break;
107 106
108 107 default:
109 108 usage();
110 109 }
111 110 }
112 111
113 112 argv += optind;
114 113
115 114 if (*argv == 0) {
116 115 usage();
117 116 /* NOTREACHED */
118 117 }
119 118
120 119 errors = 0;
121 120 while (*argv) {
122 121 errors += checkpathname(*argv, pflag);
123 122 argv += 1;
124 123 }
125 124
126 125 return (errors);
127 126 }
128 127
129 128 /*
130 129 * checkPathConf(const char *, int, long *)
131 130 *
132 131 * Calls pathconf(), and returns 1 if pathconf failed, zero
133 132 * otherwise. If pathconf() succeeded, then *valp contains the
134 133 * value returned
135 134 */
136 135 static int
137 136 checkPathConf(const char *path, int type, long *valp)
138 137 {
139 138 errno = 0;
140 139 *valp = pathconf(path, type);
141 140 if ((*valp == -1) && (errno != 0) && (errno != EACCES)) {
142 141 /*
143 142 * pathconf() is not supported on some mounted filesystems
144 143 * (e.g NFS mounts) and pathconf() is known to fail.
145 144 * So, we print a warning and use the POSIX default values.
146 145 */
147 146 if (type == _PC_PATH_MAX)
148 147 *valp = _POSIX_PATH_MAX;
149 148 else
150 149 *valp = _POSIX_NAME_MAX;
151 150
152 151 if (printWarnings) {
153 152 (void) fprintf(stderr, gettext(pathconfprob), path,
154 153 type == _PC_PATH_MAX?"_PC_PATH_MAX" :
155 154 "_PC_NAME_MAX", strerror(errno),
156 155 type == _PC_PATH_MAX ? "PATH_MAX" : "NAME_MAX",
157 156 *valp);
158 157 }
159 158 }
160 159 return ((*valp == -1) && (errno != 0));
161 160 }
162 161
163 162
164 163 #define UPDATE_LIMITS(buf)\
165 164 {\
166 165 if (pflag) {\
167 166 nameMax = _POSIX_NAME_MAX;\
168 167 pathMax = _POSIX_PATH_MAX;\
169 168 } else if (checkPathConf((buf), _PC_PATH_MAX, &pathMax) || \
170 169 checkPathConf((buf), _PC_NAME_MAX, &nameMax)) {\
171 170 (void) fprintf(stderr, gettext(notsrch), buf);\
172 171 return (1);\
173 172 }\
174 173 }
175 174
176 175 /*
177 176 * checkpathname(char *pname)
178 177 * pathchk a single pathname.
179 178 */
180 179 int
181 180 checkpathname(char *path, int pflag)
182 181 {
183 182 int checkStat;
184 183 long nameMax;
185 184 long pathMax;
186 185 char *scomp;
187 186 char *ecomp;
188 187 register char *p;
189 188
190 189 p = path;
191 190 checkStat = 1;
192 191
193 192 /*
194 193 * Get the initial NAME_MAX and PATH_MAX values
195 194 */
196 195 if (M_FSDELIM(*p)) {
197 196 char buf[2];
198 197
199 198 buf[0] = *p;
200 199 buf[1] = '\0';
201 200
202 201 UPDATE_LIMITS(buf);
203 202 } else {
204 203 /*
205 204 * This is a relative pathname, initial values
206 205 * are relative to the current directory
207 206 */
208 207 UPDATE_LIMITS(".");
209 208 }
210 209
211 210 /*
212 211 * Check to make sure that the pathname doesn't exceed the
213 212 * current PATH_MAX
214 213 */
215 214 if (pathMax != -1 && strlen(p) > (size_t)pathMax) {
216 215 (void) fprintf(stderr, gettext(pathtoolong), path);
217 216 return (1);
218 217 }
219 218
220 219
221 220 /*
222 221 * Now spin around checking all the prefixes of
223 222 * the pathname, until we hit the end of the
224 223 * argument
225 224 */
226 225 while (*p != '\0') {
227 226 /*
228 227 * Find the beginning of the next
229 228 * component. Assume that
230 229 * M_FSDELIM('\0') == 0
231 230 */
232 231 while (M_FSDELIM(*p))
233 232 p += 1;
234 233
235 234 if (*p == '\0') {
236 235 /*
237 236 * There were trailing fsdelim chars on
238 237 * the path provided, so we were
239 238 * finished, we just didn't know it.
↓ open down ↓ |
195 lines elided |
↑ open up ↑ |
240 239 */
241 240 return (0);
242 241 }
243 242
244 243 scomp = p;
245 244
246 245 /*
247 246 * Find the end of the current component
248 247 * and check for valid characters in the component
249 248 */
250 - while (*p != '\0' && !M_FSDELIM(*p)) {
249 + while (*p != '\0' && !M_FSDELIM(*p)) {
251 250 /*
252 251 * for pflag: check for PFCS characters
253 252 * otherwise assume all characters are valid
254 253 */
255 254 if (pflag && (strchr(portfsset, *p) == 0)) {
256 255 if (isprint(*p)) {
257 256 (void) fprintf(stderr,
258 257 gettext(badchar), path, *p, *p);
259 258 } else {
260 259 (void) fprintf(stderr,
261 260 gettext(badbyte), path, *p);
262 261 }
263 262 return (1);
264 263 }
265 264 p += 1;
266 265 }
267 266
268 267 ecomp = p;
269 268
270 269 /*
271 270 * Make sure that this component does not exceed
272 271 * NAME_MAX in the current prefix directory
↓ open down ↓ |
12 lines elided |
↑ open up ↑ |
273 272 */
274 273 if ((nameMax != -1) && (ecomp - scomp > nameMax)) {
275 274 (void) fprintf(stderr, gettext(nametoolong), scomp);
276 275 return (1);
277 276 } else if (!pflag && checkStat) {
278 277 /*
279 278 * Perform the extra checks that
280 279 * are required when not just
281 280 * checking for portability.
282 281 */
283 - struct stat sb;
284 - char fsdelim;
282 + struct stat sb;
283 + char fsdelim;
285 284
286 - fsdelim = *ecomp;
287 - *ecomp = '\0';
285 + fsdelim = *ecomp;
286 + *ecomp = '\0';
288 287
289 - if (stat(path, &sb) == -1) {
288 + if (stat(path, &sb) == -1) {
290 289 /*
291 290 * We error out if an
292 291 * intermediate component
293 292 * is a file, when we
294 293 * were expecting a
295 294 * directory, or it is an
296 295 * unsearchable directory.
297 296 */
298 297 if ((errno == ENOTDIR && fsdelim != '\0') ||
299 298 (errno == EACCES)) {
300 299 (void) fprintf(stderr, gettext(notsrch),
301 300 path);
302 301 return (1);
303 302 } else if (errno == ENOENT) {
304 303 checkStat = 0;
305 304 }
306 - } else if (S_ISDIR(sb.st_mode)) {
305 + } else if (S_ISDIR(sb.st_mode)) {
307 306 /*
308 307 * If the current prefix is a
309 308 * directory, then we need to
310 309 * update the limits for NAME_MAX
311 310 * for the next component and the suffix.
312 311 */
313 312 if (checkPathConf(path, _PC_NAME_MAX,
314 313 &nameMax)) {
315 314 (void) fprintf(stderr,
316 315 gettext(notsrch), path);
317 316 return (1);
318 317 }
319 318 }
320 319
321 320 /*
322 321 * restore the fsdelim char that we
323 322 * stomped to produce a prefix.
324 323 */
325 324 *ecomp = fsdelim;
326 325 } /* if (we need to stat the path) */
327 326 } /* while (more of this path to check) */
328 327
329 328 /*
330 329 * We successfully traversed the whole pathname
331 330 */
332 331 return (0);
333 332 }
334 333
335 334 void
336 335 usage()
337 336 {
338 337 (void) fprintf(stderr, gettext("usage: pathchk [-p] pathname ..."));
339 338 (void) fprintf(stderr, "\n");
340 339 exit(2);
341 340 }
↓ open down ↓ |
25 lines elided |
↑ open up ↑ |
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX