From patchwork Wed Apr 29 13:29:11 2009 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jeff Layton X-Patchwork-Id: 20714 Received: from lists.samba.org (mail.samba.org [66.70.73.150]) by demeter.kernel.org (8.14.2/8.14.2) with ESMTP id n3TDTq9N032674 for ; Wed, 29 Apr 2009 13:29:52 GMT Received: from dp.samba.org (localhost [127.0.0.1]) by lists.samba.org (Postfix) with ESMTP id 51BF3163C40 for ; Wed, 29 Apr 2009 13:29:29 +0000 (GMT) X-Spam-Checker-Version: SpamAssassin 3.1.7 (2006-10-05) on dp.samba.org X-Spam-Level: X-Spam-Status: No, score=-3.8 required=3.8 tests=AWL,BAYES_00, FORGED_RCVD_HELO,SPF_HELO_PASS,SPF_PASS autolearn=ham version=3.1.7 X-Original-To: linux-cifs-client@lists.samba.org Delivered-To: linux-cifs-client@lists.samba.org Received: from mx2.redhat.com (mx2.redhat.com [66.187.237.31]) by lists.samba.org (Postfix) with ESMTP id 4AF45163BE9 for ; Wed, 29 Apr 2009 13:29:03 +0000 (GMT) Received: from int-mx2.corp.redhat.com (int-mx2.corp.redhat.com [172.16.27.26]) by mx2.redhat.com (8.13.8/8.13.8) with ESMTP id n3TDTOlh027882; Wed, 29 Apr 2009 09:29:24 -0400 Received: from ns3.rdu.redhat.com (ns3.rdu.redhat.com [10.11.255.199]) by int-mx2.corp.redhat.com (8.13.1/8.13.1) with ESMTP id n3TDTLGi001764; Wed, 29 Apr 2009 09:29:22 -0400 Received: from localhost.localdomain (vpn-12-35.rdu.redhat.com [10.11.12.35]) by ns3.rdu.redhat.com (8.13.8/8.13.8) with ESMTP id n3TDTKJ6008654; Wed, 29 Apr 2009 09:29:21 -0400 From: Jeff Layton To: linux-cifs-client@lists.samba.org Date: Wed, 29 Apr 2009 09:29:11 -0400 Message-Id: <1241011759-7632-2-git-send-email-jlayton@redhat.com> In-Reply-To: <1241011759-7632-1-git-send-email-jlayton@redhat.com> References: <1241011759-7632-1-git-send-email-jlayton@redhat.com> X-Scanned-By: MIMEDefang 2.58 on 172.16.27.26 Cc: smfrench@gmail.com, sjayaraman@suse.de, eugene@redhat.com Subject: [linux-cifs-client] [PATCH 01/10] cifs: add function to get length of NULL termination in bytes X-BeenThere: linux-cifs-client@lists.samba.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: The Linux CIFS VFS client List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: linux-cifs-client-bounces+patchwork-cifs-client=patchwork.kernel.org@lists.samba.org Errors-To: linux-cifs-client-bounces+patchwork-cifs-client=patchwork.kernel.org@lists.samba.org It's possible to have the null terminator for a charset be a single or multiple character. Add a function to tell us how long it should be. Signed-off-by: Jeff Layton --- fs/cifs/cifs_unicode.h | 19 +++++++++++++++++++ 1 files changed, 19 insertions(+), 0 deletions(-) diff --git a/fs/cifs/cifs_unicode.h b/fs/cifs/cifs_unicode.h index 14eb9a2..6bffab5 100644 --- a/fs/cifs/cifs_unicode.h +++ b/fs/cifs/cifs_unicode.h @@ -64,6 +64,25 @@ int cifs_strtoUCS(__le16 *, const char *, int, const struct nls_table *); #endif /* + * null_charlen - return length of null character for codepage + * @codepage - codepage for which to return length of NULL terminator + * + * Since we can't guarantee that the null terminator will be a particular + * length, we have to check against the codepage. If there's a problem + * determining it, assume a single-byte NULL terminator. + */ +static inline int +null_charlen(const struct nls_table *codepage) +{ + int charlen; + char tmp[NLS_MAX_CHARSET_SIZE]; + + charlen = codepage->uni2char(0, tmp, NLS_MAX_CHARSET_SIZE); + + return charlen > 0 ? charlen : 1; +} + +/* * UniStrcat: Concatenate the second string to the first * * Returns: