Relay-Version: version B 2.10 5/3/83; site utzoo.UUCP Posting-Version: version B 2.10.2 9/18/84; site usna.UUCP Path: utzoo!watmath!clyde!burl!ulysses!allegra!mit-eddie!think!harvard!cmcl2!seismo!usna!tcs From: tcs@usna.UUCP (Terry Slattery ) Newsgroups: net.sources Subject: Mods to C which Message-ID: <117@usna.UUCP> Date: Thu, 26-Sep-85 20:38:03 EDT Article-I.D.: usna.117 Posted: Thu Sep 26 20:38:03 1985 Date-Received: Mon, 30-Sep-85 00:48:29 EDT Distribution: net Organization: U.S. Naval Academy Lines: 72 I've added a stat to the C version of which to omit printing the names of directories found. I also increased the sizes of the line buffers to prevent possible overflows. -tcs *** which.c.bak Thu Sep 26 13:35:43 1985 --- which.c Thu Sep 26 13:35:54 1985 *************** *** 7,12 */ #include char *getenv(); char *index(); --- 7,14 ----- */ #include + #include + #include char *getenv(); char *index(); *************** *** 16,23 char **av; { char *origpath, *path, *cp; ! char buf[200]; ! char patbuf[512]; int quit, found; if (ac < 2) { --- 18,26 ----- char **av; { char *origpath, *path, *cp; ! char buf[512]; ! char patbuf[1024]; ! struct stat status; int quit, found; if (ac < 2) { *************** *** 44,53 sprintf(buf, "%s/%s", (*path ? path:"."), *av); path = ++cp; ! if (access(buf, 1) == 0) { ! printf("%s\n", buf); ! found++; ! } } if (!found) printf("No %s in %s\n", *av, origpath); --- 47,58 ----- sprintf(buf, "%s/%s", (*path ? path:"."), *av); path = ++cp; ! if (access(buf, 1) == 0) ! stat(buf, &status); ! if (status.st_mode & S_IFREG) { ! printf("%s\n", buf); ! found++; ! } } if (!found) printf("No %s in %s\n", *av, origpath); Brought to you by Super Global Mega Corp .com