/* Set the environmnent required by the SWT Browser widget to bind to Mozilla.
* The SWT Browser widget relies on Mozilla on Linux. The LD_LIBRARY_PATH
* and the Mozilla environment variable MOZILLA_FIVE_HOME must point
* to the installation directory of Mozilla.
*
* 1. Use the location set by MOZILLA_FIVE_HOME if it is defined
* 2. Parse the file /etc/gre.conf if it is defined. This file is
* set by the RedtHat RPM manager.
*/
#ifdef MOZILLA_FIX
void fixEnvForMozilla() {
static int fixed = 0;
if (fixed) return;
{
char *ldPath = (char*)getenv("LD_LIBRARY_PATH");
char *mozillaFiveHome = (char*)getenv("MOZILLA_FIVE_HOME");
char *grePath = NULL; /* Gecko Runtime Environment Location */
char *XPCOM_LIB = "libxpcom.so";
fixed = 1;
/* Always dup the string so we can free later */
if (ldPath != NULL) ldPath = strdup(ldPath);
else ldPath = strdup("");
/* MOZILLA_FIVE_HOME (if defined) points to the Mozilla
* install directory. Don't look any further if it is set.
*/
if (mozillaFiveHome != NULL)
{
grePath = strdup(mozillaFiveHome);
}
/* The file gre.conf (if available) points to the
* Mozilla install directory. Don't look any further if
* it is set.
*/
if (grePath == NULL)
{
struct stat buf;
FILE *file = NULL;
#if defined(__amd64__) || defined(__x86_64__)
if (stat("/etc/gre64.conf", &buf) == 0)
{
file = fopen("/etc/gre64.conf", "r");
}
else if (stat("/etc/gre.d/gre64.conf", &buf) == 0)
{
file = fopen("/etc/gre.d/gre64.conf", "r");
} else
#endif
if (stat("/etc/gre.conf", &buf) == 0)
{
file = fopen("/etc/gre.conf", "r");
}
else if (stat("/etc/gre.d/gre.conf", &buf) == 0)
{
file = fopen("/etc/gre.d/gre.conf", "r");
}
if (file != NULL)
{
char buffer[1024];
char path[1024];
while (fgets(buffer, 1024, file) != NULL)
{
if (sscanf(buffer, "GRE_PATH=%s", path) == 1)
{
grePath = strdup(path);
break;
}
}
fclose(file);
}
}
if (grePath != NULL)
{
ldPath = (char*)realloc(ldPath, strlen(ldPath) + strlen(grePath) + 2);
if (strlen(ldPath) > 0) strcat(ldPath, ":");
strcat(ldPath, grePath);
setenv("LD_LIBRARY_PATH", ldPath, 1);
if (mozillaFiveHome == NULL) setenv("MOZILLA_FIVE_HOME", grePath, 1);
free(grePath);
}
free(ldPath);
}
}
#endif /* MOZILLA_FIX */