lib/ucs2_string.c
Source file repositories/reference/linux-study-clean/lib/ucs2_string.c
File Facts
- System
- Linux kernel
- Corpus path
lib/ucs2_string.c- Extension
.c- Size
- 4052 bytes
- Lines
- 170
- Domain
- Kernel Services
- Bucket
- lib
- Inferred role
- Kernel Services: exported/initcall integration point
- Status
- integration implementation candidate
Why This File Exists
Shared kernel service surface used by multiple subsystems, including helpers, cryptography, virtualization support, and async I/O infrastructure.
- Shared kernel service surface used by multiple subsystems, including helpers, cryptography, virtualization support, and async I/O infrastructure.
- Exports symbols or registers init work; inspect boot/module ordering and who consumes the exported contract.
Dependency Surface
linux/ucs2_string.hlinux/module.h
Detected Declarations
function ucs2_strnlenfunction ucs2_strlenfunction ucs2_strsizefunction ucs2_strscpyfunction ucs2_strncmpfunction ucs2_utf8sizefunction ucs2_as_utf8export ucs2_strnlenexport ucs2_strlenexport ucs2_strsizeexport ucs2_strscpyexport ucs2_strncmpexport ucs2_utf8sizeexport ucs2_as_utf8
Annotated Snippet
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);
unsigned long
ucs2_utf8size(const ucs2_char_t *src)
{
unsigned long i;
unsigned long j = 0;
for (i = 0; src[i]; i++) {
u16 c = src[i];
if (c >= 0x800)
j += 3;
else if (c >= 0x80)
j += 2;
else
j += 1;
}
return j;
}
EXPORT_SYMBOL(ucs2_utf8size);
/*
* copy at most maxlength bytes of whole utf8 characters to dest from the
* ucs2 string src.
*
* The return value is the number of characters copied, not including the
* final NUL character.
*/
unsigned long
ucs2_as_utf8(u8 *dest, const ucs2_char_t *src, unsigned long maxlength)
{
unsigned int i;
unsigned long j = 0;
unsigned long limit = ucs2_strnlen(src, maxlength);
for (i = 0; maxlength && i < limit; i++) {
u16 c = src[i];
if (c >= 0x800) {
if (maxlength < 3)
break;
maxlength -= 3;
dest[j++] = 0xe0 | (c & 0xf000) >> 12;
dest[j++] = 0x80 | (c & 0x0fc0) >> 6;
dest[j++] = 0x80 | (c & 0x003f);
} else if (c >= 0x80) {
if (maxlength < 2)
break;
maxlength -= 2;
dest[j++] = 0xc0 | (c & 0x7c0) >> 6;
dest[j++] = 0x80 | (c & 0x03f);
} else {
maxlength -= 1;
dest[j++] = c & 0x7f;
}
}
if (maxlength)
dest[j] = '\0';
return j;
}
EXPORT_SYMBOL(ucs2_as_utf8);
MODULE_DESCRIPTION("UCS2 string handling");
MODULE_LICENSE("GPL v2");
Annotation
- Immediate include surface: `linux/ucs2_string.h`, `linux/module.h`.
- Detected declarations: `function ucs2_strnlen`, `function ucs2_strlen`, `function ucs2_strsize`, `function ucs2_strscpy`, `function ucs2_strncmp`, `function ucs2_utf8size`, `function ucs2_as_utf8`, `export ucs2_strnlen`, `export ucs2_strlen`, `export ucs2_strsize`.
- Atlas domain: Kernel Services / lib.
- Implementation status: integration implementation candidate.
Implementation Notes
- This generated page is the file-by-file coverage layer; curated subsystem chapters should link here when they synthesize a multi-file control flow.
- Core OS pages should be promoted from atlas-only to deep-reviewed when they explain data structures, invariants, locking, lifecycle, and C implementation snippets.
- Driver-family pages are intentionally pattern-oriented unless they are part of the selected PCIe/NVMe representative device path.