Mods to C which
Terry Slattery <tcs@usna>
tcs at usna.UUCP
Fri Sep 27 10:38:03 AEST 1985
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 <stdio.h>
char *getenv();
char *index();
--- 7,14 -----
*/
#include <stdio.h>
+ #include <sys/types.h>
+ #include <sys/stat.h>
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);
More information about the Comp.sources.unix
mailing list