aboutsummaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
authorJoseph Hunkeler <jhunkeler@users.noreply.github.com>2020-06-07 02:00:13 -0400
committerGitHub <noreply@github.com>2020-06-07 02:00:13 -0400
commita9163234b166945a6d62efedf35940455ef6e138 (patch)
treef3a0874ce443e19df9ce5988dd1afcbf97242e33 /lib
parentbd83a3adb8cf3455f6515a6527f2d1293dd08ca1 (diff)
parent67c0eb41848eee453cbc0b1ba480167462270dfe (diff)
downloadspmc-a9163234b166945a6d62efedf35940455ef6e138.tar.gz
Merge pull request #43 from jhunkeler/dead-code
Dead code
Diffstat (limited to 'lib')
-rw-r--r--lib/CMakeLists.txt1
-rw-r--r--lib/find.c151
-rw-r--r--lib/fs.c72
-rw-r--r--lib/rpath.c86
4 files changed, 71 insertions, 239 deletions
diff --git a/lib/CMakeLists.txt b/lib/CMakeLists.txt
index 96147e1..e959702 100644
--- a/lib/CMakeLists.txt
+++ b/lib/CMakeLists.txt
@@ -11,7 +11,6 @@ set(libspm_src
resolve.c
fs.c
rpath.c
- find.c
shell.c
archive.c
str.c
diff --git a/lib/find.c b/lib/find.c
deleted file mode 100644
index 348a8f7..0000000
--- a/lib/find.c
+++ /dev/null
@@ -1,151 +0,0 @@
-/**
- * @file find.c
- */
-#include "spm.h"
-
-/**
- * glob callback function
- * @param epath path to file that generated the error condition
- * @param eerrno the error condition
- * @return the error condition
- */
-int errglob(const char *epath, int eerrno) {
- fprintf(stderr, "glob matching error: %s (%d)", epath, eerrno);
- return eerrno;
-}
-
-/**
- * Scan a directory for a file by name, or by wildcard
- *
- * @param root directory path to scan
- * @param filename file to find (wildcards accepted)
- * @return success=path to file, failure=NULL
- */
-char *find_file(const char *root, const char *filename) {
- glob_t results;
- int glob_flags = 0;
- int match = 0;
- char path[PATH_MAX];
- memset(path, '\0', PATH_MAX);
-
- // GUARD
- if (!root || !filename || strstr(filename, "..") || strstr(filename, "./")) {
- return NULL;
- }
-
- if (realpath(root, path) == NULL) {
- perror("Cannot determine realpath()");
- fprintf(SYSERROR);
- return NULL;
- }
-
- strcat(path, "/");
- strcat(path, filename);
-
- // Save a little time if the file exists
- if (access(path, F_OK) != -1) {
- return strdup(path);
- }
-
- // Inject wildcard
- strcat(path, "*");
- // Search for the file
- match = glob(path, glob_flags, errglob, &results);
-
- if (match != 0) {
- // report critical errors except GLOB_NOMATCH
- if (match == GLOB_NOSPACE || match == GLOB_ABORTED) {
- fprintf(SYSERROR);
- }
- globfree(&results);
- return NULL;
- }
-
- // Replace path string with wanted path string
- strcpy(path, results.gl_pathv[0]);
-
- globfree(&results);
- return strdup(path);
-}
-
-/**
- * Scan the package directory for a package by name
- * @param filename file to find
- * @return success=path to file, failure=NULL
- */
-char *find_package(const char *filename) {
- char *repo = join((char *[]) {SPM_GLOBAL.package_dir, SPM_GLOBAL.repo_target, NULL}, DIRSEPS);
- char *match = find_file(repo, filename);
- free(repo);
- return match;
-}
-
-/**
- * Determine whether `pattern` is present within a file
- * @param filename
- * @param pattern
- * @return 0=found, 1=not found, -1=OS error
- */
-int find_in_file(const char *filename, const char *pattern) {
- int result = 1; // default "not found"
-
- FILE *fp = fopen(filename, "rb");
- if (!fp) {
- return -1;
- }
-
- long int file_len = get_file_size(filename);
- if (file_len == -1) {
- fclose(fp);
- return -1;
- }
- char *buffer = (char *)calloc((size_t) file_len, sizeof(char));
- if (!buffer) {
- fclose(fp);
- return -1;
- }
- size_t pattern_len = strlen(pattern);
-
- fread(buffer, (size_t) file_len, sizeof(char), fp);
- fclose(fp);
-
- for (size_t i = 0; i < (size_t) file_len; i++) {
- if (memcmp(&buffer[i], pattern, pattern_len) == 0) {
- result = 0; // found
- break;
- }
- }
- free(buffer);
- return result;
-}
-
-/**
- * Get the full path of a shell command
- * @param program
- * @return success=absolute path to program, failure=NULL
- */
-char *find_executable(const char *program) {
- int found = 0;
- char *result = NULL;
- char *env_path = NULL;
- env_path = getenv("PATH");
- if (!env_path) {
- return NULL;
- }
- char **search_paths = split(env_path, ":");
-
- char buf[PATH_MAX];
- for (int i = 0; search_paths[i] != NULL; i++) {
- sprintf(buf, "%s%c%s", search_paths[i], DIRSEP, program);
- if (access(buf, F_OK | X_OK) == 0) {
- found = 1;
- break;
- }
- memset(buf, '\0', sizeof(buf));
- }
- if (found) {
- result = strdup(buf);
- }
- split_free(search_paths);
- return result;
-}
diff --git a/lib/fs.c b/lib/fs.c
index 0cdda41..98a18e6 100644
--- a/lib/fs.c
+++ b/lib/fs.c
@@ -764,4 +764,74 @@ char **file_readlines(const char *filename, size_t start, size_t limit, ReaderFn
fclose(fp);
}
return result;
-} \ No newline at end of file
+}
+
+/**
+ * Determine whether `pattern` is present within a file
+ * @param filename
+ * @param pattern
+ * @return 0=found, 1=not found, -1=OS error
+ */
+int find_in_file(const char *filename, const char *pattern) {
+ int result = 1; // default "not found"
+
+ FILE *fp = fopen(filename, "rb");
+ if (!fp) {
+ return -1;
+ }
+
+ long int file_len = get_file_size(filename);
+ if (file_len == -1) {
+ fclose(fp);
+ return -1;
+ }
+ char *buffer = (char *)calloc((size_t) file_len, sizeof(char));
+ if (!buffer) {
+ fclose(fp);
+ return -1;
+ }
+ size_t pattern_len = strlen(pattern);
+
+ fread(buffer, (size_t) file_len, sizeof(char), fp);
+ fclose(fp);
+
+ for (size_t i = 0; i < (size_t) file_len; i++) {
+ if (memcmp(&buffer[i], pattern, pattern_len) == 0) {
+ result = 0; // found
+ break;
+ }
+ }
+ free(buffer);
+ return result;
+}
+
+/**
+ * Get the full path of a shell command
+ * @param program
+ * @return success=absolute path to program, failure=NULL
+ */
+char *find_executable(const char *program) {
+ int found = 0;
+ char *result = NULL;
+ char *env_path = NULL;
+ env_path = getenv("PATH");
+ if (!env_path) {
+ return NULL;
+ }
+ char **search_paths = split(env_path, ":");
+
+ char buf[PATH_MAX];
+ for (int i = 0; search_paths[i] != NULL; i++) {
+ sprintf(buf, "%s%c%s", search_paths[i], DIRSEP, program);
+ if (access(buf, F_OK | X_OK) == 0) {
+ found = 1;
+ break;
+ }
+ memset(buf, '\0', sizeof(buf));
+ }
+ if (found) {
+ result = strdup(buf);
+ }
+ split_free(search_paths);
+ return result;
+}
diff --git a/lib/rpath.c b/lib/rpath.c
index f15de86..6e4fa00 100644
--- a/lib/rpath.c
+++ b/lib/rpath.c
@@ -193,49 +193,11 @@ FSTree *rpath_libraries_available(const char *root) {
* @return success=relative path from `filename` to nearest lib directory, failure=NULL
*/
char *rpath_autodetect(const char *filename, FSTree *tree, const char *destroot) {
- const char *origin;
char *rootdir = dirname(filename);
char *start = realpath(rootdir, NULL);
char *cwd = realpath(".", NULL);
char *result = NULL;
- char *visit = NULL; // Current directory
- char _relative[PATH_MAX] = {0,}; // Generated relative path to lib directory
- char *relative = _relative; // Pointer to relative path
- size_t depth_to_root = 0;
-
-#if OS_DARWIN
- origin = "@rpath";
-#elif OS_LINUX
- origin = "$ORIGIN";
-#else
- origin = NULL;
-#endif
-
- // BUG: Perl dumps its shared library in a strange place.
- // This function returns `$ORIGIN/../../../CORE` which is not what we want to see.
- // TODO: We WANT to see this: `$ORIGIN/../lib/perl5/xx.xx.xx/<arch>/CORE` not just the basename()
-
- /*
- // Change directory to the requested root
- chdir(start);
-
- // Count the relative path distance between the location of the binary, and the top of the root
- visit = strdup(start);
- for (depth_to_root = 0; strcmp(tree->root, visit) != 0; depth_to_root++) {
- // Copy the current visit pointer
- char *prev = visit;
- // Walk back another directory level
- visit = dirname(visit);
- // Free previous visit pointer
- if (prev) free(prev);
- }
- free(visit);
-
- // return to calling directory
- chdir(cwd);
- */
-
StrList *libs = strlist_init();
if (libs == NULL) {
fprintf(stderr, "failed to initialize library StrList\n");
@@ -273,54 +235,6 @@ char *rpath_autodetect(const char *filename, FSTree *tree, const char *destroot)
free(repl);
}
- /*
- for (size_t i = 0; i < strlist_count(libs_wanted); i++) {
- // zero out relative path string
- memset(_relative, '\0', sizeof(_relative));
- // Get the shared library name we are going to look for in the tree
- char *shared_library = strlist_item(libs_wanted, i);
-
- // Is the shared library in the tree?
- char *match = NULL;
- if ((match = dirname(fstree_search(tree, shared_library))) != NULL) {
- // Begin generating the relative path string
- //strcat(relative, origin);
- //strcat(relative, DIRSEPS);
-
- // Append the number of relative levels to the relative path string
- if (depth_to_root) {
- for (size_t d = 0; d < depth_to_root; d++) {
- strcat(relative, "..");
- strcat(relative, DIRSEPS);
- }
- } else {
- strcat(relative, "..");
- strcat(relative, DIRSEPS);
- }
- // Append the match to the relative path string
- strcat(relative, basename(match));
-
- // Append relative path to array of libraries (if it isn't already in there)
- if (strstr_array(libs->data, relative) == NULL) {
- char *final = realpath(relative, NULL);
- strlist_append(libs, final);
- free(final);
- }
- }
- }
- */
-
-#if OS_LINUX
- // Some programs do not require local libraries provided by SPM (i.e. libc)
- // Inject "likely" defaults here
- /*
- if (strlist_count(libs) == 0) {
- strlist_append(libs, "$ORIGIN/../lib");
- strlist_append(libs, "$ORIGIN/../lib64");
- }
- */
-#endif
-
// Populate result string
result = join(libs->data, ":");