Add functions which allow to remove strings in gadget and configuration. Signed-off-by: Krzysztof Opasiak <k.opasiak@xxxxxxxxxxx> --- include/usbg/usbg.h | 16 +++++++++++++++ src/usbg.c | 56 +++++++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 72 insertions(+) diff --git a/include/usbg/usbg.h b/include/usbg/usbg.h index 7a60c0f..ca21753 100644 --- a/include/usbg/usbg.h +++ b/include/usbg/usbg.h @@ -286,6 +286,22 @@ extern usbg_config *usbg_get_config(usbg_gadget *g, int id, const char *label); */ extern int usbg_rm_binding(usbg_binding *b); +/** + * @brief Remove configuration strings for given language + * @param c Pointer to configuration + * @param lang Language of strings which should be deleted + * @return 0 on success, usbg_error if error occurred + */ +extern int usbg_rm_config_strs(usbg_config *c, int lang); + +/** + * @brief Remove gadget strings for given language + * @param g Pointer to gadget + * @param lang Language of strings which should be deleted + * @return 0 on success, usbg_error if error occurred + */ +extern int usbg_rm_gadget_strs(usbg_gadget *g, int lang); + /* USB gadget allocation and configuration */ /** diff --git a/src/usbg.c b/src/usbg.c index 4d014a1..036a710 100644 --- a/src/usbg.c +++ b/src/usbg.c @@ -696,6 +696,23 @@ static int ubsg_rm_file(char *path, char *name) return ret; } +static int usbg_rm_dir(char *path, char *name) +{ + int ret = USBG_SUCCESS; + int nmb; + char buf[USBG_MAX_PATH_LENGTH]; + + nmb = snprintf(buf, sizeof(buf), "%s/%s", path, name); + if (nmb < sizeof(buf)) { + nmb = rmdir(buf); + if (nmb != 0) + ret = usbg_translate_error(errno); + } else { + ret = USBG_ERROR_PATH_TOO_LONG; + } + + return ret; +} static int usbg_parse_function_net_attrs(usbg_function *f, usbg_function_attrs *f_attrs) @@ -1302,6 +1319,45 @@ int usbg_rm_binding(usbg_binding *b) return ret; } +int usbg_rm_config_strs(usbg_config *c, int lang) +{ + int ret = USBG_SUCCESS; + int nmb; + char path[USBG_MAX_PATH_LENGTH]; + + if (!c) + return USBG_ERROR_INVALID_PARAM; + + nmb = snprintf(path, sizeof(path), "%s/%s/%s/0x%x", c->path, c->name, + STRINGS_DIR, lang); + if (nmb < sizeof(path)) + ret = usbg_rm_dir(path, ""); + else + ret = USBG_ERROR_PATH_TOO_LONG; + + return ret; +} + +int usbg_rm_gadget_strs(usbg_gadget *g, int lang) +{ + int ret = USBG_SUCCESS; + int nmb; + char path[USBG_MAX_PATH_LENGTH]; + + if (!g) + return USBG_ERROR_INVALID_PARAM; + + nmb = snprintf(path, sizeof(path), "%s/%s/%s/0x%x", g->path, g->name, + STRINGS_DIR, lang); + if (nmb < sizeof(path)) + ret = usbg_rm_dir(path, ""); + else + ret = USBG_ERROR_PATH_TOO_LONG; + + return ret; +} + + static int usbg_create_empty_gadget(usbg_state *s, char *name, usbg_gadget **g) { char gpath[USBG_MAX_PATH_LENGTH]; -- 1.7.9.5 -- To unsubscribe from this list: send the line "unsubscribe linux-usb" in the body of a message to majordomo@xxxxxxxxxxxxxxx More majordomo info at http://vger.kernel.org/majordomo-info.html