binreloc.c File Reference

#include "config.h"
#include <stdio.h>
#include <stdlib.h>
#include <limits.h>
#include <string.h>
Include dependency graph for binreloc.c:
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Defines

#define DIRSEP   "/"
#define DIRSEP_C   '/'
#define NULL   ((void *) 0)

Functions

static char * _br_find_exe (BrInitError *error)
static char * _br_find_exe_for_symbol (const void *symbol, BrInitError *error)
char * br_build_path (const char *dir, const char *file)
char * br_dirname (const char *path)
char * br_find_bin_dir (const char *default_bin_dir)
char * br_find_data_dir (const char *default_data_dir)
char * br_find_etc_dir (const char *default_etc_dir)
char * br_find_exe (const char *default_exe)
char * br_find_exe_dir (const char *default_dir)
char * br_find_lib_dir (const char *default_lib_dir)
char * br_find_libexec_dir (const char *default_libexec_dir)
char * br_find_locale_dir (const char *default_locale_dir)
char * br_find_prefix (const char *default_prefix)
char * br_find_sbin_dir (const char *default_sbin_dir)
int br_init (BrInitError *error)
int br_init_lib (BrInitError *error)
char * br_strcat (const char *str1, const char *str2)
static char * br_strndup (const char *str, size_t size)

Variables

static char * exe = (char *) NULL

Define Documentation

#define DIRSEP   "/"

Definition at line 38 of file binreloc.c.

#define DIRSEP_C   '/'

Definition at line 39 of file binreloc.c.

#define NULL   ((void *) 0)

Definition at line 292 of file binreloc.c.

