-
-#define NULL 0
-
-char *execat(), *getenv();
-
-getcmd(command) /* get command name (wherever it is) like shell */
-char *command;
-{
- char *pathstr;
- register char *cp;
- char fname[128];
- int fd;
-
- if ((pathstr = getenv("PATH")) == NULL)
- pathstr = ":/bin:/usr/bin";
- cp = index(command, '/')? "": pathstr;
-
- do {
- cp = execat(cp, command, fname);
- if ((fd=open(fname,0))>0)
- return(fd);
- } while (cp);
-
- printf("Couldn't open %s\n",command);
- return(-1);
-}
-
-static char *
-execat(s1, s2, si)
-register char *s1, *s2;
-char *si;
-{
- register char *s;
-
- s = si;
- while (*s1 && *s1 != ':' && *s1 != '-')
- *s++ = *s1++;
- if (si != s)
- *s++ = '/';
- while (*s2)
- *s++ = *s2++;
- *s = '\0';
- return(*s1? ++s1: 0);
-}