Annotation of 43BSD/contrib/dsh/src/getpath.c, revision 1.1.1.1

1.1       root        1: /*(@(#)getpath.c       1.2             /ra/csr/presotto/hacks/src/worm/sccs/s.getpath.c)*/
                      2: #define MAXPATHS 20
                      3: #define MAXPATHSIZE 100
                      4: 
                      5: int            npaths;                 /* number of paths to search */
                      6: char           *paths[MAXPATHS];       /* pointers to the paths */
                      7: char           thepath[256];           /* where to copy path */
                      8: 
                      9: /*
                     10:  *     input the execution search path
                     11:  */
                     12: getpath ()
                     13: {
                     14:     char       *path;
                     15: 
                     16:     path = (char *)getenv ("PATH");
                     17:     strcpy (thepath, path);
                     18:     path = thepath;
                     19:     for (npaths = 0; npaths < MAXPATHS; npaths++) {
                     20:        paths[npaths] = path;
                     21:        while (*path != ':' && *path != 0) path++;
                     22:        if (*path == 0) {
                     23:            npaths++;
                     24:            break;
                     25:        } else {
                     26:            *path++ = 0;
                     27:        }
                     28:     }
                     29: }
                     30: 
                     31: /*
                     32:  *     see if we can execute a command
                     33:  */
                     34: findcmd (path)
                     35: char   *path;                  /* path to the command */
                     36: {
                     37:     char       abspath[MAXPATHSIZE];
                     38:     int                rv;                     /* return value */
                     39:     int                indp;                   /* path index */
                     40: 
                     41:     if (*path == 0)
                     42:        return (0);
                     43: 
                     44:     if (*path == '/') {
                     45:        
                     46:        /* absolute path,  don't fool around */
                     47:        rv = access(path, 1);
                     48:     } else {
                     49: 
                     50:        /* relative path,  do some work */
                     51:        for (indp = 0; indp < npaths; indp++) {
                     52:            strcpy (abspath, paths[indp]);
                     53:            strcat (abspath, "/");
                     54:            strcat (abspath, path);
                     55:            rv = access(abspath, 1);
                     56:            if (rv == 0)
                     57:                break;
                     58:        }
                     59:     }
                     60: 
                     61:     return (rv);
                     62: }

unix.superglobalmegacorp.com

This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.