Merge pull request #76 from melak/tilib_path_facelift

Facelift MSPDEBUG_TILIB_PATH handling
This commit is contained in:
Daniel Beer 2018-09-17 16:34:14 +12:00 committed by GitHub
commit b975fd00a0
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 11 additions and 7 deletions

View File

@ -18,6 +18,7 @@
#include <limits.h> #include <limits.h>
#include <stddef.h> #include <stddef.h>
#include <stdio.h>
#include <stdlib.h> #include <stdlib.h>
#include <string.h> #include <string.h>
#include "util/output.h" #include "util/output.h"
@ -760,18 +761,21 @@ static int init_old_api(void)
int tilib_api_init(void) int tilib_api_init(void)
{ {
int ret; int ret, res;
char libpath[PATH_MAX], *path; char libpath[PATH_MAX], *path;
libpath[0] = '\0'; libpath[0] = '\0';
if ((path = getenv("MSPDEBUG_TILIB_PATH")) != NULL) { if ((path = getenv("MSPDEBUG_TILIB_PATH")) != NULL) {
if (strlen(path) + strlen(tilib_filename) + 2 < PATH_MAX) { res = snprintf(libpath, sizeof(libpath), "%s/%s", path, tilib_filename);
strcat(libpath, path); } else {
strcat(libpath, "/"); res = snprintf(libpath, sizeof(libpath), "%s", tilib_filename);
} else }
printc_err("Contents of MSP430_PATH variable are too long, ignoring\n");
if(res == -1 || res >= sizeof(libpath)) {
printc_err("MSPDEBUG_TILIB_PATH specifies too long a path\n");
return -1;
} }
strcat(libpath, tilib_filename);
lib_handle = dynload_open(libpath); lib_handle = dynload_open(libpath);