mirror of
https://git.notmuchmail.org/git/notmuch
synced 2024-11-23 11:28:13 +01:00
441a327051
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>
27 lines
528 B
C
27 lines
528 B
C
/*
|
|
* 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
|
|
}
|