#ident "$URL: svn://elmer/devel/SVN/SDDAS/trunk/libant/PathFopen.c $ %D% SwRI" /* PathFopen.c */ #include /* for FILE,etc. */ #include /* for MAXPATHLEN,etc. */ #include /* for strcpy,etc. */ #include "ant.h" /* for EnvExpand,etc. */ /* PathFopen -- open first matching file in path */ FILE * PathFopen( char *path, char *filename, char *mode) { const char SEPARATORS[] = ":"; char* dir; char fullname[MAXPATHLEN]; char path_copy[MAXPATHLEN]; FILE* fp=0; strcpy(path_copy,path); dir = strtok(path_copy,SEPARATORS); while (dir) { /* build full pathname to file */ EnvExpand(fullname,dir); strcat(fullname,"/"); strcat(fullname,filename); if ((fp = fopen(fullname,mode))) break; else dir = strtok(0,SEPARATORS); } return fp; }