]> git.cworth.org Git - glaze/blob - glaze.c
Add a simple helper program to find libGL.so.1
[glaze] / glaze.c
1 /* Copyright © 2013, Intel Corporation
2  *
3  * Permission is hereby granted, free of charge, to any person obtaining a copy
4  * of this software and associated documentation files (the "Software"), to deal
5  * in the Software without restriction, including without limitation the rights
6  * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
7  * copies of the Software, and to permit persons to whom the Software is
8  * furnished to do so, subject to the following conditions:
9  *
10  * The above copyright notice and this permission notice shall be included in
11  * all copies or substantial portions of the Software.
12  *
13  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
14  * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
15  * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
16  * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
17  * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
18  * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
19  * THE SOFTWARE.
20  */
21
22 #define _GNU_SOURCE
23 #include <dlfcn.h>
24
25 #include "glaze.h"
26
27 #include <stdio.h>
28 #include <stdlib.h>
29
30 void *
31 glaze_lookup (char *function)
32 {
33         static void *libgl_handle = NULL;
34         void *ret;
35
36         if (libgl_handle == NULL) {
37                 const char *path;
38
39                 path = getenv ("GLAZE_LIBGL");
40                 if (path == NULL) {
41                         fprintf (stderr, "GLAZE_LIBGL unset. "
42                                  "Please set to path of libGL.so under glaze.\n"
43                                 );
44                         exit (1);
45                 }
46
47                 libgl_handle = dlopen (path, RTLD_LAZY | RTLD_GLOBAL);
48                 if (libgl_handle == NULL) {
49                         fprintf (stderr, "Error: Failed to dlopen %s\n", path);
50                         exit (1);
51                 }
52         }
53
54         ret = dlsym (libgl_handle, function);
55
56         if (ret == NULL) {
57                 fprintf (stderr, "Error: glaze_lookup failed to dlsym %s\n",
58                          function);
59                 exit (1);
60         }
61
62         return ret;
63 }