From c0d79fa3fe17e4bb7a420db87e11a063cb6a3181 Mon Sep 17 00:00:00 2001 From: troky Date: Mon, 16 Jun 2014 20:06:55 +0200 Subject: [PATCH] Refactored kernel source loading (missing / delimiter). Added more debug messages. --- ocl/build_kernel.c | 30 +++++++++++++++++------------- 1 file changed, 17 insertions(+), 13 deletions(-) diff --git a/ocl/build_kernel.c b/ocl/build_kernel.c index b2afd727..dc98319b 100644 --- a/ocl/build_kernel.c +++ b/ocl/build_kernel.c @@ -5,35 +5,39 @@ static char *file_contents(const char *filename, int *length) { char *fullpath = (char *)alloca(PATH_MAX); void *buffer; - FILE *f; + FILE *f = NULL; - /* Try in the optional kernel path first, defaults to PREFIX */ - strcpy(fullpath, opt_kernel_path); - strcat(fullpath, filename); - f = fopen(fullpath, "rb"); + if (opt_kernel_path && *opt_kernel_path) { + /* Try in the optional kernel path first, defaults to PREFIX */ + snprintf(fullpath, PATH_MAX, "%s/%s", opt_kernel_path, filename); + applog(LOG_DEBUG, "Trying to open %s...", fullpath); + f = fopen(fullpath, "rb"); + } if (!f) { /* Then try from the path sgminer was called */ - strcpy(fullpath, sgminer_path); - strcat(fullpath, filename); + snprintf(fullpath, PATH_MAX, "%s/%s", sgminer_path, filename); + applog(LOG_DEBUG, "Trying to open %s...", fullpath); f = fopen(fullpath, "rb"); } if (!f) { /* Then from `pwd`/kernel/ */ - strcpy(fullpath, sgminer_path); - strcat(fullpath, "/kernel/"); - strcat(fullpath, filename); + snprintf(fullpath, PATH_MAX, "%s/kernel/%s", sgminer_path, filename); + applog(LOG_DEBUG, "Trying to open %s...", fullpath); f = fopen(fullpath, "rb"); } /* Finally try opening it directly */ - if (!f) + if (!f) { + applog(LOG_DEBUG, "Trying to open %s...", fullpath); f = fopen(filename, "rb"); + } if (!f) { - applog(LOG_ERR, "Unable to open %s or %s for reading", - filename, fullpath); + applog(LOG_ERR, "Unable to open %s for reading!", filename); return NULL; } + applog(LOG_DEBUG, "Using %s", fullpath); + fseek(f, 0, SEEK_END); *length = ftell(f); fseek(f, 0, SEEK_SET);