home *** CD-ROM | disk | FTP | other *** search
/ Simtel MSDOS 1992 December / simtel1292_SIMTEL_1292_Walnut_Creek.iso / msdos / sysutl / picnix32.arc / MAKE.ARC / PATH.C < prev    next >
Text File  |  1986-01-30  |  1KB  |  32 lines

  1.  
  2. #include <stdio.h>
  3. #include <stdlib.h>
  4. #include <string.h>
  5. #include "mstring.h"
  6.  
  7.         FILE *
  8. fopenp(name,attr)
  9.         char *name, *attr; {
  10.         char *path;
  11.         FILE *file = fopen(name,attr);
  12.         if (file==NULL
  13.          && strchr(name,'\\')==NULL 
  14.          && strchr(name,':' )==NULL 
  15.          && (path = getenv("PATH"))) {
  16.                 char *sname;
  17.                 char *p = strtok(path = strperm(path),";");
  18.                 sname = mstrcat("\\",name);
  19.                 while (p) {
  20.                         char * filename = mstrcat(p,lastchar(p)=='\\' ? name : sname);
  21.                         file = fopen(filename,attr) ;
  22.                         free(filename);
  23.                         if (file) break;
  24.                         p = strtok(NULL,";") ;
  25.                         }
  26.                 free(path);
  27.                 free(sname);
  28.                 }
  29.         return file;
  30.         }
  31.  
  32.