From: Austin Clements Date: Fri, 1 Aug 2014 02:09:52 +0000 (+2000) Subject: [PATCH v3 02/13] util: Const version of strtok_len X-Git-Url: http://git.tremily.us/?a=commitdiff_plain;h=7c715d166d1758d7cbf47598cfb8f1a2b6a0a8b3;p=notmuch-archives.git [PATCH v3 02/13] util: Const version of strtok_len --- diff --git a/5a/7a388b3110529fa5653a6111075dd6ccac0682 b/5a/7a388b3110529fa5653a6111075dd6ccac0682 new file mode 100644 index 000000000..504931638 --- /dev/null +++ b/5a/7a388b3110529fa5653a6111075dd6ccac0682 @@ -0,0 +1,121 @@ +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 B1246431FCF + for ; Thu, 31 Jul 2014 19:10:17 -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 z3-YlBSpDwZA for ; + Thu, 31 Jul 2014 19:10:11 -0700 (PDT) +Received: from dmz-mailsec-scanner-5.mit.edu (dmz-mailsec-scanner-5.mit.edu + [18.7.68.34]) + by olra.theworths.org (Postfix) with ESMTP id 688B9431FAE + for ; Thu, 31 Jul 2014 19:10:11 -0700 (PDT) +X-AuditID: 12074422-f79be6d000007518-7e-53daf70279fb +Received: from mailhub-auth-1.mit.edu ( [18.9.21.35]) + (using TLS with cipher AES256-SHA (256/256 bits)) + (Client did not present a certificate) + by dmz-mailsec-scanner-5.mit.edu (Symantec Messaging Gateway) with SMTP + id CA.05.29976.207FAD35; Thu, 31 Jul 2014 22:10:10 -0400 (EDT) +Received: from outgoing.mit.edu (outgoing-auth-1.mit.edu [18.9.28.11]) + by mailhub-auth-1.mit.edu (8.13.8/8.9.2) with ESMTP id s712A92M014709; + Thu, 31 Jul 2014 22:10:09 -0400 +Received: from drake.dyndns.org + (216-15-114-40.c3-0.arl-ubr1.sbo-arl.ma.cable.rcn.com + [216.15.114.40]) (authenticated bits=0) + (User authenticated as amdragon@ATHENA.MIT.EDU) + by outgoing.mit.edu (8.13.8/8.12.4) with ESMTP id s712A6N4029973 + (version=TLSv1/SSLv3 cipher=AES256-SHA bits=256 verify=NOT); + Thu, 31 Jul 2014 22:10:08 -0400 +Received: from amthrax by drake.dyndns.org with local (Exim 4.77) + (envelope-from ) + id 1XD2IH-00033W-S4; Thu, 31 Jul 2014 22:10:05 -0400 +From: Austin Clements +To: notmuch@notmuchmail.org +Subject: [PATCH v3 02/13] util: Const version of strtok_len +Date: Thu, 31 Jul 2014 22:09:52 -0400 +Message-Id: <1406859003-11561-3-git-send-email-amdragon@mit.edu> +X-Mailer: git-send-email 2.0.0 +In-Reply-To: <1406859003-11561-1-git-send-email-amdragon@mit.edu> +References: <1406859003-11561-1-git-send-email-amdragon@mit.edu> +X-Brightmail-Tracker: + H4sIAAAAAAAAA+NgFtrNIsWRmVeSWpSXmKPExsUixCmqrMv0/VawwZfZPBar5/JYXL85k9mB + yWPnrLvsHs9W3WIOYIrisklJzcksSy3St0vgyrj+tqjgFXfFjCllDYy7OLsYOTkkBEwk5n9b + zgJhi0lcuLeerYuRi0NIYDaTxKT7exkhnI2MEhevNLNCOHeYJOZe7GGGcOYySryf95YJpJ9N + QENi2/7ljCC2iIC0xM67s1lBbGYBR4nP+xexgdjCAtYSq3tWgdWzCKhKnP2/FKyGV8BBYuL8 + Y4wQd8hJNNz4BFbPCdT7/98CsBohoJrW01uZJzDyL2BkWMUom5JbpZubmJlTnJqsW5ycmJeX + WqRrqpebWaKXmlK6iREURuwuSjsYfx5UOsQowMGoxMPrEHorWIg1say4MvcQoyQHk5Ior81H + oBBfUn5KZUZicUZ8UWlOavEhRgkOZiUR3pcfgHK8KYmVValF+TApaQ4WJXHet9ZWwUIC6Ykl + qdmpqQWpRTBZGQ4OJQneM1+BGgWLUtNTK9Iyc0oQ0kwcnCDDeYCGXwOp4S0uSMwtzkyHyJ9i + VJQS590DkhAASWSU5sH1wuL8FaM40CvCvA9BqniAKQKu+xXQYCagwc9vXQcZXJKIkJJqYGST + vlzRWOjmlCYjuPag+ITdl/573LvlI7mYY868Y2c3a2X+r/ASC+p5I6S2/2Hp7KvCN0+GRTXM + CTukc+2kuZrJtE1uqknL72Zrrxdp/RNubNzwoyJSw/L3+9aTB3VC1ikHXzwt+jr/8FqFc+t8 + ew1+JUg9PFFQZzV9l9QRlofBzQsC38uziyixFGckGmoxFxUnAgB4UsRrzgIAAA== +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: Fri, 01 Aug 2014 02:10:17 -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 +