|
|
|
@ -5,35 +5,39 @@ static char *file_contents(const char *filename, int *length)
@@ -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; |
|
|
|
|
|
|
|
|
|
if (opt_kernel_path && *opt_kernel_path) { |
|
|
|
|
/* Try in the optional kernel path first, defaults to PREFIX */ |
|
|
|
|
strcpy(fullpath, opt_kernel_path); |
|
|
|
|
strcat(fullpath, filename); |
|
|
|
|
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); |
|
|
|
|