From patchwork Sun Jul 19 20:34:22 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Peter Maydell X-Patchwork-Id: 51265 Return-Path: X-Original-To: linaro@patches.linaro.org Delivered-To: linaro@patches.linaro.org Received: from mail-la0-f71.google.com (mail-la0-f71.google.com [209.85.215.71]) by ip-10-151-82-157.ec2.internal (Postfix) with ESMTPS id 75C7222A28 for ; Sun, 19 Jul 2015 20:34:26 +0000 (UTC) Received: by laef2 with SMTP id f2sf36397731lae.0 for ; Sun, 19 Jul 2015 13:34:25 -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:cc:subject :date:message-id:x-original-sender:x-original-authentication-results :precedence:mailing-list:list-id:list-post:list-help:list-archive :list-unsubscribe; bh=78cWooaESAZEdDI9pSnH4rGECpBhNZU9fLeVOb40+fY=; b=PXdB6fR8W7OExga4tNfSXQhh3P4TYwFj+Lu0d5kpTaFl5eps8F1UW4xVzXmUWPFxHl /z3yrvepiCzpPjN2l/EgulTXBMmP/7lhOx4lin9DqxNKxYaKVKSNSzhgXA3zM7BBxUZP 0bvCbrXsVCN07XJBs+YRiiJdPpUjQua54QYUm/jwsgdqrv0QtLJsQNdCsQfoJSep/CZx JmQX9xxUmbC+HV1vQYOg1mSH6pBHsr5H1o2yG7kn9x/9EhDS/fWvK9CQgkdv7qUd5o/L GSoDOS25dVRK9+juoKBlDfAZxdM5LUJwEWMSQdWh+CKdhqevUjK5EzxIb7OwVgDk5Wyb OH9w== X-Gm-Message-State: ALoCoQnBpqjryy4xgxsXshFOs/DoR35YgNi3Fk+ySNd1Ll3xSHt0mUUq3uZ90X6hG2Y0xkAxkzUW X-Received: by 10.152.8.110 with SMTP id q14mr13216964laa.3.1437338065007; Sun, 19 Jul 2015 13:34:25 -0700 (PDT) MIME-Version: 1.0 X-BeenThere: patchwork-forward@linaro.org Received: by 10.152.27.102 with SMTP id s6ls654067lag.102.gmail; Sun, 19 Jul 2015 13:34:24 -0700 (PDT) X-Received: by 10.152.21.103 with SMTP id u7mr24031805lae.49.1437338064862; Sun, 19 Jul 2015 13:34:24 -0700 (PDT) Received: from mail-lb0-f182.google.com (mail-lb0-f182.google.com. [209.85.217.182]) by mx.google.com with ESMTPS id o10si15979113laj.148.2015.07.19.13.34.24 for (version=TLSv1.2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Sun, 19 Jul 2015 13:34:24 -0700 (PDT) Received-SPF: pass (google.com: domain of patch+caf_=patchwork-forward=linaro.org@linaro.org designates 209.85.217.182 as permitted sender) client-ip=209.85.217.182; Received: by lbbyj8 with SMTP id yj8so85170725lbb.0 for ; Sun, 19 Jul 2015 13:34:24 -0700 (PDT) X-Received: by 10.112.166.2 with SMTP id zc2mr24455834lbb.29.1437338064524; Sun, 19 Jul 2015 13:34:24 -0700 (PDT) X-Forwarded-To: patchwork-forward@linaro.org X-Forwarded-For: patch@linaro.org patchwork-forward@linaro.org Delivered-To: patches@linaro.org Received: by 10.112.7.198 with SMTP id l6csp432409lba; Sun, 19 Jul 2015 13:34:23 -0700 (PDT) X-Received: by 10.180.20.198 with SMTP id p6mr15353802wie.38.1437338063713; Sun, 19 Jul 2015 13:34:23 -0700 (PDT) Received: from mnementh.archaic.org.uk (mnementh.archaic.org.uk. [2001:8b0:1d0::1]) by mx.google.com with ESMTPS id cm6si31366168wjb.64.2015.07.19.13.34.23 for (version=TLSv1.2 cipher=RC4-SHA bits=128/128); Sun, 19 Jul 2015 13:34:23 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of pm215@archaic.org.uk designates 2001:8b0:1d0::1 as permitted sender) client-ip=2001:8b0:1d0::1; Received: from pm215 by mnementh.archaic.org.uk with local (Exim 4.80) (envelope-from ) id 1ZGvHy-0006v8-Ac; Sun, 19 Jul 2015 21:34:22 +0100 From: Peter Maydell To: qemu-devel@nongnu.org Cc: patches@linaro.org, qemu-trivial@nongnu.org Subject: [PATCH] qemu-common.h: Document cutils.c string functions Date: Sun, 19 Jul 2015 21:34:22 +0100 Message-Id: <1437338062-26577-1-git-send-email-peter.maydell@linaro.org> X-Mailer: git-send-email 1.7.10.4 X-Removed-Original-Auth: Dkim didn't pass. X-Original-Sender: peter.maydell@linaro.org 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.182 as permitted sender) smtp.mail=patch+caf_=patchwork-forward=linaro.org@linaro.org Precedence: list Mailing-list: list patchwork-forward@linaro.org; contact patchwork-forward+owners@linaro.org List-ID: X-Google-Group-Id: 836684582541 List-Post: , List-Help: , List-Archive: List-Unsubscribe: , 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 --- We recommend pstrcpy() &c in HACKING but that's not very helpful if we don't actually document their behaviour... 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);