diff options
| author | Đoàn Trần Công Danh <congdanhqx@gmail.com> | 2021-04-24 08:05:37 +0700 |
|---|---|---|
| committer | David Bremner <david@tethera.net> | 2021-04-24 08:07:00 -0300 |
| commit | 441a327051f5357175029709030a0ee51131379d (patch) | |
| tree | fcb47d140f922b4036f0f763e25ede21b0783c3c /util | |
| parent | 62f03b6ab86bdc378198f9c1a86cb51ead289961 (diff) | |
compat: rename {,notmuch_}canonicalize_file_name
When compat canonicalize_file_name was introduced, it was limited to
C code only because it was used by C code only during that time.
>From 5ec6fd4d, (lib/open: check for split configuration when creating
database., 2021-02-16), lib/open.cc, which is C++, relies on the
existent of canonicalize_file_name.
However, we can't blindly enable canonicalize_file_name for C++ code,
because different implementation has different additional signature for
C++ and users can arbitrarily add -DHAVE_CANONICALIZE_FILE_NAME=0 to
{C,CXX}FLAGS.
Let's move our implementation into a util library.
Helped-by: Tomi Ollila <tomi.ollila@iki.fi>
Signed-off-by: Đoàn Trần Công Danh <congdanhqx@gmail.com>
Diffstat (limited to 'util')
| -rw-r--r-- | util/Makefile.local | 2 | ||||
| -rw-r--r-- | util/path-util.c | 27 | ||||
| -rw-r--r-- | util/path-util.h | 19 |
3 files changed, 47 insertions, 1 deletions
diff --git a/util/Makefile.local b/util/Makefile.local index 7ef029a5..8a0b9bc3 100644 --- a/util/Makefile.local +++ b/util/Makefile.local @@ -6,7 +6,7 @@ extra_cflags += -I$(srcdir)/$(dir) libnotmuch_util_c_srcs := $(dir)/xutil.c $(dir)/error_util.c $(dir)/hex-escape.c \ $(dir)/string-util.c $(dir)/talloc-extra.c $(dir)/zlib-extra.c \ $(dir)/util.c $(dir)/gmime-extra.c $(dir)/crypto.c \ - $(dir)/repair.c \ + $(dir)/repair.c $(dir)/path-util.c \ $(dir)/unicode-util.c libnotmuch_util_modules := $(libnotmuch_util_c_srcs:.c=.o) diff --git a/util/path-util.c b/util/path-util.c new file mode 100644 index 00000000..3267a967 --- /dev/null +++ b/util/path-util.c @@ -0,0 +1,27 @@ +/* + * SPDX-License-Identifier: GPL-3.0-or-later + */ + +#define _GNU_SOURCE + +#include "path-util.h" + +#include <limits.h> +#include <stdlib.h> + + +char * +notmuch_canonicalize_file_name (const char *path) +{ +#if HAVE_CANONICALIZE_FILE_NAME + return canonicalize_file_name (path); +#elif defined(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/util/path-util.h b/util/path-util.h new file mode 100644 index 00000000..ac85f696 --- /dev/null +++ b/util/path-util.h @@ -0,0 +1,19 @@ +/* + * SPDX-License-Identifier: GPL-3.0-or-later + */ + +#ifndef NOTMUCH_UTIL_PATH_UTIL_H_ +#define NOTMUCH_UTIL_PATH_UTIL_H_ + +#ifdef __cplusplus +extern "C" { +#endif + +char * +notmuch_canonicalize_file_name (const char *path); + +#ifdef __cplusplus +} +#endif + +#endif /* NOTMUCH_UTIL_PATH_UTIL_H_ */ |
