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 1997 Sun Microsystems, Inc. All rights reserved.
24 * Use is subject to license terms.
27 /* Copyright (c) 1984, 1986, 1987, 1988, 1989 AT&T */
28 /* All Rights Reserved */
31 #pragma ident "%Z%%M% %I% %E% SMI"
32 /* EMACS_MODES: !fill, lnumb, !overwrite, !nodelete, !picture */
37 #include "sys/types.h"
50 * getpentry() - EXTRACT ONE PRINTER ENTRY FROM DISK FILE
54 getpentry(char *name
, int want_fld
)
56 static long lastdir
= -1;
63 char * option_entry
= NULL
;
67 if (!name
|| !*name
) {
73 * Getting ``all''? If so, jump into the directory
74 * wherever we left off.
76 isNameAll
= STREQU(NAME_ALL
, name
);
80 * occasionally when a printer is removed, a printer directory
81 * is left behind, but the CONFIGFILE is removed. In this
82 * case this directory terminates the search for additional
83 * printers as we have been returning 0 in this case.
84 * Now, we loop back and try the next directory until
85 * we have no more directories or we find a directory with
89 if (!(name
= next_dir(Lp_A_Printers
, &lastdir
)))
95 * Get the printer configuration information.
98 path
= getprinterfile(name
, CONFIGFILE
);
105 if ((fd
= open_locked(path
, "r", 0)) < 0) {
109 * go around to loop again for
113 if (!isNameAll
) /* fix for bug 1117241 */
127 while (fdgets(buf
, BUFSIZ
, fd
) != NULL
) {
129 buf
[strlen(buf
) - 1] = 0;
131 for (fld
= 0; fld
< PR_MAX
; fld
++)
132 if (prtrheadings
[fld
].v
&&
133 prtrheadings
[fld
].len
&&
137 prtrheadings
[fld
].len
)) {
139 p
= buf
+ prtrheadings
[fld
].len
;
140 while (*p
&& *p
== ' ')
146 * To allow future extensions to not impact applications
147 * using old versions of this routine, ignore strange
153 if (fld
== want_fld
) {
154 if ((option_entry
= strdup(p
)) == NULL
) {
162 int save_errno
= errno
;
169 return (option_entry
);