mirror of
https://gitlab.gnome.org/GNOME/glib.git
synced 2025-02-09 20:35:49 +01:00
Changed the win32 part of this function to be thread safe and to make the
2000-04-19 Sebastian Wilhelmi <wilhelmi@ira.uka.de> * gutils.c (g_getenv): Changed the win32 part of this function to be thread safe and to make the returned environment string persistent to match the UN*X behavior. This is again a response to Bug #8983. * glib.h (G_LOCK_NAME): Removed parentheses around the lock name, as that seems to cause problems for some compilers and really isn't necessary.
This commit is contained in:
parent
70ce489b36
commit
e366512775
11
ChangeLog
11
ChangeLog
@ -1,3 +1,14 @@
|
|||||||
|
2000-04-19 Sebastian Wilhelmi <wilhelmi@ira.uka.de>
|
||||||
|
|
||||||
|
* gutils.c (g_getenv): Changed the win32 part of this function to
|
||||||
|
be thread safe and to make the returned environment string
|
||||||
|
persistent to match the UN*X behavior. This is again a response to
|
||||||
|
Bug #8983.
|
||||||
|
|
||||||
|
* glib.h (G_LOCK_NAME): Removed parentheses around the lock name,
|
||||||
|
as that seems to cause problems for some compilers and really
|
||||||
|
isn't necessary.
|
||||||
|
|
||||||
Wed Apr 19 08:32:32 2000 Tim Janik <timj@gtk.org>
|
Wed Apr 19 08:32:32 2000 Tim Janik <timj@gtk.org>
|
||||||
|
|
||||||
* gscanner.c (g_scanner_new): make sure that
|
* gscanner.c (g_scanner_new): make sure that
|
||||||
|
@ -1,3 +1,14 @@
|
|||||||
|
2000-04-19 Sebastian Wilhelmi <wilhelmi@ira.uka.de>
|
||||||
|
|
||||||
|
* gutils.c (g_getenv): Changed the win32 part of this function to
|
||||||
|
be thread safe and to make the returned environment string
|
||||||
|
persistent to match the UN*X behavior. This is again a response to
|
||||||
|
Bug #8983.
|
||||||
|
|
||||||
|
* glib.h (G_LOCK_NAME): Removed parentheses around the lock name,
|
||||||
|
as that seems to cause problems for some compilers and really
|
||||||
|
isn't necessary.
|
||||||
|
|
||||||
Wed Apr 19 08:32:32 2000 Tim Janik <timj@gtk.org>
|
Wed Apr 19 08:32:32 2000 Tim Janik <timj@gtk.org>
|
||||||
|
|
||||||
* gscanner.c (g_scanner_new): make sure that
|
* gscanner.c (g_scanner_new): make sure that
|
||||||
|
@ -1,3 +1,14 @@
|
|||||||
|
2000-04-19 Sebastian Wilhelmi <wilhelmi@ira.uka.de>
|
||||||
|
|
||||||
|
* gutils.c (g_getenv): Changed the win32 part of this function to
|
||||||
|
be thread safe and to make the returned environment string
|
||||||
|
persistent to match the UN*X behavior. This is again a response to
|
||||||
|
Bug #8983.
|
||||||
|
|
||||||
|
* glib.h (G_LOCK_NAME): Removed parentheses around the lock name,
|
||||||
|
as that seems to cause problems for some compilers and really
|
||||||
|
isn't necessary.
|
||||||
|
|
||||||
Wed Apr 19 08:32:32 2000 Tim Janik <timj@gtk.org>
|
Wed Apr 19 08:32:32 2000 Tim Janik <timj@gtk.org>
|
||||||
|
|
||||||
* gscanner.c (g_scanner_new): make sure that
|
* gscanner.c (g_scanner_new): make sure that
|
||||||
|
@ -1,3 +1,14 @@
|
|||||||
|
2000-04-19 Sebastian Wilhelmi <wilhelmi@ira.uka.de>
|
||||||
|
|
||||||
|
* gutils.c (g_getenv): Changed the win32 part of this function to
|
||||||
|
be thread safe and to make the returned environment string
|
||||||
|
persistent to match the UN*X behavior. This is again a response to
|
||||||
|
Bug #8983.
|
||||||
|
|
||||||
|
* glib.h (G_LOCK_NAME): Removed parentheses around the lock name,
|
||||||
|
as that seems to cause problems for some compilers and really
|
||||||
|
isn't necessary.
|
||||||
|
|
||||||
Wed Apr 19 08:32:32 2000 Tim Janik <timj@gtk.org>
|
Wed Apr 19 08:32:32 2000 Tim Janik <timj@gtk.org>
|
||||||
|
|
||||||
* gscanner.c (g_scanner_new): make sure that
|
* gscanner.c (g_scanner_new): make sure that
|
||||||
|
@ -1,3 +1,14 @@
|
|||||||
|
2000-04-19 Sebastian Wilhelmi <wilhelmi@ira.uka.de>
|
||||||
|
|
||||||
|
* gutils.c (g_getenv): Changed the win32 part of this function to
|
||||||
|
be thread safe and to make the returned environment string
|
||||||
|
persistent to match the UN*X behavior. This is again a response to
|
||||||
|
Bug #8983.
|
||||||
|
|
||||||
|
* glib.h (G_LOCK_NAME): Removed parentheses around the lock name,
|
||||||
|
as that seems to cause problems for some compilers and really
|
||||||
|
isn't necessary.
|
||||||
|
|
||||||
Wed Apr 19 08:32:32 2000 Tim Janik <timj@gtk.org>
|
Wed Apr 19 08:32:32 2000 Tim Janik <timj@gtk.org>
|
||||||
|
|
||||||
* gscanner.c (g_scanner_new): make sure that
|
* gscanner.c (g_scanner_new): make sure that
|
||||||
|
@ -1,3 +1,14 @@
|
|||||||
|
2000-04-19 Sebastian Wilhelmi <wilhelmi@ira.uka.de>
|
||||||
|
|
||||||
|
* gutils.c (g_getenv): Changed the win32 part of this function to
|
||||||
|
be thread safe and to make the returned environment string
|
||||||
|
persistent to match the UN*X behavior. This is again a response to
|
||||||
|
Bug #8983.
|
||||||
|
|
||||||
|
* glib.h (G_LOCK_NAME): Removed parentheses around the lock name,
|
||||||
|
as that seems to cause problems for some compilers and really
|
||||||
|
isn't necessary.
|
||||||
|
|
||||||
Wed Apr 19 08:32:32 2000 Tim Janik <timj@gtk.org>
|
Wed Apr 19 08:32:32 2000 Tim Janik <timj@gtk.org>
|
||||||
|
|
||||||
* gscanner.c (g_scanner_new): make sure that
|
* gscanner.c (g_scanner_new): make sure that
|
||||||
|
@ -1,3 +1,14 @@
|
|||||||
|
2000-04-19 Sebastian Wilhelmi <wilhelmi@ira.uka.de>
|
||||||
|
|
||||||
|
* gutils.c (g_getenv): Changed the win32 part of this function to
|
||||||
|
be thread safe and to make the returned environment string
|
||||||
|
persistent to match the UN*X behavior. This is again a response to
|
||||||
|
Bug #8983.
|
||||||
|
|
||||||
|
* glib.h (G_LOCK_NAME): Removed parentheses around the lock name,
|
||||||
|
as that seems to cause problems for some compilers and really
|
||||||
|
isn't necessary.
|
||||||
|
|
||||||
Wed Apr 19 08:32:32 2000 Tim Janik <timj@gtk.org>
|
Wed Apr 19 08:32:32 2000 Tim Janik <timj@gtk.org>
|
||||||
|
|
||||||
* gscanner.c (g_scanner_new): make sure that
|
* gscanner.c (g_scanner_new): make sure that
|
||||||
|
@ -1,3 +1,14 @@
|
|||||||
|
2000-04-19 Sebastian Wilhelmi <wilhelmi@ira.uka.de>
|
||||||
|
|
||||||
|
* gutils.c (g_getenv): Changed the win32 part of this function to
|
||||||
|
be thread safe and to make the returned environment string
|
||||||
|
persistent to match the UN*X behavior. This is again a response to
|
||||||
|
Bug #8983.
|
||||||
|
|
||||||
|
* glib.h (G_LOCK_NAME): Removed parentheses around the lock name,
|
||||||
|
as that seems to cause problems for some compilers and really
|
||||||
|
isn't necessary.
|
||||||
|
|
||||||
Wed Apr 19 08:32:32 2000 Tim Janik <timj@gtk.org>
|
Wed Apr 19 08:32:32 2000 Tim Janik <timj@gtk.org>
|
||||||
|
|
||||||
* gscanner.c (g_scanner_new): make sure that
|
* gscanner.c (g_scanner_new): make sure that
|
||||||
|
2
glib.h
2
glib.h
@ -3130,7 +3130,7 @@ void g_static_rw_lock_free (GStaticRWLock* lock);
|
|||||||
* G_TRYLOCK() respectively.
|
* G_TRYLOCK() respectively.
|
||||||
*/
|
*/
|
||||||
extern void glib_dummy_decl (void);
|
extern void glib_dummy_decl (void);
|
||||||
#define G_LOCK_NAME(name) (g__ ## name ## _lock)
|
#define G_LOCK_NAME(name) g__ ## name ## _lock
|
||||||
#ifdef G_THREADS_ENABLED
|
#ifdef G_THREADS_ENABLED
|
||||||
# define G_LOCK_DEFINE_STATIC(name) static G_LOCK_DEFINE (name)
|
# define G_LOCK_DEFINE_STATIC(name) static G_LOCK_DEFINE (name)
|
||||||
# define G_LOCK_DEFINE(name) \
|
# define G_LOCK_DEFINE(name) \
|
||||||
|
@ -3130,7 +3130,7 @@ void g_static_rw_lock_free (GStaticRWLock* lock);
|
|||||||
* G_TRYLOCK() respectively.
|
* G_TRYLOCK() respectively.
|
||||||
*/
|
*/
|
||||||
extern void glib_dummy_decl (void);
|
extern void glib_dummy_decl (void);
|
||||||
#define G_LOCK_NAME(name) (g__ ## name ## _lock)
|
#define G_LOCK_NAME(name) g__ ## name ## _lock
|
||||||
#ifdef G_THREADS_ENABLED
|
#ifdef G_THREADS_ENABLED
|
||||||
# define G_LOCK_DEFINE_STATIC(name) static G_LOCK_DEFINE (name)
|
# define G_LOCK_DEFINE_STATIC(name) static G_LOCK_DEFINE (name)
|
||||||
# define G_LOCK_DEFINE(name) \
|
# define G_LOCK_DEFINE(name) \
|
||||||
|
@ -379,38 +379,71 @@ g_getenv (const gchar *variable)
|
|||||||
|
|
||||||
return getenv (variable);
|
return getenv (variable);
|
||||||
#else
|
#else
|
||||||
gchar *v;
|
G_LOCK_DEFINE_STATIC (getenv);
|
||||||
guint k;
|
struct env_struct
|
||||||
static gchar *p = NULL;
|
{
|
||||||
static gint l;
|
gchar *key;
|
||||||
|
gchar *value;
|
||||||
|
} *env;
|
||||||
|
static GArray *environs = NULL;
|
||||||
|
gchar *system_env;
|
||||||
|
guint length, i;
|
||||||
gchar dummy[2];
|
gchar dummy[2];
|
||||||
|
|
||||||
g_return_val_if_fail (variable != NULL, NULL);
|
g_return_val_if_fail (variable != NULL, NULL);
|
||||||
|
|
||||||
v = getenv (variable);
|
G_LOCK (getenv);
|
||||||
if (!v)
|
|
||||||
return NULL;
|
if (!environs)
|
||||||
|
environs = g_array_new (FALSE, FALSE, sizeof (struct env_struct));
|
||||||
|
|
||||||
|
/* First we try to find the envinronment variable inside the already
|
||||||
|
* found ones.
|
||||||
|
*/
|
||||||
|
|
||||||
|
for (i = 0; i < environs->len; i++)
|
||||||
|
{
|
||||||
|
env = &g_array_index (environs, struct env_struct, i);
|
||||||
|
if (strcmp (env->key, variable) == 0)
|
||||||
|
{
|
||||||
|
g_assert (env->value);
|
||||||
|
G_UNLOCK (getenv);
|
||||||
|
return env->value;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/* If not found, we ask the system */
|
||||||
|
|
||||||
|
system_env = getenv (variable);
|
||||||
|
if (!system_env)
|
||||||
|
{
|
||||||
|
G_UNLOCK (getenv);
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
|
|
||||||
/* On Windows NT, it is relatively typical that environment variables
|
/* On Windows NT, it is relatively typical that environment variables
|
||||||
* contain references to other environment variables. Handle that by
|
* contain references to other environment variables. Handle that by
|
||||||
* calling ExpandEnvironmentStrings.
|
* calling ExpandEnvironmentStrings.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
g_array_set_size (environs, environs->len + 1);
|
||||||
|
|
||||||
|
env = &g_array_index (environs, struct env_struct, environs->len - 1);
|
||||||
|
|
||||||
/* First check how much space we need */
|
/* First check how much space we need */
|
||||||
k = ExpandEnvironmentStrings (v, dummy, 2);
|
length = ExpandEnvironmentStrings (system_env, dummy, 2);
|
||||||
/* Then allocate that much, and actualy do the expansion */
|
|
||||||
if (p == NULL)
|
/* Then allocate that much, and actualy do the expansion and insert
|
||||||
{
|
* the new found pair into our buffer
|
||||||
p = g_malloc (k);
|
*/
|
||||||
l = k;
|
|
||||||
}
|
env->value = g_malloc (length);
|
||||||
else if (k > l)
|
env->key = g_strdup (variable);
|
||||||
{
|
|
||||||
p = g_realloc (p, k);
|
ExpandEnvironmentStrings (system_env, env->value, length);
|
||||||
l = k;
|
|
||||||
}
|
G_UNLOCK (getenv);
|
||||||
ExpandEnvironmentStrings (v, p, k);
|
return env->value;
|
||||||
return p;
|
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
|
75
gutils.c
75
gutils.c
@ -379,38 +379,71 @@ g_getenv (const gchar *variable)
|
|||||||
|
|
||||||
return getenv (variable);
|
return getenv (variable);
|
||||||
#else
|
#else
|
||||||
gchar *v;
|
G_LOCK_DEFINE_STATIC (getenv);
|
||||||
guint k;
|
struct env_struct
|
||||||
static gchar *p = NULL;
|
{
|
||||||
static gint l;
|
gchar *key;
|
||||||
|
gchar *value;
|
||||||
|
} *env;
|
||||||
|
static GArray *environs = NULL;
|
||||||
|
gchar *system_env;
|
||||||
|
guint length, i;
|
||||||
gchar dummy[2];
|
gchar dummy[2];
|
||||||
|
|
||||||
g_return_val_if_fail (variable != NULL, NULL);
|
g_return_val_if_fail (variable != NULL, NULL);
|
||||||
|
|
||||||
v = getenv (variable);
|
G_LOCK (getenv);
|
||||||
if (!v)
|
|
||||||
return NULL;
|
if (!environs)
|
||||||
|
environs = g_array_new (FALSE, FALSE, sizeof (struct env_struct));
|
||||||
|
|
||||||
|
/* First we try to find the envinronment variable inside the already
|
||||||
|
* found ones.
|
||||||
|
*/
|
||||||
|
|
||||||
|
for (i = 0; i < environs->len; i++)
|
||||||
|
{
|
||||||
|
env = &g_array_index (environs, struct env_struct, i);
|
||||||
|
if (strcmp (env->key, variable) == 0)
|
||||||
|
{
|
||||||
|
g_assert (env->value);
|
||||||
|
G_UNLOCK (getenv);
|
||||||
|
return env->value;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/* If not found, we ask the system */
|
||||||
|
|
||||||
|
system_env = getenv (variable);
|
||||||
|
if (!system_env)
|
||||||
|
{
|
||||||
|
G_UNLOCK (getenv);
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
|
|
||||||
/* On Windows NT, it is relatively typical that environment variables
|
/* On Windows NT, it is relatively typical that environment variables
|
||||||
* contain references to other environment variables. Handle that by
|
* contain references to other environment variables. Handle that by
|
||||||
* calling ExpandEnvironmentStrings.
|
* calling ExpandEnvironmentStrings.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
g_array_set_size (environs, environs->len + 1);
|
||||||
|
|
||||||
|
env = &g_array_index (environs, struct env_struct, environs->len - 1);
|
||||||
|
|
||||||
/* First check how much space we need */
|
/* First check how much space we need */
|
||||||
k = ExpandEnvironmentStrings (v, dummy, 2);
|
length = ExpandEnvironmentStrings (system_env, dummy, 2);
|
||||||
/* Then allocate that much, and actualy do the expansion */
|
|
||||||
if (p == NULL)
|
/* Then allocate that much, and actualy do the expansion and insert
|
||||||
{
|
* the new found pair into our buffer
|
||||||
p = g_malloc (k);
|
*/
|
||||||
l = k;
|
|
||||||
}
|
env->value = g_malloc (length);
|
||||||
else if (k > l)
|
env->key = g_strdup (variable);
|
||||||
{
|
|
||||||
p = g_realloc (p, k);
|
ExpandEnvironmentStrings (system_env, env->value, length);
|
||||||
l = k;
|
|
||||||
}
|
G_UNLOCK (getenv);
|
||||||
ExpandEnvironmentStrings (v, p, k);
|
return env->value;
|
||||||
return p;
|
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user