Skip to content
Browse files

Posix: Follow XDG basedir spec for config dir

This closes issue #12.

Milkytracker will check for a config file in the old directory
`$HOME/.milkytracker_config` and if it exists will move it to the new
XDG basedir compliant directory, but not if one already exists - in case
the user wants to use an older version of Milkytracker with a separate
  • Loading branch information...
Deltafire committed Jul 27, 2015
1 parent 99a7d2e commit eb487c559defe076e380f2d3e16bf4ef45f3990b
Showing with 25 additions and 5 deletions.
  1. +25 −5 src/ppui/osinterface/posix/PPSystem_POSIX.cpp
@@ -34,6 +34,8 @@
#include <string.h>
#include <unistd.h>
#include <limits.h>
#include <sys/stat.h>
#include <sys/types.h>

#ifdef __PSP__
#include <pspkernel.h>
@@ -97,14 +99,32 @@ const SYSCHAR* System::getConfigFileName()
return buffer;
char *home = getenv("HOME");
strcpy(buffer, home);
strcat(buffer, "/.milkytracker_config");
// If $HOME isn't set, save in the current dir
strncpy(buffer, "milkytracker_config", PATH_MAX);
return buffer;
// Old location was in the home directory
char oldLoc[PATH_MAX];
strncpy(oldLoc, home, PATH_MAX);
strncat(oldLoc, "/.milkytracker_config", PATH_MAX);
// New location based on xdg basedir spec
char *xdg_config_home = getenv("XDG_CONFIG_HOME");
strncpy(buffer, xdg_config_home, PATH_MAX);
strcpy(buffer, "milkytracker_config");

strncpy(buffer, home, PATH_MAX);
strncat(buffer, "/.config", PATH_MAX);
mkdir(buffer, S_IRWXU);
strncat(buffer, "/milkytracker", PATH_MAX);
mkdir(buffer, S_IRWXU);
strncat(buffer, "/config", PATH_MAX);
// Move possible existing config into new location if not already present
if(home && access(oldLoc, F_OK) == 0 && access(buffer, F_OK) != 0)
rename(oldLoc, buffer);
return buffer;

0 comments on commit eb487c5

Please sign in to comment.
You can’t perform that action at this time.