Back to index

gcompris  8.2.2
Defines | Enumerations | Functions
binreloc.h File Reference
#include <glib.h>
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Defines

#define gbr_find_exe   nafN51135257527955_gbr_find_exe
#define gbr_find_exe_dir   nafN51135257527955_gbr_find_exe_dir
#define gbr_find_prefix   nafN51135257527955_gbr_find_prefix
#define gbr_find_bin_dir   nafN51135257527955_gbr_find_bin_dir
#define gbr_find_sbin_dir   nafN51135257527955_gbr_find_sbin_dir
#define gbr_find_data_dir   nafN51135257527955_gbr_find_data_dir
#define gbr_find_locale_dir   nafN51135257527955_gbr_find_locale_dir
#define gbr_find_lib_dir   nafN51135257527955_gbr_find_lib_dir
#define gbr_find_libexec_dir   nafN51135257527955_gbr_find_libexec_dir
#define gbr_find_etc_dir   nafN51135257527955_gbr_find_etc_dir

Enumerations

enum  GbrInitError {
  GBR_INIT_ERROR_NOMEM, GBR_INIT_ERROR_OPEN_MAPS, GBR_INIT_ERROR_READ_MAPS, GBR_INIT_ERROR_INVALID_MAPS,
  GBR_INIT_ERROR_DISABLED
}
 These error codes can be returned by br_init(), br_init_lib(), gbr_init() or gbr_init_lib(). More...

Functions

gboolean gbr_init (GError **error)
 Initialize the BinReloc library (for applications).
gboolean gbr_init_lib (GError **error)
 Initialize the BinReloc library (for libraries).
gchar * gbr_find_exe (const gchar *default_exe)
 Find the canonical filename of the current application.
gchar * gbr_find_exe_dir (const gchar *default_dir)
 Locate the directory in which the current application is installed.
gchar * gbr_find_prefix (const gchar *default_prefix)
 Locate the prefix in which the current application is installed.
gchar * gbr_find_bin_dir (const gchar *default_bin_dir)
 Locate the application's binary folder.
gchar * gbr_find_sbin_dir (const gchar *default_sbin_dir)
 Locate the application's superuser binary folder.
gchar * gbr_find_data_dir (const gchar *default_data_dir)
 Locate the application's data folder.
gchar * gbr_find_locale_dir (const gchar *default_locale_dir)
 Locate the application's localization folder.
gchar * gbr_find_lib_dir (const gchar *default_lib_dir)
 Locate the application's library folder.
gchar * gbr_find_libexec_dir (const gchar *default_libexec_dir)
 Locate the application's libexec folder.
gchar * gbr_find_etc_dir (const gchar *default_etc_dir)
 Locate the application's configuration files folder.

Define Documentation

#define gbr_find_bin_dir   nafN51135257527955_gbr_find_bin_dir

Definition at line 41 of file binreloc.h.

#define gbr_find_data_dir   nafN51135257527955_gbr_find_data_dir

Definition at line 43 of file binreloc.h.

#define gbr_find_etc_dir   nafN51135257527955_gbr_find_etc_dir

Definition at line 47 of file binreloc.h.

#define gbr_find_exe   nafN51135257527955_gbr_find_exe

Definition at line 38 of file binreloc.h.

#define gbr_find_exe_dir   nafN51135257527955_gbr_find_exe_dir

Definition at line 39 of file binreloc.h.

#define gbr_find_lib_dir   nafN51135257527955_gbr_find_lib_dir

Definition at line 45 of file binreloc.h.

#define gbr_find_libexec_dir   nafN51135257527955_gbr_find_libexec_dir

Definition at line 46 of file binreloc.h.

#define gbr_find_locale_dir   nafN51135257527955_gbr_find_locale_dir

Definition at line 44 of file binreloc.h.

#define gbr_find_prefix   nafN51135257527955_gbr_find_prefix

Definition at line 40 of file binreloc.h.

#define gbr_find_sbin_dir   nafN51135257527955_gbr_find_sbin_dir

Definition at line 42 of file binreloc.h.


Enumeration Type Documentation

These error codes can be returned by br_init(), br_init_lib(), gbr_init() or gbr_init_lib().

Enumerator:
GBR_INIT_ERROR_NOMEM 

Cannot allocate memory.

GBR_INIT_ERROR_OPEN_MAPS 

Unable to open /proc/self/maps; see errno for details.

GBR_INIT_ERROR_READ_MAPS 

Unable to read from /proc/self/maps; see errno for details.

GBR_INIT_ERROR_INVALID_MAPS 

The file format of /proc/self/maps is invalid; kernel bug?

GBR_INIT_ERROR_DISABLED 

BinReloc is disabled (the ENABLE_BINRELOC macro is not defined).

Definition at line 22 of file binreloc.h.


Function Documentation

gchar* gbr_find_bin_dir ( const gchar *  default_bin_dir)

Locate the application's binary folder.

