Add usbg_get_gadget_name() and usbg_get_gadget_udc() to avoid direct gadget structure members access. Add also usbg_get_gadget_name_len() and usbg_get_gadget_udc_len() to allow getting udc and name length. Signed-off-by: Krzysztof Opasiak <k.opasiak@xxxxxxxxxxx> --- include/usbg/usbg.h | 34 ++++++++++++++++++++++++++++++++++ src/usbg.c | 20 ++++++++++++++++++++ 2 files changed, 54 insertions(+) diff --git a/include/usbg/usbg.h b/include/usbg/usbg.h index 1ffc75d..ba7b1f5 100644 --- a/include/usbg/usbg.h +++ b/include/usbg/usbg.h @@ -303,6 +303,22 @@ extern struct gadget_attrs *usbg_get_gadget_attrs(struct gadget *g, struct gadget_attrs *g_attrs); /** + * @brief Get gadget name length + * @param g Gadget which name length should be returned + * @return Length of name string or -1 if error occurred. + */ +extern size_t usbg_get_gadget_name_len(struct gadget *g); + +/** + * @brieg Get gadget name + * @param b Pointer to gadget + * @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_gadget_name(struct gadget* g, char *buf, size_t len); + +/** * @brief Set the USB gadget vendor id * @param g Pointer to gadget * @param idVendor USB device vendor id @@ -479,6 +495,24 @@ extern void usbg_enable_gadget(struct gadget *g, char *udc); */ extern void usbg_disable_gadget(struct gadget *g); +/** + * @brief Get gadget name length + * @param g Gadget which name length should be returned + * @return Length of name string or -1 if error occurred. + * @note If gadget isn't enabled on any udc returned size is 0. + */ +extern size_t usbg_get_gadget_udc_len(struct gadget *g); + +/** + * @brieg Get name of udc to which gadget is binded + * @param b Pointer to gadget + * @param buf Buffer where udc name should be copied + * @param len Length of given buffer + * @return Pointer to destination or NULL if error occurred. + * @note If gadget isn't enabled on any udc returned string is empty. + */ +extern char *usbg_get_gadget_udc(struct gadget* g, char *buf, size_t len); + /* * USB function-specific attribute configuration */ diff --git a/src/usbg.c b/src/usbg.c index 51aa019..b13b0cb 100644 --- a/src/usbg.c +++ b/src/usbg.c @@ -640,6 +640,26 @@ struct gadget_attrs *usbg_get_gadget_attrs(struct gadget *g, return g_attrs; } +size_t usbg_get_gadget_name_len(struct gadget *g) +{ + return g ? strlen(g->name): -1; +} + +char *usbg_get_gadget_name(struct gadget* g, char *buf, size_t len) +{ + return g ? strncpy(buf, g->name, len) : NULL; +} + +size_t usbg_get_gadget_udc_len(struct gadget *g) +{ + return g ? strlen(g->udc): -1; +} + +char *usbg_get_gadget_udc(struct gadget* g, char *buf, size_t len) +{ + return g ? strncpy(buf, g->udc, len) : NULL; +} + void usbg_set_gadget_attrs(struct gadget *g, struct gadget_attrs *g_attrs) { if(!g || !g_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