Simplify filename generation code for Xorg -configure

This commit is contained in:
Alan Coopersmith 2008-11-24 20:34:46 -08:00
parent 75784e1e53
commit 5bf2c88d23

View File

@ -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;