Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Make VICE respect XDG basedir spec when loading/saving config files
git-svn-id: http://svn.code.sf.net/p/vice-emu/code/trunk@35704 379a1393-f5fb-40a0-bcee-ef074d9b53f7
- Loading branch information
compyx
committed
Oct 28, 2018
1 parent
1dd0fef
commit d54f94b
Showing
6 changed files
with
164 additions
and
6 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,91 @@ | ||
/** \file archdep_xdg.c | ||
* \brief XDG base dir specification support | ||
* \author Bas Wassink <b.wassink@ziggo.nl> | ||
*/ | ||
|
||
/* | ||
* This file is part of VICE, the Versatile Commodore Emulator. | ||
* See README for copyright notice. | ||
* | ||
* This program is free software; you can redistribute it and/or modify | ||
* it under the terms of the GNU General Public License as published by | ||
* the Free Software Foundation; either version 2 of the License, or | ||
* (at your option) any later version. | ||
* | ||
* This program is distributed in the hope that it will be useful, | ||
* but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
* GNU General Public License for more details. | ||
* | ||
* You should have received a copy of the GNU General Public License | ||
* along with this program; if not, write to the Free Software | ||
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA | ||
* 02111-1307 USA. | ||
* | ||
*/ | ||
|
||
#include "vice.h" | ||
#include <stdio.h> | ||
#include <stdlib.h> | ||
#include "lib.h" | ||
|
||
#include "archdep_defs.h" | ||
#include "archdep_home_path.h" | ||
#include "archdep_join_paths.h" | ||
|
||
#include "archdep_xdg.h" | ||
|
||
|
||
/** \brief Get XDG_DATA_HOME | ||
* | ||
* Either returns the value of $XDG_DATA_HOME or the default $HOME/.local/share | ||
* | ||
* \return heap-allocated string, free with lib_free() | ||
*/ | ||
char *archdep_xdg_data_home(void) | ||
{ | ||
const char *path = getenv("XDG_DATA_HOME"); | ||
|
||
if (path != NULL) { | ||
/* got env var, heap-allocate since the archdep_join_paths() function | ||
* also returns a heap-allocated string. | ||
*/ | ||
return lib_stralloc(path); | ||
} | ||
return archdep_join_paths(archdep_home_path(), ".local", "share", NULL); | ||
} | ||
|
||
|
||
/** \brief Get XDG_CONFIG_HOME | ||
* | ||
* Either returns the value of $XDG_CONFIG_HOME or the default $HOME/.config | ||
* | ||
* \return heap-allocated string, free with lib_free() | ||
*/ | ||
char *archdep_xdg_config_home(void) | ||
{ | ||
const char *path = getenv("XDG_CONFIG_HOME"); | ||
|
||
if (path != NULL) { | ||
return lib_stralloc(path); | ||
} | ||
return archdep_join_paths(archdep_home_path(), ".config", NULL); | ||
} | ||
|
||
|
||
/** \brief Get XDG_CACHE_HOME | ||
* | ||
* Either returns the value of $XDG_CACHE_HOME or the default $HOME/.cache | ||
* | ||
* \return heap-allocated string, free with lib_free() | ||
*/ | ||
char *archdep_xdg_cache_home(void) | ||
{ | ||
const char *path = getenv("XDG_CACHE_HOME"); | ||
|
||
if (path != NULL) { | ||
return lib_stralloc(path); | ||
} | ||
return archdep_join_paths(archdep_home_path(), ".cache", NULL); | ||
} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
/** \file archdep_xdg.g | ||
* \brief XDG base dir specification support - header | ||
* \author Bas Wassink <b.wassink@ziggo.nl> | ||
*/ | ||
|
||
/* | ||
* This file is part of VICE, the Versatile Commodore Emulator. | ||
* See README for copyright notice. | ||
* | ||
* This program is free software; you can redistribute it and/or modify | ||
* it under the terms of the GNU General Public License as published by | ||
* the Free Software Foundation; either version 2 of the License, or | ||
* (at your option) any later version. | ||
* | ||
* This program is distributed in the hope that it will be useful, | ||
* but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
* GNU General Public License for more details. | ||
* | ||
* You should have received a copy of the GNU General Public License | ||
* along with this program; if not, write to the Free Software | ||
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA | ||
* 02111-1307 USA. | ||
* | ||
*/ | ||
|
||
#ifndef VICE_ARCHDEP_XDG_H | ||
#define VICE_ARCHDEP_XDG_H | ||
|
||
char *archdep_xdg_data_home(void); | ||
char *archdep_xdg_config_home(void); | ||
char *archdep_xdg_cache_home(void); | ||
|
||
#endif |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters