From patchwork Mon Jul 27 19:54:07 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Michael Tokarev X-Patchwork-Id: 51567 Return-Path: X-Original-To: linaro@patches.linaro.org Delivered-To: linaro@patches.linaro.org Received: from mail-la0-f70.google.com (mail-la0-f70.google.com [209.85.215.70]) by patches.linaro.org (Postfix) with ESMTPS id F154B214B7 for ; Mon, 27 Jul 2015 20:01:46 +0000 (UTC) Received: by lafd3 with SMTP id d3sf31048941laf.1 for ; Mon, 27 Jul 2015 13:01:45 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:mime-version:delivered-to:from:to:date :message-id:in-reply-to:references:cc:subject:precedence:list-id :list-unsubscribe:list-archive:list-post:list-help:list-subscribe :errors-to:sender:x-original-sender :x-original-authentication-results:mailing-list; bh=jL3U40i6XXVxL7gjty4XNZwQ8JZjuP+VQ36hZT80tvI=; b=YF7Inf2XsfYCTnC502acDyQbRHdwHqmciepBPd/mdHv530D9JYd9g0yx+Yskf1vH62 SDVAlSn/+Cy18UwZq82aeDWsn1B+9gP4ATpainLSQGNkklIPoklJuSP6UNhwg6WV4ag9 sfWu79neY5nsK9r6vc8LihJWt9UuRjb4zHDLDic+PSW8dqesLbo3D9fW5FG4gOLAZKI8 gzHrNYCf9Ezd940sf4RWUgkk4Ywh7OdkCWW5SQIhTu6NuJCT8ACCfj07t6xHP+AhX4rT 0nbuw3SA7PxvjnsE+MJSH4cYxcTXCtwELrlSdhAb4ziCQ1VIXfPorvyThRrJwPrfynki 5FQQ== X-Gm-Message-State: ALoCoQnVMygS6tyMJNuBgFfuuAy/HW2w1TOnkEzej/HUl6F2JyRxuCG/V3M6uMIcQaLUeHPKKTUM X-Received: by 10.194.188.104 with SMTP id fz8mr12691897wjc.1.1438027305939; Mon, 27 Jul 2015 13:01:45 -0700 (PDT) MIME-Version: 1.0 X-BeenThere: patchwork-forward@linaro.org Received: by 10.152.2.202 with SMTP id 10ls765469law.79.gmail; Mon, 27 Jul 2015 13:01:45 -0700 (PDT) X-Received: by 10.112.24.233 with SMTP id x9mr29417256lbf.7.1438027305645; Mon, 27 Jul 2015 13:01:45 -0700 (PDT) Received: from mail-lb0-f169.google.com (mail-lb0-f169.google.com. [209.85.217.169]) by mx.google.com with ESMTPS id a5si16164234lbq.168.2015.07.27.13.01.45 for (version=TLSv1.2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Mon, 27 Jul 2015 13:01:45 -0700 (PDT) Received-SPF: pass (google.com: domain of patch+caf_=patchwork-forward=linaro.org@linaro.org designates 209.85.217.169 as permitted sender) client-ip=209.85.217.169; Received: by lblf12 with SMTP id f12so60863079lbl.2 for ; Mon, 27 Jul 2015 13:01:45 -0700 (PDT) X-Received: by 10.112.199.133 with SMTP id jk5mr29450449lbc.32.1438027305536; Mon, 27 Jul 2015 13:01:45 -0700 (PDT) X-Forwarded-To: patchwork-forward@linaro.org X-Forwarded-For: patch@linaro.org patchwork-forward@linaro.org Delivered-To: patch@linaro.org Received: by 10.112.7.198 with SMTP id l6csp1727713lba; Mon, 27 Jul 2015 13:01:44 -0700 (PDT) X-Received: by 10.140.30.166 with SMTP id d35mr43628609qgd.85.1438027299925; Mon, 27 Jul 2015 13:01:39 -0700 (PDT) Received: from lists.gnu.org (lists.gnu.org. [2001:4830:134:3::11]) by mx.google.com with ESMTPS id n8si22176056qhb.106.2015.07.27.13.01.39 for (version=TLSv1 cipher=RC4-SHA bits=128/128); Mon, 27 Jul 2015 13:01:39 -0700 (PDT) Received-SPF: pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 2001:4830:134:3::11 as permitted sender) client-ip=2001:4830:134:3::11; Received: from localhost ([::1]:55369 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1ZJoah-0002FW-4Y for patch@linaro.org; Mon, 27 Jul 2015 16:01:39 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:59571) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1ZJoZn-00018S-Fy for qemu-devel@nongnu.org; Mon, 27 Jul 2015 16:00:50 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1ZJoZk-0005Vr-07 for qemu-devel@nongnu.org; Mon, 27 Jul 2015 16:00:43 -0400 Received: from isrv.corpit.ru ([86.62.121.231]:46939) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1ZJoZj-0005VI-8O; Mon, 27 Jul 2015 16:00:39 -0400 Received: from tsrv.tls.msk.ru (tsrv.tls.msk.ru [192.168.177.2]) by isrv.corpit.ru (Postfix) with ESMTP id CE194425AF; Mon, 27 Jul 2015 23:00:37 +0300 (MSK) Received: from tls.msk.ru (mjt.vpn.tls.msk.ru [192.168.177.99]) by tsrv.tls.msk.ru (Postfix) with SMTP id 04CB6A67; Mon, 27 Jul 2015 22:54:21 +0300 (MSK) Received: (nullmailer pid 9523 invoked by uid 1000); Mon, 27 Jul 2015 19:54:20 -0000 From: Michael Tokarev To: qemu-devel@nongnu.org Date: Mon, 27 Jul 2015 22:54:07 +0300 Message-Id: X-Mailer: git-send-email 2.1.4 In-Reply-To: References: X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] X-Received-From: 86.62.121.231 Cc: qemu-trivial@nongnu.org, Peter Maydell , Michael Tokarev Subject: [Qemu-devel] [PULL 04/10] qemu-common.h: Document cutils.c string functions X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.14 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: , List-Help: , List-Subscribe: , Errors-To: qemu-devel-bounces+patch=linaro.org@nongnu.org Sender: qemu-devel-bounces+patch=linaro.org@nongnu.org X-Removed-Original-Auth: Dkim didn't pass. X-Original-Sender: mjt@tls.msk.ru X-Original-Authentication-Results: mx.google.com; spf=pass (google.com: domain of patch+caf_=patchwork-forward=linaro.org@linaro.org designates 209.85.217.169 as permitted sender) smtp.mail=patch+caf_=patchwork-forward=linaro.org@linaro.org Mailing-list: list patchwork-forward@linaro.org; contact patchwork-forward+owners@linaro.org X-Google-Group-Id: 836684582541 From: Peter Maydell Add documentation comments for various utility string functions which we have implemented in util/cutils.c: pstrcpy() strpadcpy() pstrcat() strstart() stristart() qemu_strnlen() qemu_strsep() Signed-off-by: Peter Maydell Reviewed-by: Eric Blake Signed-off-by: Michael Tokarev --- include/qemu-common.h | 114 +++++++++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 113 insertions(+), 1 deletion(-) diff --git a/include/qemu-common.h b/include/qemu-common.h index 237d654..fb3da6c 100644 --- a/include/qemu-common.h +++ b/include/qemu-common.h @@ -148,13 +148,125 @@ static inline bool is_help_option(const char *s) return !strcmp(s, "?") || !strcmp(s, "help"); } -/* cutils.c */ +/* util/cutils.c */ +/** + * pstrcpy: + * @buf: buffer to copy string into + * @buf_size: size of @buf in bytes + * @str: string to copy + * + * Copy @str into @buf, including the trailing NUL, but do not + * write more than @buf_size bytes. The resulting buffer is + * always NUL terminated (even if the source string was too long). + * If @buf_size is zero or negative then no bytes are copied. + * + * This function is similar to strncpy(), but avoids two of that + * function's problems: + * * if @str fits in the buffer, pstrcpy() does not zero-fill the + * remaining space at the end of @buf + * * if @str is too long, pstrcpy() will copy the first @buf_size-1 + * bytes and then add a NUL + */ void pstrcpy(char *buf, int buf_size, const char *str); +/** + * strpadcpy: + * @buf: buffer to copy string into + * @buf_size: size of @buf in bytes + * @str: string to copy + * @pad: character to pad the remainder of @buf with + * + * Copy @str into @buf (but *not* its trailing NUL!), and then pad the + * rest of the buffer with the @pad character. If @str is too large + * for the buffer then it is truncated, so that @buf contains the + * first @buf_size characters of @str, with no terminator. + */ void strpadcpy(char *buf, int buf_size, const char *str, char pad); +/** + * pstrcat: + * @buf: buffer containing existing string + * @buf_size: size of @buf in bytes + * @s: string to concatenate to @buf + * + * Append a copy of @s to the string already in @buf, but do not + * allow the buffer to overflow. If the existing contents of @buf + * plus @str would total more than @buf_size bytes, then write + * as much of @str as will fit followed by a NUL terminator. + * + * @buf must already contain a NUL-terminated string, or the + * behaviour is undefined. + * + * Returns: @buf. + */ char *pstrcat(char *buf, int buf_size, const char *s); +/** + * strstart: + * @str: string to test + * @val: prefix string to look for + * @ptr: NULL, or pointer to be written to indicate start of + * the remainder of the string + * + * Test whether @str starts with the prefix @val. + * If it does (including the degenerate case where @str and @val + * are equal) then return true. If @ptr is not NULL then a + * pointer to the first character following the prefix is written + * to it. If @val is not a prefix of @str then return false (and + * @ptr is not written to). + * + * Returns: true if @str starts with prefix @val, false otherwise. + */ int strstart(const char *str, const char *val, const char **ptr); +/** + * stristart: + * @str: string to test + * @val: prefix string to look for + * @ptr: NULL, or pointer to be written to indicate start of + * the remainder of the string + * + * Test whether @str starts with the case-insensitive prefix @val. + * This function behaves identically to strstart(), except that the + * comparison is made after calling qemu_toupper() on each pair of + * characters. + * + * Returns: true if @str starts with case-insensitive prefix @val, + * false otherwise. + */ int stristart(const char *str, const char *val, const char **ptr); +/** + * qemu_strnlen: + * @s: string + * @max_len: maximum number of bytes in @s to scan + * + * Return the length of the string @s, like strlen(), but do not + * examine more than @max_len bytes of the memory pointed to by @s. + * If no NUL terminator is found within @max_len bytes, then return + * @max_len instead. + * + * This function has the same behaviour as the POSIX strnlen() + * function. + * + * Returns: length of @s in bytes, or @max_len, whichever is smaller. + */ int qemu_strnlen(const char *s, int max_len); +/** + * qemu_strsep: + * @input: pointer to string to parse + * @delim: string containing delimiter characters to search for + * + * Locate the first occurrence of any character in @delim within + * the string referenced by @input, and replace it with a NUL. + * The location of the next character after the delimiter character + * is stored into @input. + * If the end of the string was reached without finding a delimiter + * character, then NULL is stored into @input. + * If @input points to a NULL pointer on entry, return NULL. + * The return value is always the original value of *@input (and + * so now points to a NUL-terminated string corresponding to the + * part of the input up to the first delimiter). + * + * This function has the same behaviour as the BSD strsep() function. + * + * Returns: the pointer originally in @input. + */ char *qemu_strsep(char **input, const char *delim); time_t mktimegm(struct tm *tm); int qemu_fls(int i);