Search
lxdream.org :: lxdream :: r1205:a486ac64f34b
lxdream 0.9.1
released Jun 29
Download Now
changeset1205:a486ac64f34b
parent1204:c4b725d901b1
child1206:a9b41bcb8410
authornkeynes
dateMon Jan 30 20:11:08 2012 +1000 (7 years ago)
Replace wordexp() with a hand-coded env-var substitution. More portable, and
avoids bugs with some wordexp() implementations
src/Makefile.am
src/Makefile.in
src/lxpaths.c
src/lxpaths.h
src/pvr2/glrender.c
src/test/testlxpaths.c
1.1 --- a/src/Makefile.am Mon Jan 30 17:47:29 2012 +1000
1.2 +++ b/src/Makefile.am Mon Jan 30 20:11:08 2012 +1000
1.3 @@ -13,7 +13,7 @@
1.4 PLUGINLDFLAGS = @PLUGINLDFLAGS@
1.5 bin_PROGRAMS = lxdream
1.6 noinst_PROGRAMS = gendec genglsl genmach
1.7 -check_PROGRAMS = test/testxlt
1.8 +check_PROGRAMS = test/testxlt test/testlxpaths
1.9
1.10 pkglib_PROGRAMS=
1.11 EXTRA_DIST=drivers/genkeymap.pl checkver.pl drivers/dummy.c
1.12 @@ -25,7 +25,7 @@
1.13
1.14 version.c: checkversion
1.15
1.16 -TESTS = test/testxlt
1.17 +TESTS = test/testxlt test/testlxpaths
1.18 BUILT_SOURCES = sh4/sh4core.c sh4/sh4dasm.c sh4/sh4x86.c sh4/sh4stat.c \
1.19 pvr2/shaders.def pvr2/shaders.h drivers/mac_keymap.h version.c
1.20 CLEANFILES = sh4/sh4core.c sh4/sh4dasm.c sh4/sh4x86.c sh4/sh4stat.c \
1.21 @@ -240,6 +240,8 @@
1.22
1.23
1.24 test_testxlt_SOURCES = test/testxlt.c xlat/xltcache.c xlat/xltcache.h
1.25 +test_testlxpaths_SOURCES = test/testlxpaths.c lxpaths.c
1.26 +test_testlxpaths_LDADD = @GLIB_LIBS@
1.27
1.28 sh4/sh4core.c: gendec$(EXEEXT) sh4/sh4.def sh4/sh4core.in
1.29 $(mkdir_p) `dirname $@`
2.1 --- a/src/Makefile.in Mon Jan 30 17:47:29 2012 +1000
2.2 +++ b/src/Makefile.in Mon Jan 30 20:11:08 2012 +1000
2.3 @@ -38,7 +38,8 @@
2.4 host_triplet = @host@
2.5 bin_PROGRAMS = lxdream$(EXEEXT)
2.6 noinst_PROGRAMS = gendec$(EXEEXT) genglsl$(EXEEXT) genmach$(EXEEXT)
2.7 -check_PROGRAMS = test/testxlt$(EXEEXT) $(am__EXEEXT_1)
2.8 +check_PROGRAMS = test/testxlt$(EXEEXT) test/testlxpaths$(EXEEXT) \
2.9 + $(am__EXEEXT_1)
2.10 pkglib_PROGRAMS = $(am__EXEEXT_2) $(am__EXEEXT_3) $(am__EXEEXT_4) \
2.11 $(am__EXEEXT_5) $(am__EXEEXT_6) $(am__EXEEXT_7)
2.12 @BUILD_SHARED_TRUE@am__append_1 = plugin.c plugin.h
2.13 @@ -297,6 +298,10 @@
2.14 lxdream_dummy_@SOEXT@_OBJECTS = $(am_lxdream_dummy_@SOEXT@_OBJECTS)
2.15 @BUILD_SHARED_TRUE@lxdream_dummy_@SOEXT@_DEPENDENCIES = \
2.16 @BUILD_SHARED_TRUE@ lxdream_dummy.lo
2.17 +am_test_testlxpaths_OBJECTS = testlxpaths.$(OBJEXT) lxpaths.$(OBJEXT)
2.18 +test_testlxpaths_OBJECTS = $(am_test_testlxpaths_OBJECTS)
2.19 +test_testlxpaths_DEPENDENCIES =
2.20 +am__dirstamp = $(am__leading_dot)dirstamp
2.21 am__test_testsh4x86_SOURCES_DIST = test/testsh4x86.c x86dasm/x86dasm.c \
2.22 x86dasm/x86dasm.h x86dasm/i386-dis.c x86dasm/dis-init.c \
2.23 x86dasm/dis-buf.c sh4/sh4trans.c sh4/sh4x86.c xlat/xltcache.c \
2.24 @@ -316,7 +321,6 @@
2.25 @BUILD_SH4X86_TRUE@ test_testsh4x86-cpu.$(OBJEXT)
2.26 test_testsh4x86_OBJECTS = $(am_test_testsh4x86_OBJECTS)
2.27 test_testsh4x86_DEPENDENCIES =
2.28 -am__dirstamp = $(am__leading_dot)dirstamp
2.29 am_test_testxlt_OBJECTS = testxlt.$(OBJEXT) xltcache.$(OBJEXT)
2.30 test_testxlt_OBJECTS = $(am_test_testxlt_OBJECTS)
2.31 test_testxlt_LDADD = $(LDADD)
2.32 @@ -336,14 +340,14 @@
2.33 $(audio_pulse_@SOEXT@_SOURCES) $(audio_sdl_@SOEXT@_SOURCES) \
2.34 $(gendec_SOURCES) $(genglsl_SOURCES) $(genmach_SOURCES) \
2.35 $(input_lirc_@SOEXT@_SOURCES) $(lxdream_SOURCES) \
2.36 - $(lxdream_dummy_@SOEXT@_SOURCES) $(test_testsh4x86_SOURCES) \
2.37 - $(test_testxlt_SOURCES)
2.38 + $(lxdream_dummy_@SOEXT@_SOURCES) $(test_testlxpaths_SOURCES) \
2.39 + $(test_testsh4x86_SOURCES) $(test_testxlt_SOURCES)
2.40 DIST_SOURCES = $(audio_alsa_@SOEXT@_SOURCES) \
2.41 $(audio_esd_@SOEXT@_SOURCES) $(audio_pulse_@SOEXT@_SOURCES) \
2.42 $(audio_sdl_@SOEXT@_SOURCES) $(gendec_SOURCES) \
2.43 $(genglsl_SOURCES) $(genmach_SOURCES) \
2.44 $(input_lirc_@SOEXT@_SOURCES) $(am__lxdream_SOURCES_DIST) \
2.45 - $(lxdream_dummy_@SOEXT@_SOURCES) \
2.46 + $(lxdream_dummy_@SOEXT@_SOURCES) $(test_testlxpaths_SOURCES) \
2.47 $(am__test_testsh4x86_SOURCES_DIST) $(test_testxlt_SOURCES)
2.48 ETAGS = etags
2.49 CTAGS = ctags
2.50 @@ -555,7 +559,7 @@
2.51
2.52 EXTRA_DIST = drivers/genkeymap.pl checkver.pl drivers/dummy.c
2.53 AM_CFLAGS = -D__EXTENSIONS__ -D_BSD_SOURCE -D_GNU_SOURCE
2.54 -TESTS = test/testxlt
2.55 +TESTS = test/testxlt test/testlxpaths
2.56 BUILT_SOURCES = sh4/sh4core.c sh4/sh4dasm.c sh4/sh4x86.c sh4/sh4stat.c \
2.57 pvr2/shaders.def pvr2/shaders.h drivers/mac_keymap.h version.c
2.58
2.59 @@ -647,6 +651,8 @@
2.60 genglsl_LDADD = @GLIB_LIBS@ @GTK_LIBS@ $(INTLLIBS)
2.61 genmach_LDADD = @GLIB_LIBS@ @GTK_LIBS@ $(INTLLIBS)
2.62 test_testxlt_SOURCES = test/testxlt.c xlat/xltcache.c xlat/xltcache.h
2.63 +test_testlxpaths_SOURCES = test/testlxpaths.c lxpaths.c
2.64 +test_testlxpaths_LDADD = @GLIB_LIBS@
2.65 all: $(BUILT_SOURCES)
2.66 $(MAKE) $(AM_MAKEFLAGS) all-am
2.67
2.68 @@ -766,6 +772,9 @@
2.69 test/$(am__dirstamp):
2.70 @$(mkdir_p) test
2.71 @: > test/$(am__dirstamp)
2.72 +test/testlxpaths$(EXEEXT): $(test_testlxpaths_OBJECTS) $(test_testlxpaths_DEPENDENCIES) test/$(am__dirstamp)
2.73 + @rm -f test/testlxpaths$(EXEEXT)
2.74 + $(LINK) $(test_testlxpaths_LDFLAGS) $(test_testlxpaths_OBJECTS) $(test_testlxpaths_LDADD) $(LIBS)
2.75 test/testsh4x86$(EXEEXT): $(test_testsh4x86_OBJECTS) $(test_testsh4x86_DEPENDENCIES) test/$(am__dirstamp)
2.76 @rm -f test/testsh4x86$(EXEEXT)
2.77 $(LINK) $(test_testsh4x86_LDFLAGS) $(test_testsh4x86_OBJECTS) $(test_testsh4x86_LDADD) $(LIBS)
2.78 @@ -906,6 +915,7 @@
2.79 @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/lxdream-x86dasm.Po@am__quote@
2.80 @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/lxdream-xltcache.Po@am__quote@
2.81 @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/lxdream-yuv.Po@am__quote@
2.82 +@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/lxpaths.Po@am__quote@
2.83 @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/mdparse.Po@am__quote@
2.84 @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/test_testsh4x86-cpu.Po@am__quote@
2.85 @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/test_testsh4x86-dis-buf.Po@am__quote@
2.86 @@ -919,6 +929,7 @@
2.87 @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/test_testsh4x86-util.Po@am__quote@
2.88 @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/test_testsh4x86-x86dasm.Po@am__quote@
2.89 @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/test_testsh4x86-xltcache.Po@am__quote@
2.90 +@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/testlxpaths.Po@am__quote@
2.91 @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/testxlt.Po@am__quote@
2.92 @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/xltcache.Po@am__quote@
2.93
2.94 @@ -2560,6 +2571,20 @@
2.95 @AMDEP_TRUE@@am__fastdepCC_FALSE@ DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@
2.96 @am__fastdepCC_FALSE@ $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(lxdream_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) -c -o lxdream-joy_linux.obj `if test -f 'drivers/joy_linux.c'; then $(CYGPATH_W) 'drivers/joy_linux.c'; else $(CYGPATH_W) '$(srcdir)/drivers/joy_linux.c'; fi`
2.97
2.98 +testlxpaths.o: test/testlxpaths.c
2.99 +@am__fastdepCC_TRUE@ if $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) -MT testlxpaths.o -MD -MP -MF "$(DEPDIR)/testlxpaths.Tpo" -c -o testlxpaths.o `test -f 'test/testlxpaths.c' || echo '$(srcdir)/'`test/testlxpaths.c; \
2.100 +@am__fastdepCC_TRUE@ then mv -f "$(DEPDIR)/testlxpaths.Tpo" "$(DEPDIR)/testlxpaths.Po"; else rm -f "$(DEPDIR)/testlxpaths.Tpo"; exit 1; fi
2.101 +@AMDEP_TRUE@@am__fastdepCC_FALSE@ source='test/testlxpaths.c' object='testlxpaths.o' libtool=no @AMDEPBACKSLASH@
2.102 +@AMDEP_TRUE@@am__fastdepCC_FALSE@ DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@
2.103 +@am__fastdepCC_FALSE@ $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) -c -o testlxpaths.o `test -f 'test/testlxpaths.c' || echo '$(srcdir)/'`test/testlxpaths.c
2.104 +
2.105 +testlxpaths.obj: test/testlxpaths.c
2.106 +@am__fastdepCC_TRUE@ if $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) -MT testlxpaths.obj -MD -MP -MF "$(DEPDIR)/testlxpaths.Tpo" -c -o testlxpaths.obj `if test -f 'test/testlxpaths.c'; then $(CYGPATH_W) 'test/testlxpaths.c'; else $(CYGPATH_W) '$(srcdir)/test/testlxpaths.c'; fi`; \
2.107 +@am__fastdepCC_TRUE@ then mv -f "$(DEPDIR)/testlxpaths.Tpo" "$(DEPDIR)/testlxpaths.Po"; else rm -f "$(DEPDIR)/testlxpaths.Tpo"; exit 1; fi
2.108 +@AMDEP_TRUE@@am__fastdepCC_FALSE@ source='test/testlxpaths.c' object='testlxpaths.obj' libtool=no @AMDEPBACKSLASH@
2.109 +@AMDEP_TRUE@@am__fastdepCC_FALSE@ DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@
2.110 +@am__fastdepCC_FALSE@ $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) -c -o testlxpaths.obj `if test -f 'test/testlxpaths.c'; then $(CYGPATH_W) 'test/testlxpaths.c'; else $(CYGPATH_W) '$(srcdir)/test/testlxpaths.c'; fi`
2.111 +
2.112 test_testsh4x86-testsh4x86.o: test/testsh4x86.c
2.113 @am__fastdepCC_TRUE@ if $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(test_testsh4x86_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) -MT test_testsh4x86-testsh4x86.o -MD -MP -MF "$(DEPDIR)/test_testsh4x86-testsh4x86.Tpo" -c -o test_testsh4x86-testsh4x86.o `test -f 'test/testsh4x86.c' || echo '$(srcdir)/'`test/testsh4x86.c; \
2.114 @am__fastdepCC_TRUE@ then mv -f "$(DEPDIR)/test_testsh4x86-testsh4x86.Tpo" "$(DEPDIR)/test_testsh4x86-testsh4x86.Po"; else rm -f "$(DEPDIR)/test_testsh4x86-testsh4x86.Tpo"; exit 1; fi
3.1 --- a/src/lxpaths.c Mon Jan 30 17:47:29 2012 +1000
3.2 +++ b/src/lxpaths.c Mon Jan 30 20:11:08 2012 +1000
3.3 @@ -18,7 +18,7 @@
3.4
3.5 #include <ctype.h>
3.6 #include <unistd.h>
3.7 -#include <wordexp.h>
3.8 +#include <stdlib.h>
3.9 #include <glib/gstrfuncs.h>
3.10 #include <glib/gutils.h>
3.11
3.12 @@ -72,37 +72,78 @@
3.13
3.14 gchar *get_expanded_path( const gchar *input )
3.15 {
3.16 - wordexp_t we;
3.17 - if( input == NULL ) {
3.18 + char result[PATH_MAX];
3.19 +
3.20 + char *d, *e;
3.21 + const char *s;
3.22 + d = result;
3.23 + e = result+sizeof(result)-1;
3.24 + s = input;
3.25 +
3.26 + if( input == NULL )
3.27 return NULL;
3.28 +
3.29 + while( *s ) {
3.30 + if( d == e ) {
3.31 + return g_strdup(input); /* expansion too long */
3.32 + }
3.33 + char c = *s++;
3.34 + if( c == '$' ) {
3.35 + if( *s == '{' ) {
3.36 + s++;
3.37 + const char *q = s;
3.38 + while( *q != '}' ) {
3.39 + if( ! *q ) {
3.40 + return g_strdup(input); /* unterminated variable */
3.41 + }
3.42 + q++;
3.43 + }
3.44 + char *tmp = g_strndup(s, (q-s));
3.45 + s = q+1;
3.46 + char *value = getenv(tmp);
3.47 + g_free(tmp);
3.48 + if( value != NULL ) {
3.49 + int len = strlen(value);
3.50 + if( d + len > e )
3.51 + return g_strdup(input);
3.52 + strcpy(d, value);
3.53 + d+=len;
3.54 + } /* Else, empty string */
3.55 + } else {
3.56 + const char *q = s;
3.57 + while( isalnum(*q) || *q == '_' ) {
3.58 + q++;
3.59 + }
3.60 + if( q == s ) {
3.61 + *d++ = '$';
3.62 + } else {
3.63 + char *tmp = g_strndup(s,q-s);
3.64 + s = q;
3.65 + char *value = getenv(tmp);
3.66 + g_free(tmp);
3.67 + if( value != NULL ) {
3.68 + int len = strlen(value);
3.69 + if( d + len > e )
3.70 + return g_strdup(input);
3.71 + strcpy(d, value);
3.72 + d += len;
3.73 + }
3.74 + }
3.75 + }
3.76 + } else if( c == '\\' ) {
3.77 + c = *s++;
3.78 + if( c ) {
3.79 + *d++ = c;
3.80 + } else {
3.81 + *d++ = '\\';
3.82 + }
3.83 + } else {
3.84 + *d++ = c;
3.85 + }
3.86 }
3.87 - memset(&we,0,sizeof(we));
3.88 - int result = wordexp(input, &we, WRDE_NOCMD);
3.89 - if( result != 0 || we.we_wordc == 0 ) {
3.90 - /* On failure, return the original input unchanged */
3.91 - return g_strdup(input);
3.92 - } else {
3.93 - /* On success, concatenate all 'words' together into a single
3.94 - * space-separated string
3.95 - */
3.96 - int length = we.we_wordc, i;
3.97 - gchar *result, *p;
3.98 -
3.99 - for( i=0; i<we.we_wordc; i++ ) {
3.100 - length += strlen(we.we_wordv[i]);
3.101 - }
3.102 - p = result = g_malloc(length);
3.103 - for( i=0; i<we.we_wordc; i++ ) {
3.104 - if( i != 0 )
3.105 - *p++ = ' ';
3.106 - strcpy( p, we.we_wordv[i] );
3.107 - p += strlen(p);
3.108 - }
3.109 - wordfree(&we);
3.110 - return result;
3.111 - }
3.112 + *d = '\0';
3.113 + return g_strdup(result);
3.114 }
3.115 -
3.116 gchar *get_absolute_path( const gchar *in_path )
3.117 {
3.118 char tmp[PATH_MAX];
4.1 --- a/src/lxpaths.h Mon Jan 30 17:47:29 2012 +1000
4.2 +++ b/src/lxpaths.h Mon Jan 30 20:11:08 2012 +1000
4.3 @@ -19,6 +19,8 @@
4.4 #ifndef lxdream_paths_H
4.5 #define lxdream_paths_H
4.6
4.7 +#include <glib/gtypes.h>
4.8 +
4.9 /****************** System paths ****************/
4.10 /**
4.11 * Location of the shared lxdreamrc (e.g. /usr/local/etc/lxdreamrc)
5.1 --- a/src/pvr2/glrender.c Mon Jan 30 17:47:29 2012 +1000
5.2 +++ b/src/pvr2/glrender.c Mon Jan 30 20:11:08 2012 +1000
5.3 @@ -46,10 +46,10 @@
5.4 GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA, GL_DST_ALPHA,
5.5 GL_ONE_MINUS_DST_ALPHA };
5.6 int pvr2_poly_texblend[4] = {
5.7 - GL_REPLACE,
5.8 - GL_MODULATE,
5.9 - GL_DECAL,
5.10 - GL_MODULATE
5.11 + GL_REPLACE,
5.12 + GL_MODULATE,
5.13 + GL_DECAL,
5.14 + GL_MODULATE
5.15 };
5.16
5.17 static gboolean have_shaders = FALSE;
6.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
6.2 +++ b/src/test/testlxpaths.c Mon Jan 30 20:11:08 2012 +1000
6.3 @@ -0,0 +1,105 @@
6.4 +/**
6.5 + * $Id$
6.6 + *
6.7 + * Test cases for path helper functions
6.8 + *
6.9 + * Copyright (c) 2012 Nathan Keynes.
6.10 + *
6.11 + * This program is free software; you can redistribute it and/or modify
6.12 + * it under the terms of the GNU General Public License as published by
6.13 + * the Free Software Foundation; either version 2 of the License, or
6.14 + * (at your option) any later version.
6.15 + *
6.16 + * This program is distributed in the hope that it will be useful,
6.17 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
6.18 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
6.19 + * GNU General Public License for more details.
6.20 + */
6.21 +
6.22 +#include <stdlib.h>
6.23 +#include <stdio.h>
6.24 +#include <string.h>
6.25 +#include <glib/gmem.h>
6.26 +#include "lxpaths.h"
6.27 +
6.28 +char *lxdream_get_global_config_path_value() { }
6.29 +
6.30 +struct expanded_path_case_t {
6.31 + const char *input;
6.32 + const char *output;
6.33 +};
6.34 +
6.35 +char *env_vars[] = { "TEST1=quux", "TEST2=${BLAH}", "TEST3=", "2=3", "TEST_HOME=/home/foo", NULL };
6.36 +const char *unset_env_vars[] = { "PATH_TEST", "1", NULL };
6.37 +struct expanded_path_case_t expanded_path_cases[] = {
6.38 + {NULL, NULL},
6.39 + {"", ""},
6.40 + {"a", "a"},
6.41 + {"$", "$"},
6.42 + {"blah$", "blah$"},
6.43 + {"\\$", "$"},
6.44 + {"foo\\${TEST}\\n\\\\r", "foo${TEST}n\\r"},
6.45 + {"/home/user/.lxdreamrc", "/home/user/.lxdreamrc"},
6.46 + {"${TEST_HOME}/.lxdreamrc", "/home/foo/.lxdreamrc"},
6.47 + {"$TEST_HOME/bar", "/home/foo/bar"},
6.48 + {"/home/$TEST1/blah", "/home/quux/blah"},
6.49 + {"/tmp/${TEST2}/abcd", "/tmp/${BLAH}/abcd"},
6.50 + {"$TEST1$TEST2$TEST3$1$2", "quux${BLAH}3"},
6.51 + {NULL,NULL}
6.52 +};
6.53 +
6.54 +gboolean check_expanded_path( const char *input, const char *output )
6.55 +{
6.56 + char * result = get_expanded_path(input);
6.57 + if( output == NULL ) {
6.58 + if( result != NULL ) {
6.59 + printf( "Unexpected non-null result from get_expanded_path(NULL), got '%s'\n", result );
6.60 + g_free(result);
6.61 + return FALSE;
6.62 + } else {
6.63 + return TRUE;
6.64 + }
6.65 + } else if( result == NULL ) {
6.66 + printf( "Unexpected NULL result from get_expanded_path('%s'), expected '%s'\n", input, output );
6.67 + return FALSE;
6.68 + } else if( strcmp(result, output) != 0 ) {
6.69 + printf( "Unexpected result from get_expanded_path('%s'), expected '%s' but was '%s'\n", input, output, result );
6.70 + g_free(result);
6.71 + return FALSE;
6.72 + } else {
6.73 + g_free(result);
6.74 + return TRUE;
6.75 + }
6.76 +}
6.77 +
6.78 +
6.79 +gboolean test_get_expanded_path()
6.80 +{
6.81 + int count, i;
6.82 + int fails = 0;
6.83 +
6.84 + for( i=0; env_vars[i] != NULL; i++ ) {
6.85 + putenv(env_vars[i]);
6.86 + }
6.87 + for( i=0; unset_env_vars[i] != NULL; i++ ) {
6.88 + unsetenv(unset_env_vars[i]);
6.89 + }
6.90 +
6.91 + for( count=0; expanded_path_cases[count].input != NULL || count == 0; count++ ) {
6.92 + gboolean success = check_expanded_path(expanded_path_cases[count].input, expanded_path_cases[count].output);
6.93 + if( !success )
6.94 + fails ++;
6.95 + }
6.96 + printf( "get_expanded_path: %d/%d (%s)\n", (count-fails), count, (fails == 0 ? "OK" : "ERROR"));
6.97 + return fails == 0 ? TRUE : FALSE;
6.98 +
6.99 + /* FIXME: Should probably restore the env state, but doesn't matter at the moment */
6.100 +}
6.101 +
6.102 +int main()
6.103 +{
6.104 + gboolean result = TRUE;
6.105 + result = test_get_expanded_path() && result;
6.106 +
6.107 + return result ? 0 : 1;
6.108 +}
.