1287111Smarcel/*
2287111Smarcel * Copyright 2002 Massachusetts Institute of Technology
3287111Smarcel *
4287111Smarcel * Permission to use, copy, modify, and distribute this software and
5287111Smarcel * its documentation for any purpose and without fee is hereby
6287111Smarcel * granted, provided that both the above copyright notice and this
7287111Smarcel * permission notice appear in all copies, that both the above
8287111Smarcel * copyright notice and this permission notice appear in all
9287111Smarcel * supporting documentation, and that the name of M.I.T. not be used
10287111Smarcel * in advertising or publicity pertaining to distribution of the
11287111Smarcel * software without specific, written prior permission.  M.I.T. makes
12287111Smarcel * no representations about the suitability of this software for any
13287111Smarcel * purpose.  It is provided "as is" without express or implied
14287111Smarcel * warranty.
15287111Smarcel *
16287111Smarcel * THIS SOFTWARE IS PROVIDED BY M.I.T. ``AS IS''.  M.I.T. DISCLAIMS
17287111Smarcel * ALL EXPRESS OR IMPLIED WARRANTIES WITH REGARD TO THIS SOFTWARE,
18287111Smarcel * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
19287111Smarcel * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. IN NO EVENT
20287111Smarcel * SHALL M.I.T. BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
21287111Smarcel * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
22287111Smarcel * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
23287111Smarcel * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
24287111Smarcel * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
25287111Smarcel * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
26287111Smarcel * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
27287111Smarcel * SUCH DAMAGE.
28287111Smarcel */
29287111Smarcel
30287111Smarcel#include <sys/cdefs.h>
31287111Smarcel__FBSDID("$FreeBSD$");
32287111Smarcel
33287111Smarcel/*
34287111Smarcel * I din't use "namespace.h" here because none of the relevant utilities
35287111Smarcel * are threaded, so I'm not concerned about cancellation points or other
36287111Smarcel * niceties.
37287111Smarcel */
38287111Smarcel#include <sys/limits.h>
39287111Smarcel
40287111Smarcel#include <limits.h>
41287111Smarcel#include <stdlib.h>
42287111Smarcel#include <string.h>
43287111Smarcel#include <unistd.h>
44287111Smarcel
45287111Smarcel#define	_PATH_UTIL_COMPAT	"/etc/compat-FreeBSD-4-util"
46287111Smarcel#define	_ENV_UTIL_COMPAT	"_COMPAT_FreeBSD_4"
47287111Smarcel
48287111Smarcelint
49287111Smarcelcheck_utility_compat(const char *utility)
50287111Smarcel{
51287111Smarcel	char buf[PATH_MAX];
52287111Smarcel	char *p, *bp;
53287111Smarcel	int len;
54287111Smarcel
55287111Smarcel	if ((p = getenv(_ENV_UTIL_COMPAT)) != NULL) {
56287111Smarcel		strlcpy(buf, p, sizeof buf);
57287111Smarcel	} else {
58287111Smarcel		if ((len = readlink(_PATH_UTIL_COMPAT, buf, sizeof(buf) - 1)) < 0)
59287111Smarcel			return 0;
60287111Smarcel		buf[len] = '\0';
61287111Smarcel	}
62287111Smarcel	if (buf[0] == '\0')
63287111Smarcel		return 1;
64287111Smarcel
65287111Smarcel	bp = buf;
66287111Smarcel	while ((p = strsep(&bp, ",")) != NULL) {
67287111Smarcel		if (strcmp(p, utility) == 0)
68287111Smarcel			return 1;
69287111Smarcel	}
70287111Smarcel	return 0;
71287111Smarcel}
72287111Smarcel