src/binreloc.c File Reference

#include <stdio.h>
#include <stdlib.h>
#include <limits.h>
#include <string.h>
#include "binreloc.h"

Include dependency graph for binreloc.c:

Go to the source code of this file.

Defines

#define NULL   ((void *) 0)

Functions

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

Variables

static char * exe = (char *) NULL


Define Documentation

#define NULL   ((void *) 0)
 

Definition at line 283 of file binreloc.c.

Referenced by _br_find_exe(), _br_find_exe_for_symbol(), TEXTURE_HANDLE::Activate(), ROADSTRIP::Add(), OBJECTS::Add(), CONFIGFILE::Add(), TRACK::AddNewRoad(), MULTIPLAY::AddRecord(), BACKDROP::BACKDROP(), BEZIERCOLBRANCH::BEZIERCOLBRANCH(), BEZIERNODE::BEZIERNODE(), JOEMODEL::BinaryRead(), 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(), VGUI::ControlGrab::BuildControlVectors(), REPLAY::BuildFuncMem(), ChangeDisplay(), JOEMODEL::CleanUp(), REPLAY::Clear(), CONFIGFILE::Clear(), VGUI::SpinningCar::ClearCar(), CONFIGFILE::ClearParam(), ROADSTRIP::ClearPatches(), TRACK::ClearRoads(), JOEPACK::ClosePack(), ROADSTRIP::CollideBranch(), OBJECTCOLLISION::CollideBranch(), OBJECTCOLLISION::CollideBranch_double(), OBJECTCOLLISION::CollideBranchGetTrisInBBox(), OBJECTCOLLISION::CollideBranchModel(), ROADSTRIP::CollideBruteForce(), TRACK::CollideRoads(), CONFIGFILE::CONFIGFILE(), CONFIGVARIABLE::CONFIGVARIABLE(), NET::Connect(), GAMECONTROLS::ControlIteratorGetControl(), VGUI::ControlSet::ControlSet(), TEXTURE_HANDLE::CopyFrom(), CONFIGFILE::DebugPrint(), TRACK::Delete(), BEZIERCOLBRANCH::DeleteChildren(), OBJCOLBRANCH::DeleteChildren(), ROADSTRIP::DeleteLastPatch(), OBJECTS::delmodel(), OBJECTS::delobject(), NET::Disconnect(), OBJECTS::Draw(), SETTINGS::FindHomeDir(), TEXTURES::FindTexture(), ROADSTRIP::GenerateCollisionTree(), OBJECTCOLLISION::GenerateCollisionTree(), TRACK::GetBezier(), Vamos_Body::Car::GetCollisionModel(), Vamos_Body::Car::GetColPatch(), UTILITY::GetFolderIndex(), TRACK::GetLapSequence(), ROADSTRIP::GetLastPatch(), MOUSE::GetMouseButtons(), MOUSE::GetMouseControls(), REPLAY::GetNextPacket(), REPLAY::GetNextState(), CONFIGFILE::GetParam(), TRACK::GetPatch(), SETTINGS::GetValidVideoModes(), VGUI::Calibrate::GrabJoyMove(), OBJECTS::GroupObjectListByTexture(), REPLAY::IncrementFrame(), UTILITY::Init(), SOUNDMANAGER::Init(), Vamos_World::World::interact(), NET::IsEqualToPacket(), MOUSE::IsPressed(), JOEMODEL::JOEMODEL(), JOEPACK::JOEPACK(), TEXTURE_HANDLE::Load(), JOEMODEL::Load(), VGUI::SpinningCar::LoadCar(), JOEMODEL::LoadFromHandle(), OBJECTS::LoadObjectsFromFolder(), Vamos_Body::Car::LoadPart(), REPLAY::LoadState(), TEXTURES::LoadTexture(), SOUNDMANAGER::LoadWave(), LoadWorld(), main(), MULTIPLAY::MULTIPLAY(), NET::NET(), ROADSTRIP::NumPatches(), TRACK::NumRoads(), OBJCOLBRANCH::OBJCOLBRANCH(), OBJCOLNODE::OBJCOLNODE(), OBJECTS::OBJECTS(), JOEPACK::Pack_fclose(), JOEPACK::Pack_fread(), PBUFFER::PBUFFER(), REPLAY::PlayStart(), REPLAY::PlayStop(), PBUFFER::Put(), ROADSTRIP::ReadFrom(), MULTIPLAY::ReadState(), REPLAY::REPLAY(), ROADSTRIP::ROADSTRIP(), ROADSTRIPNODE::ROADSTRIPNODE(), Screenshot(), NET::Send(), MULTIPLAY::SendState(), Vamos_Body::Car::shadow_texture(), VGUI::SpinningCar::SpinningCar(), REPLAY::Stop(), TEXTURE_HANDLE::TEXTURE_HANDLE(), TRACK::TRACK(), TEXTURE_HANDLE::Unload(), NET::Update(), MULTIPLAY::Update(), MOUSE::UpdateCamera(), MULTIPLAY::UpdateFuncmem(), ROADSTRIP::Visualize(), TRACK::VisualizeRoads(), TRACK::Write(), CONFIGFILE::Write(), GAMECONTROLS::WriteControlFile(), ROADSTRIP::WriteTo(), NET::WriteToPacket(), JOEMODEL::~JOEMODEL(), MULTIPLAY::~MULTIPLAY(), PBUFFER::~PBUFFER(), and REPLAY::~REPLAY().


Function Documentation

static char* _br_find_exe BrInitError error  )  [static]
 

Definition at line 39 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, and NULL.

Referenced by br_init().

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

Definition at line 178 of file binreloc.c.

References BR_INIT_ERROR_DISABLED, and NULL.

Referenced by br_init_lib().

char* br_build_path const char *  dir,
const char *  file
 

Definition at line 684 of file binreloc.c.

References br_strcat.

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 740 of file binreloc.c.

References br_strndup(), and NULL.

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 432 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 499 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 631 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 343 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 371 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 565 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 598 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 532 of file binreloc.c.

References br_build_path, br_find_data_dir, 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 399 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 465 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 304 of file binreloc.c.

References _br_find_exe(), and NULL.

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 326 of file binreloc.c.

References _br_find_exe_for_symbol(), and NULL.

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 661 of file binreloc.c.

References NULL.

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

Definition at line 706 of file binreloc.c.

References NULL.

Referenced by br_dirname().


Variable Documentation

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

Definition at line 286 of file binreloc.c.


Generated on Thu Oct 19 04:09:15 2006 by  doxygen 1.4.6