strconf.c revision 4b908718db419b27633010608bf691c20684c0e2
/*
* CDDL HEADER START
*
* The contents of this file are subject to the terms of the
* Common Development and Distribution License, Version 1.0 only
* (the "License"). You may not use this file except in compliance
* with the License.
*
* You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
* See the License for the specific language governing permissions
* and limitations under the License.
*
* When distributing Covered Code, include this CDDL HEADER in each
* file and include the License file at usr/src/OPENSOLARIS.LICENSE.
* If applicable, add the following below this CDDL HEADER, with the
* fields enclosed by brackets "[]" replaced with your own identifying
* information: Portions Copyright [yyyy] [name of copyright owner]
*
* CDDL HEADER END
*/
/*
* Copyright 2005 Sun Microsystems, Inc. All rights reserved.
* Use is subject to license terms.
*/
/* Copyright (c) 1984, 1986, 1987, 1988, 1989 AT&T */
/* All Rights Reserved */
#pragma ident "%Z%%M% %I% %E% SMI" /* SVr4.0 1.5 */
/*
* Streams Command strconf: display the configuration of the
* stream associated with stdin.
*
* USAGE: strconf
* or: strconf -m module
* or: strconf -t
*
* strconf with no options lists the modules on the stream.
* -m module echos "yes" and returns 0 if the module is on the stream.
* echos "no" and returns 2 if not.
* -t lists only the topmost module. returns 0 if there is a
* module, 2 if not.
*
* RETURNS:
* 0 SUCCESS it works
* 1 ERR_USAGE bad invocation
* 2 ERR_MODULE module not there
* 3 ERR_STDIN an ioctl on the stdin stream failed
* 4 ERR_MEM couldn't allocate memory
*/
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <unistd.h>
#define OPTLIST "m:t"
#define USAGE "USAGE: %s [ -m module | -t ]\n"
#define SUCCESS 0
#define FAILURE 1
/* (there can be more) */
static char *Cmd_namep; /* how was it invoked? */
static int more_modules(struct str_list *, int);
int
{
char *modp; /* ptr to module name */
int i; /* loop var & junk (what else?) */
/*
* init
*/
/*
* parse args
*/
if (argc > 1) {
switch (i) {
case 'm': /* module present ? */
break;
case 't': /* list topmost */
break;
default:
return (ERR_USAGE);
}
}
return (ERR_USAGE);
}
}
if (topmost && mod_present) {
"%s: [-t] and [-m] options cannot be used together\n",
return (ERR_USAGE);
}
/*
* get number of modules on stream
* allocate more room if needed
*/
perror("I_LIST");
"%s: I_LIST ioctl failed\n", Cmd_namep);
return (ERR_STDIN);
}
return (ERR_MEM);
/*
* get list of modules on stream
*/
perror("I_LIST");
return (ERR_STDIN);
}
/*
* list topmost module
*/
if (topmost) {
return (SUCCESS);
}
return (ERR_MODULE);
}
/*
* check if module is present
*/
if (mod_present) {
FMNAMESZ) == 0) {
(void) puts("yes");
return (SUCCESS);
}
}
(void) puts("no");
return (ERR_MODULE);
}
/*
* print names of all modules and topmost driver on stream
*/
return (SUCCESS);
}
/*
* more_modules(listp, n) allocate space for 'n' modules in 'listp'
*
* returns: SUCCESS or FAILURE
*/
static int
{
int i;
if (n > MAXMODULES) {
"%s: too many modules (%d) -- max is %d\n",
Cmd_namep, n, MAXMODULES);
return (FAILURE);
}
perror("calloc");
"%s: failed to allocate space for module list\n",
return (FAILURE);
}
FMNAMESZ);
return (SUCCESS);
}