Beispiel #1
0
static char* GetPath_XDG_CACHE_HOME(void)
{
	char* path = NULL;
	char* home = NULL;
#if defined(WIN32)
	home = GetPath_XDG_RUNTIME_DIR();

	if (home)
	{
		path = GetCombinedPath(home, "cache");

		if (!PathFileExistsA(path))
			if (!CreateDirectoryA(path, NULL))
				path = NULL;
	}

	free(home);
#else
	/**
	 * There is a single base directory relative to which user-specific non-essential (cached) data should be written.
	 * This directory is defined by the environment variable $XDG_CACHE_HOME.
	 *
	 * $XDG_CACHE_HOME defines the base directory relative to which user specific non-essential data files should be stored.
	 * If $XDG_CACHE_HOME is either not set or empty, a default equal to $HOME/.cache should be used.
	 */
	path = GetEnvAlloc("XDG_CACHE_HOME");

	if (path)
		return path;

	home = GetPath_HOME();

	if (!home)
		return NULL;

	path = (char*) malloc(strlen(home) + strlen("/.cache") + 1);

	if (!path)
	{
		free(home);
		return NULL;
	}

	sprintf(path, "%s%s", home, "/.cache");
	free(home);
#endif
	return path;
}
Beispiel #2
0
char* GetKnownPath(int id)
{
	char* path = NULL;

	switch (id)
	{
		case KNOWN_PATH_HOME:
			path = GetPath_HOME();
			break;

		case KNOWN_PATH_TEMP:
			path = GetPath_TEMP();

			break;

		case KNOWN_PATH_XDG_DATA_HOME:
			path = GetPath_XDG_DATA_HOME();
			break;

		case KNOWN_PATH_XDG_CONFIG_HOME:
			path = GetPath_XDG_CONFIG_HOME();
			break;

		case KNOWN_PATH_XDG_CACHE_HOME:
			path = GetPath_XDG_CACHE_HOME();
			break;

		case KNOWN_PATH_XDG_RUNTIME_DIR:
			path = GetPath_XDG_RUNTIME_DIR();
			break;

		default:
			path = NULL;
			break;
	}

	return path;
}