From b0457835cf383281e41fe5d6bf60a7376ec2dad3 Mon Sep 17 00:00:00 2001 From: Jani Nikula Date: Fri, 25 Sep 2015 19:48:19 +0300 Subject: [PATCH] [PATCH 6/9 v3 part 1/2] util: add strcmp_null, a strcmp that handles NULL parameters --- 8d/9f14f8025226d33cbdd7b8a5305bf5d29b3d15 | 117 ++++++++++++++++++++++ 1 file changed, 117 insertions(+) create mode 100644 8d/9f14f8025226d33cbdd7b8a5305bf5d29b3d15 diff --git a/8d/9f14f8025226d33cbdd7b8a5305bf5d29b3d15 b/8d/9f14f8025226d33cbdd7b8a5305bf5d29b3d15 new file mode 100644 index 000000000..b4c6c6873 --- /dev/null +++ b/8d/9f14f8025226d33cbdd7b8a5305bf5d29b3d15 @@ -0,0 +1,117 @@ +Return-Path: +X-Original-To: notmuch@notmuchmail.org +Delivered-To: notmuch@notmuchmail.org +Received: from localhost (localhost [127.0.0.1]) + by arlo.cworth.org (Postfix) with ESMTP id 8B3796DE0C3A + for ; Fri, 25 Sep 2015 09:48:43 -0700 (PDT) +X-Virus-Scanned: Debian amavisd-new at cworth.org +X-Spam-Flag: NO +X-Spam-Score: -0.513 +X-Spam-Level: +X-Spam-Status: No, score=-0.513 tagged_above=-999 required=5 tests=[AWL=0.207, + RCVD_IN_DNSWL_LOW=-0.7, RCVD_IN_MSPIKE_H3=-0.01, RCVD_IN_MSPIKE_WL=-0.01] + autolearn=disabled +Received: from arlo.cworth.org ([127.0.0.1]) + by localhost (arlo.cworth.org [127.0.0.1]) (amavisd-new, port 10024) + with ESMTP id I0Zcjhcw11WQ for ; + Fri, 25 Sep 2015 09:48:41 -0700 (PDT) +Received: from mail-wi0-f173.google.com (mail-wi0-f173.google.com + [209.85.212.173]) + by arlo.cworth.org (Postfix) with ESMTPS id 5D2736DE025E + for ; Fri, 25 Sep 2015 09:48:41 -0700 (PDT) +Received: by wiclk2 with SMTP id lk2so29885597wic.0 + for ; Fri, 25 Sep 2015 09:48:39 -0700 (PDT) +X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; + d=1e100.net; s=20130820; + h=x-gm-message-state:from:to:subject:date:message-id:in-reply-to + :references; + bh=1NDdt0CrFsdCyf6Od/6ni1a1RTGcud64elm99YDXTCM=; + b=gFSvl17MwDK2yRAJ40EIcm9goPL+/wrbERvNarJnN9cf0CM+v152ud8v0shVfe0H9C + 0rnaAQEimh+SowLGrhZySNx4Sjbnhf0tSg1MSYmmH2UF5SmHwAXlCGkdroBUh1QpsCT6 + JnSYHNZW43xoSxH9ydQbbAjPrMENk2KPxkBvuK7gsB3NuY9HK8DzxqRPSl6BAsIpPkTO + VA3HvEcpVoa1KKNvTS0ZZ3nUvnfq+iteiRc+JaIgfVvTr0fROiUgQaN99+1AeBsXc0z9 + q6OP2xtRzZXjRaZyBD6Y/6vzeOtCOJlfaIkSNxDbKQ7KtgMj4KUOCuBw4sHyr1mTrdK4 + ZL1w== +X-Gm-Message-State: + ALoCoQlPCnJ2QCVYbdGk31ZlJLHzEI1Iay1FU2vi5obHVRmvbMRP30rS5xTt1vEhqitdoEZ0NHHC +X-Received: by 10.194.115.199 with SMTP id jq7mr7964818wjb.82.1443199719657; + Fri, 25 Sep 2015 09:48:39 -0700 (PDT) +Received: from localhost (mobile-access-bcee63-221.dhcp.inet.fi. + [188.238.99.221]) + by smtp.gmail.com with ESMTPSA id x7sm4081902wia.10.2015.09.25.09.48.38 + (version=TLSv1/SSLv3 cipher=OTHER); + Fri, 25 Sep 2015 09:48:38 -0700 (PDT) +From: Jani Nikula +To: David Bremner , Jani Nikula , + notmuch@notmuchmail.org +Subject: [PATCH 6/9 v3 part 1/2] util: add strcmp_null, + a strcmp that handles NULL parameters +Date: Fri, 25 Sep 2015 19:48:19 +0300 +Message-Id: <1443199700-16654-1-git-send-email-jani@nikula.org> +X-Mailer: git-send-email 2.1.4 +In-Reply-To: <878u7v2y3x.fsf@zancas.localnet> +References: <878u7v2y3x.fsf@zancas.localnet> +X-BeenThere: notmuch@notmuchmail.org +X-Mailman-Version: 2.1.18 +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, 25 Sep 2015 16:48:43 -0000 + +Add strcmp_null, a strcmp that handles NULL strings; in strcmp terms a +NULL string is considered to be less than a non-NULL string. +--- + util/string-util.c | 13 +++++++++++++ + util/string-util.h | 5 +++++ + 2 files changed, 18 insertions(+) + +diff --git a/util/string-util.c b/util/string-util.c +index 76c0b9025d0f..92af937f45ec 100644 +--- a/util/string-util.c ++++ b/util/string-util.c +@@ -223,6 +223,19 @@ parse_boolean_term (void *ctx, const char *str, + } + + int ++strcmp_null (const char *s1, const char *s2) ++{ ++ if (s1 && s2) ++ return strcmp (s1, s2); ++ else if (! s1 && ! s2) ++ return 0; ++ else if (s1) ++ return 1; /* s1 (non-NULL) is greater than s2 (NULL) */ ++ else ++ return -1; /* s1 (NULL) is less than s2 (non-NULL) */ ++} ++ ++int + strcase_equal (const void *a, const void *b) + { + return strcasecmp (a, b) == 0; +diff --git a/util/string-util.h b/util/string-util.h +index 80d24d1c1053..87917b8fd279 100644 +--- a/util/string-util.h ++++ b/util/string-util.h +@@ -64,6 +64,11 @@ int + parse_boolean_term (void *ctx, const char *str, + char **prefix_out, char **term_out); + ++/* strcmp that handles NULL strings; in strcmp terms a NULL string is ++ * considered to be less than a non-NULL string. ++ */ ++int strcmp_null (const char *s1, const char *s2); ++ + /* GLib GEqualFunc compatible strcasecmp wrapper */ + int strcase_equal (const void *a, const void *b); + +-- +2.1.4 + -- 2.26.2