The path is generated by the following pseudo-code evaluation:

 prefix + "/bin"
Parameters:
default_bin_dirA default path which will used as fallback.
Returns:
A string containing the bin folder's path, which must be freed when no longer necessary. If BinReloc is not initialized, or if the initialization function failed, then a copy of default_bin_dir will be returned. If default_bin_dir is NULL, then NULL will be returned.

Definition at line 478 of file binreloc.c.

{
       gchar *prefix, *dir;

       prefix = gbr_find_prefix (NULL);
       if (prefix == NULL) {
              /* BinReloc not initialized. */
              if (default_bin_dir != NULL)
                     return g_strdup (default_bin_dir);
              else
                     return NULL;
       }

       dir = g_build_filename (prefix, "bin", NULL);
       g_free (prefix);
       return dir;
}
gchar* gbr_find_data_dir ( const gchar *  default_data_dir)

Locate the application's data folder.

The path is generated by the following pseudo-code evaluation:

 prefix + "/share"
Parameters:
default_data_dirA default path which will used as fallback.
Returns:
A string containing the data folder's path, which must be freed when no longer necessary. If BinReloc is not initialized, or if the initialization function failed, then a copy of default_data_dir will be returned. If default_data_dir is NULL, then NULL will be returned.

Definition at line 545 of file binreloc.c.

{
       gchar *prefix, *dir;

       prefix = gbr_find_prefix (NULL);
       if (prefix == NULL) {
              /* BinReloc not initialized. */
              if (default_data_dir != NULL)
                     return g_strdup (default_data_dir);
              else
                     return NULL;
       }

       dir = g_build_filename (prefix, "share", NULL);
       g_free (prefix);
       return dir;
}
gchar* gbr_find_etc_dir ( const gchar *  default_etc_dir)

Locate the application's configuration files folder.

The path is generated by the following pseudo-code evaluation:

 prefix + "/etc"
Parameters:
default_etc_dirA default path which will used as fallback.
Returns:
A string containing the etc folder's path, which must be freed when no longer necessary. If BinReloc is not initialized, or if the initialization function failed, then a copy of default_etc_dir will be returned. If default_etc_dir is NULL, then NULL will be returned.

Definition at line 677 of file binreloc.c.

{
       gchar *prefix, *dir;

       prefix = gbr_find_prefix (NULL);
       if (prefix == NULL) {
              /* BinReloc not initialized. */
              if (default_etc_dir != NULL)
                     return g_strdup (default_etc_dir);
              else
                     return NULL;
       }

       dir = g_build_filename (prefix, "etc", NULL);
       g_free (prefix);
       return dir;
}
gchar* gbr_find_exe ( const gchar *  default_exe)

Find the canonical filename of the current application.

Parameters:
default_exeA default filename which will be used as fallback.
Returns:
A string containing the application's canonical filename, which must be freed when no longer necessary. If BinReloc is not initialized, or if the initialization function failed, then a copy of default_exe will be returned. If default_exe is NULL, then NULL will be returned.

Definition at line 388 of file binreloc.c.

{
       if (exe == NULL) {
              /* BinReloc is not initialized. */
              if (default_exe != NULL)
                     return g_strdup (default_exe);
              else
                     return NULL;
       }
       return g_strdup (exe);
}
gchar* gbr_find_exe_dir ( const gchar *  default_dir)

Locate the directory in which the current application is installed.

The prefix is generated by the following pseudo-code evaluation:

 dirname(exename)
Parameters:
default_dirA default directory which will used as fallback.
Returns:
A string containing the directory, which must be freed when no longer necessary. If BinReloc is not initialized, or if the initialization function failed, then a copy of default_dir will be returned. If default_dir is NULL, then NULL will be returned.

Definition at line 416 of file binreloc.c.

{
       if (exe == NULL) {
              /* BinReloc not initialized. */
              if (default_dir != NULL)
                     return g_strdup (default_dir);
              else
                     return NULL;
       }

       return g_path_get_dirname (exe);
}
gchar* gbr_find_lib_dir ( const gchar *  default_lib_dir)

Locate the application's library folder.

The path is generated by the following pseudo-code evaluation:

 prefix + "/lib"
Parameters:
default_lib_dirA default path which will used as fallback.
Returns:
A string containing the library folder's path, which must be freed when no longer necessary. If BinReloc is not initialized, or if the initialization function failed, then a copy of default_lib_dir will be returned. If default_lib_dir is NULL, then NULL will be returned.

Definition at line 611 of file binreloc.c.

{
       gchar *prefix, *dir;

       prefix = gbr_find_prefix (NULL);
       if (prefix == NULL) {
              /* BinReloc not initialized. */
              if (default_lib_dir != NULL)
                     return g_strdup (default_lib_dir);
              else
                     return NULL;
       }

       dir = g_build_filename (prefix, "lib", NULL);
       g_free (prefix);
       return dir;
}
gchar* gbr_find_libexec_dir ( const gchar *  default_libexec_dir)

