)
----------------------------------------------------------------------*/
int
- LibBrownie_SearchLib_IsExistLibrary(
+ SearchLib_IsExistLibrary(
char *pstr_path,
char *pstr_solibname )
{
}
+/*----------------------------------------------------------------------
+Search & Get Library Exist-Path from colon-separated Path Lists.
+----------------------------------------------------------------------*/
+int
+ SearchLib_SearchLibInPathArrays(
+ char *pstr_solibpath, // out
+ char *pstr_pathlist, // in
+ char *pstr_solibname ) // in
+{
+ int i_flag;
+ int i_result;
+ int i_err;
+ size_t sz_len;
+ char *pstr_pathtemp;
+ char *pstr_nowpath;
+ char *pstr_nowpos;
+
+ // alloc & copy pstr_pathlist -> pstr_pathtemp ---
+ sz_len = strlen( pstr_pathlist );
+ pstr_pathtemp = (char *)alloca( sz_len + 1 );
+ strncpy( pstr_pathtemp, pstr_pathlist, sz_len + 1 );
+
+ i_result = -0x01;
+ i_flag = 0x00;
+ pstr_nowpath = pstr_pathtemp;
+ pstr_nowpos = pstr_pathtemp;
+ do{
+ if(( ':' == *pstr_nowpos ) || ( '\0' == *pstr_nowpos)) {
+ if( '\0' == *pstr_nowpos ) { i_flag = 0x01; }
+ else { *pstr_nowpos = '\0'; }
+
+ i_err = SearchLib_IsExistLibrary( pstr_nowpath, pstr_solibname );
+ if( 0x00 == i_err ) {
+ i_result = 0x00;
+ strncpy( pstr_solibpath, pstr_nowpath, DRD64_MAX_PATH );
+ goto goto_SearchLib_SearchLibInPathArrays_post;
+ }
+
+ if( 0x00 == i_flag ) { *pstr_nowpos = ':'; }
+
+ pstr_nowpath = pstr_nowpos + 1;
+ }
+
+ }while( '\0' != *pstr_nowpos++ );
+
+goto_SearchLib_SearchLibInPathArrays_post:
+ return i_result;
+}
+
+
/***********************************************************************
int LibBrownie_GetLibraryPath(
char *pstr_solibpath, [OUT] .so existed Library FullPath
char *pstr_solibname, [IN] .so Library Filename
- char *pstr_rpath, [IN] rpath string from .dynamic seciton
+ char *pstr_dt_rpath, [IN] RPATH string from .dynamic seciton
+ char *pstr_dt_runpath, [IN] RUNPATH string from .dynamic seciton
char *pstr_ldsohints [IN] LD_LIBRARYPATH env string.
)
LibBrownie_GetLibraryPath(
char *pstr_solibpath,
char *pstr_solibname,
- char *pstr_rpath,
+ char *pstr_dt_rpath,
+ char *pstr_dt_runpath,
+ char *pstr_env_ldlibpath,
char *pstr_ldsohints )
{
- int i_result;
- int i_flag;
- size_t sz_len;
- char *pstr_hintslist;
- char *pstr_nowpath;
- char *pstr_nowpos;
+ int i_err;
+ int i_result = 0x00;
if( NULL == pstr_solibpath ) {
return -0x01;
return -0x02;
}
- // LocalLibrary ( rpath in .dynamic section)
- if( NULL != pstr_rpath ) {
- if( '\0' != *pstr_rpath ) {
- i_result = LibBrownie_SearchLib_IsExistLibrary( pstr_rpath, pstr_solibname );
- if( 0x00 == i_result ) {
- pstr_nowpath = pstr_rpath;
- goto goto_LibBrownie_GetLibraryPath_setting;
- }
+ // <Order Info from man ld.so>------------------------------------------
+ // 1. DT_RPATH of the referencing object unless that object also
+ // contains a DT_RUNPATH tag
+ // 2. DT_RPATH of the program unless the referencing object contains
+ // a DT_RUNPATH tag
+ if( NULL != pstr_dt_rpath ) {
+ // XXX: pstr_dt_runpath != NULL for WARNING!!
+ i_err = SearchLib_SearchLibInPathArrays(
+ pstr_solibpath, pstr_dt_rpath, pstr_solibname );
+ if( 0x00 == i_err ) {
+ i_result = 0x01;
+ goto goto_LibBrownie_GetLibraryPath_post;
}
}
- // System Library ( in /usr/lib | /usr/local/lib | ... )
- // Get from LD_LIBRARYPATH dir.
- sz_len = strlen( pstr_ldsohints );
- pstr_hintslist = (char *)alloca( sz_len + 1 );
- if( NULL == pstr_hintslist ) {
- return -0x03;
+ // <Order Info from man ld.so>------------------------------------------
+ // 3. Path indicated by LD_LIBRARY_PATH environment variable
+ if( NULL != pstr_env_ldlibpath ) {
+ i_err = SearchLib_SearchLibInPathArrays(
+ pstr_solibpath, pstr_env_ldlibpath, pstr_solibname );
+ if( 0x00 == i_err ) {
+ i_result = 0x03;
+ goto goto_LibBrownie_GetLibraryPath_post;
+ }
+ }
+
+ // <Order Info from man ld.so>------------------------------------------
+ // 4. DT_RUNPATH of the referencing object
+ if( NULL != pstr_dt_runpath ) {
+ i_err = SearchLib_SearchLibInPathArrays(
+ pstr_solibpath, pstr_dt_runpath, pstr_solibname );
+ if( 0x00 == i_err ) {
+ i_result = 0x04;
+ goto goto_LibBrownie_GetLibraryPath_post;
+ }
}
- strncpy( pstr_hintslist, pstr_ldsohints, sz_len + 1 );
+ // <Order Info from man ld.so>------------------------------------------
+ // 5. Hints file produced by the ldconfig(8) utility
+ i_err = SearchLib_SearchLibInPathArrays(
+ pstr_solibpath, pstr_ldsohints, pstr_solibname );
+ if( 0x00 == i_err ) {
+ i_result = 0x05;
+ goto goto_LibBrownie_GetLibraryPath_post;
+ }
- i_flag = 0x00;
- pstr_nowpath = pstr_hintslist;
- pstr_nowpos = pstr_hintslist;
- do{
- if(( ':' == *pstr_nowpos ) || ( '\0' == *pstr_nowpos)) {
- if( '\0' == *pstr_nowpos ) { i_flag = 0x01; }
- else { *pstr_nowpos = '\0'; }
- i_result = LibBrownie_SearchLib_IsExistLibrary( pstr_nowpath, pstr_solibname );
- if( 0x00 == i_result ) {
- goto goto_LibBrownie_GetLibraryPath_setting;
- }
-
- if( 0x00 != i_flag ) {
- return -0x04;
- }
- else
- { *pstr_nowpos = ':'; }
-
- pstr_nowpath = pstr_nowpos + 1;
- }
-
- }while( '\0' != *pstr_nowpos++ );
+ // 6. The /lib and /usr/lib directories, unless the referencing
+ // object was linked using the "-z nodefaultlib" option
+ i_err = SearchLib_SearchLibInPathArrays(
+ pstr_solibpath, "/lib:/usr/lib", pstr_solibname );
+ if( 0x00 == i_err ) {
+ i_result = 0x06;
+ }
-goto_LibBrownie_GetLibraryPath_setting:
- strncpy( pstr_solibpath, pstr_nowpath, DRD64_MAX_PATH );
+goto_LibBrownie_GetLibraryPath_post:
- return 0x00;
+ return i_result;
}