summaryrefslogtreecommitdiff
path: root/hw/xfree86/common
diff options
context:
space:
mode:
authorAlan Coopersmith <alan.coopersmith@sun.com>2008-11-24 20:34:46 -0800
committerAlan Coopersmith <alan.coopersmith@sun.com>2008-11-24 20:34:46 -0800
commit5bf2c88d2317230b95b2904cb975167d03ee13a2 (patch)
tree4df4b75781010158173a2a25a953b5aae1b8ca15 /hw/xfree86/common
parent75784e1e53ad78e21518696dd9d297bc08c17d54 (diff)
Simplify filename generation code for Xorg -configure
Diffstat (limited to 'hw/xfree86/common')
-rw-r--r--hw/xfree86/common/xf86Configure.c41
1 files changed, 19 insertions, 22 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;
-
- if (home[0] == '/' && home[1] == '\0')
- home[0] = '\0';
- sprintf(filename, "%s/%s", home,configfile);
-
+ } else {
+ /* Determine if trailing slash is present or needed */
+ int l = strlen(home);
+
+ if (home[l-1] != '/') {
+ addslash = "/";
+ }
}
+ snprintf(filename, sizeof(filename), "%s%s" XF86CONFIGFILE ".new",
+ home, addslash);
+
xf86writeConfigFile(filename, xf86config);
xf86DoConfigurePass1 = FALSE;