From 8642661469ac5e36e27c155f8c0e8b0677228a10 Mon Sep 17 00:00:00 2001 From: Krzysztof Opasiak Date: Fri, 14 Feb 2014 16:31:06 +0100 Subject: [PATCH] libusbgx: Add getter for function name. Add usbg_get_function_name() and usbg_get_function_name_len() to avoid direct function structure members access. Signed-off-by: Krzysztof Opasiak [Port from libusbg and update description] Signed-off-by: Krzysztof Opasiak --- 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 c8f2f9d..96d9b81 100644 --- a/include/usbg/usbg.h +++ b/include/usbg/usbg.h @@ -451,6 +451,22 @@ extern void usbg_set_gadget_product(struct gadget *g, int lang, char *prd); extern struct function *usbg_create_function(struct gadget *g, enum function_type type, char *instance, union attrs *f_attrs); +/** + * @brief Get function name length + * @param f Config which name length should be returned + * @return Length of name string or -1 if error occurred. + */ +extern size_t usbg_get_function_name_len(struct function *f); + +/** + * @brieg Get config name + * @param f Pointer to function + * @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_function_name(struct function *f, char *buf, size_t len); + /* USB configurations allocation and configuration */ /** diff --git a/src/usbg.c b/src/usbg.c index 6a31de5..9a461dd 100644 --- a/src/usbg.c +++ b/src/usbg.c @@ -945,6 +945,16 @@ char *usbg_get_config_name(struct config *c, char *buf, size_t len) return c ? strncpy(buf, c->name, len) : NULL; } +size_t usbg_get_function_name_len(struct function *f) +{ + return f ? strlen(f->name) : -1; +} + +char *usbg_get_function_name(struct function *f, char *buf, size_t len) +{ + return f ? strncpy(buf, f->name, len) : NULL; +} + void usbg_set_config_attrs(struct config *c, struct config_attrs *c_attrs) { if (!c || !c_attrs) -- 2.7.4