/* * linux/tools/lib/string.c * * Copied from linux/lib/string.c, where it is: * * Copyright (C) 1991, 1992 Linus Torvalds * * More specifically, the first copied function was strtobool, which * was introduced by: * * d0f1fed29e6e ("Add a strtobool function matching semantics of existing in kernel equivalents") * Author: Jonathan Cameron <jic23@cam.ac.uk> */ #include <stdlib.h> #include <string.h> #include <errno.h> #include <linux/string.h> #include <linux/compiler.h> /** * memdup - duplicate region of memory * * @src: memory region to duplicate * @len: memory region length */ void *memdup(const void *src, size_t len) { void *p = malloc(len); if (p) memcpy(p, src, len); return p; } /** * strtobool - convert common user inputs into boolean values * @s: input string * @res: result * * This routine returns 0 iff the first character is one of 'Yy1Nn0'. * Otherwise it will return -EINVAL. Value pointed to by res is * updated upon finding a match. */ int strtobool(const char *s, bool *res) { switch (s[0]) { case 'y': case 'Y': case '1': *res = true; break; case 'n': case 'N': case '0': *res = false; break; default: return -EINVAL; } return 0; } /** * strlcpy - Copy a C-string into a sized buffer * @dest: Where to copy the string to * @src: Where to copy the string from * @size: size of destination buffer * * Compatible with *BSD: the result is always a valid * NUL-terminated string that fits in the buffer (unless, * of course, the buffer size is zero). It does not pad * out the result like strncpy() does. * * If libc has strlcpy() then that version will override this * implementation: */ size_t __weak strlcpy(char *dest, const char *src, size_t size) { size_t ret = strlen(src); if (size) { size_t len = (ret >= size) ? size - 1 : ret; memcpy(dest, src, len); dest[len] = '\0'; } return ret; } amp;id=69973b830859bc6529a7a0468ba0d80ee5117826'>tree</a><a class='active' href='/cgit.cgi/linux/net-next.git/commit/net/decnet/Makefile?h=nds-private-remove&id=69973b830859bc6529a7a0468ba0d80ee5117826'>commit</a><a href='/cgit.cgi/linux/net-next.git/diff/net/decnet/Makefile?h=nds-private-remove&id=69973b830859bc6529a7a0468ba0d80ee5117826'>diff</a></td><td class='form'><form class='right' method='get' action='/cgit.cgi/linux/net-next.git/log/net/decnet/Makefile'> <input type='hidden' name='h' value='nds-private-remove'/><input type='hidden' name='id' value='69973b830859bc6529a7a0468ba0d80ee5117826'/><select name='qt'> <option value='grep'>log msg</option> <option value='author'>author</option> <option value='committer'>committer</option> <option value='range'>range</option> </select> <input class='txt' type='search' size='10' name='q' value=''/> <input type='submit' value='search'/> </form> </td></tr></table> <div class='path'>path: <a href='/cgit.cgi/linux/net-next.git/commit/?h=nds-private-remove&id=69973b830859bc6529a7a0468ba0d80ee5117826'>root</a>/<a href='/cgit.cgi/linux/net-next.git/commit/net?h=nds-private-remove&id=69973b830859bc6529a7a0468ba0d80ee5117826'>net</a>/<a href='/cgit.cgi/linux/net-next.git/commit/net/decnet?h=nds-private-remove&id=69973b830859bc6529a7a0468ba0d80ee5117826'>decnet</a>/<a href='/cgit.cgi/linux/net-next.git/commit/net/decnet/Makefile?h=nds-private-remove&id=69973b830859bc6529a7a0468ba0d80ee5117826'>Makefile</a></div><div class='content'><div class='cgit-panel'><b>diff options</b><form method='get'><input type='hidden' name='h' value='nds-private-remove'/><input type='hidden' name='id' value='69973b830859bc6529a7a0468ba0d80ee5117826'/><table><tr><td colspan='2'/></tr><tr><td class='label'>context:</td><td class='ctrl'><select name='context' onchange='this.form.submit();'><option value='1'>1</option><option value='2'>2</option><option value='3' selected='selected'>3</option><option value='4'>4</option><option value='5'>5</option><option value='6'>6</option><option value='7'>7</option><option value='8'>8</option><option value='9'>9</option><option value='10'>10</option><option value='15'>15</option><option value='20'>20</option><option value='25'>25</option><option value='30'>30</option><option value='35'>35</option><option value='40'>40</option></select></td></tr><tr><td class='label'>space:</td><td class='ctrl'><select name='ignorews' onchange='this.form.submit();'><option value='0' selected='selected'>include</option><option value='1'>ignore</option></select></td></tr><tr><td class='label'>mode:</td><td class='ctrl'><select name='dt' onchange='this.form.submit();'><option value='0' selected='selected'>unified</option><option value='1'>ssdiff</option><option value='2'>stat only</option></select></td></tr><tr><td/><td class='ctrl'><noscript><input type='submit' value='reload'/></noscript></td></tr></table></form></div><table summary='commit info' class='commit-info'> <tr><th>author</th><td>Linus Torvalds <torvalds@linux-foundation.org></td><td class='right'>2016-12-11 11:17:54 -0800</td></tr> <tr><th>committer</th><td>Linus Torvalds <torvalds@linux-foundation.org></td><td class='right'>2016-12-11 11:17:54 -0800</td></tr> <tr><th>commit</th><td colspan='2' class='oid'><a href='/cgit.cgi/linux/net-next.git/commit/net/decnet/Makefile?h=nds-private-remove&id=69973b830859bc6529a7a0468ba0d80ee5117826'>69973b830859bc6529a7a0468ba0d80ee5117826</a> (<a href='/cgit.cgi/linux/net-next.git/patch/net/decnet/Makefile?id=69973b830859bc6529a7a0468ba0d80ee5117826'>patch</a>)</td></tr> <tr><th>tree</th><td colspan='2' class='oid'><a href='/cgit.cgi/linux/net-next.git/tree/?h=nds-private-remove&id=69973b830859bc6529a7a0468ba0d80ee5117826'>5f11fe15ed9d9a3ab9c92242030e54b73ecdce45</a> /<a href='/cgit.cgi/linux/net-next.git/tree/net/decnet/Makefile?h=nds-private-remove&id=69973b830859bc6529a7a0468ba0d80ee5117826'>net/decnet/Makefile</a></td></tr> <tr><th>parent</th><td colspan='2' class='oid'><a href='/cgit.cgi/linux/net-next.git/commit/net/decnet/Makefile?h=nds-private-remove&id=2e4333c14de06a333783d6812cf3c4998f78b0c8'>2e4333c14de06a333783d6812cf3c4998f78b0c8</a> (<a href='/cgit.cgi/linux/net-next.git/diff/net/decnet/Makefile?h=nds-private-remove&id=69973b830859bc6529a7a0468ba0d80ee5117826&id2=2e4333c14de06a333783d6812cf3c4998f78b0c8'>diff</a>)</td></tr></table> <div class='commit-subject'>Linux 4.9</div><div class='commit-msg'></div><div class='diffstat-header'><a href='/cgit.cgi/linux/net-next.git/diff/?h=nds-private-remove&id=69973b830859bc6529a7a0468ba0d80ee5117826'>Diffstat</a> (limited to 'net/decnet/Makefile')</div><table summary='diffstat' class='diffstat'>