40#if defined __APPLE__ || defined _POSIX_C_SOURCE >= 1 || defined _XOPEN_SOURCE || defined _BSD_SOURCE \
41 || defined _SVID_SOURCE || defined _POSIX_SOURCE || defined __DragonFly__ || defined __FreeBSD__ \
42 || defined __NetBSD__ || defined __OpenBSD__
46#define HAVE_GETPWNAM_R 1
70 char *application_directory = NULL;
74 int length = wai_getExecutablePath(NULL, 0, &dirname_length);
77 application_directory = (
char*)malloc(length + 1);
80 wai_getExecutablePath(application_directory, length, &dirname_length);
82 application_directory[dirname_length] =
'\0';
84 return application_directory;
91 g_strlcpy(localedir, path ? path :
"", bufsize);
96void dt_loc_init(
const char *datadir,
const char *moduledir,
const char *localedir,
const char *configdir,
const char *cachedir,
const char *tmpdir,
const char *kerneldir)
111 dt_free(application_directory);
116 if(
IS_NULL_PTR(user) || g_strcmp0(user, g_get_user_name()) == 0)
118 const char *home_dir = g_getenv(
"HOME");
119 return g_strdup((!
IS_NULL_PTR(home_dir)) ? home_dir : g_get_home_dir());
122#if defined HAVE_GETPWNAM_R
126 struct passwd *result;
127#ifdef _SC_GETPW_R_SIZE_MAX
128 int bufsize = sysconf(_SC_GETPW_R_SIZE_MAX);
137 gchar *buffer = g_malloc0_n(bufsize,
sizeof(gchar));
143 getpwnam_r(user, &pwd, buffer, bufsize, &result);
150 gchar *dir = g_strdup(pwd.pw_dir);
159gchar *
dt_loc_init_generic(
const char *absolute_value,
const char *application_directory,
const char *default_value)
161 gchar *result = NULL;
172 if(application_directory)
177#if defined(__APPLE__)
195 g_snprintf(complete_path,
sizeof(complete_path),
"%s/../Resources%s", application_directory, default_value + 2);
200 g_snprintf(complete_path,
sizeof(complete_path),
"%s/%s", application_directory, default_value);
203 g_snprintf(complete_path,
sizeof(complete_path),
"%s/%s", application_directory, default_value);
205 path = g_strdup(complete_path);
210 path = g_strdup(default_value);
215 if(g_file_test(path, G_FILE_TEST_EXISTS) ==
FALSE) g_mkdir_with_parents(path, 0700);
226 char *default_config_dir = g_build_filename(g_get_user_config_dir(),
"ansel", NULL);
244 const gchar *xdg = g_getenv(
"XDG_CACHE_HOME");
245 if(!
IS_NULL_PTR(xdg) && xdg[0] && g_path_is_absolute(xdg))
return g_build_filename(xdg,
"ansel", NULL);
265 const gchar *local_app_data = g_getenv(
"LOCALAPPDATA");
266 if(
IS_NULL_PTR(local_app_data) || !local_app_data[0]) local_app_data = g_get_user_data_dir();
267 return g_build_filename(local_app_data,
"cache",
"ansel", NULL);
273 return g_build_filename(g_get_home_dir(),
".cache",
"ansel", NULL);
295 fprintf(stderr,
"directory for %s has not been set.\n", context);
300 wchar_t *wdirectory = g_utf8_to_utf16 (
directory, -1, NULL, NULL, NULL);
301 DWORD attribs = GetFileAttributesW(wdirectory);
303 if (attribs != INVALID_FILE_ATTRIBUTES &&
304 (attribs & FILE_ATTRIBUTE_DIRECTORY))
310 fprintf(stderr,
"%s: directory '%s' fails to open.'\n", context,
directory);
322 fprintf(stderr,
"opendir '%s' fails with: '%s'\n",
directory, strerror(errno));
#define DARKTABLE_LOCALEDIR
#define DARKTABLE_KERNELSDIR
#define DARKTABLE_DATADIR
#define DARKTABLE_SHAREDIR
#define DARKTABLE_MODULEDIR
gchar * directory
documentation root given after –doc, or NULL
gchar * dt_loc_default_user_cache_dir(void)
Resolve the default user cache directory the way dt_loc_init_user_cache_dir() does,...
void dt_loc_get_sharedir(char *sharedir, size_t bufsize)
void dt_loc_init_tmp_dir(const char *tmpdir)
const char * dt_loc_moduledir(void)
const char * dt_loc_sharedir(void)
void dt_loc_init_moduledir(const char *application_directory, const char *moduledir)
void dt_loc_get_user_cache_dir(char *cachedir, size_t bufsize)
void dt_loc_get_tmp_dir(char *tmpdir, size_t bufsize)
const char * dt_loc_datadir(void)
const char * dt_loc_cachedir(void)
void dt_loc_get_kerneldir(char *kerneldir, size_t bufsize)
void dt_loc_get_datadir(char *datadir, size_t bufsize)
void dt_loc_get_localedir(char *localedir, size_t bufsize)
gchar * dt_loc_init_generic(const char *absolute_value, const char *application_directory, const char *default_value)
void dt_loc_init_datadir(const char *application_directory, const char *datadir)
void dt_loc_init_user_cache_dir(const char *cachedir)
void dt_loc_init(const char *datadir, const char *moduledir, const char *localedir, const char *configdir, const char *cachedir, const char *tmpdir, const char *kerneldir)
const char * dt_loc_kerneldir(void)
void dt_loc_get_moduledir(char *moduledir, size_t bufsize)
void dt_loc_init_kerneldir(const char *application_directory, const char *kerneldir)
void dt_loc_init_localedir(const char *application_directory, const char *localedir)
const char * dt_loc_tmpdir(void)
void dt_loc_init_sharedir(const char *application_directory)
static char * _application_directory(void)
const char * dt_loc_configdir(void)
void dt_loc_init_user_config_dir(const char *configdir)
void dt_loc_resolve_localedir(char *localedir, size_t bufsize)
Resolve the locale directory the way dt_loc_init() does, creating it if missing, but set no global an...
gchar * dt_loc_get_home_dir(const gchar *user)
void dt_check_opendir(const char *context, const char *directory)
const char * dt_loc_localedir(void)
void dt_loc_get_user_config_dir(char *configdir, size_t bufsize)
static gchar * g_realpath(const char *path)
void dt_print(dt_debug_thread_t thread, const char *msg,...) __attribute__((format(printf
Print to stdout when thread is enabled, prefixed with seconds since startup.
#define IS_NULL_PTR(p)
C is way too permissive with !=, == and if(var) checks, which can mean too many things depending on w...
#define dt_free(ptr)
g_free() ptr and set it to NULL, skipping both if it is already NULL.
char * dt_osx_get_bundle_res_path()
#define DT_PATH_MAX
Buffer size for a filesystem path anywhere in Ansel.
gchar * dt_util_fix_path(const gchar *path)