* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
+#include <stdio.h>
#include <string.h>
#include <errno.h>
#include <sys/queue.h>
return NULL;
}
+int resource_fwrite(const struct resource *r, FILE *f)
+{
+ const size_t goal = resource_size(r);
+ size_t total = 0;
+
+ while (total < goal) {
+ size_t wlen = fwrite(r->begin + total, 1, goal - total, f);
+ if (wlen == 0) {
+ perror(__func__);
+ return -1;
+ }
+
+ total += wlen;
+ }
+
+ return 0;
+}
+
+int resource_fwrite_file(const struct resource *r, const char *fname)
+{
+ FILE *f;
+ int ret;
+
+ f = fopen(fname, "w");
+ if (f == NULL) {
+ perror(__func__);
+ return -1;
+ }
+
+ ret = resource_fwrite(r, f);
+ fclose(f);
+ return ret;
+}
+
void resource_register(struct resource *r)
{
TAILQ_INSERT_TAIL(&resource_list, r, next);
*/
#include <sys/queue.h>
+#include <stdio.h>
#include <stddef.h>
#include <rte_eal.h>
*/
const struct resource *resource_find(const char *name);
+/**
+ * Write the raw data of the resource to the given file.
+ * @return 0 on success
+ */
+int resource_fwrite(const struct resource *r, FILE *f);
+
+/**
+ * Write the raw data of the resource to the given file given by name.
+ * The name is relative to the current working directory.
+ * @return 0 on success
+ */
+int resource_fwrite_file(const struct resource *r, const char *fname);
+
/**
* Register a resource in the global list of resources.
* Not intended for direct use, please check the REGISTER_RESOURCE
static int test_resource_c(void)
{
const struct resource *r;
+ FILE *f;
r = resource_find("test_resource_c");
TEST_ASSERT_NOT_NULL(r, "No test_resource_c found");
"Found resource %s, expected test_resource_c",
r->name);
+ TEST_ASSERT_SUCCESS(resource_fwrite_file(r, "test_resource.c"),
+ "Failed to to write file %s", r->name);
+
+ f = fopen("test_resource.c", "r");
+ TEST_ASSERT_NOT_NULL(f,
+ "Missing extracted file resource.c");
+ fclose(f);
+ remove("test_resource.c");
+
return 0;
}