ECC-539: Reuse the codes_resolve_path function

This commit is contained in:
Shahram Najm 2021-01-25 14:47:40 +00:00
parent d9cd84512b
commit e1a2cbb13c
3 changed files with 8 additions and 7 deletions

View File

@ -961,7 +961,7 @@ long grib_get_api_version(void);
void grib_print_api_version(FILE* out);
const char* grib_get_package_name(void);
grib_context* grib_context_get_default(void);
char* codes_resolve_path(grib_context* c, char* path);
char* codes_resolve_path(grib_context* c, const char* path);
char* grib_context_full_defs_path(grib_context* c, const char* basename);
char* grib_samples_path(const grib_context* c);
char* grib_definition_path(const grib_context* c);

View File

@ -605,7 +605,7 @@ grib_context* grib_context_new(grib_context* parent)
/* GRIB-235: Resolve path to expand symbolic links etc */
/* Note: return value is allocated. Client has to free */
char* codes_resolve_path(grib_context* c, char* path)
char* codes_resolve_path(grib_context* c, const char* path)
{
char* result = NULL;
#if defined(ECCODES_HAVE_REALPATH)

View File

@ -1289,14 +1289,15 @@ void grib_print_full_statistics(grib_runtime_options* options)
options->filter_handle_count, options->handle_count, options->file_count);
}
static int filenames_equal(const char * f1, const char * f2)
static int filenames_equal(const char* f1, const char* f2)
{
char resolved1[8192] = {0,};
char resolved2[8192] = {0,};
int eq = 0;
realpath(f1, resolved1);
realpath(f2, resolved2);
grib_context* c = grib_context_get_default();
char* resolved1 = codes_resolve_path(c, f1);
char* resolved2 = codes_resolve_path(c, f2);
eq = (strcmp(resolved1, resolved2)==0);
grib_context_free(c, resolved1);
grib_context_free(c, resolved2);
return eq;
}