Print this page
*** NO COMMENTS ***
Split |
Close |
Expand all |
Collapse all |
--- old/usr/src/cmd/ypcmd/revnetgroup/util.c
+++ new/usr/src/cmd/ypcmd/revnetgroup/util.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 (the "License").
6 6 * You may not use this file except in compliance with the License.
7 7 *
8 8 * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
9 9 * or http://www.opensolaris.org/os/licensing.
10 10 * See the License for the specific language governing permissions
11 11 * and limitations under the License.
12 12 *
13 13 * When distributing Covered Code, include this CDDL HEADER in each
↓ open down ↓ |
13 lines elided |
↑ open up ↑ |
14 14 * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
15 15 * If applicable, add the following below this CDDL HEADER, with the
16 16 * fields enclosed by brackets "[]" replaced with your own identifying
17 17 * information: Portions Copyright [yyyy] [name of copyright owner]
18 18 *
19 19 * CDDL HEADER END
20 20 */
21 21
22 22 /*
23 23 * Copyright (c) 1990, 2010, Oracle and/or its affiliates. All rights reserved.
24 + * Copyright 2012 Nexenta Systems, Inc. All rights reserved.
24 25 */
25 26
26 27 #include <stdio.h>
27 28 #include <string.h>
28 29 #include "util.h"
29 30
30 31
31 32
32 33
33 34 /*
34 35 * This is just like fgets, but recognizes that "\\n" signals a continuation
35 36 * of a line
36 37 */
37 38 char *
38 39 getaline(line, maxlen, fp)
39 40 char *line;
40 41 int maxlen;
41 42 FILE *fp;
42 43 {
43 44 register char *p;
44 45 register char *start;
45 46 int c;
46 47
47 48 start = line;
48 49
49 50 nextline:
50 51 if (fgets(start, maxlen, fp) == NULL) {
51 52 return (NULL);
52 53 }
53 54 for (p = start; *p; p++) {
54 55 if (*p == '\n') {
55 56 if (p > start && *(p-1) == '\\') {
56 57 start = p - 1;
57 58 maxlen++;
58 59 goto nextline;
59 60 } else {
60 61 return (line);
61 62 }
62 63 }
63 64 maxlen--;
64 65 }
65 66
66 67 /*
67 68 * Input line is too long. Rest of the line needs to be discarded.
68 69 * Reinsert the last char into the stream. This is done so that
69 70 * in case the last char read is '\' and it is followed by a '\n'
70 71 * then the next line too can be discarded.
71 72 */
72 73 if (p > start)
73 74 (void) ungetc(*(p-1), fp);
74 75
75 76 /*
76 77 * Discard the rest of the line
77 78 */
78 79 while ((c = getc(fp)) != EOF) {
79 80 if (c == '\n')
80 81 break;
81 82 else if (c == '\\') {
82 83 /*
83 84 * Ignore the next character except EOF
84 85 */
85 86 if (getc(fp) == EOF)
86 87 break;
87 88 }
88 89 }
89 90
↓ open down ↓ |
56 lines elided |
↑ open up ↑ |
90 91 maxlen = strlen(line) + 1;
91 92
92 93 /*
93 94 * Certain functions expects a newline in the buffer.
94 95 */
95 96 if (maxlen >= 2)
96 97 line[maxlen - 2] = '\n';
97 98 (void) fprintf(stderr, "Following line too long - remaining chars "
98 99 "ignored\n--- %s", line);
99 100 return (line);
100 -}
101 -
102 -
103 -void
104 -fatal(message)
105 - char *message;
106 -{
107 - (void) fprintf(stderr, "fatal error: %s\n", message);
108 - exit(1);
109 101 }
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX