MCPcopy Create free account
hub / github.com/F-Stack/f-stack / arrayize

Function arrayize

tools/libutil/login_cap.c:105–143  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

103 */
104
105static const char **
106arrayize(const char *str, const char *chars, int *size)
107{
108 int i;
109 char *ptr;
110 const char *cptr;
111 const char **res = NULL;
112
113 /* count the sub-strings */
114 for (i = 0, cptr = str; *cptr; i++) {
115 int count = strcspn(cptr, chars);
116 cptr += count;
117 if (*cptr)
118 ++cptr;
119 }
120
121 /* alloc the array */
122 if ((ptr = allocstr(str)) != NULL) {
123 if ((res = allocarray(++i)) == NULL)
124 free((void *)(uintptr_t)(const void *)str);
125 else {
126 /* now split the string */
127 i = 0;
128 while (*ptr) {
129 int count = strcspn(ptr, chars);
130 res[i++] = ptr;
131 ptr += count;
132 if (*ptr)
133 *ptr++ = '\0';
134 }
135 res[i] = NULL;
136 }
137 }
138
139 if (size)
140 *size = i;
141
142 return res;
143}
144
145
146/*

Callers 1

login_getcaplistFunction · 0.85

Calls 4

strcspnFunction · 0.85
allocstrFunction · 0.85
allocarrayFunction · 0.85
freeFunction · 0.50

Tested by

no test coverage detected