This repository has been archived by the owner on Aug 27, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Move utf16 functions to kernel core and rename
We want to be able to use the utf16 functions that are currently present in the EFI variables code in platform-specific code as well. Move them to the kernel core, and in the process rename them to accurately describe what they do - they don't handle UTF16, only UCS2. Signed-off-by: Matthew Garrett <matthew.garrett@nebula.com> Signed-off-by: Matt Fleming <matt.fleming@intel.com>
- Loading branch information
Matthew Garrett
authored and
Matt Fleming
committed
Apr 15, 2013
1 parent
7791c84
commit 0635eb8
Showing
6 changed files
with
89 additions
and
62 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
#ifndef _LINUX_UCS2_STRING_H_ | ||
#define _LINUX_UCS2_STRING_H_ | ||
|
||
#include <linux/types.h> /* for size_t */ | ||
#include <linux/stddef.h> /* for NULL */ | ||
|
||
typedef u16 ucs2_char_t; | ||
|
||
unsigned long ucs2_strnlen(const ucs2_char_t *s, size_t maxlength); | ||
unsigned long ucs2_strlen(const ucs2_char_t *s); | ||
unsigned long ucs2_strsize(const ucs2_char_t *data, unsigned long maxlength); | ||
int ucs2_strncmp(const ucs2_char_t *a, const ucs2_char_t *b, size_t len); | ||
|
||
#endif /* _LINUX_UCS2_STRING_H_ */ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -404,4 +404,7 @@ config OID_REGISTRY | |
help | ||
Enable fast lookup object identifier registry. | ||
|
||
config UCS2_STRING | ||
tristate | ||
|
||
endmenu |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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); |