int LibBrownie_FreeLoadLibraryPath( Byte b_ldbits );
+/* drd64_libbrownie_searchlib.c Functions ====================*/
+#ifdef DRD64_SRC_LIBBROWNIE_SEARCHLIB
+ #define LIBBROWNIE_SEARCHLIB_API
+#else
+ #define LIBBROWNIE_SEARCHLIB_API extern
+#endif
+LIBBROWNIE_SEARCHLIB_API
+ int LibBrownie_GetLibraryPath(
+ char *pstr_solibpath, char *pstr_solibname, char *pstr_rpath, char *pstr_ldsohints );
+
+
#endif /* DRD64_HEADER_XXX */
/* EOF of drd64_.h ----------------------------------- */
drd64_libbrownie_error.o \
drd64_libbrownie_inetaddr.o \
drd64_libbrownie_socket.o \
- drd64_libbrownie_ldsohints.o
+ drd64_libbrownie_ldsohints.o \
+ drd64_libbrownie_searchlib.o
LIBBROWNIE_HEADER = drd64_libbrownie.h \
drd64_libbrownie_error.h \
drd64_libbrownie_ldsohints.h \
+ drd64_libbrownie_searchlib.h \
../include/libbrownie.h \
$(SUPER_HEADER)
TEST_OBJS = \
test_libbrownie.o \
test_libbrownie_error.o \
- test_libbrownie_ldsohints.o
+ test_libbrownie_ldsohints.o \
+ test_libbrownie_searchlib.o
TEST_HEADER = test_libbrownie.h
drd64_libbrownie_ldsohints.o: drd64_libbrownie_ldsohints.c $(LIBBROWNIE_HEADER)
$(CC) -c -o drd64_libbrownie_ldsohints.o $(FLAGS_DEBUG) \
drd64_libbrownie_ldsohints.c
+drd64_libbrownie_searchlib.o: drd64_libbrownie_searchlib.c $(LIBBROWNIE_HEADER)
+ $(CC) -c -o drd64_libbrownie_searchlib.o $(FLAGS_DEBUG) \
+ drd64_libbrownie_searchlib.c
test_libbrownie.o: test_libbrownie.c $(LIBBROWNIE_HEADER) $(TEST_HEADER)
$(CC) -c -o test_libbrownie_ldsohints.o \
$(FLAGS_DEBUG) $(FLAGS_COMPILE) $(TEST_FLAGS_COMPILE) \
test_libbrownie_ldsohints.c
+test_libbrownie_searchlib.o: test_libbrownie_searchlib.c $(LIBBROWNIE_HEADER) $(TEST_HEADER)
+ $(CC) -c -o test_libbrownie_searchlib.o \
+ $(FLAGS_DEBUG) $(FLAGS_COMPILE) $(TEST_FLAGS_COMPILE) \
+ test_libbrownie_searchlib.c
$(TEST_TARGET): $(TEST_OBJS) $(LIBBROWNIE_OBJS) $(LIBBROWNIE_TARGET)
$(CC) -o $(TEST_TARGET) $(FLAGS_DEBUG) $(LIBBROWNIE_OBJS) $(TEST_OBJS) $(LIBBROWNIE_TARGET) \
#include<fcntl.h>
#include<assert.h>
#include<sys/types.h>
+#include<sys/stat.h>
#include<sys/socket.h>
#include<sys/un.h>
#include<netinet/in.h>
#include"../include/libbrownie.h"
#include"drd64_libbrownie_error.h"
#include"drd64_libbrownie_ldsohints.h"
+#include"drd64_libbrownie_searchlib.h"
#endif /* DRD64_HEADER_XXX */
--- /dev/null
+/*DrDeAmOn64DrDeAmOn64DrDeAmOn64DrDeAmOn64DrDeAmOn64DrDeAmOn64DrDeAmOn64
+
+ D r . D e a m o n 6 4
+ for INTEL64(R), AMD64(R)
+
+ Copyright(C) 2007-2009 Koine Yuusuke(koinec). All rights reserved.
+
+Redistribution and use in source and binary forms, with or without
+modification, are permitted provided that the following conditions are met:
+
+ 1. Redistributions of source code must retain the above copyright notice,
+ this list of conditions and the following disclaimer.
+ 2. Redistributions in binary form must reproduce the above copyright
+ notice, this list of conditions and the following disclaimer in the
+ documentation and/or other materials provided with the distribution.
+
+THIS SOFTWARE IS PROVIDED BY Koine Yuusuke(koinec) ``AS IS'' AND ANY
+EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
+WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
+DISCLAIMED. IN NO EVENT SHALL Koine Yuusuke(koinec) OR CONTRIBUTORS BE
+LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
+OF THE POSSIBILITY OF SUCH DAMAGE.
+
+DrDeAmOn64DrDeAmOn64DrDeAmOn64DrDeAmOn64DrDeAmOn64DrDeAmOn64DrDeAmOn64*/
+
+/* File Info -----------------------------------------------------------
+File: drd64_.c
+Function:
+Comment:
+----------------------------------------------------------------------*/
+
+#define DRD64_SRC_LIBBROWNIE_SEARCHLIB
+#include"drd64_libbrownie.h"
+
+
+/*----------------------------------------------------------------------
+----------------------------------------------------------------------*/
+int
+ LibBrownie_SearchLib_IsExistLibrary(
+ char *pstr_path,
+ char *pstr_solibname )
+{
+ int i_result;
+ size_t sz_len;
+ struct stat t_filestat;
+ char str_solibpath[DRD64_MAX_PATH];
+
+ sz_len = strnlen( pstr_path, DRD64_MAX_PATH );
+ sz_len += strnlen( pstr_solibname, DRD64_MAX_PATH );
+
+ if( DRD64_MAX_PATH - 1 <= sz_len ) {
+ return -0x01;
+ }
+
+ strncpy( str_solibpath, pstr_path, DRD64_MAX_PATH );
+ strncat( str_solibpath, "/", DRD64_MAX_PATH );
+ strncat( str_solibpath, pstr_solibname, DRD64_MAX_PATH );
+ i_result = stat( str_solibpath, &t_filestat );
+
+ return i_result;
+}
+
+
+/***********************************************************************
+***********************************************************************/
+LIBBROWNIE_SEARCHLIB_API
+int
+ LibBrownie_GetLibraryPath(
+ char *pstr_solibpath,
+ char *pstr_solibname,
+ char *pstr_rpath,
+ char *pstr_ldsohints )
+{
+ int i_result;
+ int i_flag;
+ size_t sz_len;
+ char *pstr_hintslist;
+ char *pstr_nowpath;
+ char *pstr_nowpos;
+
+ if( NULL == pstr_solibpath ) {
+ return -0x01;
+ }
+
+ if( NULL == pstr_ldsohints ) {
+ return -0x02;
+ }
+
+ if( NULL != pstr_rpath ) {
+ i_result = LibBrownie_SearchLib_IsExistLibrary( pstr_rpath, pstr_solibname );
+ if( 0x00 == i_result ) {
+ pstr_nowpath = pstr_rpath;
+ goto goto_LibBrownie_GetLibraryPath_setting;
+ }
+ }
+
+ sz_len = strlen( pstr_ldsohints );
+ pstr_hintslist = (char *)alloca( sz_len + 1 );
+ if( NULL == pstr_hintslist ) {
+ return -0x03;
+ }
+
+ strncpy( pstr_hintslist, pstr_ldsohints, sz_len + 1 );
+
+ 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++ );
+
+goto_LibBrownie_GetLibraryPath_setting:
+ strncpy( pstr_solibpath, pstr_nowpath, DRD64_MAX_PATH );
+ strncat( pstr_solibpath, "/", DRD64_MAX_PATH );
+ strncat( pstr_solibpath, pstr_solibname, DRD64_MAX_PATH );
+
+ return 0x00;
+}
+
+
+/* EOF of drd64_.c ----------------------------------- */
--- /dev/null
+/*DrDeAmOn64DrDeAmOn64DrDeAmOn64DrDeAmOn64DrDeAmOn64DrDeAmOn64DrDeAmOn64
+
+ D r . D e a m o n 6 4
+ for INTEL64(R), AMD64(R)
+
+ Copyright(C) 2007-2009 Koine Yuusuke(koinec). All rights reserved.
+
+Redistribution and use in source and binary forms, with or without
+modification, are permitted provided that the following conditions are met:
+
+ 1. Redistributions of source code must retain the above copyright notice,
+ this list of conditions and the following disclaimer.
+ 2. Redistributions in binary form must reproduce the above copyright
+ notice, this list of conditions and the following disclaimer in the
+ documentation and/or other materials provided with the distribution.
+
+THIS SOFTWARE IS PROVIDED BY Koine Yuusuke(koinec) ``AS IS'' AND ANY
+EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
+WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
+DISCLAIMED. IN NO EVENT SHALL Koine Yuusuke(koinec) OR CONTRIBUTORS BE
+LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
+OF THE POSSIBILITY OF SUCH DAMAGE.
+
+DrDeAmOn64DrDeAmOn64DrDeAmOn64DrDeAmOn64DrDeAmOn64DrDeAmOn64DrDeAmOn64*/
+
+/* File Info -----------------------------------------------------------
+File: drd64_.h
+Function: Header
+Comment:
+----------------------------------------------------------------------*/
+
+#ifndef DRD64_HEADER_LIBBROWNIE_SEARCHLIB
+#define DRD64_HEADER_LIBBROWNIE_SEARCHLIB
+
+#ifdef DRD64_SRC_LIBBROWNIE_SEARCHLIB
+ #define LIBBROWNIE_SEARCHLIB_EXTERN
+#else
+ #define LIBBROWNIE_SEARCHLIB_EXTERN extern
+#endif
+
+
+
+#endif /* DRD64_HEADER_XXX */
+
+/* EOF of drd64_.h ----------------------------------- */
Test_LibBrownie_Error();
Test_LibBrownie_LdSoHints();
+ Test_LibBrownie_SearchLib();
CU_basic_run_tests();
CU_cleanup_registry();
#endif
DRD64_TEST_LIBBROWNIE_LDSOHINTS_EXTERN int Test_LibBrownie_LdSoHints( void );
+#ifdef DRD64_SRC_TEST_LIBBROWNIE_SEARCHLIB
+ #define DRD64_TEST_LIBBROWNIE_SEARCHLIB_EXTERN
+#else
+ #define DRD64_TEST_LIBBROWNIE_SEARCHLIB_EXTERN extern
+#endif
+DRD64_TEST_LIBBROWNIE_SEARCHLIB_EXTERN int Test_LibBrownie_SearchLib( void );
#endif /* DRD64_HEADER_XXX */
--- /dev/null
+/*DrDeAmOn64DrDeAmOn64DrDeAmOn64DrDeAmOn64DrDeAmOn64DrDeAmOn64DrDeAmOn64
+
+ D r . D e a m o n 6 4
+ for INTEL64(R), AMD64(R)
+
+ Copyright(C) 2007-2009 Koine Yuusuke(koinec). All rights reserved.
+
+Redistribution and use in source and binary forms, with or without
+modification, are permitted provided that the following conditions are met:
+
+ 1. Redistributions of source code must retain the above copyright notice,
+ this list of conditions and the following disclaimer.
+ 2. Redistributions in binary form must reproduce the above copyright
+ notice, this list of conditions and the following disclaimer in the
+ documentation and/or other materials provided with the distribution.
+
+THIS SOFTWARE IS PROVIDED BY Koine Yuusuke(koinec) ``AS IS'' AND ANY
+EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
+WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
+DISCLAIMED. IN NO EVENT SHALL Koine Yuusuke(koinec) OR CONTRIBUTORS BE
+LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
+OF THE POSSIBILITY OF SUCH DAMAGE.
+
+DrDeAmOn64DrDeAmOn64DrDeAmOn64DrDeAmOn64DrDeAmOn64DrDeAmOn64DrDeAmOn64*/
+
+/* File Info -----------------------------------------------------------
+File: drd64_.c
+Function:
+Comment:
+----------------------------------------------------------------------*/
+
+#define DRD64_SRC_TEST_LIBBROWNIE_SEARCHLIB
+#include"test_libbrownie.h"
+#include"drd64_libbrownie.h"
+
+/*----------------------------------------------------------------------
+----------------------------------------------------------------------*/
+void Test_LibBrownie_SearchLib_test00_001_sub(int i_testid, char *pstr_solibname)
+{
+ int i_result;
+ char *pstr_result;
+ char str_resolvpath[DRD64_MAX_PATH];
+
+ pstr_result = LibBrownie_GetLoadLibraryPath( LIBBROWNIE_LDHINTS_ELF64 );
+ CU_ASSERT( NULL != pstr_result );
+
+ i_result = LibBrownie_GetLibraryPath(
+ str_resolvpath, pstr_solibname, NULL, pstr_result );
+ CU_ASSERT( 0x00 == i_result );
+ printf(" SearchLib Test%03d: %s\n", i_testid, str_resolvpath );
+
+ return;
+}
+
+/*----------------------------------------------------------------------
+----------------------------------------------------------------------*/
+void Test_LibBrownie_SearchLib_test00_001(void)
+{
+ int i_result;
+ char *pstr_result;
+ char str_resolvpath[DRD64_MAX_PATH];
+
+ i_result = LibBrownie_Init();
+ CU_ASSERT( i_result == 0x00 );
+
+ Test_LibBrownie_SearchLib_test00_001_sub( 1, "libc.so.7" );
+ Test_LibBrownie_SearchLib_test00_001_sub( 2, "libbz2.so.4" );
+ Test_LibBrownie_SearchLib_test00_001_sub( 3, "libX11.so.6" );
+ Test_LibBrownie_SearchLib_test00_001_sub( 4, "libLTO.so" );
+
+ LibBrownie_FreeLoadLibraryPath( LIBBROWNIE_LDHINTS_ELF64 );
+
+ LibBrownie_Term();
+
+ return;
+}
+
+
+
+/*----------------------------------------------------------------------
+----------------------------------------------------------------------*/
+DRD64_TEST_LIBBROWNIE_SEARCHLIB_EXTERN
+int
+ Test_LibBrownie_SearchLib(
+ void )
+{
+ CU_pSuite pt_brownie;
+
+ pt_brownie = CU_add_suite( "LibBrownie_SearchLib", NULL, NULL );
+
+ CU_add_test( pt_brownie, "LibBrownie_SearchLib_test00_001",
+ Test_LibBrownie_SearchLib_test00_001 );
+
+ return 0x00;
+}
+
+
+/* EOF of drd64_.c ----------------------------------- */