2 * linux/tools/lib/string.c
4 * Copied from linux/lib/string.c, where it is:
6 * Copyright (C) 1991, 1992 Linus Torvalds
8 * More specifically, the first copied function was strtobool, which
11 * d0f1fed29e6e ("Add a strtobool function matching semantics of existing in kernel equivalents")
12 * Author: Jonathan Cameron <jic23@cam.ac.uk>
18 #include <linux/string.h>
19 #include <linux/compiler.h>
22 * memdup - duplicate region of memory
24 * @src: memory region to duplicate
25 * @len: memory region length
27 void *memdup(const void *src, size_t len)
29 void *p = malloc(len);
38 * strtobool - convert common user inputs into boolean values
42 * This routine returns 0 iff the first character is one of 'Yy1Nn0', or
43 * [oO][NnFf] for "on" and "off". Otherwise it will return -EINVAL. Value
44 * pointed to by res is updated upon finding a match.
46 int strtobool(const char *s, bool *res)
84 * strlcpy - Copy a C-string into a sized buffer
85 * @dest: Where to copy the string to
86 * @src: Where to copy the string from
87 * @size: size of destination buffer
89 * Compatible with *BSD: the result is always a valid
90 * NUL-terminated string that fits in the buffer (unless,
91 * of course, the buffer size is zero). It does not pad
92 * out the result like strncpy() does.
94 * If libc has strlcpy() then that version will override this
97 size_t __weak strlcpy(char *dest, const char *src, size_t size)
99 size_t ret = strlen(src);
102 size_t len = (ret >= size) ? size - 1 : ret;
103 memcpy(dest, src, len);