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: }

Defined functions

findcmd defined in line 34; used 1 times
getpath defined in line 12; used 1 times

Defined variables

npaths defined in line 5; used 6 times
paths defined in line 6; used 2 times
thepath defined in line 7; used 2 times

Defined macros

MAXPATHS defined in line 2; used 2 times
  • in line 6, 19
MAXPATHSIZE defined in line 3; used 1 times
  • in line 37
Last modified: 1983-07-21
Generated: 2016-12-26
Generated by src2html V0.67
page hit count: 911
Valid CSS Valid XHTML 1.0 Strict