[PATCH v2 15/26] libusbg: Add getter for config name.

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

 



Add usbg_get_config_name() and usbg_get_config_name_len()
to avoid direct config structure members access.

Signed-off-by: Krzysztof Opasiak <k.opasiak@xxxxxxxxxxx>
---
 include/usbg/usbg.h |   16 ++++++++++++++++
 src/usbg.c          |   10 ++++++++++
 2 files changed, 26 insertions(+)

diff --git a/include/usbg/usbg.h b/include/usbg/usbg.h
index 458bb6d..3317ed0 100644
--- a/include/usbg/usbg.h
+++ b/include/usbg/usbg.h
@@ -480,6 +480,22 @@ extern struct config *usbg_create_config(struct gadget *g, char *name,
 		struct config_attrs *c_attrs, struct config_strs *c_strs);
 
 /**
+ * @brief Get config name length
+ * @param c Config which name length should be returned
+ * @return Length of name string or -1 if error occurred.
+ */
+extern size_t usbg_get_config_name_len(struct config *c);
+
+/**
+ * @brieg Get config name
+ * @param c Pointer to config
+ * @param buf Buffer where name should be copied
+ * @param len Length of given buffer
+ * @return Pointer to destination or NULL if error occurred.
+ */
+extern char *usbg_get_config_name(struct config *c, char *buf, size_t len);
+
+/**
  * @brief Set the USB configuration attributes
  * @param c Pointer to configuration
  * @param c_attrs Configuration attributes
diff --git a/src/usbg.c b/src/usbg.c
index 79e7df0..ab9bcdf 100644
--- a/src/usbg.c
+++ b/src/usbg.c
@@ -914,6 +914,16 @@ struct config *usbg_create_config(struct gadget *g, char *name,
 	return c;
 }
 
+size_t usbg_get_config_name_len(struct config *c)
+{
+	return c ? strlen(c->name) : -1;
+}
+
+char *usbg_get_config_name(struct config *c, char *buf, size_t len)
+{
+	return c ? strncpy(buf, c->name, len) : NULL;
+}
+
 void usbg_set_config_attrs(struct config *c, struct config_attrs *c_attrs)
 {
 	if (!c || !c_attrs)
-- 
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