libusbgx: Add getter for configfs path in state.
authorKrzysztof Opasiak <k.opasiak@samsung.com>
Fri, 14 Feb 2014 13:11:59 +0000 (14:11 +0100)
committerKrzysztof Opasiak <k.opasiak@samsung.com>
Tue, 22 Dec 2015 19:35:20 +0000 (20:35 +0100)
Add usbg_get_configfs_path_len() and usbg_get_configfs_path()
to avoid direct access to state structure.

Signed-off-by: Krzysztof Opasiak <k.opasiak@samsung.com>
[Port from libusbg and update description]
Signed-off-by: Krzysztof Opasiak <k.opasiak@samsung.com>
include/usbg/usbg.h
src/usbg.c

index 028732b..d787cdc 100644 (file)
@@ -233,6 +233,22 @@ extern struct state *usbg_init(char *configfs_path);
  */
 extern void usbg_cleanup(struct state *s);
 
+/**
+ * @brief Get ConfigFS path length
+ * @param s Pointer to state
+ * @return Length of path or -1 if error occurred.
+ */
+extern size_t usbg_get_configfs_path_len(struct state *s);
+
+/**
+ * @brieg Get ConfigFS path
+ * @param s Pointer to state
+ * @param buf Buffer where path should be copied
+ * @param len Length of given buffer
+ * @return Pointer to destination or NULL if error occurred.
+ */
+extern char *usbg_get_configfs_path(struct state *s, char *buf, size_t len);
+
 /* USB gadget queries */
 
 /**
index 6e27358..6b48d68 100644 (file)
@@ -470,6 +470,16 @@ void usbg_cleanup(struct state *s)
        free(s);
 }
 
+size_t usbg_get_configfs_path_len(struct state *s)
+{
+       return s ? strlen(s->path) : -1;
+}
+
+char *usbg_get_configfs_path(struct state *s, char *buf, size_t len)
+{
+       return s ? strncpy(buf, s->path, len) : NULL;
+}
+
 struct gadget *usbg_get_gadget(struct state *s, const char *name)
 {
        struct gadget *g;