Skip to content

Instantly share code, notes, and snippets.

@shizeeg
Last active December 15, 2015 22:39
Show Gist options
  • Save shizeeg/5334901 to your computer and use it in GitHub Desktop.
Save shizeeg/5334901 to your computer and use it in GitHub Desktop.
XDG Directories.
/****************************************************************************
* xdg-dirs show XDG environment variables.
* Copyright (C) 2013 sh!zeeg <shizeeg@ya.ru>
*
* 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 3 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, see <http://www.gnu.org/licenses/>.
****************************************************************************/
#include <stdio.h>
#include <stdlib.h>
int main(int argc, char *argv[])
{
const char *XDGDIRS[] = {
"XDG_DATA_HOME",
"XDG_CONFIG_HOME",
"XDG_DATA_DIRS",
"XDG_CONFIG_DIRS",
"XDG_CACHE_HOME",
"XDG_RUNTIME_DIR"
};
int MAXVAR = sizeof(XDGDIRS) / sizeof(XDGDIRS[0]);
int i;
if (argc > 1)
{
char *env;
for (i = 1; i < argc; i++)
{
printf("%s\t= %s\n", argv[i], getenv(argv[i]));
}
return argc;
}
for (i = 0; i < MAXVAR; i++)
{
printf("%s\t= %s\n", XDGDIRS[i], getenv(XDGDIRS[i]));
}
return MAXVAR;
}
// vim: ts=8:sw=8:et
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment