From 5bf2c88d2317230b95b2904cb975167d03ee13a2 Mon Sep 17 00:00:00 2001 From: Alan Coopersmith Date: Mon, 24 Nov 2008 20:34:46 -0800 Subject: [PATCH] Simplify filename generation code for Xorg -configure --- hw/xfree86/common/xf86Configure.c | 39 ++++++++++++++----------------- 1 file changed, 18 insertions(+), 21 deletions(-) diff --git a/hw/xfree86/common/xf86Configure.c b/hw/xfree86/common/xf86Configure.c index 6680a618e..777806043 100644 --- a/hw/xfree86/common/xf86Configure.c +++ b/hw/xfree86/common/xf86Configure.c @@ -662,12 +662,17 @@ configureDDCMonitorSection (int screennum) return ptr; } +#if !defined(PATH_MAX) +# define PATH_MAX 1024 +#endif + void -DoConfigure() +DoConfigure(void) { int i,j, screennum = -1; char *home = NULL; - char *filename = NULL; + char filename[PATH_MAX]; + char *addslash = ""; XF86ConfigPtr xf86config = NULL; char **vlist, **vl; int *dev2screen; @@ -765,29 +770,21 @@ DoConfigure() xf86config->conf_input_lst = configureInputSection(); xf86config->conf_layout_lst = configureLayoutSection(); - if (!(home = getenv("HOME"))) + home = getenv("HOME"); + if ((home == NULL) || (home[0] = '\0')) { home = "/"; - { -#if !defined(PATH_MAX) -#define PATH_MAX 1024 -#endif - const char* configfile = XF86CONFIGFILE".new"; - char homebuf[PATH_MAX]; - /* getenv might return R/O memory, as with OS/2 */ - strncpy(homebuf,home,PATH_MAX-1); - homebuf[PATH_MAX-1] = '\0'; - home = homebuf; - if (!(filename = - (char *)xalloc(strlen(home) + - strlen(configfile) + 3))) - goto bail; + } else { + /* Determine if trailing slash is present or needed */ + int l = strlen(home); - if (home[0] == '/' && home[1] == '\0') - home[0] = '\0'; - sprintf(filename, "%s/%s", home,configfile); - + if (home[l-1] != '/') { + addslash = "/"; + } } + snprintf(filename, sizeof(filename), "%s%s" XF86CONFIGFILE ".new", + home, addslash); + xf86writeConfigFile(filename, xf86config); xf86DoConfigurePass1 = FALSE;