#include <unistd.h>
#include <errno.h>
#include "main/imports.h"
-#include "dri_util.h"
+#include "utils.h"
#include "xmlconfig.h"
-/*
- * OS dependent ways of getting the name of the running program
- */
-#if (defined(__unix__) || defined(unix)) && !defined(USG)
-#include <sys/param.h>
-#endif
-
#undef GET_PROGRAM_NAME
#if (defined(__GNU_LIBRARY__) || defined(__GLIBC__)) && !defined(__UCLIBC__)
#elif defined(__NetBSD__) && defined(__NetBSD_Version) && (__NetBSD_Version >= 106000100)
# include <stdlib.h>
# define GET_PROGRAM_NAME() getprogname()
+#elif defined(__APPLE__)
+# include <stdlib.h>
+# define GET_PROGRAM_NAME() getprogname()
#elif defined(__sun)
/* Solaris has getexecname() which returns the full path - return just
the basename to match BSD getprogname() */
# include <stdlib.h>
# include <libgen.h>
-# define GET_PROGRAM_NAME() basename(getexecname())
+
+static const char *__getProgramName () {
+ static const char *progname;
+
+ if (progname == NULL) {
+ const char *e = getexecname();
+ if (e != NULL) {
+ /* Have to make a copy since getexecname can return a readonly
+ string, but basename expects to be able to modify its arg. */
+ char *n = strdup(e);
+ if (n != NULL) {
+ progname = basename(n);
+ }
+ }
+ }
+ return progname;
+}
+
+# define GET_PROGRAM_NAME() __getProgramName()
#endif
#if !defined(GET_PROGRAM_NAME)
-# if defined(OpenBSD) || defined(NetBSD) || defined(__UCLIBC__)
+# if defined(__OpenBSD__) || defined(NetBSD) || defined(__UCLIBC__) || defined(ANDROID)
/* 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. */
return count;
}
-/** \brief Like strdup but using MALLOC and with error checking. */
+/** \brief Like strdup but using malloc and with error checking. */
#define XSTRDUP(dest,source) do { \
GLuint len = strlen (source); \
- if (!(dest = MALLOC (len+1))) { \
+ if (!(dest = malloc(len+1))) { \
fprintf (stderr, "%s: %d: out of memory.\n", __FILE__, __LINE__); \
abort(); \
} \
*
* Works similar to strtod. Leading space is NOT skipped. The input
* number may have an optional sign. '.' is interpreted as decimal
- * point and may occor at most once. Optionally the number may end in
+ * point and may occur at most once. Optionally the number may end in
* [eE]<exponent>, where <exponent> is an integer as recognized by
* strToI. In that case the result is number * 10^exponent. After
* returning tail points to the first character that is not part of
if (*range == ',')
++nRanges;
- if ((ranges = MALLOC (nRanges*sizeof(driOptionRange))) == NULL) {
+ if ((ranges = malloc(nRanges*sizeof(driOptionRange))) == NULL) {
fprintf (stderr, "%s: %d: out of memory.\n", __FILE__, __LINE__);
abort();
}
else
range = NULL;
}
- FREE (cp);
+ free(cp);
if (i < nRanges) {
- FREE (ranges);
+ free(ranges);
return GL_FALSE;
} else
assert (range == NULL);
return GL_FALSE;
}
+/**
+ * Print message to \c stderr if the \c LIBGL_DEBUG environment variable
+ * is set.
+ *
+ * Is called from the drivers.
+ *
+ * \param f \c printf like format string.
+ */
+static void
+__driUtilMessage(const char *f, ...)
+{
+ va_list args;
+
+ if (getenv("LIBGL_DEBUG")) {
+ fprintf(stderr, "libGL: ");
+ va_start(args, f);
+ vfprintf(stderr, f, args);
+ va_end(args);
+ fprintf(stderr, "\n");
+ }
+}
+
/** \brief Output a warning message. */
#define XML_WARNING1(msg) do {\
__driUtilMessage ("Warning in %s line %d, column %d: "msg, data->name, \
} else
defaultVal = attrVal[OA_DEFAULT];
if (!parseValue (&cache->values[opt], cache->info[opt].type, defaultVal))
- XML_FATAL ("illegal default value: %s.", defaultVal);
+ XML_FATAL ("illegal default value for %s: %s.", cache->info[opt].name, defaultVal);
if (attrVal[OA_VALID]) {
if (cache->info[opt].type == DRI_BOOL)
GLuint size, 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 (driOptionValue));
+ info->info = 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();
for (i = 0; attr[i]; i += 2) {
if (!strcmp (attr[i], "driver")) driver = attr[i+1];
else if (!strcmp (attr[i], "screen")) screen = attr[i+1];
- else XML_WARNING("unkown device attribute: %s.", attr[i]);
+ else XML_WARNING("unknown device attribute: %s.", attr[i]);
}
if (driver && strcmp (driver, data->driverName))
data->ignoringDevice = data->inDevice;
/** \brief Parse attributes of an application element. */
static void parseAppAttr (struct OptConfData *data, const XML_Char **attr) {
GLuint i;
- const XML_Char *name = NULL, *exec = NULL;
+ const XML_Char *exec = NULL;
for (i = 0; attr[i]; i += 2) {
- if (!strcmp (attr[i], "name")) name = attr[i+1];
+ if (!strcmp (attr[i], "name")) /* not needed here */;
else if (!strcmp (attr[i], "executable")) exec = attr[i+1];
- else XML_WARNING("unkown application attribute: %s.", attr[i]);
+ else XML_WARNING("unknown application attribute: %s.", attr[i]);
}
if (exec && strcmp (exec, data->execName))
data->ignoringApp = data->inApp;
for (i = 0; attr[i]; i += 2) {
if (!strcmp (attr[i], "name")) name = attr[i+1];
else if (!strcmp (attr[i], "value")) value = attr[i+1];
- else XML_WARNING("unkown option attribute: %s.", attr[i]);
+ else XML_WARNING("unknown option attribute: %s.", attr[i]);
}
if (!name) XML_WARNING1 ("name attribute missing in option.");
if (!value) XML_WARNING1 ("value attribute missing in option.");
static void initOptionCache (driOptionCache *cache, const driOptionCache *info) {
cache->info = info->info;
cache->tableSize = info->tableSize;
- cache->values = MALLOC ((1<<info->tableSize) * sizeof (driOptionValue));
+ cache->values = malloc((1<<info->tableSize) * sizeof (driOptionValue));
if (cache->values == NULL) {
fprintf (stderr, "%s: %d: out of memory.\n", __FILE__, __LINE__);
abort();
if ((home = getenv ("HOME"))) {
GLuint len = strlen (home);
- filenames[1] = MALLOC (len + 7+1);
+ filenames[1] = malloc(len + 7+1);
if (filenames[1] == NULL)
__driUtilMessage ("Can't allocate memory for %s/.drirc.", home);
else {
XML_ParserFree (p);
}
- if (filenames[1])
- FREE (filenames[1]);
+ free(filenames[1]);
}
void driDestroyOptionInfo (driOptionCache *info) {
GLuint i, size = 1 << info->tableSize;
for (i = 0; i < size; ++i) {
if (info->info[i].name) {
- FREE (info->info[i].name);
- if (info->info[i].ranges)
- FREE (info->info[i].ranges);
+ free(info->info[i].name);
+ free(info->info[i].ranges);
}
}
- FREE (info->info);
+ free(info->info);
}
}
void driDestroyOptionCache (driOptionCache *cache) {
- if (cache->values)
- FREE (cache->values);
+ free(cache->values);
}
GLboolean driCheckOption (const driOptionCache *cache, const char *name,