1 /* $XConsortium: qualify.c /main/3 1995/10/27 16:14:33 rswiston $ */
3 * (c) Copyright 1993, 1994 Hewlett-Packard Company *
4 * (c) Copyright 1993, 1994 International Business Machines Corp. *
5 * (c) Copyright 1993, 1994 Sun Microsystems, Inc. *
6 * (c) Copyright 1993, 1994 Novell, Inc. *
11 /*********************************************************************
14 * takes: an unqualified filename like foo.txt, and
15 * a colon-separated list of pathnames, such as
16 * /etc/opt/dt:/opt/dt/config
18 * returns: a fully qualified filename. Space for the filename
19 * has been allocated off the heap. It is the responsibility
20 * of the calling function to dispose of the space.
21 **********************************************************************/
23 char * qualifyWithFirst
29 char * paths = strdup(searchPath);
30 char * savepaths = paths;
35 /* assert that the arguments cannot be NULL */
37 if (filename == NULL || searchPath == NULL)
42 /* if there is a :, zero it */
44 if ((path = strchr(paths, ':')) != NULL)
47 /* allocate space and create the qualified filename */
49 chance = (char *)malloc(strlen(paths) + strlen(filename) + 2);
50 sprintf(chance,"%s/%s",paths,filename);
52 /* see if it is there by opening it for reading */
54 if (f = fopen(chance,"r")) {
56 /* it's there so close it, .... */
60 /* ... restore the colon, .... */
65 /* return the fully qualified filename */
73 /* reached the end of the list of paths */
78 /* try the next path */