From: Austin Clements Date: Tue, 29 Jul 2014 16:48:01 +0000 (+2000) Subject: [PATCH v2 03/14] util: Const version of strtok_len X-Git-Url: http://git.tremily.us/?a=commitdiff_plain;h=491d53dee144608dc11f644a33e14c968d5db3d2;p=notmuch-archives.git [PATCH v2 03/14] util: Const version of strtok_len --- diff --git a/c5/a12467cc98ac026b344c508cfd4efdde9d647e b/c5/a12467cc98ac026b344c508cfd4efdde9d647e new file mode 100644 index 000000000..7973cdecf --- /dev/null +++ b/c5/a12467cc98ac026b344c508cfd4efdde9d647e @@ -0,0 +1,122 @@ +Return-Path: +X-Original-To: notmuch@notmuchmail.org +Delivered-To: notmuch@notmuchmail.org +Received: from localhost (localhost [127.0.0.1]) + by olra.theworths.org (Postfix) with ESMTP id B13F2429E40 + for ; Tue, 29 Jul 2014 09:49:12 -0700 (PDT) +X-Virus-Scanned: Debian amavisd-new at olra.theworths.org +X-Spam-Flag: NO +X-Spam-Score: -2.3 +X-Spam-Level: +X-Spam-Status: No, score=-2.3 tagged_above=-999 required=5 + tests=[RCVD_IN_DNSWL_MED=-2.3] autolearn=disabled +Received: from olra.theworths.org ([127.0.0.1]) + by localhost (olra.theworths.org [127.0.0.1]) (amavisd-new, port 10024) + with ESMTP id Ze3SmhrymQ7T for ; + Tue, 29 Jul 2014 09:49:06 -0700 (PDT) +Received: from dmz-mailsec-scanner-3.mit.edu (dmz-mailsec-scanner-3.mit.edu + [18.9.25.14]) + (using TLSv1 with cipher DHE-RSA-AES256-SHA (256/256 bits)) + (No client certificate requested) + by olra.theworths.org (Postfix) with ESMTPS id 3026A431FD8 + for ; Tue, 29 Jul 2014 09:48:30 -0700 (PDT) +X-AuditID: 1209190e-f79946d000007db1-ff-53d7d05d6d7e +Received: from mailhub-auth-4.mit.edu ( [18.7.62.39]) + (using TLS with cipher AES256-SHA (256/256 bits)) + (Client did not present a certificate) + by dmz-mailsec-scanner-3.mit.edu (Symantec Messaging Gateway) with SMTP + id AC.F5.32177.D50D7D35; Tue, 29 Jul 2014 12:48:29 -0400 (EDT) +Received: from outgoing.mit.edu (outgoing-auth-1.mit.edu [18.9.28.11]) + by mailhub-auth-4.mit.edu (8.13.8/8.9.2) with ESMTP id s6TGmIIJ002608; + Tue, 29 Jul 2014 12:48:18 -0400 +Received: from drake.dyndns.org (31-33-71.wireless.csail.mit.edu + [128.31.33.71]) (authenticated bits=0) + (User authenticated as amdragon@ATHENA.MIT.EDU) + by outgoing.mit.edu (8.13.8/8.12.4) with ESMTP id s6TGmFJt030248 + (version=TLSv1/SSLv3 cipher=AES256-SHA bits=256 verify=NOT); + Tue, 29 Jul 2014 12:48:17 -0400 +Received: from amthrax by drake.dyndns.org with local (Exim 4.77) + (envelope-from ) + id 1XCAZS-0007Gg-O0; Tue, 29 Jul 2014 12:48:14 -0400 +From: Austin Clements +To: notmuch@notmuchmail.org +Subject: [PATCH v2 03/14] util: Const version of strtok_len +Date: Tue, 29 Jul 2014 12:48:01 -0400 +Message-Id: <1406652492-27803-4-git-send-email-amdragon@mit.edu> +X-Mailer: git-send-email 2.0.0 +In-Reply-To: <1406652492-27803-1-git-send-email-amdragon@mit.edu> +References: <1406652492-27803-1-git-send-email-amdragon@mit.edu> +X-Brightmail-Tracker: + H4sIAAAAAAAAA+NgFtrNIsWRmVeSWpSXmKPExsUixG6nrht74XqwQedbVYvVc3ksrt+cyezA + 5LFz1l12j2erbjEHMEVx2aSk5mSWpRbp2yVwZVx/W1TwirtixpSyBsZdnF2MnBwSAiYSOy5v + Y4SwxSQu3FvP1sXIxSEkMJtJYseEOYwQzkZGiR+XrrNDOMeYJI6232WBcOYySsy4sJ4FpJ9N + QENi2/7lYLNEBKQldt6dzQpiMws4Snzev4gNxBYWsJaYuvccWD2LgKrEnTt9YDavgINE/5EX + LBB3yEk03PgEVs8J1Hvr3l0mEFsIqObQrM0sExj5FzAyrGKUTcmt0s1NzMwpTk3WLU5OzMtL + LdI11svNLNFLTSndxAgKI05Jvh2MXw8qHWIU4GBU4uHdMPdasBBrYllxZe4hRkkOJiVRXr19 + 14OF+JLyUyozEosz4otKc1KLDzFKcDArifDynQXK8aYkVlalFuXDpKQ5WJTEed9aWwULCaQn + lqRmp6YWpBbBZGU4OJQkeF+fB2oULEpNT61Iy8wpQUgzcXCCDOcBGr4PpIa3uCAxtzgzHSJ/ + ilFRSpx3E0hCACSRUZoH1wuL81eM4kCvCPMeBKniAaYIuO5XQIOZgAazuoANLklESEk1MBqv + 0bQ6//lX1iy/G3n7FzwNv3T0nodr6Ms7DVLTxIKWzix+eTFi41nVu5w7g7cknarlKXWRv/+r + l0+jaWeoxbvPK7bUW//Y++9eiKJc3EmRAjmf6QbHm24eMnzJ4/sqe1bCYXvOG9WpfQIH9rCd + evTGXPDViiMv5RfmOs1j567nW+k4LV7vnZYSS3FGoqEWc1FxIgCZUloLzgIAAA== +X-BeenThere: notmuch@notmuchmail.org +X-Mailman-Version: 2.1.13 +Precedence: list +List-Id: "Use and development of the notmuch mail system." + +List-Unsubscribe: , + +List-Archive: +List-Post: +List-Help: +List-Subscribe: , + +X-List-Received-Date: Tue, 29 Jul 2014 16:49:13 -0000 + +Because of limitations in the C type system, we can't a strtok_len +that can work on both const string and non-const strings. The C +library solves this by taking a const char* and returning a char* +in functions like this (e.g., strchr), but that's not const-safe. +Solve it by introducing strtok_len_c, a version of strtok_len for +const strings. +--- + util/string-util.c | 8 ++++++++ + util/string-util.h | 3 +++ + 2 files changed, 11 insertions(+) + +diff --git a/util/string-util.c b/util/string-util.c +index 3e7066c..a90501e 100644 +--- a/util/string-util.c ++++ b/util/string-util.c +@@ -37,6 +37,14 @@ strtok_len (char *s, const char *delim, size_t *len) + return *len ? s : NULL; + } + ++const char * ++strtok_len_c (const char *s, const char *delim, size_t *len) ++{ ++ /* strtok_len is already const-safe, but we can't express both ++ * versions in the C type system. */ ++ return strtok_len ((char*)s, delim, len); ++} ++ + char * + sanitize_string (const void *ctx, const char *str) + { +diff --git a/util/string-util.h b/util/string-util.h +index ccad17f..e409cb3 100644 +--- a/util/string-util.h ++++ b/util/string-util.h +@@ -23,6 +23,9 @@ extern "C" { + + char *strtok_len (char *s, const char *delim, size_t *len); + ++/* Const version of strtok_len. */ ++const char *strtok_len_c (const char *s, const char *delim, size_t *len); ++ + /* Return a talloced string with str sanitized. + * + * Whitespace characters (tabs and newlines) are replaced with spaces, +-- +2.0.0 +