4 * The contents of this file are subject to the terms of the
5 * Common Development and Distribution License, Version 1.0 only
6 * (the "License"). You may not use this file except in compliance
9 * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
10 * or http://www.opensolaris.org/os/licensing.
11 * See the License for the specific language governing permissions
12 * and limitations under the License.
14 * When distributing Covered Code, include this CDDL HEADER in each
15 * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
16 * If applicable, add the following below this CDDL HEADER, with the
17 * fields enclosed by brackets "[]" replaced with your own identifying
18 * information: Portions Copyright [yyyy] [name of copyright owner]
23 * Copyright 2005 Sun Microsystems, Inc. All rights reserved.
24 * Use is subject to license terms.
27 #pragma ident "%Z%%M% %I% %E% SMI"
41 * static char *_file_getline(FILE *fp)
43 * FILE *fp - file pointer to read from
45 * char *(return) - an entry from the stream
47 * This routine will read in a line at a time. If the line ends in a
48 * newline, it returns. If the line ends in a backslash newline, it
49 * continues reading more. It will ignore lines that start in # or
53 _file_getline(FILE *fp
)
55 char entry
[BUFSIZ
], *tmp
;
58 size
= sizeof (entry
);
62 while (fgets(tmp
, size
, fp
)) {
63 if ((tmp
== entry
) && ((*tmp
== '#') || (*tmp
== '\n'))) {
66 if ((*tmp
== '#') || (*tmp
== '\n')) {
85 return (strdup(entry
));
89 main(int ac
, char *av
[])
92 char file
[80], ofile
[80];
96 (void) setlocale(LC_ALL
, "");
98 #if !defined(TEXT_DOMAIN)
99 #define TEXT_DOMAIN "SYS_TEST"
101 (void) textdomain(TEXT_DOMAIN
);
103 while ((c
= getopt(ac
, av
, "f:o:")) != EOF
)
107 (void) strlcpy(file
, optarg
, sizeof (file
));
110 (void) strlcpy(ofile
, optarg
, sizeof (ofile
));
113 (void) fprintf(stderr
, gettext(
114 "Usage: %s [-f file] [-o output file]\n"),
119 if ((fp
= fopen(file
, "r")) != NULL
) {
122 fd
= open(ofile
, O_RDWR
|O_APPEND
);
123 if ((fd
< 0) && (errno
== ENOENT
))
124 fd
= open(ofile
, O_RDWR
|O_CREAT
|O_EXCL
, 0644);
127 (void) fprintf(stderr
,
128 gettext("Error trying to open file.\n"));
132 lseek(fd
, 0, SEEK_END
);
134 if ((fp2
= fdopen(fd
, "a")) != NULL
) {
135 while ((cp
= _file_getline(fp
)) != NULL
) {
136 (void) fprintf(fp2
, "%s", cp
);
140 (void) fprintf(stderr
,
141 gettext("Error trying to open file.\n"));
145 (void) fprintf(stderr
,
146 gettext("Error trying to open file.\n"));