Add functions which allow to remove strings in gadget and configuration. Signed-off-by: Krzysztof Opasiak <k.opas...@samsung.com> --- 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 bda63a1..d0b9dbe 100644 --- a/include/usbg/usbg.h +++ b/include/usbg/usbg.h @@ -277,6 +277,22 @@ extern usbg_config *usbg_get_config(usbg_gadget *g, const char *name); */ extern int usbg_remove_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_remove_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_remove_gadget_strs(usbg_gadget *g, int lang); + /* USB gadget allocation and configuration */ /** diff --git a/src/usbg.c b/src/usbg.c index 3a89e3a..9f67f9d 100644 --- a/src/usbg.c +++ b/src/usbg.c @@ -588,6 +588,23 @@ static int usbg_remove_file(char *path, char *name) return ret; } +static int usbg_remove_dir(char *path, char *name) +{ + int ret = USBG_SUCCESS; + int nmb; + char buf[PATH_MAX]; + + nmb = snprintf(buf, PATH_MAX, "%s/%s", path, name); + if (nmb < PATH_MAX) { + 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) @@ -1140,6 +1157,45 @@ int usbg_remove_binding(usbg_binding *b) return ret; } +int usbg_remove_config_strs(usbg_config *c, int lang) +{ + int ret = USBG_SUCCESS; + int nmb; + char path[PATH_MAX]; + + if (!c) + return USBG_ERROR_INVALID_PARAM; + + nmb = snprintf(path, PATH_MAX, "%s/%s/%s/0x%x", c->path, c->name, + STRINGS_DIR, lang); + if (nmb < PATH_MAX) + ret = usbg_remove_dir(path, ""); + else + ret = USBG_ERROR_PATH_TOO_LONG; + + return ret; +} + +int usbg_remove_gadget_strs(usbg_gadget *g, int lang) +{ + int ret = USBG_SUCCESS; + int nmb; + char path[PATH_MAX]; + + if (!g) + return USBG_ERROR_INVALID_PARAM; + + nmb = snprintf(path, PATH_MAX, "%s/%s/%s/0x%x", g->path, g->name, + STRINGS_DIR, lang); + if (nmb < PATH_MAX) + ret = usbg_remove_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[PATH_MAX]; -- 1.7.9.5 -- To unsubscribe from this list: send the line "unsubscribe linux-usb" in the body of a message to majord...@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html