[PATCH 1/3] app: use cross-platform basename function

Bruce Richardson bruce.richardson at intel.com
Wed Aug 6 15:38:31 CEST 2025


Replace use of the Linux/BSD-only basename function with "rte_basename".
Since the DPDK basename function is guaranteed to do a copy into the
destination buffer of known length, we can sometimes simplify the code,
or make it safer, as part of this change.

Signed-off-by: Bruce Richardson <bruce.richardson at intel.com>
---
 app/test-dma-perf/main.c | 6 +++---
 app/test/process.h       | 2 +-
 2 files changed, 4 insertions(+), 4 deletions(-)

diff --git a/app/test-dma-perf/main.c b/app/test-dma-perf/main.c
index 0586b3e1d0..3ad66637e6 100644
--- a/app/test-dma-perf/main.c
+++ b/app/test-dma-perf/main.c
@@ -549,13 +549,13 @@ main(int argc, char *argv[])
 		return -1;
 	}
 	if (rst_path_ptr == NULL) {
-		strlcpy(rst_path, cfg_path_ptr, PATH_MAX);
-		char *token = strtok(basename(rst_path), ".");
+		rte_basename(cfg_path_ptr, rst_path, sizeof(rst_path));
+		char *token = strtok(rst_path, ".");
 		if (token == NULL) {
 			printf("Config file error.\n");
 			return -1;
 		}
-		strcat(token, "_result.csv");
+		strlcat(token, "_result.csv", sizeof(rst_path));
 		rst_path_ptr = rst_path;
 	}
 
diff --git a/app/test/process.h b/app/test/process.h
index 9fb2bf481c..0dba48aa18 100644
--- a/app/test/process.h
+++ b/app/test/process.h
@@ -217,7 +217,7 @@ get_current_prefix(char *prefix, int size)
 		return NULL;
 
 	/* get the prefix */
-	snprintf(prefix, size, "%s", basename(dirname(buf)));
+	rte_basename(dirname(buf), prefix, size);
 
 	return prefix;
 }
-- 
2.48.1



More information about the dev mailing list