From: Austin Clements Date: Sun, 27 Jul 2014 03:52:42 +0000 (+2000) Subject: [PATCH 03/14] util: Const version of strtok_len X-Git-Url: http://git.tremily.us/?a=commitdiff_plain;h=4c1ac9993c622a8ce89aa088ff856c97d11f6a11;p=notmuch-archives.git [PATCH 03/14] util: Const version of strtok_len --- diff --git a/f8/f7894a387b4449868219214372c7a144ee975c b/f8/f7894a387b4449868219214372c7a144ee975c new file mode 100644 index 000000000..0657aecb2 --- /dev/null +++ b/f8/f7894a387b4449868219214372c7a144ee975c @@ -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 A5532429E43 + for ; Sat, 26 Jul 2014 20:53:41 -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 Ifjy6GaXZucE for ; + Sat, 26 Jul 2014 20:53:36 -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 7340A431FD4 + for ; Sat, 26 Jul 2014 20:53:09 -0700 (PDT) +X-AuditID: 12074422-f79be6d000007518-50-53d477a27def +Received: from mailhub-auth-3.mit.edu ( [18.9.21.43]) + (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 ED.39.29976.3A774D35; Sat, 26 Jul 2014 23:53:07 -0400 (EDT) +Received: from outgoing.mit.edu (outgoing-auth-1.mit.edu [18.9.28.11]) + by mailhub-auth-3.mit.edu (8.13.8/8.9.2) with ESMTP id s6R3r54F004155; + Sat, 26 Jul 2014 23:53:06 -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 s6R3r0L0016392 + (version=TLSv1/SSLv3 cipher=AES256-SHA bits=256 verify=NOT); + Sat, 26 Jul 2014 23:53:05 -0400 +Received: from amthrax by drake.dyndns.org with local (Exim 4.77) + (envelope-from ) + id 1XBFW8-00051B-7q; Sat, 26 Jul 2014 23:53:00 -0400 +From: Austin Clements +To: notmuch@notmuchmail.org +Subject: [PATCH 03/14] util: Const version of strtok_len +Date: Sat, 26 Jul 2014 23:52:42 -0400 +Message-Id: <1406433173-19169-4-git-send-email-amdragon@mit.edu> +X-Mailer: git-send-email 2.0.0 +In-Reply-To: <1406433173-19169-1-git-send-email-amdragon@mit.edu> +References: <1406433173-19169-1-git-send-email-amdragon@mit.edu> +X-Brightmail-Tracker: + H4sIAAAAAAAAA+NgFlrPIsWRmVeSWpSXmKPExsUixCmqrbu4/EqwwacFLBbXb85kdmD0eLbq + FnMAYxSXTUpqTmZZapG+XQJXxvW3RQWvuCtmTClrYNzF2cXIySEhYCKxYst1NghbTOLCvfVA + NheHkMBsJok5p04xQjgbGSXOXjvGCuHcYZLonNDCDOHMZZT4cekCI0g/m4CGxLb9y8FsEQFp + iZ13ZwN1cHAwC6hJ/OlSATGFBSwk3iwsBalgEVCVuPinlx3E5hVwkPjzpZcR4go5iYYbn8Au + 4hRwlDj+7AQbSKsQUM2tS4kTGPkXMDKsYpRNya3SzU3MzClOTdYtTk7My0st0jXVy80s0UtN + Kd3ECAoXdhelHYw/DyodYhTgYFTi4c1guxIsxJpYVlyZe4hRkoNJSZR3vxlQiC8pP6UyI7E4 + I76oNCe1+BCjBAezkgivUDFQjjclsbIqtSgfJiXNwaIkzvvW2ipYSCA9sSQ1OzW1ILUIJivD + waEkwSsFjAshwaLU9NSKtMycEoQ0EwcnyHAeoOEbSkGGFxck5hZnpkPkTzEqSonz/gJJCIAk + Mkrz4Hph8fyKURzoFWFe1jKgKh5gKoDrfgU0mAloMIv/ZZDBJYkIKakGRlGOjw9SHour7bDI + W79g/ZfCLKFFZ41OMOf8vnbJtarzUoibf/fjh6a3Xq51K3+4/tin1IfcomwMnenf3OSP3RBb + 3PhiyYbLSe1+39fKlon87vwgU73x9uKfP7ku/ZCTYcu7P9vmT87zR67r2d5Od90S7Cr9UDtg + cZwCo8Is1wdzbjOzmMWwRSixFGckGmoxFxUnAgBGQRtJwgIAAA== +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: Sun, 27 Jul 2014 03:53:41 -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 +