Skip to content

Commit

Permalink
Search LD_LIBRARY_PATH on linux, closes #1
Browse files Browse the repository at this point in the history
  • Loading branch information
dtcooper committed Oct 20, 2024
1 parent 8dd5880 commit 3d19757
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 2 deletions.
2 changes: 1 addition & 1 deletion LICENSE
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
MIT License

Copyright (c) 2017-2022, David Cooper <[email protected]>
Copyright (c) 2017-2024, David Cooper <[email protected]>

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
Expand Down
29 changes: 28 additions & 1 deletion src/fakehostname.c
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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;
Expand Down

0 comments on commit 3d19757

Please sign in to comment.