10Sstevel@tonic-gate /*
20Sstevel@tonic-gate * CDDL HEADER START
30Sstevel@tonic-gate *
40Sstevel@tonic-gate * The contents of this file are subject to the terms of the
5*3125Sjacobs * Common Development and Distribution License (the "License").
6*3125Sjacobs * You may not use this file except in compliance with the License.
70Sstevel@tonic-gate *
80Sstevel@tonic-gate * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
90Sstevel@tonic-gate * or http://www.opensolaris.org/os/licensing.
100Sstevel@tonic-gate * See the License for the specific language governing permissions
110Sstevel@tonic-gate * and limitations under the License.
120Sstevel@tonic-gate *
130Sstevel@tonic-gate * When distributing Covered Code, include this CDDL HEADER in each
140Sstevel@tonic-gate * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
150Sstevel@tonic-gate * If applicable, add the following below this CDDL HEADER, with the
160Sstevel@tonic-gate * fields enclosed by brackets "[]" replaced with your own identifying
170Sstevel@tonic-gate * information: Portions Copyright [yyyy] [name of copyright owner]
180Sstevel@tonic-gate *
190Sstevel@tonic-gate * CDDL HEADER END
200Sstevel@tonic-gate */
21*3125Sjacobs
22871Scasper /*
23*3125Sjacobs * Copyright 2006 Sun Microsystems, Inc. All rights reserved.
24871Scasper * Use is subject to license terms.
25871Scasper */
26*3125Sjacobs
270Sstevel@tonic-gate /* Copyright (c) 1984, 1986, 1987, 1988, 1989 AT&T */
280Sstevel@tonic-gate /* All Rights Reserved */
290Sstevel@tonic-gate
300Sstevel@tonic-gate
31871Scasper #pragma ident "%Z%%M% %I% %E% SMI"
320Sstevel@tonic-gate /* EMACS_MODES: !fill, lnumb, !overwrite, !nodelete, !picture */
330Sstevel@tonic-gate
340Sstevel@tonic-gate #include "string.h"
350Sstevel@tonic-gate #include "errno.h"
360Sstevel@tonic-gate #include "sys/types.h"
370Sstevel@tonic-gate #include "stdlib.h"
380Sstevel@tonic-gate
390Sstevel@tonic-gate #include "lp.h"
400Sstevel@tonic-gate #include "printers.h"
410Sstevel@tonic-gate
420Sstevel@tonic-gate /**
430Sstevel@tonic-gate ** getpwheel() - GET PRINT WHEEL INFO FROM DISK
440Sstevel@tonic-gate **/
450Sstevel@tonic-gate
460Sstevel@tonic-gate PWHEEL *
470Sstevel@tonic-gate #if defined(__STDC__)
getpwheel(char * name)480Sstevel@tonic-gate getpwheel (
490Sstevel@tonic-gate char * name
500Sstevel@tonic-gate )
510Sstevel@tonic-gate #else
520Sstevel@tonic-gate getpwheel (name)
530Sstevel@tonic-gate char *name;
540Sstevel@tonic-gate #endif
550Sstevel@tonic-gate {
560Sstevel@tonic-gate static long lastdir = -1;
570Sstevel@tonic-gate
58*3125Sjacobs PWHEEL *pwp;
590Sstevel@tonic-gate
600Sstevel@tonic-gate register FALERT *pa;
610Sstevel@tonic-gate
620Sstevel@tonic-gate
630Sstevel@tonic-gate if (!name || !*name) {
640Sstevel@tonic-gate errno = EINVAL;
650Sstevel@tonic-gate return (0);
660Sstevel@tonic-gate }
670Sstevel@tonic-gate
680Sstevel@tonic-gate /*
690Sstevel@tonic-gate * Getting ``all''? If so, jump into the directory
700Sstevel@tonic-gate * wherever we left off.
710Sstevel@tonic-gate */
720Sstevel@tonic-gate if (STREQU(NAME_ALL, name)) {
730Sstevel@tonic-gate if (!(name = next_dir(Lp_A_PrintWheels, &lastdir)))
740Sstevel@tonic-gate return (0);
750Sstevel@tonic-gate } else
760Sstevel@tonic-gate lastdir = -1;
770Sstevel@tonic-gate
780Sstevel@tonic-gate /*
790Sstevel@tonic-gate * Get the information for the alert.
800Sstevel@tonic-gate */
810Sstevel@tonic-gate if (!(pa = getalert(Lp_A_PrintWheels, name))) {
820Sstevel@tonic-gate
830Sstevel@tonic-gate /*
840Sstevel@tonic-gate * Unless the world has turned weird, we shouldn't
850Sstevel@tonic-gate * get ENOTDIR if we're doing the ``all'' case--because
860Sstevel@tonic-gate * getting here in the all case meant the printwheel
870Sstevel@tonic-gate * directory exists, but ENOTDIR means it doesn't!
880Sstevel@tonic-gate */
890Sstevel@tonic-gate if (errno == ENOTDIR)
900Sstevel@tonic-gate errno = ENOENT; /* printwheel doesn't exist */
910Sstevel@tonic-gate
920Sstevel@tonic-gate return (0);
930Sstevel@tonic-gate }
940Sstevel@tonic-gate
95*3125Sjacobs pwp = calloc(1, sizeof (*pwp));
96*3125Sjacobs pwp->alert = *pa;
97*3125Sjacobs pwp->name = Strdup(name);
980Sstevel@tonic-gate
99*3125Sjacobs return (pwp);
1000Sstevel@tonic-gate }
1010Sstevel@tonic-gate
1020Sstevel@tonic-gate /**
1030Sstevel@tonic-gate ** putpwheel() - PUT PRINT WHEEL INFO TO DISK
1040Sstevel@tonic-gate **/
1050Sstevel@tonic-gate
1060Sstevel@tonic-gate int
1070Sstevel@tonic-gate #if defined(__STDC__)
putpwheel(char * name,PWHEEL * pwheelp)1080Sstevel@tonic-gate putpwheel (
1090Sstevel@tonic-gate char * name,
1100Sstevel@tonic-gate PWHEEL * pwheelp
1110Sstevel@tonic-gate )
1120Sstevel@tonic-gate #else
1130Sstevel@tonic-gate putpwheel (name, pwheelp)
1140Sstevel@tonic-gate char *name;
1150Sstevel@tonic-gate PWHEEL *pwheelp;
1160Sstevel@tonic-gate #endif
1170Sstevel@tonic-gate {
1180Sstevel@tonic-gate register char *path;
1190Sstevel@tonic-gate
1200Sstevel@tonic-gate struct stat statbuf;
1210Sstevel@tonic-gate
1220Sstevel@tonic-gate
1230Sstevel@tonic-gate if (!name || !*name) {
1240Sstevel@tonic-gate errno = EINVAL;
1250Sstevel@tonic-gate return (-1);
1260Sstevel@tonic-gate }
1270Sstevel@tonic-gate
1280Sstevel@tonic-gate if (STREQU(name, NAME_ALL)) {
1290Sstevel@tonic-gate errno = ENOENT;
1300Sstevel@tonic-gate return (-1);
1310Sstevel@tonic-gate }
1320Sstevel@tonic-gate
1330Sstevel@tonic-gate /*
1340Sstevel@tonic-gate * Create the parent directory for this printer
1350Sstevel@tonic-gate * if it doesn't yet exist.
1360Sstevel@tonic-gate */
1370Sstevel@tonic-gate if (!(path = makepath(Lp_A_PrintWheels, name, (char *)0)))
1380Sstevel@tonic-gate return (-1);
1390Sstevel@tonic-gate if (Stat(path, &statbuf) == 0) {
140871Scasper if (!S_ISDIR(statbuf.st_mode)) {
1410Sstevel@tonic-gate Free (path);
1420Sstevel@tonic-gate errno = ENOTDIR;
1430Sstevel@tonic-gate return (-1);
1440Sstevel@tonic-gate }
1450Sstevel@tonic-gate } else if (errno != ENOENT || mkdir_lpdir(path, MODE_DIR) == -1) {
1460Sstevel@tonic-gate Free (path);
1470Sstevel@tonic-gate return (-1);
1480Sstevel@tonic-gate }
1490Sstevel@tonic-gate Free (path);
1500Sstevel@tonic-gate
1510Sstevel@tonic-gate /*
1520Sstevel@tonic-gate * Now write out the alert condition.
1530Sstevel@tonic-gate */
1540Sstevel@tonic-gate if (putalert(Lp_A_PrintWheels, name, &(pwheelp->alert)) == -1)
1550Sstevel@tonic-gate return (-1);
1560Sstevel@tonic-gate
1570Sstevel@tonic-gate return (0);
1580Sstevel@tonic-gate }
1590Sstevel@tonic-gate
1600Sstevel@tonic-gate /**
1610Sstevel@tonic-gate ** delpwheel() - DELETE PRINT WHEEL INFO FROM DISK
1620Sstevel@tonic-gate **/
1630Sstevel@tonic-gate
1640Sstevel@tonic-gate #if defined(__STDC__)
1650Sstevel@tonic-gate static int _delpwheel ( char * );
1660Sstevel@tonic-gate #else
1670Sstevel@tonic-gate static int _delpwheel();
1680Sstevel@tonic-gate #endif
1690Sstevel@tonic-gate
1700Sstevel@tonic-gate int
1710Sstevel@tonic-gate #if defined(__STDC__)
delpwheel(char * name)1720Sstevel@tonic-gate delpwheel (
1730Sstevel@tonic-gate char * name
1740Sstevel@tonic-gate )
1750Sstevel@tonic-gate #else
1760Sstevel@tonic-gate delpwheel (name)
1770Sstevel@tonic-gate char *name;
1780Sstevel@tonic-gate #endif
1790Sstevel@tonic-gate {
1800Sstevel@tonic-gate long lastdir;
1810Sstevel@tonic-gate
1820Sstevel@tonic-gate
1830Sstevel@tonic-gate if (!name || !*name) {
1840Sstevel@tonic-gate errno = EINVAL;
1850Sstevel@tonic-gate return (-1);
1860Sstevel@tonic-gate }
1870Sstevel@tonic-gate
1880Sstevel@tonic-gate if (STREQU(NAME_ALL, name)) {
1890Sstevel@tonic-gate lastdir = -1;
1900Sstevel@tonic-gate while ((name = next_dir(Lp_A_PrintWheels, &lastdir)))
1910Sstevel@tonic-gate if (_delpwheel(name) == -1)
1920Sstevel@tonic-gate return (-1);
1930Sstevel@tonic-gate return (0);
1940Sstevel@tonic-gate } else
1950Sstevel@tonic-gate return (_delpwheel(name));
1960Sstevel@tonic-gate }
1970Sstevel@tonic-gate
1980Sstevel@tonic-gate /**
1990Sstevel@tonic-gate ** _delpwheel()
2000Sstevel@tonic-gate **/
2010Sstevel@tonic-gate
2020Sstevel@tonic-gate static int
2030Sstevel@tonic-gate #if defined(__STDC__)
_delpwheel(char * name)2040Sstevel@tonic-gate _delpwheel (
2050Sstevel@tonic-gate char * name
2060Sstevel@tonic-gate )
2070Sstevel@tonic-gate #else
2080Sstevel@tonic-gate _delpwheel (name)
2090Sstevel@tonic-gate char *name;
2100Sstevel@tonic-gate #endif
2110Sstevel@tonic-gate {
2120Sstevel@tonic-gate register char *path;
2130Sstevel@tonic-gate
2140Sstevel@tonic-gate if (delalert(Lp_A_PrintWheels, name) == -1)
2150Sstevel@tonic-gate return (-1);
2160Sstevel@tonic-gate if (!(path = makepath(Lp_A_PrintWheels, name, (char *)0)))
2170Sstevel@tonic-gate return (-1);
2180Sstevel@tonic-gate if (Rmdir(path)) {
2190Sstevel@tonic-gate Free (path);
2200Sstevel@tonic-gate return (-1);
2210Sstevel@tonic-gate }
2220Sstevel@tonic-gate Free (path);
2230Sstevel@tonic-gate return (0);
2240Sstevel@tonic-gate }
2250Sstevel@tonic-gate
2260Sstevel@tonic-gate /**
2270Sstevel@tonic-gate ** freepwheel() - FREE MEMORY ALLOCATED FOR PRINT WHEEL STRUCTURE
2280Sstevel@tonic-gate **/
2290Sstevel@tonic-gate
2300Sstevel@tonic-gate void
2310Sstevel@tonic-gate #if defined(__STDC__)
freepwheel(PWHEEL * ppw)2320Sstevel@tonic-gate freepwheel (
2330Sstevel@tonic-gate PWHEEL * ppw
2340Sstevel@tonic-gate )
2350Sstevel@tonic-gate #else
2360Sstevel@tonic-gate freepwheel (ppw)
2370Sstevel@tonic-gate PWHEEL *ppw;
2380Sstevel@tonic-gate #endif
2390Sstevel@tonic-gate {
2400Sstevel@tonic-gate if (!ppw)
2410Sstevel@tonic-gate return;
2420Sstevel@tonic-gate if (ppw->name)
2430Sstevel@tonic-gate Free (ppw->name);
2440Sstevel@tonic-gate if (ppw->alert.shcmd)
2450Sstevel@tonic-gate Free (ppw->alert.shcmd);
246*3125Sjacobs Free (ppw);
247*3125Sjacobs
2480Sstevel@tonic-gate return;
2490Sstevel@tonic-gate }
250