From owner-freebsd-bugs Wed Mar 15 9:20:10 2000 Delivered-To: freebsd-bugs@freebsd.org Received: from freefall.freebsd.org (freefall.FreeBSD.ORG [204.216.27.21]) by hub.freebsd.org (Postfix) with ESMTP id 8430D37BD28 for ; Wed, 15 Mar 2000 09:20:02 -0800 (PST) (envelope-from gnats@FreeBSD.org) Received: (from gnats@localhost) by freefall.freebsd.org (8.9.3/8.9.2) id JAA55860; Wed, 15 Mar 2000 09:20:02 -0800 (PST) (envelope-from gnats@FreeBSD.org) Received: from kiwi.datasys.net (kiwi.datasys.net [209.119.145.2]) by hub.freebsd.org (Postfix) with ESMTP id 0D41837BD83 for ; Wed, 15 Mar 2000 09:19:47 -0800 (PST) (envelope-from ayan@kiwi.datasys.net) Received: (from ayan@localhost) by kiwi.datasys.net (8.9.3/8.9.3) id MAA44288; Wed, 15 Mar 2000 12:19:33 -0500 (EST) (envelope-from ayan) Message-Id: <200003151719.MAA44288@kiwi.datasys.net> Date: Wed, 15 Mar 2000 12:19:33 -0500 (EST) From: Ayan George Reply-To: ayan@kiwi.datasys.net To: FreeBSD-gnats-submit@freebsd.org X-Send-Pr-Version: 3.2 Subject: bin/17395: bin Sender: owner-freebsd-bugs@FreeBSD.ORG Precedence: bulk X-Loop: FreeBSD.org >Number: 17395 >Category: bin >Synopsis: This is a replacement for the perl version of which. >Confidential: no >Severity: non-critical >Priority: low >Responsible: freebsd-bugs >State: open >Quarter: >Keywords: >Date-Required: >Class: change-request >Submitter-Id: current-users >Arrival-Date: Wed Mar 15 09:20:01 PST 2000 >Closed-Date: >Last-Modified: >Originator: Ayan George >Release: FreeBSD 4.0-CURRENT i386 >Organization: DSS Online, LLC >Environment: >Description: /* * Copyright (c) 2000 Ayan George . United States. All rights * reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions are * met: 1. Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. 2. * Redistributions in binary form must reproduce the above copyright notice, * this list of conditions and the following disclaimer in the documentation * and/or other materials provided with the distribution. * * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND ANY * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE * DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE FOR * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF * SUCH DAMAGE. * * $Id: which.c,v 1.1 2000/03/03 21:23:19 ayan Exp $ * */ #include #include #include #include #include #include #define PROCESS_ALL 0x01 #define QUIET_OUTPUT 0x02 int main(int argc, char *argv[]) { char *directory; char *path; char *toklist; char filename[FILENAME_MAX]; /* FILENAME_MAX is defined in stdio.h. */ int arg; int mode = 0; int rc = 1; gid_t myegid; uid_t myeuid; struct stat file_stat; path = getenv("PATH"); if (path != NULL) { myegid = getegid(); myeuid = geteuid(); while ((arg = getopt(argc, argv, "ahs")) != (-1)) { switch (arg) { case 'a': mode = (mode | PROCESS_ALL); break; case 's': mode = (mode | QUIET_OUTPUT); break; case 'h': fprintf(stderr, "usage: which [-a] [-s] program ...\n"); exit(0); break; } } argc -= optind; argv += optind; if (argc == 0) exit(0); else while (argc > 0) { toklist = strdup(path); while ((directory = (char *) strsep(&toklist, ":")) != NULL) { sprintf(filename, "%s/%s", directory, *argv); if (stat(filename, &file_stat) != (-1)) { if ((file_stat.st_mode & 0100) || ((file_stat.st_mode & 0010) && (myegid == file_stat.st_gid)) || ((file_stat.st_mode & 0001) && (myeuid == file_stat.st_uid))) { rc = 0; if (!(mode & QUIET_OUTPUT)) { write(1, filename, strlen(filename)); putchar('\n'); } } } } free(toklist); if (!(mode & PROCESS_ALL)) exit(rc); --argc; ++argv; } } exit(rc); } >How-To-Repeat: Since this is a complete rewrite, there I don't see a need for a diff. This replaces /usr/src/usr.bin/which/which.pl. This does not require Perl to execute. >Fix: >Release-Note: >Audit-Trail: >Unformatted: To Unsubscribe: send mail to majordomo@FreeBSD.org with "unsubscribe freebsd-bugs" in the body of the message