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