summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorKrzysztof Opasiak <k.opasiak@samsung.com>2016-12-15 16:18:06 +0100
committerKrzysztof Opasiak <k.opasiak@samsung.com>2017-03-03 14:02:26 +0100
commit4247abdab150d333d9afd807c9837f9313e265fd (patch)
tree4160a9eaee9d16cc90a13f7ddb9be7b2aea026f4
parent576d384c39db4764867e390da1742b6f7df16f27 (diff)
downloadlibusbg-4247abdab150d333d9afd807c9837f9313e265fd.tar.gz
libusbg-4247abdab150d333d9afd807c9837f9313e265fd.tar.bz2
libusbg-4247abdab150d333d9afd807c9837f9313e265fd.zip
libusbgx: Add usbg_get_gadget_strs_langs()
Add a function which allows to get the list of languages in which gadget strings are currently available. Thanks to this function now we may iterate through all strings languages available in particular gadget and print their values for each language. Signed-off-by: Krzysztof Opasiak <k.opasiak@samsung.com>
-rw-r--r--include/usbg/usbg.h8
-rw-r--r--src/usbg.c56
2 files changed, 64 insertions, 0 deletions
diff --git a/include/usbg/usbg.h b/include/usbg/usbg.h
index 5f4a4c5..ba760f5 100644
--- a/include/usbg/usbg.h
+++ b/include/usbg/usbg.h
@@ -563,6 +563,14 @@ extern int usbg_get_gadget_strs(usbg_gadget *g, int lang,
struct usbg_gadget_strs *g_strs);
/**
+ * @brief Get the array of languages available in this gadget
+ * @param g Pointer to gadget
+ * @param langs array of available language codes
+ * @return 0 on success usbg_error if error occurred
+ */
+extern int usbg_get_gadget_strs_langs(usbg_gadget *g, int **langs);
+
+/**
* @brief Free gadget strings
* @details This function releases the memory allocated for strings
* not for struct usbg_gadget_strs itself.
diff --git a/src/usbg.c b/src/usbg.c
index 1cb4a13..5bd1090 100644
--- a/src/usbg.c
+++ b/src/usbg.c
@@ -1649,6 +1649,62 @@ int usbg_get_gadget_strs(usbg_gadget *g, int lang,
g_strs) : USBG_ERROR_INVALID_PARAM;
}
+static int usbg_get_strs_langs_by_path(const char *epath, const char *name,
+ int **langs)
+{
+ int i, n;
+ struct dirent **dent;
+ char spath[USBG_MAX_PATH_LENGTH];
+ int *buf;
+ int ret = USBG_SUCCESS;
+
+ n = snprintf(spath, sizeof(spath), "%s/%s/%s", epath, name,
+ STRINGS_DIR);
+ if (n >= sizeof(spath)) {
+ ret = USBG_ERROR_PATH_TOO_LONG;
+ goto out;
+ }
+
+ n = scandir(spath, &dent, file_select, alphasort);
+ if (n < 0) {
+ ret = usbg_translate_error(errno);
+ goto out;
+ }
+
+ buf = calloc(n + 1, sizeof(*buf));
+ if (!buf)
+ ret = USBG_ERROR_NO_MEM;
+
+ /* Keep the buffer 0 terminated */
+ buf[n] = 0;
+ for (i = 0; i < n; i++) {
+ if (ret == USBG_SUCCESS) {
+ char *pos;
+ unsigned long int res;
+
+ res = strtoul(dent[i]->d_name, &pos, 16);
+ if (*pos == '\0' && res < 65535)
+ buf[i] = (int)res;
+ else
+ ret = USBG_ERROR_OTHER_ERROR;
+ }
+ free(dent[i]);
+ }
+ free(dent);
+
+ if (ret != USBG_SUCCESS)
+ free(buf);
+ else
+ *langs = buf;
+out:
+ return ret;
+}
+
+int usbg_get_gadget_strs_langs(usbg_gadget *g, int **langs)
+{
+ return usbg_get_strs_langs_by_path(g->path, g->name, langs);
+}
+
int usbg_set_gadget_str(usbg_gadget *g, usbg_gadget_str str, int lang,
const char *val)
{