Last active
December 20, 2015 18:49
-
-
Save sonOfRa/6178469 to your computer and use it in GitHub Desktop.
Tox Config dir Gist
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
/* xdg.c | |
* | |
* Miscellaneous functions and data structures for doing random things. | |
* | |
* Copyright (C) 2013 Tox project All Rights Reserved. | |
* | |
* This file is part of Tox. | |
* | |
* Tox 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. | |
* | |
* Tox 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 Tox. If not, see <http://www.gnu.org/licenses/>. | |
* | |
*/ | |
#include "xdg.h" | |
#include <string.h> | |
#include <stdlib.h> | |
#include <stdio.h> | |
#ifdef __APPLE__ | |
#include <CFString.h> | |
#endif | |
char *get_user_config_dir(void) | |
{ | |
char *user_config_dir; | |
#ifdef __unix | |
if (getenv("XDG_CONFIG_HOME")) return getenv("XDG_CONFIG_HOME"); | |
char *home = getenv("HOME"); | |
char *config = "/.config"; | |
user_config_dir = malloc(strlen(home) + strlen(config) + 1); | |
if (user_config_dir) { | |
strcpy(user_config_dir, home); | |
strcat(user_config_dir, config); | |
} | |
return user_config_dir; | |
#elif defined _win32 | |
return "You are on Windows."; | |
#elif defined __APPLE__ | |
char home[1024]; | |
char *config = "./config"; | |
CFStringGetCString( (CFStringRef)NSHomeDirectory() , home , sizeof(home) , kCFStringEncodingUTF8 ); | |
user_config_dir = malloc(strlen(home) + strlen(config) + 1); | |
if(user_config_dir) { | |
strcpy(user_config_dir, home); | |
strcat(user_config_dir, config); | |
} | |
return user_config_dir; | |
#endif | |
} | |
int main(void) | |
{ | |
char *user_config_dir = get_user_config_dir(); | |
printf("%s\n", user_config_dir); | |
return 0; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment