Mesa (master): egl: Make _eglChooseDriver return the filename of the driver .

Brian Paul brianp at kemper.freedesktop.org
Fri Aug 21 14:35:30 UTC 2009


Module: Mesa
Branch: master
Commit: b1f156f0ecc93e456757fa95497b2af9b045d4de
URL:    http://cgit.freedesktop.org/mesa/mesa/commit/?id=b1f156f0ecc93e456757fa95497b2af9b045d4de

Author: Chia-I Wu <olvaffe at gmail.com>
Date:   Fri Aug 21 13:55:30 2009 +0800

egl: Make _eglChooseDriver return the filename of the driver.

The real difference is that the driver suffix is now appended.  This
also fixes an annoying bug that EGL_DRIVER could not specify the path to
a driver because a suffix was always appended.

Signed-off-by: Chia-I Wu <olvaffe at gmail.com>

---

 src/egl/main/egldriver.c |   46 +++++++++++++++++++++++++++++++++-------------
 1 files changed, 33 insertions(+), 13 deletions(-)

diff --git a/src/egl/main/egldriver.c b/src/egl/main/egldriver.c
index 06e10f6..87786e3 100644
--- a/src/egl/main/egldriver.c
+++ b/src/egl/main/egldriver.c
@@ -87,6 +87,8 @@ _eglChooseDriver(_EGLDisplay *dpy, char **argsRet)
 {
    char *path = NULL;
    const char *args = NULL;
+   const char *suffix = NULL;
+   const char *p;
 
    path = getenv("EGL_DRIVER");
    if (path)
@@ -97,11 +99,30 @@ _eglChooseDriver(_EGLDisplay *dpy, char **argsRet)
       /* assume (wrongly!) that the native display is a display string */
       path = _eglSplitDisplayString((const char *) dpy->NativeDisplay, &args);
    }
+   suffix = "so";
+#elif defined(_EGL_PLATFORM_WINDOWS)
+   suffix = "dll";
 #endif /* _EGL_PLATFORM_X */
 
    if (!path)
       path = _eglstrdup(DefaultDriverName);
 
+   /* append suffix if there isn't */
+   p = strrchr(path, '.');
+   if (!p && suffix) {
+      size_t len = strlen(path);
+      char *tmp = malloc(len + strlen(suffix) + 2);
+      if (tmp) {
+         memcpy(tmp, path, len);
+         tmp[len++] = '.';
+         tmp[len] = '\0';
+         strcat(tmp + len, suffix);
+
+         free(path);
+         path = tmp;
+      }
+   }
+
    if (argsRet)
       *argsRet = (args) ? _eglstrdup(args) : NULL;
 
@@ -113,13 +134,12 @@ _eglChooseDriver(_EGLDisplay *dpy, char **argsRet)
  * Open the named driver and find its bootstrap function: _eglMain().
  */
 static _EGLMain_t
-_eglOpenLibrary(const char *driverName, lib_handle *handle)
+_eglOpenLibrary(const char *driverPath, lib_handle *handle)
 {
    _EGLMain_t mainFunc;
    lib_handle lib;
-   char driverFilename[1000];
 
-   assert(driverName);
+   assert(driverPath);
 
 #if defined(_EGL_PLATFORM_WINDOWS)
 /* Use static linking on Windows for now */
@@ -128,31 +148,31 @@ _eglOpenLibrary(const char *driverName, lib_handle *handle)
    mainFunc = (_EGLMain_t)_eglMain;
 #else
    /* XXX untested */
-   sprintf(driverFilename, "%s.dll", driverName);
-   _eglLog(_EGL_DEBUG, "dlopen(%s)", driverFilename);
-   lib = open_library(driverFilename);
+   _eglLog(_EGL_DEBUG, "dlopen(%s)", driverPath);
+   lib = open_library(driverPath);
    if (!lib) {
       _eglLog(_EGL_WARNING, "Could not open %s",
-              driverFilename);
+              driverPath);
       return NULL;
    }
    mainFunc = (_EGLMain_t) GetProcAddress(lib, "_eglMain");
 #endif
 #elif defined(_EGL_PLATFORM_X)
-   /* XXX also prepend a directory path??? */
-   sprintf(driverFilename, "%s.so", driverName);
-   _eglLog(_EGL_DEBUG, "dlopen(%s)", driverFilename);
-   lib = open_library(driverFilename);
+   _eglLog(_EGL_DEBUG, "dlopen(%s)", driverPath);
+   lib = open_library(driverPath);
    if (!lib) {
       _eglLog(_EGL_WARNING, "Could not open %s (%s)",
-              driverFilename, dlerror());
+              driverPath, dlerror());
+      if (!getenv("EGL_DRIVER"))
+         _eglLog(_EGL_WARNING,
+                 "The driver can be overridden by setting EGL_DRIVER");
       return NULL;
    }
    mainFunc = (_EGLMain_t) dlsym(lib, "_eglMain");
 #endif
 
    if (!mainFunc) {
-      _eglLog(_EGL_WARNING, "_eglMain not found in %s", driverFilename);
+      _eglLog(_EGL_WARNING, "_eglMain not found in %s", driverPath);
       if (lib)
          close_library(lib);
       return NULL;




More information about the mesa-commit mailing list