summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAidan MacDonald <amachronic@protonmail.com>2021-07-20 21:13:37 +0100
committerAidan MacDonald <amachronic@protonmail.com>2021-07-20 21:30:55 +0100
commit966e210e6d699ba69c0f72a2661b0f6204293247 (patch)
tree72e969af704c35137e065da8696b9472e1297a1e
parent740a50687f67f3684e4b5698f8f30e3adebb8f6e (diff)
downloadrockbox-966e210e6d699ba69c0f72a2661b0f6204293247.tar.gz
rockbox-966e210e6d699ba69c0f72a2661b0f6204293247.zip
Small fixes to kbd_create_layout
- Make the argument const since it's not actually mutated - Actually return the size of the buffer used since this is what it was supposed to do (although no existing callers cared anyway) Change-Id: I0802071cf63d4af419f427ff54adca50b14918ad
-rw-r--r--apps/plugins/lib/kbd_helper.c8
-rw-r--r--apps/plugins/lib/kbd_helper.h2
2 files changed, 7 insertions, 3 deletions
diff --git a/apps/plugins/lib/kbd_helper.c b/apps/plugins/lib/kbd_helper.c
index e3a844a993..f99282575d 100644
--- a/apps/plugins/lib/kbd_helper.c
+++ b/apps/plugins/lib/kbd_helper.c
@@ -34,11 +34,12 @@
34 * success returns size of buffer used 34 * success returns size of buffer used
35 * failure returns 0 35 * failure returns 0
36*/ 36*/
37int kbd_create_layout(char *layout, unsigned short *buf, int bufsz) 37int kbd_create_layout(const char *layout, unsigned short *buf, int bufsz)
38{ 38{
39 unsigned short *pbuf; 39 unsigned short *pbuf;
40 const unsigned char *p = layout; 40 const unsigned char *p = layout;
41 int len = 0; 41 int len = 0;
42 int total_len = 0;
42 pbuf = buf; 43 pbuf = buf;
43 while (*p && (pbuf - buf + (ptrdiff_t) sizeof(unsigned short)) < bufsz) 44 while (*p && (pbuf - buf + (ptrdiff_t) sizeof(unsigned short)) < bufsz)
44 { 45 {
@@ -47,6 +48,7 @@ int kbd_create_layout(char *layout, unsigned short *buf, int bufsz)
47 { 48 {
48 *pbuf = len; 49 *pbuf = len;
49 pbuf += len+1; 50 pbuf += len+1;
51 total_len += len + 1;
50 len = 0; 52 len = 0;
51 } 53 }
52 else 54 else
@@ -57,7 +59,9 @@ int kbd_create_layout(char *layout, unsigned short *buf, int bufsz)
57 { 59 {
58 *pbuf = len; 60 *pbuf = len;
59 pbuf[len+1] = 0xFEFF; /* mark end of characters */ 61 pbuf[len+1] = 0xFEFF; /* mark end of characters */
60 return len + 1; 62 total_len += len + 1;
63 return total_len * sizeof(unsigned short);
61 } 64 }
65
62 return 0; 66 return 0;
63} 67}
diff --git a/apps/plugins/lib/kbd_helper.h b/apps/plugins/lib/kbd_helper.h
index 90443cbf3f..ee2ce7551c 100644
--- a/apps/plugins/lib/kbd_helper.h
+++ b/apps/plugins/lib/kbd_helper.h
@@ -22,6 +22,6 @@
22#define KBD_HELPER_H 22#define KBD_HELPER_H
23 23
24/* create a custom keyboard layout for kbd_input */ 24/* create a custom keyboard layout for kbd_input */
25int kbd_create_layout(char *layout, unsigned short *buf, int bufsz); 25int kbd_create_layout(const char *layout, unsigned short *buf, int bufsz);
26 26
27#endif /* KBD_HELPER_H */ 27#endif /* KBD_HELPER_H */