lib/string.c
Source file repositories/reference/linux-study-clean/lib/string.c
File Facts
- System
- Linux kernel
- Corpus path
lib/string.c- Extension
.c- Size
- 18558 bytes
- Lines
- 865
- 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.
- Defines or uses C structs; map object ownership, embedded links, reference counts, and lock ownership.
Dependency Surface
linux/bits.hlinux/bug.hlinux/ctype.hlinux/errno.hlinux/limits.hlinux/linkage.hlinux/minmax.hlinux/stddef.hlinux/string.hlinux/types.hasm/page.hasm/rwonce.hlinux/unaligned.hasm/word-at-a-time.h
Detected Declarations
function Copyrightfunction strcasecmpfunction sized_strscpyfunction strlcatfunction strcmpfunction strncmpfunction strlenfunction strnlenfunction strspnfunction strcspnfunction memsetfunction memset16function memset32function memset64function memcpy_fromiofunction memcpyfunction memcmpfunction simpleexport strncasecmpexport strcasecmpexport strcpyexport sized_strscpyexport stpcpyexport strcatexport strncatexport strlcatexport strcmpexport strncmpexport strchrexport strchrnulexport strrchrexport strnchrexport strlenexport strnlenexport strspnexport strcspnexport strpbrkexport strsepexport memsetexport memset16export memset32export memset64export memcpyexport memmoveexport memcmpexport bcmpexport memscanexport strstr
Annotated Snippet
if (has_zero(c, &data, &constants)) {
data = prep_zero_mask(c, data, &constants);
data = create_zero_mask(data);
*(unsigned long *)(dest+res) = c & zero_bytemask(data);
return res + find_zero(data);
}
count -= sizeof(unsigned long);
if (unlikely(!count)) {
c &= ALLBUTLAST_BYTE_MASK;
*(unsigned long *)(dest+res) = c;
return -E2BIG;
}
*(unsigned long *)(dest+res) = c;
res += sizeof(unsigned long);
max -= sizeof(unsigned long);
}
while (count > 1) {
char c;
c = src[res];
dest[res] = c;
if (!c)
return res;
res++;
count--;
}
/* Force NUL-termination. */
dest[res] = '\0';
/* Return E2BIG if the source didn't stop */
return src[res] ? -E2BIG : res;
}
EXPORT_SYMBOL(sized_strscpy);
/**
* stpcpy - copy a string from src to dest returning a pointer to the new end
* of dest, including src's %NUL-terminator. May overrun dest.
* @dest: pointer to end of string being copied into. Must be large enough
* to receive copy.
* @src: pointer to the beginning of string being copied from. Must not overlap
* dest.
*
* stpcpy differs from strcpy in a key way: the return value is a pointer
* to the new %NUL-terminating character in @dest. (For strcpy, the return
* value is a pointer to the start of @dest). This interface is considered
* unsafe as it doesn't perform bounds checking of the inputs. As such it's
* not recommended for usage. Instead, its definition is provided in case
* the compiler lowers other libcalls to stpcpy.
*/
char *stpcpy(char *__restrict__ dest, const char *__restrict__ src);
char *stpcpy(char *__restrict__ dest, const char *__restrict__ src)
{
while ((*dest++ = *src++) != '\0')
/* nothing */;
return --dest;
}
EXPORT_SYMBOL(stpcpy);
#ifndef __HAVE_ARCH_STRCAT
char *strcat(char *dest, const char *src)
{
char *tmp = dest;
while (*dest)
dest++;
while ((*dest++ = *src++) != '\0')
;
return tmp;
}
EXPORT_SYMBOL(strcat);
#endif
#ifndef __HAVE_ARCH_STRNCAT
char *strncat(char *dest, const char *src, size_t count)
{
char *tmp = dest;
if (count) {
while (*dest)
dest++;
while ((*dest++ = *src++) != 0) {
if (--count == 0) {
*dest = '\0';
break;
}
}
}
return tmp;
Annotation
- Immediate include surface: `linux/bits.h`, `linux/bug.h`, `linux/ctype.h`, `linux/errno.h`, `linux/limits.h`, `linux/linkage.h`, `linux/minmax.h`, `linux/stddef.h`.
- Detected declarations: `function Copyright`, `function strcasecmp`, `function sized_strscpy`, `function strlcat`, `function strcmp`, `function strncmp`, `function strlen`, `function strnlen`, `function strspn`, `function strcspn`.
- 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.