1string(9F) Kernel Functions for Drivers string(9F)
2
3
4
6 string, strcasecmp, strncasecmp, strncat, strlcat, strchr, strrchr,
7 strcmp, strncmp, strcpy, strncpy, strlcpy, strfree, strspn, strdup,
8 ddi_strdup, strlen, strnlen - string operations
9
11 #include <sys/ddi.h>
12
13 int strcasecmp(const char *s1, const char *s2);
14
15
16 int strncasecmp(const char *s1, const char *s2, size_t n);
17
18
19 char *strncat(char * s1, const char * s2, size_t n);
20
21
22 size_t strlcat(char *dst, const char *src, size_t dstsize);
23
24
25 char *strchr(const char *str, int chr);
26
27
28 char *strrchr(const char *str, int chr);
29
30
31 int strcmp(const char *s1, const char *s2);
32
33
34 int strncmp(const char *s1, const char *s2, size_t n);
35
36
37 char *strcpy(char * dst, const char * src);
38
39
40 char *strncpy(char * dst, const char * src, size_t n);
41
42
43 size_t strlcpy(char *dst, const char *src, size_t dstsize);
44
45
46 void strfree(char *s);
47
48
49 size_t strspn(const char *s1, const char *s2);
50
51
52 char *strdup(const char *s1);
53
54
55 char *ddi_strdup(const char *s1, int flag);
56
57
58 size_t strlen(const char *s);
59
60
61 size_t strnlen(const char *s, size_t n);
62
63
65 Solaris DDI specific (Solaris DDI).
66
68 The arguments s, s1, and s2 point to strings (arrays of characters ter‐
69 minated by a null character). The strcat(), strncat(), strlcat(), str‐
70 cpy(), strncpy(), strlcpy(), and strfree() functions all alter their
71 first argument. Additionally, the strcpy() function does not check for
72 overflow of the array.
73
74 strcasecmp(), strncasecmp()
75 The strcasecmp() and strncasecmp() functions are case-insensitive ver‐
76 sions of strcmp() and strncmp() respectively, described below. They
77 assume the ASCII character set and ignore differences in case when com‐
78 paring lower and upper case characters.
79
80 strncat(), strlcat()
81 The strncat() function appends at most n characters of string s2,
82 including the terminating null character, to the end of string s1. It
83 returns a pointer to the null-terminated result. The initial character
84 of s2 overrides the null character at the end of s1. If copying takes
85 place between objects that overlap, the behavior of strncat()and strl‐
86 cat() is undefined.
87
88
89 The strlcat() function appends at most (dstsize-strlen(dst)-1) char‐
90 acters of src to dst (dstsize being the size of the string buffer
91 dst). If the string pointed to by dst contains a null-terminated string
92 that fits into dstsize bytes when strlcat() is called, the string
93 pointed to by dst will be a null-terminated string that fits in dstsize
94 bytes (including the terminating null character) when it completes, and
95 the initial character of src will override the null character at the
96 end of dst. If the string pointed to by dst is longer than dstsize
97 bytes when strlcat() is called, the string pointed to by dst will not
98 be changed. The function returns min{dstsize,strlen(dst)}+strlen(src).
99 Buffer overflow can be checked as follows:
100
101 if (strlcat(dst, src, dstsize) >= dstsize)
102 return −1;
103
104
105 strchr(), strrchr()
106 The strchr() function returns a pointer to the first occurrence of c
107 (converted to a char) in string s, or a null pointer if c does not
108 occur in the string. The strrchr() function returns a pointer to the
109 last occurrence of c. The null character terminating a string is con‐
110 sidered to be part of the string.
111
112 strcmp(), strncmp()
113 The strcmp() function compares two strings byte-by-byte, according to
114 the ordering of your machine's character set. The function returns an
115 integer greater than, equal to, or less than 0, if the string pointed
116 to by s1 is greater than, equal to, or less than the string pointed to
117 by s2 respectively. The sign of a non-zero return value is determined
118 by the sign of the difference between the values of the first pair of
119 bytes that differ in the strings being compared. The strncmp() function
120 makes the same comparison but looks at a maximum of n bytes. Bytes fol