From: David Bremner Date: Mon, 27 Jan 2014 14:12:12 +0000 (+2000) Subject: [PATCH] compat: add canonicalize_file_name X-Git-Url: http://git.tremily.us/?a=commitdiff_plain;h=ec67ee02f1008bd7a927d4acdb2d5876c8f5b0bc;p=notmuch-archives.git [PATCH] compat: add canonicalize_file_name --- diff --git a/bb/ec268bebdc0fc1d0b6160017f3ce3c5cde4ea6 b/bb/ec268bebdc0fc1d0b6160017f3ce3c5cde4ea6 new file mode 100644 index 000000000..b78c7ee90 --- /dev/null +++ b/bb/ec268bebdc0fc1d0b6160017f3ce3c5cde4ea6 @@ -0,0 +1,188 @@ +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 C276C431FBD + for ; Mon, 27 Jan 2014 06:12:37 -0800 (PST) +X-Virus-Scanned: Debian amavisd-new at olra.theworths.org +X-Spam-Flag: NO +X-Spam-Score: 0 +X-Spam-Level: +X-Spam-Status: No, score=0 tagged_above=-999 required=5 tests=[none] + 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 dRa8c9ENhinp for ; + Mon, 27 Jan 2014 06:12:31 -0800 (PST) +Received: from yantan.tethera.net (yantan.tethera.net [199.188.72.155]) + (using TLSv1 with cipher DHE-RSA-AES128-SHA (128/128 bits)) + (No client certificate requested) + by olra.theworths.org (Postfix) with ESMTPS id E1301431FBF + for ; Mon, 27 Jan 2014 06:12:29 -0800 (PST) +Received: from remotemail by yantan.tethera.net with local (Exim 4.80) + (envelope-from ) + id 1W7mvL-00060d-Bb; Mon, 27 Jan 2014 10:12:27 -0400 +Received: (nullmailer pid 7908 invoked by uid 1000); Mon, 27 Jan 2014 + 14:12:23 -0000 +From: David Bremner +To: notmuch@notmuchmail.org +Subject: [PATCH] compat: add canonicalize_file_name +Date: Mon, 27 Jan 2014 10:12:12 -0400 +Message-Id: <1390831932-7865-1-git-send-email-david@tethera.net> +X-Mailer: git-send-email 1.8.5.2 +In-Reply-To: <8761p6n0wc.fsf@zancas.localnet> +References: <8761p6n0wc.fsf@zancas.localnet> +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: Mon, 27 Jan 2014 14:12:37 -0000 + +the POSIX 2008 behaviour of realpath is not available everywhere so we +provide a simple wrapper function. We use (and provide) the gnu +extension canonicalize_file_name to make it cleaner to test for the +feature we need; otherwise we have to rely on realpath segfaulting if +the second argument is null. +--- + compat/Makefile.local | 4 ++++ + compat/canonicalize_file_name.c | 18 ++++++++++++++++++ + compat/compat.h | 8 ++++++++ + compat/have_canonicalize_file_name.c | 10 ++++++++++ + configure | 16 ++++++++++++++++ + notmuch-config.c | 2 +- + 6 files changed, 57 insertions(+), 1 deletion(-) + create mode 100644 compat/canonicalize_file_name.c + create mode 100644 compat/have_canonicalize_file_name.c + +diff --git a/compat/Makefile.local b/compat/Makefile.local +index b0d5417..bcb9f0e 100644 +--- a/compat/Makefile.local ++++ b/compat/Makefile.local +@@ -5,6 +5,10 @@ extra_cflags += -I$(srcdir)/$(dir) + + notmuch_compat_srcs := + ++ifneq ($(HAVE_CANONICALIZE_FILE_NAME),1) ++notmuch_compat_srcs += $(dir)/canonicalize_file_name.c ++endif ++ + ifneq ($(HAVE_GETLINE),1) + notmuch_compat_srcs += $(dir)/getline.c $(dir)/getdelim.c + endif +diff --git a/compat/canonicalize_file_name.c b/compat/canonicalize_file_name.c +new file mode 100644 +index 0000000..e92c0f6 +--- /dev/null ++++ b/compat/canonicalize_file_name.c +@@ -0,0 +1,18 @@ ++#include "compat.h" ++#include ++#undef _GNU_SOURCE ++#include ++ ++char * ++canonicalize_file_name (const char * path) ++{ ++#ifdef PATH_MAX ++ char *resolved_path = malloc (PATH_MAX+1); ++ if (resolved_path == NULL) ++ return NULL; ++ ++ return realpath (path, resolved_path); ++#else ++#error undefined PATH_MAX _and_ missing canonicalize_file_name not supported ++#endif ++} +diff --git a/compat/compat.h b/compat/compat.h +index 5a402d5..634d505 100644 +--- a/compat/compat.h ++++ b/compat/compat.h +@@ -37,6 +37,14 @@ extern "C" { + #define _POSIX_PTHREAD_SEMANTICS 1 + #endif + ++#if !HAVE_CANONICALIZE_FILE_NAME ++/* we only call this function from C, and this makes testing easier */ ++#ifndef __cplusplus ++char * ++canonicalize_file_name (const char *path); ++#endif ++#endif ++ + #if !HAVE_GETLINE + #include + #include +diff --git a/compat/have_canonicalize_file_name.c b/compat/have_canonicalize_file_name.c +new file mode 100644 +index 0000000..24c848e +--- /dev/null ++++ b/compat/have_canonicalize_file_name.c +@@ -0,0 +1,10 @@ ++#define _GNU_SOURCE ++#include ++ ++int main() ++{ ++ char *found; ++ char *string; ++ ++ found = canonicalize_file_name (string); ++} +diff --git a/configure b/configure +index 13b6062..5b7c941 100755 +--- a/configure ++++ b/configure +@@ -526,6 +526,18 @@ EOF + exit 1 + fi + ++printf "Checking for canonicalize_file_name... " ++if ${CC} -o compat/have_canonicalize_file_name "$srcdir"/compat/have_canonicalize_file_name.c > /dev/null 2>&1 ++then ++ printf "Yes.\n" ++ have_canonicalize_file_name=1 ++else ++ printf "No (will use our own instead).\n" ++ have_canonicalize_file_name=0 ++fi ++rm -f compat/have_canonicalize_file_name ++ ++ + printf "Checking for getline... " + if ${CC} -o compat/have_getline "$srcdir"/compat/have_getline.c > /dev/null 2>&1 + then +@@ -751,6 +763,10 @@ zsh_completion_dir = ${ZSHCOMLETIONDIR:=\$(prefix)/share/zsh/functions/Completio + + # Whether the getline function is available (if not, then notmuch will + # build its own version) ++HAVE_CANONICALIZE_FILE_NAME = ${have_canonicalize_file_name} ++ ++# Whether the getline function is available (if not, then notmuch will ++# build its own version) + HAVE_GETLINE = ${have_getline} + + # Whether the strcasestr function is available (if not, then notmuch will +diff --git a/notmuch-config.c b/notmuch-config.c +index 8d28653..4886d36 100644 +--- a/notmuch-config.c ++++ b/notmuch-config.c +@@ -454,7 +454,7 @@ notmuch_config_save (notmuch_config_t *config) + } + + /* Try not to overwrite symlinks. */ +- filename = realpath (config->filename, NULL); ++ filename = canonicalize_file_name (config->filename); + if (! filename) { + if (errno == ENOENT) { + filename = strdup (config->filename); +-- +1.8.5.2 +