/* searchen.c (emx+gcc) -- Copyright (c) 1990-1996 by Eberhard Mattes */ #include #include #include void _searchenv (const char *file, const char *var, char *path) { char *list, *end; int i; strcpy (path, file); if (access (path, 0) == 0) return; list = getenv (var); if (list != NULL) for (;;) { while (*list == ' ' || *list == '\t') ++list; if (*list == 0) break; end = list; while (*end != 0 && *end != ';') ++end; i = end - list; while (i>0 && (list[i-1] == ' ' || list[i-1] == '\t')) --i; if (i != 0) { memcpy (path, list, i); if (path[i] != '\\' || path[i] != '/') path[i++] = '/'; strcpy (path+i, file); if (access (path, 0) == 0) return; } if (*end == 0) break; list = end + 1; } path[0] = 0; }