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
This commit is contained in:
parent
740a50687f
commit
966e210e6d
2 changed files with 7 additions and 3 deletions
|
@ -34,11 +34,12 @@
|
||||||
* success returns size of buffer used
|
* success returns size of buffer used
|
||||||
* failure returns 0
|
* failure returns 0
|
||||||
*/
|
*/
|
||||||
int kbd_create_layout(char *layout, unsigned short *buf, int bufsz)
|
int kbd_create_layout(const char *layout, unsigned short *buf, int bufsz)
|
||||||
{
|
{
|
||||||
unsigned short *pbuf;
|
unsigned short *pbuf;
|
||||||
const unsigned char *p = layout;
|
const unsigned char *p = layout;
|
||||||
int len = 0;
|
int len = 0;
|
||||||
|
int total_len = 0;
|
||||||
pbuf = buf;
|
pbuf = buf;
|
||||||
while (*p && (pbuf - buf + (ptrdiff_t) sizeof(unsigned short)) < bufsz)
|
while (*p && (pbuf - buf + (ptrdiff_t) sizeof(unsigned short)) < bufsz)
|
||||||
{
|
{
|
||||||
|
@ -47,6 +48,7 @@ int kbd_create_layout(char *layout, unsigned short *buf, int bufsz)
|
||||||
{
|
{
|
||||||
*pbuf = len;
|
*pbuf = len;
|
||||||
pbuf += len+1;
|
pbuf += len+1;
|
||||||
|
total_len += len + 1;
|
||||||
len = 0;
|
len = 0;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
|
@ -57,7 +59,9 @@ int kbd_create_layout(char *layout, unsigned short *buf, int bufsz)
|
||||||
{
|
{
|
||||||
*pbuf = len;
|
*pbuf = len;
|
||||||
pbuf[len+1] = 0xFEFF; /* mark end of characters */
|
pbuf[len+1] = 0xFEFF; /* mark end of characters */
|
||||||
return len + 1;
|
total_len += len + 1;
|
||||||
|
return total_len * sizeof(unsigned short);
|
||||||
}
|
}
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
|
@ -22,6 +22,6 @@
|
||||||
#define KBD_HELPER_H
|
#define KBD_HELPER_H
|
||||||
|
|
||||||
/* create a custom keyboard layout for kbd_input */
|
/* create a custom keyboard layout for kbd_input */
|
||||||
int kbd_create_layout(char *layout, unsigned short *buf, int bufsz);
|
int kbd_create_layout(const char *layout, unsigned short *buf, int bufsz);
|
||||||
|
|
||||||
#endif /* KBD_HELPER_H */
|
#endif /* KBD_HELPER_H */
|
||||||
|
|
Loading…
Reference in a new issue