/** Initialize the BinReloc library (for applications). * * This function must be called before using any other BinReloc functions. * It attempts to locate the application's canonical filename. * * @note If you want to use BinReloc for a library, then you should call * gbr_init_lib() instead. * * @param error If BinReloc failed to initialize, then the error report will * be stored in this variable. Set to NULL if you don't want an * error report. See the #GbrInitError for a list of error * codes. * * @returns TRUE on success, FALSE if BinReloc failed to initialize. */ gboolean gbr_init(GError ** error) { GbrInitError errcode = 0; /* Locate the application's filename. */ exe = _br_find_exe(&errcode); if (exe != NULL) /* Success! */ return TRUE; else { /* Failed :-( */ set_gerror(error, errcode); return FALSE; } }
/* Initialize the BinReloc library (for applications). * * This function must be called before using any other BinReloc functions. * It attempts to locate the application's canonical filename. * * @note If you want to use BinReloc for a library, then you should call * _gimp_reloc_init_lib() instead. * @note Initialization failure is not fatal. BinReloc functions will just * fallback to the supplied default path. * * @param error If BinReloc failed to initialize, then the error report will * be stored in this variable. Set to NULL if you don't want an * error report. See the #GimpBinrelocInitError for a list of error * codes. * * @returns TRUE on success, FALSE if BinReloc failed to initialize. */ gboolean _gimp_reloc_init (GError **error) { GimpBinrelocInitError errcode; /* Shut up compiler warning about uninitialized variable. */ errcode = GIMP_RELOC_INIT_ERROR_NOMEM; /* Locate the application's filename. */ exe = _br_find_exe (&errcode); if (exe != NULL) /* Success! */ return TRUE; else { /* Failed :-( */ set_gerror (error, errcode); return FALSE; } }
/** Initialize the BinReloc library (for applications). * * This function must be called before using any other BinReloc functions. * It attempts to locate the application's canonical filename. * * @note If you want to use BinReloc for a library, then you should call * br_init_lib() instead. * * @param error If BinReloc failed to initialize, then the error code will * be stored in this variable. Set to NULL if you want to * ignore this. See #BrInitError for a list of error codes. * * @returns 1 on success, 0 if BinReloc failed to initialize. */ int br_init (BrInitError *error) { exe = _br_find_exe (error); return exe != NULL; }
/** * ar_runtime_get_directory: * @directory: * * Returns: the path to use for @directory */ const char * ar_runtime_get_directory (ArRuntimeDirectory directory) { char *path = NULL; g_return_val_if_fail (app_name != NULL, NULL); g_return_val_if_fail (directory < AR_RUNTIME_LAST_DIRECTORY, NULL); if (cached_directories[directory]) return cached_directories[directory]; switch ((int) directory) { #ifdef ENABLE_BINRELOC case AR_RUNTIME_PREFIX: #ifdef G_OS_WIN32 path = g_win32_get_package_installation_directory_of_module (NULL); #else { GbrInitError errv = 0; const char *env; if ((env = g_getenv ("AR_RELOC_ROOT")) != NULL) { path = g_strdup (env); } else { char *exe, *bindir, *prefix; exe = _br_find_exe (&errv); if (exe == NULL) { g_printerr ("Failed to locate the binary relocation prefix (error code %u)\n", errv); } else { bindir = g_path_get_dirname (exe); g_free (exe); prefix = g_path_get_dirname (bindir); g_free (bindir); if (prefix != NULL && strcmp (prefix, ".") != 0) { path = prefix; } else { g_free (prefix); } } } } #endif /* G_OS_WIN32 */ break; #else /* !ENABLE_BINRELOC */ case AR_RUNTIME_PREFIX: path = g_strdup (PREFIX); break; case AR_RUNTIME_LIBRARY_DIRECTORY: path = g_strdup (LIBDIR); break; case AR_RUNTIME_DATA_DIRECTORY: path = g_strdup (DATADIR); break; case AR_RUNTIME_PKG_DATA_DIRECTORY: path = g_strdup (PKGDATADIR); break; case AR_RUNTIME_PKG_LIBRARY_DIRECTORY: path = g_strdup (PKGLIBDIR); break; #endif /* ENABLE_BINRELOC */ default: { const DerivedDirectory *base = &derived_directories[directory - AR_RUNTIME_FIRST_DERIVED_DIRECTORY]; path = g_build_filename (ar_runtime_get_directory (base->base_dir), base->name ? base->name : app_name, NULL); } } cached_directories[directory] = path; return path; }