X-Git-Url: https://git.cworth.org/git?a=blobdiff_plain;f=glaze.c;fp=glaze.c;h=72070256fb4365d6874ba58a3d28f94495c5f9e9;hb=cec0694a7f219bd3590e6a04beba34ca45539540;hp=0000000000000000000000000000000000000000;hpb=0b190cc8fbca0f970eadd8c0f1d5792c41f71cf6;p=glaze diff --git a/glaze.c b/glaze.c new file mode 100644 index 0000000..7207025 --- /dev/null +++ b/glaze.c @@ -0,0 +1,63 @@ +/* Copyright © 2013, Intel Corporation + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN + * THE SOFTWARE. + */ + +#define _GNU_SOURCE +#include + +#include "glaze.h" + +#include +#include + +void * +glaze_lookup (char *function) +{ + static void *libgl_handle = NULL; + void *ret; + + if (libgl_handle == NULL) { + const char *path; + + path = getenv ("GLAZE_LIBGL"); + if (path == NULL) { + fprintf (stderr, "GLAZE_LIBGL unset. " + "Please set to path of libGL.so under glaze.\n" + ); + exit (1); + } + + libgl_handle = dlopen (path, RTLD_LAZY | RTLD_GLOBAL); + if (libgl_handle == NULL) { + fprintf (stderr, "Error: Failed to dlopen %s\n", path); + exit (1); + } + } + + ret = dlsym (libgl_handle, function); + + if (ret == NULL) { + fprintf (stderr, "Error: glaze_lookup failed to dlsym %s\n", + function); + exit (1); + } + + return ret; +}