STRING(9F) | Kernel Functions for Drivers | STRING(9F) |
#include <sys/ddi.h> #include <sys/sunddi.h> int strcasecmp(const char *s1, const char *s2);
int strncasecmp(const char *s1, const char *s2, size_t n);
char *strcat(char * s1, const char * s2);
char *strncat(char * s1, const char * s2, size_t n);
size_t strlcat(char *dst, const char *src, size_t dstsize);
char *strchr(const char *str, int chr);
char *strrchr(const char *str, int chr);
int strcmp(const char *s1, const char *s2);
int strncmp(const char *s1, const char *s2, size_t n);
char *strcpy(char * dst, const char * src);
char *strncpy(char * dst, const char * src, size_t n);
size_t strlcpy(char *dst, const char *src, size_t dstsize);
void strfree(char *s);
size_t strspn(const char *s1, const char *s2);
char *strdup(const char *s1);
char *ddi_strdup(const char *s1, int flag);
size_t strlen(const char *s);
size_t strnlen(const char *s, size_t n);
char *strtok_r(char *s1, const char *s2, char **lasts);
The strlcat() function appends at most (dstsize-strlen(dst)-1) characters of src to dst (dstsize being the size of the string buffer dst). If the string pointed to by dst contains a null-terminated string that fits into dstsize bytes when strlcat() is called, the string pointed to by dst will be a null-terminated string that fits in dstsize bytes (including the terminating null character) when it completes, and the initial character of src will override the null character at the end of dst. If the string pointed to by dst is longer than dstsize bytes when strlcat() is called, the string pointed to by dst will not be changed. The function returns min{dstsize,strlen(dst)}+strlen(src). Buffer overflow can be checked as follows:
if (strlcat(dst, src, dstsize) >= dstsize) return −1;
The strlcpy() function copies at most dstsize−1 characters (dstsize being the size of the string buffer dst) from src to dst, truncating src if necessary. The result is always null-terminated. The function returns strlen(src). Buffer overflow can be checked as follows:
if (strlcpy(dst, src, dstsize) >= dstsize) return −1;
The strdup() function behaves the same as the ddi_strdup() when called with the KM_SLEEP flag. This means that strdup() can sleep until memory is available and will always succeed.
The strnlen() function returns the smaller of n or the number of bytes in s, not including the terminating null character. The strnlen() function never examines more than n bytes of the string pointed to by s.
In the first call to strtok_r(), s1 points to a null-terminated string, s2 to a null-terminated string of separator characters, and the value pointed to by lasts is ignored. The strtok_r() function returns a pointer to the first character of the first token, writes a null character into s1 immediately following the returned token, and updates the pointer to which lasts points.
In subsequent calls, s1 is a null pointer and lasts is unchanged from the previous call so that subsequent calls move through the string s1, returning successive tokens until no tokens remain. The separator string s2 can be different from call to call. When no token remains in s1, a null pointer is returned.
The ddi_strdup() function can be called from interrupt context only if the KM_NOSLEEP flag is set.
All the other string manipulation functions can be called from user, interrupt, or kernel context.
ATTRIBUTE TYPE | ATTRIBUTE VALUE |
Interface Stability | Committed |
Writing Device Drivers
May 20, 2022 | OmniOS |