feat(strings): strcasecmp/ffs/bcopy/bzero
This commit is contained in:
@@ -0,0 +1,133 @@
|
||||
#ifndef VLIBC_STRINGS_H
|
||||
#define VLIBC_STRINGS_H
|
||||
|
||||
/*
|
||||
* vlibc — <strings.h>.
|
||||
*
|
||||
* BSD/XSI legacy string functions, gated by the active compatibility
|
||||
* profile (see include/vlibc/features.h). This ENTIRE header is a legacy
|
||||
* extension: nothing it declares is POSIX.1-2008 base, so at level 1
|
||||
* (onlyposix) it is empty. POSIX mandates that <strings.h> (BSD legacy)
|
||||
* and <string.h> (ISO C) remain separate headers; the two never share a
|
||||
* declaration, so including both can never conflict.
|
||||
*
|
||||
* strcasecmp / strncasecmp — XSI case-insensitive comparisons (ASCII
|
||||
* 'A'..'Z'/'a'..'z' fold only, byte-wise);
|
||||
* ffs / ffsl / ffsll — XSI find-first-set-bit, 1-based;
|
||||
* bcmp / bcopy / bzero — BSD legacy byte operations (bcopy takes
|
||||
* (src, dst) — the arguments are REVERSED
|
||||
* relative to memcpy/memmove);
|
||||
* index / rindex — BSD legacy names for strchr / strrchr.
|
||||
*
|
||||
* This header includes <vlibc/features.h> itself, so the gate below always
|
||||
* sees the configured VLIBC_LEVEL even when the caller included no vlibc
|
||||
* header first, and <stddef.h> for size_t.
|
||||
*/
|
||||
|
||||
#include <vlibc/features.h>
|
||||
|
||||
#if VLIBC_LEVEL_GE(2)
|
||||
|
||||
#include <stddef.h>
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
/*
|
||||
* Compare s1 and s2 byte-wise, ignoring case: each byte is read as
|
||||
* unsigned char and an ASCII 'A'..'Z' is folded to 'a'..'z' before the
|
||||
* comparison; bytes at or above 0x80 pass through unmodified. Return
|
||||
* negative, zero, or positive when s1 is less than, equal to, or greater
|
||||
* than s2.
|
||||
* pure: reads memory, no side effects.
|
||||
*/
|
||||
__attribute__((pure)) int
|
||||
strcasecmp(const char *s1, const char *s2);
|
||||
|
||||
/*
|
||||
* Compare at most n bytes of s1 and s2 as strcasecmp does, stopping early
|
||||
* at the first difference or the first NUL; return negative, zero, or
|
||||
* positive like strcasecmp. The NUL terminator of either string ends the
|
||||
* comparison even when n is larger.
|
||||
* pure: reads memory, no side effects.
|
||||
*/
|
||||
__attribute__((pure)) int
|
||||
strncasecmp(const char *s1, const char *s2, size_t n);
|
||||
|
||||
/*
|
||||
* Return the 1-based index of the least significant set bit of i, or 0
|
||||
* when i has no set bit: ffs(0) == 0, ffs(1) == 1, ffs(8) == 4,
|
||||
* ffs(INT_MIN) == 32.
|
||||
* const: the result depends only on i.
|
||||
*/
|
||||
__attribute__((const)) int
|
||||
ffs(int i);
|
||||
|
||||
/*
|
||||
* Same as ffs for long: ffsl(0) == 0, ffsl(1L << 40) == 41,
|
||||
* ffsl(LONG_MIN) == 64 (long is 64-bit on x86_64).
|
||||
* const: the result depends only on i.
|
||||
*/
|
||||
__attribute__((const)) int
|
||||
ffsl(long i);
|
||||
|
||||
/*
|
||||
* Same as ffs for long long: ffsll(0) == 0, ffsll(LLONG_MIN) == 64.
|
||||
* const: the result depends only on i.
|
||||
*/
|
||||
__attribute__((const)) int
|
||||
ffsll(long long i);
|
||||
|
||||
/*
|
||||
* Compare the first n bytes of s1 and s2 as unsigned char, like memcmp;
|
||||
* unlike strcmp a NUL byte does not end the comparison. Return 0 when the
|
||||
* n bytes are equal, nonzero otherwise.
|
||||
* pure: reads memory, no side effects.
|
||||
*/
|
||||
__attribute__((pure)) int
|
||||
bcmp(const void *s1, const void *s2, size_t n);
|
||||
|
||||
/*
|
||||
* Copy n bytes from src to dst. The regions may overlap and the copy
|
||||
* behaves like memmove. NOTE the argument order: source first, destination
|
||||
* second — the reverse of memcpy/memmove.
|
||||
* No intent attribute: it writes memory.
|
||||
*/
|
||||
void
|
||||
bcopy(const void *src, void *dst, size_t n);
|
||||
|
||||
/*
|
||||
* Fill n bytes at s with zero.
|
||||
* No intent attribute: it writes memory.
|
||||
*/
|
||||
void
|
||||
bzero(void *s, size_t n);
|
||||
|
||||
/*
|
||||
* Return a pointer to the first occurrence of c (converted to unsigned
|
||||
* char) in s, or NULL when absent. The terminating NUL is part of the
|
||||
* string, so index(s, '\0') returns a pointer to it. Legacy name for
|
||||
* strchr.
|
||||
* pure: reads memory, no side effects.
|
||||
*/
|
||||
__attribute__((pure)) char *
|
||||
index(const char *s, int c);
|
||||
|
||||
/*
|
||||
* Return a pointer to the last occurrence of c (converted to unsigned
|
||||
* char) in s, or NULL when absent. The terminating NUL is part of the
|
||||
* string, so rindex(s, '\0') returns a pointer to it. Legacy name for
|
||||
* strrchr.
|
||||
* pure: reads memory, no side effects.
|
||||
*/
|
||||
__attribute__((pure)) char *
|
||||
rindex(const char *s, int c);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif /* VLIBC_LEVEL_GE(2) */
|
||||
|
||||
#endif /* VLIBC_STRINGS_H */
|
||||
Reference in New Issue
Block a user