src/thirdparty/binreloc/prefix.c File Reference

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

Include dependency graph for prefix.c:

Go to the source code of this file.

Defines

#define BR_PTHREADS   1
#define NULL   ((void *) 0)
#define br_return_val_if_fail(expr, val)   if (!(expr)) return val

Functions

char * br_strcat (const char *str1, const char *str2)
static char * br_strndup (char *str, size_t size)
char * br_extract_dir (const char *path)
char * br_extract_prefix (const char *path)
void br_set_locate_fallback_func (br_locate_fallback_func func, void *data)

Variables

static br_locate_fallback_func fallback_func = (br_locate_fallback_func) NULL
static void * fallback_data = NULL


Define Documentation

#define BR_PTHREADS   1

Definition at line 35 of file prefix.c.

#define br_return_val_if_fail ( expr,
val   )     if (!(expr)) return val

Definition at line 55 of file prefix.c.

Referenced by br_strndup().

#define NULL   ((void *) 0)

Definition at line 50 of file prefix.c.

Referenced by _wrap_EGameObject_interact_with(), _wrap_EGameObject_move(), _wrap_EGameObject_pass_edge(), _wrap_EGameObject_render_cockpit_fixed_after(), _wrap_EGameObject_render_cockpit_fixed_before(), _wrap_EGameObject_render_cockpit_virtual(), _wrap_ESensor_pass_edge(), _wrap_GCycle_drop_wall(), _wrap_GCycle_interact_with(), _wrap_GCycle_pass_edge(), _wrap_GCycle_timestep_core(), _wrap_GCycleMovement_can_make_turn(), _wrap_GCycleMovement_turn(), _wrap_GSensor_pass_edge(), _wrap_new_EGameObject(), _wrap_new_GCycle(), _wrap_new_NNetObject(), _wrap_new_TConfItemBase(), _wrap_new_TConfItemBase__SWIG_0(), _wrap_new_TConfItemBase__SWIG_1(), _wrap_new_TOutput(), _wrap_new_TOutput__SWIG_1(), _wrap_new_UMenu(), _wrap_new_UMenuItemInt(), _wrap_new_UMenuItemString(), _wrap_NNetObject_request_sync(), _wrap_TDirectories_file_matches_wildcard(), _wrap_TDirectories_file_matches_wildcard__SWIG_0(), _wrap_TDirectories_file_matches_wildcard__SWIG_1(), _wrap_TDirectories_file_name_to_menu_name(), _wrap_TDirectories_get_files(), _wrap_TOutput_add_literal(), _wrap_TOutput_add_locale(), _wrap_TOutput_set_template_parameter_string(), _wrap_TPath_get_read_path(), _wrap_TPath_get_write_path(), _wrap_TPath_is_valid_path(), _wrap_TPath_open(), _wrap_TPath_open__SWIG_0(), _wrap_TPath_open__SWIG_1(), _wrap_TPath_open__SWIG_2(), _wrap_TPath_open__SWIG_3(), _wrap_TPathResource_get_write_path(), _wrap_UMenu_message(), _wrap_UMenuItem_render(), _wrap_UMenuItemAction_render(), _wrap_UMenuItemExit_render(), _wrap_UMenuItemInt_render(), _wrap_UMenuItemString_render(), _wrap_UMenuItemSubmenu_render(), SwigDirector_NNetObject::AcceptClientSync(), eCamera::Act(), SwigDirector_NNetObject::ActionOnDelete(), SwigDirector_NNetObject::ActionOnQuit(), gCycleChatBot::Activate(), nBandwidthSceduler::AddArbitrator(), SwigDirector_NNetObject::AddRef(), tPlayback::AdvanceSection(), memblock::Alloc(), gAITeam::BalanceWithAIs(), BCDouble(), BCFun(), BCSimple(), eWallView::Belongs(), br_strndup(), SwigDirector_NNetObject::BroadcastExistence(), COperation::BuildCode(), ROperation::BuildCode(), tXmlParserNamespace::tXmlParser::cb_startElement(), CFunction::CFunction(), nSocket::CheckNewConnection(), eGrid::Clear(), ClearAITeam(), nNetObject::ClearAll(), nNetObject::ClearAllDeleted(), nNetObject::ClearKnows(), gAIPlayer::ClearObject(), gAIPlayer::ClearTarget(), eHalfEdge::ClearWall(), ConnectToServerCore(), COperation::ContainFunc(), ROperation::ContainFunc(), COperation::ContainFuncNoRec(), ROperation::ContainFuncNoRec(), COperation::ContainVar(), ROperation::ContainVar(), gAIPlayer::ControlObject(), COperation::COperation(), eFace::CorrectArea(), CountSameConnection(), gBaseZoneHack::CountZonesOfTeam(), Registry::create(), eFace::Create(), gNetPlayerWall::CreateEdge(), SwigDirector_NNetObject::CreatorDescriptor(), eHalfEdge::CrossesNewWall(), gCycle::CurrentWall(), GrowingArrayBase::Delete(), nServerInfo::DeleteUnreachable(), tJUST_CONTROLLED_PTR< nNetObject >::Destroy(), tControlledPTR< eHalfEdge >::Destroy(), tCheckedPTRConst< T >::Destroy(), tCheckedPTR< T >::Destroy(), COperation::Destroy(), ROperation::Destroy(), memblock::Dispose(), do_chat(), SwigDirector_GSimpleAIFactory::DoCreate(), nConsoleDateFilter::DoFilterLine(), SwigDirector_NNetObject::DoGetMachine(), eNetGameObject::DoRemoveFromGame(), SwigDirector_GSimpleAI::DoThink(), eGrid::DrawLine(), gCycle::DropWall(), gCycleMemory::Earliest(), eAxis::eAxis(), gCycle::Edge(), eWall::Edge(), eh_getdir(), gAIPlayer::EmergencySurvive(), gParser::endElementAlternative(), eTeam::Enforce(), gMenuItemPlayer::Enter(), gMenuItemSpectate::Enter(), SwigDirector_UMenuItemAction::Enter(), ePlayer::ePlayer(), ePlayerNetID::ePlayerNetID(), eSensor::eSensor(), eSoundMixer::eSoundMixer(), uMenuItemInput::Event(), eWavData::eWavData(), rSysDep::ExitGL(), COperation::Expr(), ROperation::Expr(), uActionPlayer::Find(), eGameObject::FindCurrentFace(), ePlayerNetID::FindDefaultTeam(), eHalfEdge::FindPath(), ePlayerNetID::FindPlayerByName(), tLanguage::FindSloppy(), tLanguage::FindStrict(), eGrid::FindSurroundingFace(), floattest::floattest(), gAIPlayer::gAIPlayer(), gCycle::gCycle(), tDecoratableManager< Decorated >::GetBase(), eSoundMixer::GetCurrentSong(), gCycleMovement::GetDestinationBefore(), tDirectories::GetFiles(), nServerInfo::GetMasters(), gCycleMovement::GetMaxSpaceAhead(), nObserverPtr< ePlayerNetID >::GetPointer(), GetQueryMessageStats(), tResourceManager::GetResource(), nServerInfo::GetSmallServerInfo(), tDirectories::GetSpecList(), eVoter::GetVoter(), gParser::gParser(), gResMenEntry::gResMenEntry(), eGrid::Grow(), GrowingArrayBase::GrowingArrayBase(), uMenu::HandleEvent(), COperation::HasError(), ROperation::HasError(), tHeapElement::Heap(), nBandwidthArbitrator::Heap(), eHalfEdge::Heap(), SwigDirector_UMenuItemAction::Help(), eMusicTrack::Init(), eAxis::Init(), init_game_objects(), SwigDirector_NNetObject::InitAfterCreation(), rSysDep::InitGL(), tPlaybackBlockBase::Initialize(), eGrid::Insert(), eHalfEdge::IntersectWith(), gParser::isElement(), SwigDirector_UMenuItemAction::IsSelectable(), gParser::isValidAlternative(), gCycle::Kill(), gCycle::KillAt(), gCycleMemory::Latest(), leak(), gArena::LeastDangerousSpawnPoint(), SwigDirector_UMenuItemAction::LeftRightRelease(), eMusicTrack::LoadFile(), eMusicTrack::LoadPlaylist(), gCycleVisuals::LoadTextureSafe(), gCycleVisuals::LoadTextureSafe2(), nKrawall::nMethod::LocalMethods(), tResourceManager::locateResource(), login_callback(), lowlevel_sr_InitDisplay(), main(), MainMenu(), uMenu::Message(), eGameObject::Move(), myHTTPFetch(), eCamera::MyInit(), gCycleMovement::MyInitAfterCreation(), gCycle::MyInitAfterCreation(), gParser::myxmlGetPropBool(), gParser::myxmlGetPropFloat(), gParser::myxmlGetPropInt(), tXmlParserNamespace::myxmlParserInputBufferCreateFilenameFunc(), nBandwidthArbitrator::nBandwidthArbitrator(), nDescriptor::nDescriptor(), gAIPlayer::NewObject(), nBandwidthTaskPriorizer::Next(), COperation::NMembers(), ROperation::NMembers(), nServerInfoAdmin::nServerInfoAdmin(), ntest(), COperation::NthMember(), ROperation::NthMember(), gAIPlayer::Object(), nNetObject::Object(), nNetObject::ObjectDangerous(), eTeam::OldestAIPlayer(), eTeam::OldestHumanPlayer(), eTeam::OldestPlayer(), gCycleMovement::OnRemoveFromGame(), gCycle::OnRemoveFromGame(), gBaseZoneHack::OnVanish(), tResourceManager::openResource(), tControlledPTR< eHalfEdge >::operator bool(), tCheckedPTRBase::operator bool(), tLocaleItem::operator const char *(), tControlledPTR< eHalfEdge >::operator!(), operator!=(), COperation::operator=(), CFunction::operator=(), ROperation::operator=(), RFunction::operator=(), operator==(), operator>>(), own_game(), gParser::Parse(), gParser::parseAlternativeContent(), gParser::parseAxes(), gParser::parseField(), gParser::parseMap(), gParser::parseObstacleWall(), gParser::parseSettings(), gParser::parseShapeCircle(), gParser::parseWall(), gParser::parseWorld(), gParser::parseZoneArthemis_v1(), gNetPlayerWall::PartialCopyIntoGrid(), ParticleGroup::ParticleGroup(), PasswordCallback(), nBandwidthTaskPriorizer::PeekNext(), rViewportConfiguration::Port(), PrepareTeamText(), nServerInfo::Prev(), cWidget::WithDataFunctions::ProcessConditional(), gParser::processSubAlt(), eGrid::ProcessWallsInRange(), ProcessWallsRecursive(), nServerInfo::QueryServer(), quitWithMessagePrepare(), eGrid::Range(), gNetPlayerWall::ReadSync(), gCycle::ReadSync(), gNetPlayerWall::real_CopyIntoGrid(), rec_peer(), ePlayerNetID::ReceiveControlNet(), nNetObject::RelabelOnConnect(), tJUST_CONTROLLED_PTR< nNetObject >::Release(), tControlledPTR< eHalfEdge >::Release(), SwigDirector_NNetObject::Release(), tReferenceHolder< T >::ReleaseAll(), gNetPlayerWall::ReleaseData(), SwigDirector_NNetObject::ReleaseOwnership(), tReferenceHolder< T >::Remove(), tMemManager::Remove(), tList< uSelectItem< Vote > >::Remove(), tListItemBase::Remove(), tHeapBase::Remove(), nBandwidthSceduler::RemoveArbitrator(), ePlayerNetID::RemoveChatbots(), eTeam::RemovePlayerDirty(), eGameObject::RenderAll(), SwigDirector_UMenuItemAction::RenderBackground(), ePoint::Replace(), GrowingArrayBase::ResizeBase(), ret_to_MainMenu(), RFunction::RFunction(), gDestination::RightAfter(), gDestination::RightBefore(), gAIPlayer::RightBeforeDeath(), RInclude(), ROperation::ROperation(), rTextureRenderTarget::rTextureRenderTarget(), RunGLTest(), nServerInfo::RunMaster(), RVar::RVar(), SafeDeletePtr(), SDL_SavePNG(), se_ChatTeam(), se_ClearLegacySpectator(), se_GetLocalPlayer(), se_GetWatchedObject(), se_KillGameTimer(), se_SoundExit(), se_SoundInit(), se_UserName(), nBasicNetworkSystem::Select(), CFunction::SetName(), RFunction::SetName(), gAIPlayer::SetNumberOfAIs(), nObserverPtr< ePlayerNetID >::SetObject(), eHalfEdge::SetOther(), gServerMenuItem::SetServer(), ePlayerNetID::SetTeamWish(), eWallHolder::SetWall(), sg_CreateWinDeathZone(), sg_FavoritesMenu(), sg_GetCurrentTime(), sg_HostGameMenu(), sg_SetIcon(), eSoundMixer::ShutDown(), sn_DoDestroy(), tListItemBase::Sort(), SwigDirector_UMenuItemAction::SpaceRight(), ePlayerNetID::SpectateAll(), sr_ExitDisplay(), sr_Read_stdin(), gGame::StateUpdate(), rSysDep::StopNetSyncThread(), su_GetInput(), COperation::Substitute(), ROperation::Substitute(), ePlayerNetID::Suspend(), SWIG_Ruby_ConvertPtrAndOwn(), SWIG_TypePrettyName(), eCamera::SwitchCenter(), nNetObject::SyncAll(), gCycle::SyncEnemy(), SwigDirector_NNetObject::TakeOwnership(), tCallback::tCallback(), tCommandLineData::tCommandLineData(), nServerInfo::TellMasterAboutMe(), gAIPlayer::Think(), gAIPlayer::ThinkSurvive(), gAIPlayer::ThinkTrace(), gBaseZoneHack::Timestep(), gCamera::Timestep(), eGameObject::TimestepThisWrapper(), tListItem< tConsoleFilter >::tListItem(), tMemStackItem::tMemStackItem(), tTextFileRecorder::tTextFileRecorder(), eFace::Unlink(), ePoint::Unlink(), eHalfEdge::Unlink(), eWavData::Unload(), nDeletedInfo::UnSet(), gServerMenu::Update(), ePlayerNetID::Update(), uPlayerPrototype::uPlayerPrototype(), COperation::Val(), ROperation::Val(), tXmlParserNamespace::tXmlParser::ValidateXml(), ePlayerNetID::WaitToLeaveChat(), gNetPlayerWall::Wall(), eTeam::YoungestAIPlayer(), eTeam::YoungestHumanPlayer(), eTeam::YoungestPlayer(), CFunction::~CFunction(), CVar::~CVar(), deptest::~deptest(), eFloor::~eFloor(), eGrid::~eGrid(), eNetGameObject::~eNetGameObject(), ePath::~ePath(), eTimer::~eTimer(), eVoteItemHarm::~eVoteItemHarm(), eWall::~eWall(), eWallHolder::~eWallHolder(), gAIPlayer::~gAIPlayer(), gCycleMovement::~gCycleMovement(), gMaxSpaceAheadHitInfoClearer::~gMaxSpaceAheadHitInfoClearer(), GrowingArrayBase::~GrowingArrayBase(), gServerMenuItem::~gServerMenuItem(), nBandwidthArbitrator::~nBandwidthArbitrator(), nIConfItemWatcher::~nIConfItemWatcher(), nNetObject::~nNetObject(), nObserver::~nObserver(), nServerInfo::~nServerInfo(), nServerInfoAdmin::~nServerInfoAdmin(), RFunction::~RFunction(), RVar::~RVar(), su_TimerCallback::~su_TimerCallback(), tConsole::~tConsole(), tRing::~tRing(), tTextFileRecorder::~tTextFileRecorder(), uAction::~uAction(), and uPlayerPrototype::~uPlayerPrototype().


