1*40d5720eSchristos /* $NetBSD: suutil.c,v 1.1 2007/10/17 21:05:39 christos Exp $ */
2*40d5720eSchristos
3*40d5720eSchristos /*
4*40d5720eSchristos * Copyright (c) 1988 The Regents of the University of California.
5*40d5720eSchristos * All rights reserved.
6*40d5720eSchristos *
7*40d5720eSchristos * Redistribution and use in source and binary forms, with or without
8*40d5720eSchristos * modification, are permitted provided that the following conditions
9*40d5720eSchristos * are met:
10*40d5720eSchristos * 1. Redistributions of source code must retain the above copyright
11*40d5720eSchristos * notice, this list of conditions and the following disclaimer.
12*40d5720eSchristos * 2. Redistributions in binary form must reproduce the above copyright
13*40d5720eSchristos * notice, this list of conditions and the following disclaimer in the
14*40d5720eSchristos * documentation and/or other materials provided with the distribution.
15*40d5720eSchristos * 3. Neither the name of the University nor the names of its contributors
16*40d5720eSchristos * may be used to endorse or promote products derived from this software
17*40d5720eSchristos * without specific prior written permission.
18*40d5720eSchristos *
19*40d5720eSchristos * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
20*40d5720eSchristos * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
21*40d5720eSchristos * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
22*40d5720eSchristos * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
23*40d5720eSchristos * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
24*40d5720eSchristos * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
25*40d5720eSchristos * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
26*40d5720eSchristos * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
27*40d5720eSchristos * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
28*40d5720eSchristos * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
29*40d5720eSchristos * SUCH DAMAGE.
30*40d5720eSchristos */
31*40d5720eSchristos #include <sys/cdefs.h>
32*40d5720eSchristos __RCSID("$NetBSD: suutil.c,v 1.1 2007/10/17 21:05:39 christos Exp $");
33*40d5720eSchristos
34*40d5720eSchristos #include <sys/param.h>
35*40d5720eSchristos #include <stdio.h>
36*40d5720eSchristos #include <unistd.h>
37*40d5720eSchristos #include <string.h>
38*40d5720eSchristos #include "suutil.h"
39*40d5720eSchristos
40*40d5720eSchristos int
chshell(const char * sh)41*40d5720eSchristos chshell(const char *sh)
42*40d5720eSchristos {
43*40d5720eSchristos const char *cp;
44*40d5720eSchristos
45*40d5720eSchristos setusershell();
46*40d5720eSchristos while ((cp = getusershell()) != NULL)
47*40d5720eSchristos if (strcmp(cp, sh) == 0)
48*40d5720eSchristos return 1;
49*40d5720eSchristos return 0;
50*40d5720eSchristos }
51*40d5720eSchristos
52*40d5720eSchristos char *
ontty(void)53*40d5720eSchristos ontty(void)
54*40d5720eSchristos {
55*40d5720eSchristos char *p;
56*40d5720eSchristos static char buf[MAXPATHLEN + 4];
57*40d5720eSchristos
58*40d5720eSchristos buf[0] = 0;
59*40d5720eSchristos if ((p = ttyname(STDERR_FILENO)) != NULL)
60*40d5720eSchristos (void)snprintf(buf, sizeof buf, " on %s", p);
61*40d5720eSchristos return buf;
62*40d5720eSchristos }
63*40d5720eSchristos
64