2 * CDE - Common Desktop Environment
4 * Copyright (c) 1993-2012, The Open Group. All rights reserved.
6 * These libraries and programs are free software; you can
7 * redistribute them and/or modify them under the terms of the GNU
8 * Lesser General Public License as published by the Free Software
9 * Foundation; either version 2 of the License, or (at your option)
12 * These libraries and programs are distributed in the hope that
13 * they will be useful, but WITHOUT ANY WARRANTY; without even the
14 * implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
15 * PURPOSE. See the GNU Lesser General Public License for more
18 * You should have received a copy of the GNU Lesser General Public
19 * License along with these librararies and programs; if not, write
20 * to the Free Software Foundation, Inc., 51 Franklin Street, Fifth
21 * Floor, Boston, MA 02110-1301 USA
23 /* $XConsortium: qualify.c /main/3 1995/10/27 16:14:33 rswiston $ */
25 * (c) Copyright 1993, 1994 Hewlett-Packard Company *
26 * (c) Copyright 1993, 1994 International Business Machines Corp. *
27 * (c) Copyright 1993, 1994 Sun Microsystems, Inc. *
28 * (c) Copyright 1993, 1994 Novell, Inc. *
34 /*********************************************************************
37 * takes: an unqualified filename like foo.txt, and
38 * a colon-separated list of pathnames, such as
39 * /etc/opt/dt:/opt/dt/config
41 * returns: a fully qualified filename. Space for the filename
42 * has been allocated off the heap. It is the responsibility
43 * of the calling function to dispose of the space.
44 **********************************************************************/
46 char * qualifyWithFirst
52 char * paths = strdup(searchPath);
53 char * savepaths = paths;
58 /* assert that the arguments cannot be NULL */
60 if (filename == NULL || searchPath == NULL)
65 /* if there is a :, zero it */
67 if ((path = strchr(paths, ':')) != NULL)
70 /* allocate space and create the qualified filename */
72 chance = (char *)malloc(strlen(paths) + strlen(filename) + 2);
73 sprintf(chance,"%s/%s",paths,filename);
75 /* see if it is there by opening it for reading */
77 if (f = fopen(chance,"r")) {
79 /* it's there so close it, .... */
83 /* ... restore the colon, .... */
88 /* return the fully qualified filename */
96 /* reached the end of the list of paths */
101 /* try the next path */