|
@@ -279,6 +279,31 @@ size_t strspn(const char *s, const char *accept)
|
279
|
279
|
}
|
280
|
280
|
#endif
|
281
|
281
|
|
|
282
|
+#ifndef __HAVE_ARCH_STRCSPN
|
|
283
|
+/**
|
|
284
|
+ * strcspn - Calculate the length of the initial substring of @s which only
|
|
285
|
+ * contain letters not in @reject
|
|
286
|
+ * @s: The string to be searched
|
|
287
|
+ * @accept: The string to search for
|
|
288
|
+ */
|
|
289
|
+size_t strcspn(const char *s, const char *reject)
|
|
290
|
+{
|
|
291
|
+ const char *p;
|
|
292
|
+ const char *r;
|
|
293
|
+ size_t count = 0;
|
|
294
|
+
|
|
295
|
+ for (p = s; *p != '\0'; ++p) {
|
|
296
|
+ for (r = reject; *r != '\0'; ++r) {
|
|
297
|
+ if (*p == *r)
|
|
298
|
+ return count;
|
|
299
|
+ }
|
|
300
|
+ ++count;
|
|
301
|
+ }
|
|
302
|
+
|
|
303
|
+ return count;
|
|
304
|
+}
|
|
305
|
+#endif
|
|
306
|
+
|
282
|
307
|
#ifndef __HAVE_ARCH_STRPBRK
|
283
|
308
|
/**
|
284
|
309
|
* strpbrk - Find the first occurrence of a set of characters
|
|
@@ -541,9 +566,21 @@ void * memchr(const void *s, int c, size_t n)
|
541
|
566
|
|
542
|
567
|
#endif
|
543
|
568
|
|
544
|
|
-char * strdup(const char *s) {
|
545
|
|
- char *new = malloc(strlen(s)+1);
|
546
|
|
- if (new)
|
547
|
|
- strcpy(new,s);
|
|
569
|
+char * strndup(const char *s, size_t n)
|
|
570
|
+{
|
|
571
|
+ size_t len = strlen(s);
|
|
572
|
+ char *new;
|
|
573
|
+
|
|
574
|
+ if (len>n)
|
|
575
|
+ len = n;
|
|
576
|
+ new = malloc(len+1);
|
|
577
|
+ if (new) {
|
|
578
|
+ new[len] = '\0';
|
|
579
|
+ memcpy(new,s,len);
|
|
580
|
+ }
|
548
|
581
|
return new;
|
549
|
582
|
}
|
|
583
|
+
|
|
584
|
+char * strdup(const char *s) {
|
|
585
|
+ return strndup(s, ~((size_t)0));
|
|
586
|
+}
|