From: Uwe Hermann Date: Tue, 15 Aug 2017 20:15:47 +0000 (+0200) Subject: resource: Also check $SIGROK_FIRMWARE_DIR for firmware files. X-Git-Url: https://sigrok.org/gitaction?a=commitdiff_plain;h=1503d4571b1ed2a1afb75198ca3b7ffc97c829f8;p=libsigrok.git resource: Also check $SIGROK_FIRMWARE_DIR for firmware files. If the SIGROK_FIRMWARE_DIR environment variable is specified, look there first for firmware files. --- diff --git a/README.devices b/README.devices index 584899e2..3e0d5f2d 100644 --- a/README.devices +++ b/README.devices @@ -14,6 +14,7 @@ the device is connected to the PC (usually via USB), before it can be used. The default locations where libsigrok expects the firmware files are: + $SIGROK_FIRMWARE_DIR (environment variable) $HOME/.local/share/sigrok-firmware $prefix/share/sigrok-firmware /usr/local/share/sigrok-firmware diff --git a/src/resource.c b/src/resource.c index 63415930..ec32a442 100644 --- a/src/resource.c +++ b/src/resource.c @@ -102,9 +102,9 @@ static int resource_open_default(struct sr_resource *res, #ifdef FIRMWARE_DIR const char *builtindir; #endif - const char *subdir; + const char *subdir, *env; const char *const *datadirs; - FILE *file; + FILE *file = NULL; (void)cb_data; @@ -120,7 +120,15 @@ static int resource_open_default(struct sr_resource *res, return SR_ERR_ARG; } - file = try_open_file(g_get_user_data_dir(), subdir, name); + env = g_getenv("SIGROK_FIRMWARE_DIR"); + if (!env) + sr_dbg("SIGROK_FIRMWARE_DIR environment variable not set, ignoring."); + else + file = try_open_file(env, "", name); + + if (!file) + file = try_open_file(g_get_user_data_dir(), subdir, name); + /* * Scan the hard-coded directory before the system directories to * avoid picking up possibly outdated files from a system install.