Referenced by _br_find_exe(), _br_find_exe_for_symbol(), br_dirname(), br_find_bin_dir(), br_find_data_dir(), br_find_etc_dir(), br_find_exe(), br_find_exe_dir(), br_find_lib_dir(), br_find_libexec_dir(), br_find_locale_dir(), br_find_prefix(), br_find_sbin_dir(), br_init(), br_init_lib(), br_strcat(), br_strndup(), GWEN_Buffer_AllocRoom(), GWEN_BufferedIO_ReadRawForced(), GWEN_BufferedIO_WriteRawForced(), GWEN_ConfigMgr_Factory(), GWEN_Crypt_CryptAlgo_dup(), GWEN_Crypt_CryptAlgo_free(), GWEN_Crypt_CryptAlgo_fromDb(), GWEN_Crypt_CryptAlgo_SetInitVector(), GWEN_Crypt_HashAlgo_dup(), GWEN_Crypt_HashAlgo_free(), GWEN_Crypt_HashAlgo_fromDb(), GWEN_Crypt_HashAlgo_SetInitVector(), GWEN_Crypt_Key_dup(), GWEN_Crypt_Key_fromDb(), GWEN_Crypt_KeyDes3K_SetIV(), GWEN_Crypt_KeyRsa__ReadMpi(), GWEN_Crypt_KeyRsa__sKeyElementToData(), GWEN_Crypt_KeyRsa_dup(), GWEN_Crypt_KeyRsa_fromDb(), GWEN_Crypt_KeyRsa_fromModExp(), GWEN_Crypt_KeyRsa_fromModPrivExp(), GWEN_Crypt_KeyRsa_Sign(), GWEN_Crypt_KeySym_freeData(), GWEN_Crypt_KeySym_fromData(), GWEN_Crypt_KeySym_fromDb(), GWEN_Crypt_KeySym_Generate(), GWEN_Crypt_PaddAlgo_fromDb(), GWEN_Crypt_Token_GetContext(), GWEN_Crypt_Token_GetKeyInfo(), GWEN_Crypt_Token_KeyInfo_free(), GWEN_Crypt_Token_KeyInfo_SetKeyDescr(), GWEN_Crypt_Token_Plugin_CreateToken(), GWEN_Crypt_Token_PluginManager_CheckToken(), GWEN_Crypt_Token_PluginManager_GetPluginDescrs(), GWEN_Crypt_TokenFile__Decipher(), GWEN_Crypt_TokenFile__Encipher(), GWEN_Crypt_TokenFile__GenerateKey(), GWEN_Crypt_TokenFile__GetContext(), GWEN_Crypt_TokenFile__GetContextIdList(), GWEN_Crypt_TokenFile__GetKey(), GWEN_Crypt_TokenFile__GetKeyIdList(), GWEN_Crypt_TokenFile__GetKeyInfo(), GWEN_Crypt_TokenFile__SetContext(), GWEN_Crypt_TokenFile__SetKeyInfo(), GWEN_Crypt_TokenFile__Sign(), GWEN_Crypt_TokenFile__Verify(), GWEN_Crypt_TokenFile_GetContext(), GWEN_CryptHead_fromBuffer(), GWEN_CryptHead_SetKey(), GWEN_CryptHead_SetKeyName(), GWEN_CryptMgr_Decrypt(), GWEN_CryptMgr_Encrypt(), GWEN_CryptMgr_SetLocalKeyName(), GWEN_CryptMgr_SetPeerKeyName(), GWEN_CryptMgr_Verify(), GWEN_CryptMgrKeys_DecryptKey(), GWEN_CryptMgrKeys_EncryptKey(), GWEN_CryptMgrKeys_SignData(), GWEN_CryptMgrKeys_VerifyData(), GWEN_Date_CurrentDate(), GWEN_Date_fromGregorian(), GWEN_Date_fromString(), GWEN_Date_fromStringWithTemplate(), GWEN_DB__ReadValues(), GWEN_DB_count_cb(), GWEN_DB_FindFirstGroup(), GWEN_DB_FindFirstVar(), GWEN_DB_FindGroup(), GWEN_DB_FindNextGroup(), GWEN_DB_FindNextVar(), GWEN_DB_FindVar(), GWEN_DB_GetBinValueFromNode(), GWEN_DB_GetCharValueFromNode(), GWEN_DB_GetFirstGroup(), GWEN_DB_GetFirstValue(), GWEN_DB_GetFirstVar(), GWEN_DB_GetGroup(), GWEN_DB_GetNextGroup(), GWEN_DB_GetNextValue(), GWEN_DB_GetNextVar(), GWEN_DB_GetValue(), GWEN_DB_Group_dup(), GWEN_DB_GroupName(), GWEN_DB_Groups_Foreach(), GWEN_DB_Node_Append_UnDirty(), GWEN_DB_Node_dup(), GWEN_DB_Node_InsertUnDirty(), GWEN_DB_Node_Unlink_UnDirty(), GWEN_DB_ReadFileAs(), GWEN_DB_ReadFromFastBuffer(), GWEN_DB_ReadFromFd(), GWEN_DB_ReadFromString(), GWEN_DB_Values_Foreach(), GWEN_DB_VariableName(), GWEN_DB_Variables_Foreach(), GWEN_DB_WriteGroupToIoLayer(), GWEN_DB_WriteToBuffer(), GWEN_DB_WriteToFd(), GWEN_DBIO_ExportToBuffer(), GWEN_DBIO_ExportToFile(), GWEN_DBIO_ImportFromFile(), GWEN_Directory_GetAllEntries(), GWEN_Directory_GetDirEntries(), GWEN_Directory_GetFileEntries(), GWEN_Directory_GetFileEntriesWithType(), GWEN_Gui_CGui_GetPassword(), GWEN_Gui_CGui_SetCharSet(), GWEN_Gui_CGui_SetPasswordStatus(), GWEN_Gui_WaitForSockets(), GWEN_HttpSession__RecvPacket(), GWEN_HttpSession_ConnectionTest(), GWEN_HttpSession_Init(), GWEN_HttpSession_RecvPacket(), GWEN_HttpSession_SendPacket(), GWEN_HttpSession_SetHttpContentType(), GWEN_HttpSession_SetHttpUserAgent(), GWEN_I18N_BindTextDomain_Codeset(), GWEN_I18N_BindTextDomain_Dir(), GWEN_I18N_SetLocale(), GWEN_IdList64_Iterator_GetFirstId(), GWEN_IdList64_Iterator_GetNextId(), GWEN_InheritData_freeData(), GWEN_Io_Layer_Connect(), GWEN_Io_Layer_DelRequest(), GWEN_Io_Layer_Disconnect(), GWEN_Io_Layer_ReadBytes(), GWEN_Io_Layer_ReadPacket(), GWEN_Io_Layer_ReadPacketToBuffer(), GWEN_Io_Layer_WriteBytes(), GWEN_Io_Layer_WriteChar(), GWEN_Io_Layer_WriteString(), GWEN_Io_LayerBuffered_AbortInRequests(), GWEN_Io_LayerBuffered_AbortOutRequests(), GWEN_Io_LayerBuffered_AddRequest(), GWEN_Io_LayerBuffered_DelRequest(), GWEN_Io_LayerBuffered_ReadLineToBuffer(), GWEN_Io_LayerBuffered_TryFlush(), GWEN_Io_LayerBuffered_WorkOnReadRequest(), GWEN_Io_LayerBuffered_WorkOnWriteRequest(), GWEN_Io_LayerCodec_AbortInRequests(), GWEN_Io_LayerCodec_AbortOutRequests(), GWEN_Io_LayerCodec_AbortRequests(), GWEN_Io_LayerCodec_AddRequest(), GWEN_Io_LayerCodec_CheckWriteOut(), GWEN_Io_LayerCodec_DelRequest(), GWEN_Io_LayerCodec_EnsureReadOk(), GWEN_Io_LayerCodec_Reset(), GWEN_Io_LayerCodec_WorkOnOutRequests(), GWEN_Io_LayerCodec_WorkOnReadRequest(), GWEN_Io_LayerCodec_WorkOnWriteRequest(), GWEN_Io_LayerFile_DelRequest(), GWEN_Io_LayerFile_freeData(), GWEN_Io_LayerFile_new(), GWEN_Io_LayerFile_WorkOnRequests(), GWEN_Io_LayerHttp_AbortInRequests(), GWEN_Io_LayerHttp_AbortOutRequests(), GWEN_Io_LayerHttp_AddRequest(), GWEN_Io_LayerHttp_DelRequest(), GWEN_Io_LayerHttp_WorkOnReadRequest1(), GWEN_Io_LayerHttp_WorkOnReadRequest2(), GWEN_Io_LayerHttp_WorkOnWriteRequest1(), GWEN_Io_LayerHttp_WorkOnWriteRequest2(), GWEN_Io_LayerMemory_new(), GWEN_Io_LayerPackets_Abort(), GWEN_Io_LayerPackets_DelRequest(), GWEN_Io_LayerPackets_GetReadRequest(), GWEN_Io_LayerPackets_WorkOnReadRequests(), GWEN_Io_LayerPackets_WorkOnWriteRequests(), GWEN_Io_LayerSocket_AbortRequests(), GWEN_Io_LayerSocket_AddRequest(), GWEN_Io_LayerSocket_CheckForIncoming(), GWEN_Io_LayerSocket_DelRequest(), GWEN_Io_LayerSocket_new(), GWEN_Io_LayerSocket_SetLocalAddr(), GWEN_Io_LayerSocket_SetPeerAddr(), GWEN_Io_LayerSocket_WorkOnRequests(), GWEN_Io_LayerTls__readFile(), GWEN_Io_LayerTls_DelRequest(), GWEN_Io_LayerTls_GetPeerCert(), GWEN_Io_LayerTls_Prepare(), GWEN_Io_LayerTls_SetDhParamFile(), GWEN_Io_LayerTls_SetLocalCertFile(), GWEN_Io_LayerTls_SetLocalKeyFile(), GWEN_Io_LayerTls_SetLocalTrustFile(), GWEN_Io_LayerTls_SetRemoteHostName(), GWEN_Io_LayerTls_WorkOnRequests(), GWEN_Io_Manager_ModuleFini(), GWEN_Io_Manager_WaitForRequest(), GWEN_Io_Request_TakeIncomingLayer(), GWEN_IpcManager__SendMsg(), GWEN_IpcManager__Work(), GWEN_IpcManager_AddServer(), GWEN_IpcManager_Disconnect(), GWEN_IpcManager_RemoveClient(), GWEN_MDigest_SetDigestLen(), GWEN_MemCache__MakeRoom(), GWEN_MemCache_CreateEntry(), GWEN_Padd_AddPkcs1Pss(), GWEN_PluginManager_GetPluginDescrs(), GWEN_PluginManager_LoadPlugin(), GWEN_Proxy_Connect(), GWEN_SigHead_fromBuffer(), GWEN_SigHead_SetDateTime(), GWEN_SigHead_SetKeyName(), GWEN_SigTail_fromBuffer(), GWEN_SigTail_SetSignature(), GWEN_StringList_fromString(), GWEN_Tag16_fromBuffer2(), GWEN_Text_DoubleToBuffer(), GWEN_Text_StringToDouble(), GWEN_Time__fromString(), GWEN_Tree_Add(), GWEN_Tree_Del(), GWEN_Tree_Insert(), GWEN_Tree_InsertChild(), GWEN_TreeElement_GetBelow(), GWEN_TreeElement_GetFirstChild(), GWEN_TreeElement_GetLastChild(), GWEN_TreeElement_GetParent(), GWEN_XML__ReadTag(), GWEN_XmlCtxStore_AddAttr(), GWEN_XmlCtxStore_AddData(), GWEN_XmlCtxStore_EndTag(), GWEN_XmlCtxStore_StartTag(), GWEN_XMLGL__FindNameSpaceByUrl(), GWEN_XMLGL__GetNameSpaceByPrefix(), GWEN_XMLGL__SampleNameSpaces(), GWEN_XMLGL__TranslateName(), GWEN_XMLNode_FindNameSpaceByName(), GWEN_XMLNode_FindNameSpaceByUrl(), GWEN_XMLNode_fromString(), GWEN_XMLNode_SetNamespace(), GWEN_XMLNode_toBuffer(), GWEN_XMLNode_WriteFile(), GWEN_XsdNode_Unlink(), and test_gui().


