This is an example of how to export a gadget to file. Common reason of doing this is to share schema of gadget between different devices or preserve gadget between reboots.
#include <errno.h>
#include <string.h>
#include <stdio.h>
int main(int argc, char **argv)
{
int ret = -EINVAL;
int usbg_ret;
FILE *output;
if (argc != 3) {
fprintf(stderr, "Usage: gadget-export gadget_name file_name\n");
return ret;
}
output = fopen(argv[2], "w");
if (!output) {
fprintf(stderr, "Error on fopen. Error: %s\n", strerror(errno));
goto out1;
}
usbg_ret =
usbg_init(
"/sys/kernel/config", &s);
if (usbg_ret != USBG_SUCCESS) {
fprintf(stderr, "Error on USB gadget init\n");
goto out2;
}
if (!g) {
fprintf(stderr, "Error on get gadget\n");
goto out3;
}
if (usbg_ret != USBG_SUCCESS) {
fprintf(stderr, "Error on export gadget\n");
goto out3;
}
ret = 0;
out3:
out2:
fclose(output);
out1:
return ret;
}
const char * usbg_strerror(usbg_error e)
Get the short description of error.
Definition usbg_error.c:123
int usbg_export_gadget(usbg_gadget *g, FILE *stream)
Exports whole gadget to file.
Definition usbg_schemes_libconfig.c:776
usbg_gadget * usbg_get_gadget(usbg_state *s, const char *name)
Get a gadget device by name.
Definition usbg.c:1149
int usbg_init(const char *configfs_path, usbg_state **state)
Initialize the libusbgx library state.
Definition usbg.c:1086
void usbg_cleanup(usbg_state *s)
Clean up the libusbgx library state.
Definition usbg.c:1131
const char * usbg_error_name(usbg_error e)
Get the error name as a constant string.
Definition usbg_error.c:62
Definition usbg_internal.h:103
Definition usbg_internal.h:93