Convert uses of XKeycodeToKeysym (deprecated) to XkbKeycodeToKeysym
[oweals/cde.git] / cde / programs / dtlogin / qualify.c
1 /*
2  * CDE - Common Desktop Environment
3  *
4  * Copyright (c) 1993-2012, The Open Group. All rights reserved.
5  *
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)
10  * any later version.
11  *
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
16  * details.
17  *
18  * You should have received a copy of the GNU Lesser General Public
19  * License along with these libraries and programs; if not, write
20  * to the Free Software Foundation, Inc., 51 Franklin Street, Fifth
21  * Floor, Boston, MA 02110-1301 USA
22  */
23 /* $XConsortium: qualify.c /main/3 1995/10/27 16:14:33 rswiston $ */
24 /*                                                                      *
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.                                *
29  */
30 #include <stdio.h>
31 #include <string.h>
32 #include <stdlib.h>
33
34 /*********************************************************************
35  * qualifyWithFirst
36  *
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
40  *
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  **********************************************************************/
45
46 char * qualifyWithFirst
47   (
48   char * filename,
49   char * searchPath
50   )
51 {
52 char * paths = NULL;
53 char * savepaths = NULL;
54 char * path;
55 char * chance;
56 FILE * f;
57
58   /* assert that the arguments cannot be NULL */
59
60   if (filename == NULL || searchPath == NULL)
61     return NULL;
62
63   paths = strdup(searchPath);
64   savepaths = paths;
65
66   while (1) {
67
68     /* if there is a :, zero it */
69
70     if ((path = strchr(paths, ':')) != NULL)
71       *path = 0;
72
73     /* allocate space and create the qualified filename */
74
75     chance = (char *)malloc(strlen(paths) + strlen(filename) + 2);
76     sprintf(chance,"%s/%s",paths,filename);
77
78     /* see if it is there by opening it for reading */
79
80     if (f = fopen(chance,"r")) {
81
82       /* it's there so close it, .... */
83
84       fclose(f);
85
86       /* ... restore the colon, .... */
87
88       if (path)
89         *path = ':';
90
91       /* return the fully qualified filename */
92
93       free(savepaths);
94       return chance;
95     }
96
97     free(chance);
98
99     /* reached the end of the list of paths */
100
101     if (path == NULL)
102       break;
103
104     /* try the next path */
105
106     paths = path + 1;
107   }
108   free(savepaths);
109   return NULL;
110 }