1106065Swollman/*
2106065Swollman * Copyright 2002 Massachusetts Institute of Technology
3106065Swollman *
4106065Swollman * Permission to use, copy, modify, and distribute this software and
5106065Swollman * its documentation for any purpose and without fee is hereby
6106065Swollman * granted, provided that both the above copyright notice and this
7106065Swollman * permission notice appear in all copies, that both the above
8106065Swollman * copyright notice and this permission notice appear in all
9106065Swollman * supporting documentation, and that the name of M.I.T. not be used
10106065Swollman * in advertising or publicity pertaining to distribution of the
11106065Swollman * software without specific, written prior permission.  M.I.T. makes
12106065Swollman * no representations about the suitability of this software for any
13106065Swollman * purpose.  It is provided "as is" without express or implied
14106065Swollman * warranty.
15106065Swollman *
16106065Swollman * THIS SOFTWARE IS PROVIDED BY M.I.T. ``AS IS''.  M.I.T. DISCLAIMS
17106065Swollman * ALL EXPRESS OR IMPLIED WARRANTIES WITH REGARD TO THIS SOFTWARE,
18106065Swollman * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
19106065Swollman * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. IN NO EVENT
20106065Swollman * SHALL M.I.T. BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
21106065Swollman * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
22106065Swollman * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
23106065Swollman * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
24106065Swollman * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
25106065Swollman * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
26106065Swollman * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
27106065Swollman * SUCH DAMAGE.
28106065Swollman */
29106065Swollman
30106065Swollman#include <sys/cdefs.h>
31106065Swollman__FBSDID("$FreeBSD$");
32106065Swollman
33114443Snectar/*
34114443Snectar * I din't use "namespace.h" here because none of the relevant utilities
35114443Snectar * are threaded, so I'm not concerned about cancellation points or other
36114443Snectar * niceties.
37114443Snectar */
38244568Sdelphij#include <sys/limits.h>
39244568Sdelphij
40106065Swollman#include <limits.h>
41106065Swollman#include <stdlib.h>
42106065Swollman#include <string.h>
43106065Swollman#include <unistd.h>
44106065Swollman
45106065Swollman#define	_PATH_UTIL_COMPAT	"/etc/compat-FreeBSD-4-util"
46106065Swollman#define	_ENV_UTIL_COMPAT	"_COMPAT_FreeBSD_4"
47106065Swollman
48106065Swollmanint
49106065Swollmancheck_utility_compat(const char *utility)
50106065Swollman{
51244568Sdelphij	char buf[PATH_MAX];
52106065Swollman	char *p, *bp;
53106065Swollman	int len;
54106065Swollman
55106065Swollman	if ((p = getenv(_ENV_UTIL_COMPAT)) != NULL) {
56114443Snectar		strlcpy(buf, p, sizeof buf);
57106065Swollman	} else {
58244568Sdelphij		if ((len = readlink(_PATH_UTIL_COMPAT, buf, sizeof(buf) - 1)) < 0)
59106065Swollman			return 0;
60106065Swollman		buf[len] = '\0';
61106065Swollman	}
62106065Swollman	if (buf[0] == '\0')
63106065Swollman		return 1;
64106065Swollman
65106065Swollman	bp = buf;
66106065Swollman	while ((p = strsep(&bp, ",")) != NULL) {
67106065Swollman		if (strcmp(p, utility) == 0)
68106065Swollman			return 1;
69106065Swollman	}
70106065Swollman	return 0;
71106065Swollman}
72