From 4a6fec9c6f7cf8704fc124b38277672eaec942dc Mon Sep 17 00:00:00 2001 From: Markus Neteler Date: Mon, 17 Jun 2024 00:33:04 +0200 Subject: [PATCH 1/2] lib/gis: lib/display, fixing slash to HOST_DIRSEP Fixes hardcoded slash to HOST_DIRSEP. Fixes #3296 --- lib/display/r_raster.c | 5 +++-- lib/gis/tempfile.c | 6 ++++-- 2 files changed, 7 insertions(+), 4 deletions(-) diff --git a/lib/display/r_raster.c b/lib/display/r_raster.c index 381fbf640e8..f73a0645204 100644 --- a/lib/display/r_raster.c +++ b/lib/display/r_raster.c @@ -92,6 +92,7 @@ int D_open_driver(void) if (!p && (m || c)) { char *cmd; char progname[GPATH_MAX]; + char sep[2] = {HOST_DIRSEP, '\0'}; cmd = G_recreate_command(); @@ -108,9 +109,9 @@ int D_open_driver(void) char element[GPATH_MAX]; G_temp_element(element); - strcat(element, "/"); + strcat(element, sep); strcat(element, "MONITORS"); - strcat(element, "/"); + strcat(element, sep); strcat(element, m); G_file_name(progname, element, "render.py", G_mapset()); } diff --git a/lib/gis/tempfile.c b/lib/gis/tempfile.c index 2c20c21cce0..8c51b853be3 100644 --- a/lib/gis/tempfile.c +++ b/lib/gis/tempfile.c @@ -159,11 +159,12 @@ void G_temp_element(char *element) void G__temp_element(char *element, int tmp) { const char *machine; + char sep[2] = {HOST_DIRSEP, '\0'}; strcpy(element, ".tmp"); machine = G__machine_name(); if (machine != NULL && *machine != 0) { - strcat(element, "/"); + strcat(element, sep); strcat(element, machine); } @@ -185,11 +186,12 @@ void G__temp_element(char *element, int tmp) void G__temp_element_basedir(char *element, const char *basedir) { const char *machine; + char sep[2] = {HOST_DIRSEP, '\0'}; strcpy(element, ".tmp"); machine = G__machine_name(); if (machine != NULL && *machine != 0) { - strcat(element, "/"); + strcat(element, sep); strcat(element, machine); } From 67494960ace29519dc069a423d7f1d5843638d93 Mon Sep 17 00:00:00 2001 From: Markus Neteler Date: Mon, 17 Jun 2024 16:24:54 +0200 Subject: [PATCH 2/2] change more occurences of '/' to HOST_DIRSEP --- lib/db/dbmi_driver/d_mkdir.c | 4 ++-- lib/gis/copy_dir.c | 2 +- lib/gis/mapset_msc.c | 6 +++--- lib/raster/gdal.c | 2 +- 4 files changed, 7 insertions(+), 7 deletions(-) diff --git a/lib/db/dbmi_driver/d_mkdir.c b/lib/db/dbmi_driver/d_mkdir.c index 4f41df7328c..2a0aefd69db 100644 --- a/lib/db/dbmi_driver/d_mkdir.c +++ b/lib/db/dbmi_driver/d_mkdir.c @@ -66,7 +66,7 @@ static int make_parent_dir(char *path, int mode) char *slash; int stat; - slash = rfind(path, '/'); + slash = rfind(path, HOST_DIRSEP); if (slash == NULL || slash == path) return DB_OK; /* no parent dir to make. return ok */ @@ -83,7 +83,7 @@ static int make_parent_dir(char *path, int mode) else { stat = DB_FAILED; } - *slash = '/'; /* put the slash back into the path */ + *slash = HOST_DIRSEP; /* put the slash back into the path */ return stat; } diff --git a/lib/gis/copy_dir.c b/lib/gis/copy_dir.c index 226e25a5a39..6662c2d6585 100644 --- a/lib/gis/copy_dir.c +++ b/lib/gis/copy_dir.c @@ -83,7 +83,7 @@ int G_recursive_copy(const char *src, const char *dst) if (G_lstat(dst, &sb) == 0 && S_ISDIR(sb.st_mode)) { char path[GPATH_MAX]; - const char *p = strrchr(src, '/'); + const char *p = strrchr(src, HOST_DIRSEP); /* src => dst/src */ sprintf(path, "%s/%s", dst, (p ? p + 1 : src)); diff --git a/lib/gis/mapset_msc.c b/lib/gis/mapset_msc.c index 8553ff3807d..71c77b0689c 100644 --- a/lib/gis/mapset_msc.c +++ b/lib/gis/mapset_msc.c @@ -197,14 +197,14 @@ int make_mapset_element_impl(const char *p_path, const char *p_element, p++; /* add trailing slash if missing */ --p; - if (*p++ != '/') { - *p++ = '/'; + if (*p++ != HOST_DIRSEP) { + *p++ = HOST_DIRSEP; *p = 0; } /* now append element, one directory at a time, to path */ while (1) { - if (*element == '/' || *element == 0) { + if (*element == HOST_DIRSEP || *element == 0) { *p = 0; char *msg = NULL; diff --git a/lib/raster/gdal.c b/lib/raster/gdal.c index a3bfce1b3b8..445698e622e 100644 --- a/lib/raster/gdal.c +++ b/lib/raster/gdal.c @@ -204,7 +204,7 @@ static void read_gdal_options(void) p = G_find_key_value("directory", key_val); if (!p) p = "gdal"; - if (*p == '/') { + if (*p == HOST_DIRSEP) { st->opts.dir = G_store(p); } else {