fix some 0->NULLs
[mesa.git] / src / mesa / drivers / dri / common / xmlconfig.c
index f45ab06ac414eb8ffe2253e9df83f3dc2fd5207a..b635894fe53858bb0064a22c0f808924394cf56e 100644 (file)
 
 #undef GET_PROGRAM_NAME
 
-#if defined(__GNU_LIBRARY__) || defined(__GLIBC__)
+#if (defined(__GNU_LIBRARY__) || defined(__GLIBC__)) && !defined(__UCLIBC__)
+#    if !defined(__GLIBC__) || (__GLIBC__ < 2)
+/* These aren't declared in any libc5 header */
+extern char *program_invocation_name, *program_invocation_short_name;
+#    endif
 #    define GET_PROGRAM_NAME() program_invocation_short_name
 #elif defined(__FreeBSD__) && (__FreeBSD__ >= 2)
 #    include <osreldate.h>
 #endif
 
 #if !defined(GET_PROGRAM_NAME)
-#    if defined(OpenBSD) || defined(NetBSD)
-/* This is a hack. It's said to work on OpenBSD, NetBSD and GNU. It's
+#    if defined(OpenBSD) || defined(NetBSD) || defined(__UCLIBC__)
+/* This is a hack. It's said to work on OpenBSD, NetBSD and GNU.
+ * Rogelio M.Serrano Jr. reported it's also working with UCLIBC. It's
  * used as a last resort, if there is no documented facility available. */
 static const char *__getProgramName () {
     extern const char *__progname;
-    return progname;
+    char * arg = strrchr(__progname, '/');
+    if (arg)
+        return arg+1;
+    else
+        return __progname;
 }
 #        define GET_PROGRAM_NAME() __getProgramName()
 #    else
 #        define GET_PROGRAM_NAME() ""
-#        warning "Per application configuration won't with your OS version work."
+#        warning "Per application configuration won't work with your OS version."
 #    endif
 #endif
 
@@ -251,7 +260,7 @@ static GLfloat strToF (const XML_Char *string, const XML_Char **tail) {
     string = numStart;
 
     /* scale of the first digit */
-    scale = sign * powf (10.0f, (GLfloat)(pointPos-1 + exponent));
+    scale = sign * (GLfloat)pow (10.0, (GLdouble)(pointPos-1 + exponent));
 
     /* second pass: parse digits */
     do {
@@ -642,13 +651,17 @@ void driParseOptionInfo (driOptionCache *info,
     struct OptInfoData *data = &userData;
     GLuint realNoptions;
 
-  /* determine hash table size and allocate memory */
+  /* determine hash table size and allocate memory:
+   * 3/2 of the number of options, rounded up, so there remains always
+   * at least one free entry. This is needed for detecting undefined
+   * options in configuration files without getting a hash table overflow.
+   * Round this up to a power of two. */
+    GLuint minSize = (nConfigOptions*3 + 1) / 2;
     GLuint size, log2size;
-    for (size = 1, log2size = 0; size < nConfigOptions*3/2;
-        size <<= 1, ++log2size);
+    for (size = 1, log2size = 0; size < minSize; size <<= 1, ++log2size);
     info->tableSize = log2size;
     info->info = CALLOC (size * sizeof (driOptionInfo));
-    info->values = CALLOC (size * sizeof (driOptionInfo));
+    info->values = CALLOC (size * sizeof (driOptionValue));
     if (info->info == NULL || info->values == NULL) {
        fprintf (stderr, "%s: %d: out of memory.\n", __FILE__, __LINE__);
        abort();
@@ -837,7 +850,7 @@ static void optConfEndElem (void *userData, const XML_Char *name) {
 }
 
 /** \brief Initialize an option cache based on info */
-static void initOptionCache (driOptionCache *cache, driOptionCache *info) {
+static void initOptionCache (driOptionCache *cache, const driOptionCache *info) {
     cache->info = info->info;
     cache->tableSize = info->tableSize;
     cache->values = MALLOC ((1<<info->tableSize) * sizeof (driOptionValue));
@@ -888,7 +901,7 @@ static void parseOneConfigFile (XML_Parser p) {
 #undef BUF_SIZE
 }
 
-void driParseConfigFiles (driOptionCache *cache, driOptionCache *info,
+void driParseConfigFiles (driOptionCache *cache, const driOptionCache *info,
                          GLint screenNum, const char *driverName) {
     char *filenames[2] = {"/etc/drirc", NULL};
     char *home;
@@ -900,11 +913,7 @@ void driParseConfigFiles (driOptionCache *cache, driOptionCache *info,
     userData.cache = cache;
     userData.screenNum = screenNum;
     userData.driverName = driverName;
-#ifndef _SOLO    
     userData.execName = GET_PROGRAM_NAME();
-#else
-    userData.execName = "Solo";
-#endif    
 
     if ((home = getenv ("HOME"))) {
        GLuint len = strlen (home);