[PATCH v3 2/6] libusbg: Add remove gadget/config strings functionality.

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



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 9188a7b..a55c16e 100644
--- a/include/usbg/usbg.h
+++ b/include/usbg/usbg.h
@@ -279,6 +279,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 5e39adb..35bee51 100644
--- a/src/usbg.c
+++ b/src/usbg.c
@@ -587,6 +587,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[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)
@@ -1141,6 +1158,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[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_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[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_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[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




[Index of Archives]     [Linux Media]     [Linux Input]     [Linux Audio Users]     [Yosemite News]     [Linux Kernel]     [Linux SCSI]     [Old Linux USB Devel Archive]

  Powered by Linux