Function Documentation

char* br_extract_dir ( const char *  path  ) 

br_extract_dir: path: A path. Returns: A directory name. This string should be freed when no longer needed.

Extracts the directory component of path. Similar to g_dirname() or the dirname commandline application.

Example: br_extract_dir ("/usr/local/foobar"); --> Returns: "/usr/local"

Definition at line 390 of file prefix.c.

00390           :
00391  * br_extract_dir ("/usr/local/foobar");  --> Returns: "/usr/local"
00392  */
00393 char *
00394 br_extract_dir (const char *path)
00395 {
00396         char *end, *result;
00397 
00398         br_return_val_if_fail (path != (char *) NULL, (char *) NULL);
00399 
00400         end = strrchr (path, '/');
00401         if (!end) return strdup (".");
00402 
00403         while (end > path && *end == '/')
00404                 end--;
00405         result = br_strndup ((char *) path, end - path + 1);
00406         if (!*result)
00407         {
00408                 free (result);
                return strdup ("/");

char* br_extract_prefix ( const char *  path  ) 

br_extract_prefix: path: The full path of an executable or library. Returns: The prefix, or NULL on error. This string should be freed when no longer needed.

Extracts the prefix from path. This function assumes that your executable or library is installed in an LSB-compatible directory structure.

Example: br_extract_prefix ("/usr/bin/gnome-panel"); --> Returns "/usr" br_extract_prefix ("/usr/local/lib/libfoo.so"); --> Returns "/usr/local" br_extract_prefix ("/usr/local/libfoo.so"); --> Returns "/usr"

Definition at line 425 of file prefix.c.

00430 {
00431         char *end, *tmp, *result;
00432 
00433         br_return_val_if_fail (path != (char *) NULL, (char *) NULL);
00434 
00435         if (!*path) return strdup ("/");
00436         end = strrchr (path, '/');
00437         if (!end) return strdup (path);
00438 
00439         tmp = br_strndup ((char *) path, end - path);
00440         if (!*tmp)
00441         {
00442                 free (tmp);
00443                 return strdup ("/");
00444         }
00445         end = strrchr (tmp, '/');
00446         if (!end) return tmp;
00447 
00448         result = br_strndup (tmp, end - tmp);
00449         free (tmp);
00450 
00451         if (!*result)
00452         {
00453                 free (result);
00454                 result = strdup ("/");

void br_set_locate_fallback_func ( br_locate_fallback_func  func,
void *  data 
)

br_set_fallback_function: func: A function to call to find the binary. data: User data to pass to func.

Sets a function to call to find the path to the binary, in case "/proc/self/maps" can't be opened. The function set should return a string that is safe to free with free().

Definition at line 467 of file prefix.c.

00472 {

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

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

Concatenate str1 and str2 to a newly allocated string.

Definition at line 339 of file prefix.c.

00344 {
00345         char *result;
00346         size_t len1, len2;
00347 
00348         if (!str1) str1 = "";
00349         if (!str2) str2 = "";
00350 
00351         len1 = strlen (str1);
00352         len2 = strlen (str2);
00353 
00354         result = (char *) malloc (len1 + len2 + 1);
00355         memcpy (result, str1, len1);
00356         memcpy (result + len1, str2, len2);

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

Definition at line 361 of file prefix.c.

References br_return_val_if_fail, calloc, NULL, and strdup.

00366 {
00367         char *result = (char *) NULL;
00368         size_t len;
00369 
00370         br_return_val_if_fail (str != (char *) NULL, (char *) NULL);
00371 
00372         len = strlen (str);
00373         if (!len) return strdup ("");
00374         if (size > len) size = len;
00375 


Variable Documentation

void* fallback_data = NULL [static]

Definition at line 60 of file prefix.c.

br_locate_fallback_func fallback_func = (br_locate_fallback_func) NULL [static]

Definition at line 59 of file prefix.c.


Generated on Sat Mar 15 23:07:52 2008 for Armagetron Advanced by  doxygen 1.5.4