Locate the application's libexec folder.

The path is generated by the following pseudo-code evaluation:

 prefix + "/libexec"
Parameters:
default_libexec_dirA default path which will used as fallback.
Returns:
A string containing the libexec folder's path, which must be freed when no longer necessary. If BinReloc is not initialized, or if the initialization function failed, then a copy of default_libexec_dir will be returned. If default_libexec_dir is NULL, then NULL will be returned.

Definition at line 644 of file binreloc.c.

{
       gchar *prefix, *dir;

       prefix = gbr_find_prefix (NULL);
       if (prefix == NULL) {
              /* BinReloc not initialized. */
              if (default_libexec_dir != NULL)
                     return g_strdup (default_libexec_dir);
              else
                     return NULL;
       }

       dir = g_build_filename (prefix, "libexec", NULL);
       g_free (prefix);
       return dir;
}
gchar* gbr_find_locale_dir ( const gchar *  default_locale_dir)

Locate the application's localization folder.

The path is generated by the following pseudo-code evaluation:

 prefix + "/share/locale"
Parameters:
default_locale_dirA default path which will used as fallback.
Returns:
A string containing the localization folder's path, which must be freed when no longer necessary. If BinReloc is not initialized, or if the initialization function failed, then a copy of default_locale_dir will be returned. If default_locale_dir is NULL, then NULL will be returned.

Definition at line 578 of file binreloc.c.

{
       gchar *data_dir, *dir;

       data_dir = gbr_find_data_dir (NULL);
       if (data_dir == NULL) {
              /* BinReloc not initialized. */
              if (default_locale_dir != NULL)
                     return g_strdup (default_locale_dir);
              else
                     return NULL;
       }

       dir = g_build_filename (data_dir, "locale", NULL);
       g_free (data_dir);
       return dir;
}
gchar* gbr_find_prefix ( const gchar *  default_prefix)

Locate the prefix in which the current application is installed.

The prefix is generated by the following pseudo-code evaluation:

 dirname(dirname(exename))
Parameters:
default_prefixA default prefix which will used as fallback.
Returns:
A string containing the prefix, which must be freed when no longer necessary. If BinReloc is not initialized, or if the initialization function failed, then a copy of default_prefix will be returned. If default_prefix is NULL, then NULL will be returned.

Definition at line 445 of file binreloc.c.

{
       gchar *dir1, *dir2;

       if (exe == NULL) {
              /* BinReloc not initialized. */
              if (default_prefix != NULL)
                     return g_strdup (default_prefix);
              else
                     return NULL;
       }

       dir1 = g_path_get_dirname (exe);
       dir2 = g_path_get_dirname (dir1);
       g_free (dir1);
       return dir2;
}
gchar* gbr_find_sbin_dir ( const gchar *  default_sbin_dir)

Locate the application's superuser binary folder.

The path is generated by the following pseudo-code evaluation:

 prefix + "/sbin"
Parameters:
default_sbin_dirA default path which will used as fallback.
Returns:
A string containing the sbin folder's path, which must be freed when no longer necessary. If BinReloc is not initialized, or if the initialization function failed, then a copy of default_sbin_dir will be returned. If default_bin_dir is NULL, then NULL will be returned.

Definition at line 511 of file binreloc.c.

{
       gchar *prefix, *dir;

       prefix = gbr_find_prefix (NULL);
       if (prefix == NULL) {
              /* BinReloc not initialized. */
              if (default_sbin_dir != NULL)
                     return g_strdup (default_sbin_dir);
              else
                     return NULL;
       }

       dir = g_build_filename (prefix, "sbin", NULL);
       g_free (prefix);
       return dir;
}
gboolean gbr_init ( GError **  error)

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.
Parameters:
errorIf 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.

Definition at line 301 of file binreloc.c.

{
       GbrInitError errcode = GBR_INIT_ERROR_DISABLED;

       /* Locate the application's filename. */
       exe = _br_find_exe (&errcode);
       if (exe != NULL)
              /* Success! */
              return TRUE;
       else {
              /* Failed :-( */
              set_gerror (error, errcode);
              return FALSE;
       }
}

Here is the call graph for this function:

Here is the caller graph for this function:

gboolean gbr_init_lib ( GError **  error)

Initialize the BinReloc library (for libraries).

This function must be called before using any other BinReloc functions. It attempts to locate the calling library's canonical filename.

Note:
The BinReloc source code MUST be included in your library, or this function won't work correctly.
Returns:
TRUE on success, FALSE if a filename cannot be found.

Definition at line 329 of file binreloc.c.

{
       GbrInitError errcode = GBR_INIT_ERROR_DISABLED;

       exe = _br_find_exe_for_symbol ((const void *) "", &errcode);
       if (exe != NULL)
              /* Success! */
              return TRUE;
       else {
              /* Failed :-( */
              set_gerror (error, errcode);
              return exe != NULL;
       }
}

Here is the call graph for this function: