]> sigrok.org Git - libsigrok.git/blobdiff - src/resource.c
korad-kaxxxxp: Simplify korad_kaxxxxp_receive_data() event loop function.
[libsigrok.git] / src / resource.c
index b921d93da8df5ecef1849460f2f3df8d8b3aae0e..ec32a4420f7755de5c5491047a756c59d56d3ba7 100644 (file)
@@ -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.
@@ -135,7 +143,7 @@ static int resource_open_default(struct sr_resource *res,
                        file = try_open_file(*datadirs++, subdir, name);
        }
        if (!file) {
-               sr_err("Failed to locate '%s'.", name);
+               sr_dbg("Failed to locate '%s'.", name);
                return SR_ERR;
        }
 
@@ -224,15 +232,15 @@ SR_API int sr_resource_set_hooks(struct sr_context *ctx,
                return SR_ERR_ARG;
        }
        if (open_cb && close_cb && read_cb) {
-               ctx->resource_open_cb  = open_cb;
+               ctx->resource_open_cb = open_cb;
                ctx->resource_close_cb = close_cb;
-               ctx->resource_read_cb  = read_cb;
-               ctx->resource_cb_data  = cb_data;
+               ctx->resource_read_cb = read_cb;
+               ctx->resource_cb_data = cb_data;
        } else if (!open_cb && !close_cb && !read_cb) {
-               ctx->resource_open_cb  = &resource_open_default;
+               ctx->resource_open_cb = &resource_open_default;
                ctx->resource_close_cb = &resource_close_default;
-               ctx->resource_read_cb  = &resource_read_default;
-               ctx->resource_cb_data  = ctx;
+               ctx->resource_read_cb = &resource_read_default;
+               ctx->resource_cb_data = ctx;
        } else {
                sr_err("%s: inconsistent callback pointers.", __func__);
                return SR_ERR_ARG;
@@ -266,7 +274,8 @@ SR_PRIV int sr_resource_open(struct sr_context *ctx,
        ret = (*ctx->resource_open_cb)(res, name, ctx->resource_cb_data);
 
        if (ret != SR_OK)
-               sr_err("Failed to open resource '%s'.", name);
+               sr_err("Failed to open resource '%s' (use loglevel 5/spew for"
+                      " details).", name);
 
        return ret;
 }
@@ -332,7 +341,7 @@ SR_PRIV gssize sr_resource_read(struct sr_context *ctx,
  * @param max_size Size limit. Error out if the resource is larger than this.
  *
  * @return A buffer containing the resource data, or NULL on failure. Must
- *  be freed by the caller using g_free().
+ *         be freed by the caller using g_free().
  *
  * @private
  */