diff options
| author | Takashi Iwai <tiwai@suse.de> | 2013-04-25 13:02:35 +0200 |
|---|---|---|
| committer | Takashi Iwai <tiwai@suse.de> | 2013-04-25 13:02:35 +0200 |
| commit | 2fc565e4eaf8fc633bfc741b90e1f28dba732ee1 (patch) | |
| tree | 98c994692f84aee07cf1c7b4cda245ae5235a94d /lib/ucs2_string.c | |
| parent | 7fc7d047216aa4923d401c637be2ebc6e3d5bd9b (diff) | |
| parent | 5cc50fc858a5ab37dc2744d72d7ffed96f23afd8 (diff) | |
Merge tag 'asoc-v3.10-3' of git://git.kernel.org/pub/scm/linux/kernel/git/broonie/sound into for-next
ASoC: More updates for v3.10
A few more fixes, nothing too major though the DMA changes fix modular
builds.
Diffstat (limited to 'lib/ucs2_string.c')
| -rw-r--r-- | lib/ucs2_string.c | 51 |
1 files changed, 51 insertions, 0 deletions
diff --git a/lib/ucs2_string.c b/lib/ucs2_string.c new file mode 100644 index 000000000000..6f500ef2301d --- /dev/null +++ b/lib/ucs2_string.c @@ -0,0 +1,51 @@ +#include <linux/ucs2_string.h> +#include <linux/module.h> + +/* Return the number of unicode characters in data */ +unsigned long +ucs2_strnlen(const ucs2_char_t *s, size_t maxlength) +{ + unsigned long length = 0; + + while (*s++ != 0 && length < maxlength) + length++; + return length; +} +EXPORT_SYMBOL(ucs2_strnlen); + +unsigned long +ucs2_strlen(const ucs2_char_t *s) +{ + return ucs2_strnlen(s, ~0UL); +} +EXPORT_SYMBOL(ucs2_strlen); + +/* + * Return the number of bytes is the length of this string + * Note: this is NOT the same as the number of unicode characters + */ +unsigned long +ucs2_strsize(const ucs2_char_t *data, unsigned long maxlength) +{ + return ucs2_strnlen(data, maxlength/sizeof(ucs2_char_t)) * sizeof(ucs2_char_t); +} +EXPORT_SYMBOL(ucs2_strsize); + +int +ucs2_strncmp(const ucs2_char_t *a, const ucs2_char_t *b, size_t len) +{ + while (1) { + if (len == 0) + return 0; + if (*a < *b) + return -1; + if (*a > *b) + return 1; + if (*a == 0) /* implies *b == 0 */ + return 0; + a++; + b++; + len--; + } +} +EXPORT_SYMBOL(ucs2_strncmp); |
