From owner-svn-src-head@freebsd.org Fri Feb 24 17:36:57 2017 Return-Path: Delivered-To: svn-src-head@mailman.ysv.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:1900:2254:206a::19:1]) by mailman.ysv.freebsd.org (Postfix) with ESMTP id 0F812CEB5DA; Fri, 24 Feb 2017 17:36:57 +0000 (UTC) (envelope-from hselasky@FreeBSD.org) Received: from repo.freebsd.org (repo.freebsd.org [IPv6:2610:1c1:1:6068::e6a:0]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (Client did not present a certificate) by mx1.freebsd.org (Postfix) with ESMTPS id C1F3A1F27; Fri, 24 Feb 2017 17:36:56 +0000 (UTC) (envelope-from hselasky@FreeBSD.org) Received: from repo.freebsd.org ([127.0.1.37]) by repo.freebsd.org (8.15.2/8.15.2) with ESMTP id v1OHatpV072198; Fri, 24 Feb 2017 17:36:55 GMT (envelope-from hselasky@FreeBSD.org) Received: (from hselasky@localhost) by repo.freebsd.org (8.15.2/8.15.2/Submit) id v1OHatUB072197; Fri, 24 Feb 2017 17:36:55 GMT (envelope-from hselasky@FreeBSD.org) Message-Id: <201702241736.v1OHatUB072197@repo.freebsd.org> X-Authentication-Warning: repo.freebsd.org: hselasky set sender to hselasky@FreeBSD.org using -f From: Hans Petter Selasky Date: Fri, 24 Feb 2017 17:36:55 +0000 (UTC) To: src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-head@freebsd.org Subject: svn commit: r314215 - head/sys/compat/linuxkpi/common/include/linux X-SVN-Group: head MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-BeenThere: svn-src-head@freebsd.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: SVN commit messages for the src tree for head/-current List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Fri, 24 Feb 2017 17:36:57 -0000 Author: hselasky Date: Fri Feb 24 17:36:55 2017 New Revision: 314215 URL: https://svnweb.freebsd.org/changeset/base/314215 Log: Implement more string functions in the LinuxKPI. MFC after: 1 week Sponsored by: Mellanox Technologies Modified: head/sys/compat/linuxkpi/common/include/linux/string.h Modified: head/sys/compat/linuxkpi/common/include/linux/string.h ============================================================================== --- head/sys/compat/linuxkpi/common/include/linux/string.h Fri Feb 24 17:03:14 2017 (r314214) +++ head/sys/compat/linuxkpi/common/include/linux/string.h Fri Feb 24 17:36:55 2017 (r314215) @@ -2,7 +2,7 @@ * Copyright (c) 2010 Isilon Systems, Inc. * Copyright (c) 2010 iX Systems, Inc. * Copyright (c) 2010 Panasas, Inc. - * Copyright (c) 2013-2016 Mellanox Technologies, Ltd. + * Copyright (c) 2013-2017 Mellanox Technologies, Ltd. * All rights reserved. * * Redistribution and use in source and binary forms, with or without @@ -31,29 +31,111 @@ #ifndef _LINUX_STRING_H_ #define _LINUX_STRING_H_ +#include + #include #include #include +#include +#include #include #define strnicmp(...) strncasecmp(__VA_ARGS__) +static inline int +match_string(const char *const *table, int n, const char *key) +{ + int i; + + for (i = 0; i != n && table[i] != NULL; i++) { + if (strcmp(table[i], key) == 0) + return (i); + } + return (-EINVAL); +} + +static inline void * +memdup_user(const void *ptr, size_t len) +{ + void *retval; + int error; + + retval = malloc(len, M_KMALLOC, M_WAITOK); + error = linux_copyin(ptr, retval, len); + if (error != 0) { + free(retval, M_KMALLOC); + return (ERR_PTR(error)); + } + return (retval); +} + static inline void * kmemdup(const void *src, size_t len, gfp_t gfp) { void *dst; dst = kmalloc(len, gfp); - if (dst) + if (dst != NULL) memcpy(dst, src, len); return (dst); } +static inline char * +kstrdup(const char *string, gfp_t gfp) +{ + char *retval; + size_t len; + + len = strlen(string) + 1; + retval = kmalloc(len, gfp); + if (retval != NULL) + memcpy(retval, string, len); + return (retval); +} + +static inline char * +kstrndup(const char *string, size_t len, gfp_t gfp) +{ + char *retval; + + retval = kmalloc(len + 1, gfp); + if (retval != NULL) + strncpy(retval, string, len); + return (retval); +} + static inline const char * kstrdup_const(const char *src, gfp_t gfp) { return (kmemdup(src, strlen(src) + 1, gfp)); } -#endif /* _LINUX_STRING_H_ */ +static inline char * +skip_spaces(const char *str) +{ + while (isspace(*str)) + ++str; + return (__DECONST(char *, str)); +} + +static inline void * +memchr_inv(const void *start, int c, size_t length) +{ + const u8 *ptr; + const u8 *end; + u8 ch; + + ch = c; + ptr = start; + end = ptr + length; + + while (ptr != end) { + if (*ptr != ch) + return (__DECONST(void *, ptr)); + ptr++; + } + return (NULL); +} + +#endif /* _LINUX_STRING_H_ */