From 3d197578639bf1fe89f28e4c677388c8797a45e0 Mon Sep 17 00:00:00 2001 From: David Cooper Date: Sun, 20 Oct 2024 13:51:00 -0400 Subject: [PATCH] Search LD_LIBRARY_PATH on linux, closes #1 --- LICENSE | 2 +- src/fakehostname.c | 29 ++++++++++++++++++++++++++++- 2 files changed, 29 insertions(+), 2 deletions(-) diff --git a/LICENSE b/LICENSE index 0bd3098..9ed0848 100644 --- a/LICENSE +++ b/LICENSE @@ -1,6 +1,6 @@ MIT License -Copyright (c) 2017-2022, David Cooper +Copyright (c) 2017-2024, David Cooper Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal diff --git a/src/fakehostname.c b/src/fakehostname.c index af7721e..04b7e4d 100644 --- a/src/fakehostname.c +++ b/src/fakehostname.c @@ -23,7 +23,9 @@ static char *new_hostname; char *get_lib_path() { static char lib_path[PATH_MAX]; - char lib_locations[] = LIB_LOCATIONS; + #ifndef __linux__ + char lib_locations[] = LIB_LOCATIONS; + #endif if (custom_lib_path != NULL) { DEBUG("Using custom library path: %s\n", custom_lib_path) @@ -35,6 +37,31 @@ char *get_lib_path() { return custom_lib_path; } + #ifdef __linux__ + char *lib_locations; + char *ld_library_path = getenv("LD_LIBRARY_PATH"); + if (ld_library_path != NULL) { + DEBUG("Found LD_LIBRARY_PATH and prepending it to lib location search: %s\n", ld_library_path) + + lib_locations = malloc(strlen(ld_library_path) + strlen(LIB_LOCATIONS) + 2); + if (lib_locations == NULL) { + printf("Error allocating memory!\n"); + exit(1); + } + strcpy(lib_locations, ld_library_path); + strcat(lib_locations, ":"); + strcat(lib_locations, LIB_LOCATIONS); + } else { + lib_locations = malloc(strlen(LIB_LOCATIONS) + 1); + if (lib_locations == NULL) { + printf("Error allocating memory!\n"); + exit(1); + } + strcpy(lib_locations, LIB_LOCATIONS); + } + #endif + + DEBUG("Searching for libs in: %s\n", lib_locations) for ( char *lib_path_prefix = strtok(lib_locations, ":"); lib_path_prefix != NULL;