Function Documentation

static char* _br_find_exe ( BrInitError error  )  [static]

For internal use only.

Find the canonical filename of the executable. Returns the filename (which must be freed) or NULL on error. If the parameter 'error' is not NULL, the error code will be stored there, if an error occured.

Definition at line 48 of file binreloc.c.

References BR_INIT_ERROR_DISABLED, BR_INIT_ERROR_INVALID_MAPS, BR_INIT_ERROR_NOMEM, BR_INIT_ERROR_OPEN_MAPS, BR_INIT_ERROR_READ_MAPS, DIRSEP_C, and NULL.

Referenced by br_init().

Here is the caller graph for this function:

static char* _br_find_exe_for_symbol ( const void *  symbol,
BrInitError error 
) [static]

For internal use only.

Find the canonical filename of the executable which owns symbol. Returns a filename which must be freed, or NULL on error.

Definition at line 187 of file binreloc.c.

References BR_INIT_ERROR_DISABLED, and NULL.

Referenced by br_init_lib().

Here is the caller graph for this function:

char* br_build_path ( const char *  dir,
const char *  file 
)

Definition at line 693 of file binreloc.c.

References br_strcat, DIRSEP, and DIRSEP_C.

char* br_dirname ( const char *  path  ) 

Extracts the directory component of a path.

Similar to g_dirname() or the dirname commandline application.

Example:

 br_dirname ("/usr/local/foobar");  --> Returns: "/usr/local"
Parameters:
path A path.
Returns:
A directory name. This string should be freed when no longer needed.

Definition at line 749 of file binreloc.c.

References br_strndup(), DIRSEP, DIRSEP_C, and NULL.

Here is the call graph for this function:

char* br_find_bin_dir ( const char *  default_bin_dir  ) 

Locate the application's binary folder.

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

 prefix + "/bin"
Parameters:
default_bin_dir A 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 441 of file binreloc.c.

References br_build_path, br_find_prefix, and NULL.

char* br_find_data_dir ( const char *  default_data_dir  ) 

Locate the application's data folder.

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

 prefix + "/share"
Parameters:
default_data_dir A 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 508 of file binreloc.c.

References br_build_path, br_find_prefix, and NULL.

char* br_find_etc_dir ( const char *  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_dir A 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 640 of file binreloc.c.

References br_build_path, br_find_prefix, and NULL.

char* br_find_exe ( const char *  default_exe  ) 

Find the canonical filename of the current application.

Parameters:
default_exe A 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 br_init() failed, then a copy of default_exe will be returned. If default_exe is NULL, then NULL will be returned.

Definition at line 352 of file binreloc.c.

References NULL.

char* br_find_exe_dir ( const char *  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_dir A 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 380 of file binreloc.c.

References br_dirname, and NULL.

char* br_find_lib_dir ( const char *  default_lib_dir  ) 

Locate the application's library folder.

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

 prefix + "/lib"
Parameters:
default_lib_dir A 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 574 of file binreloc.c.

References br_build_path, br_find_prefix, and NULL.

char* br_find_libexec_dir ( const char *  default_libexec_dir  ) 

Locate the application's libexec folder.

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

 prefix + "/libexec"
Parameters:
default_libexec_dir A 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 607 of file binreloc.c.

References br_build_path, br_find_prefix, and NULL.

char* br_find_locale_dir ( const char *  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_dir A 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 541 of file binreloc.c.

References br_build_path, br_find_data_dir, and NULL.

char* br_find_prefix ( const char *  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_prefix A 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 408 of file binreloc.c.

References br_dirname, and NULL.

char* br_find_sbin_dir ( const char *  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_dir A 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 474 of file binreloc.c.

References br_build_path, br_find_prefix, and NULL.

int br_init ( BrInitError 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 br_init_lib() instead.
Parameters:
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.

Definition at line 313 of file binreloc.c.

References _br_find_exe(), and NULL.

Here is the call graph for this function:

int br_init_lib ( BrInitError 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.
Parameters:
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 a filename cannot be found.

Definition at line 335 of file binreloc.c.

References _br_find_exe_for_symbol(), and NULL.

Here is the call graph for this function:

char* br_strcat ( const char *  str1,
const char *  str2 
)

Concatenate str1 and str2 to a newly allocated string.

Parameters:
str1 A string.
str2 Another string.
Returns:
A newly-allocated string. This string should be freed when no longer needed.

Definition at line 670 of file binreloc.c.

References NULL.

static char* br_strndup ( const char *  str,
size_t  size 
) [static]

Definition at line 715 of file binreloc.c.

References NULL.

Referenced by br_dirname().

Here is the caller graph for this function:


Variable Documentation

char* exe = (char *) NULL [static]

Definition at line 295 of file binreloc.c.

Generated on Mon Jul 5 22:52:51 2010 for gwenhywfar by  doxygen 1.6.3