* [PATCH 0/3] Use cross-platform rte_basename function
@ 2025-08-06 13:38 Bruce Richardson
2025-08-06 13:38 ` [PATCH 1/3] app: use cross-platform basename function Bruce Richardson
` (2 more replies)
0 siblings, 3 replies; 4+ messages in thread
From: Bruce Richardson @ 2025-08-06 13:38 UTC (permalink / raw)
To: dev; +Cc: Bruce Richardson
To enable more of DPDK to be buildable and usable on Windows, common
code should use rte_basename in place of regular basename() function.
Therefore update EAL common code and code in apps to use that new
rte_basename function.
In some cases rte_basename is easier to use than basename, since it
outputs to a new buffer, so also update idxd driver to use
rte_basename, since it simplifies the code, even though that code
does not need to work on non-Linux systems.
Depends-on: series-35845 ("improve cmdline file handling in testpmd")
Bruce Richardson (3):
app: use cross-platform basename function
eal: use common basename function
dma/idxd: use DPDK basename function
app/test-dma-perf/main.c | 6 +++---
app/test/process.h | 2 +-
drivers/dma/idxd/idxd_bus.c | 12 ++++--------
lib/eal/common/eal_common_proc.c | 5 +----
4 files changed, 9 insertions(+), 16 deletions(-)
--
2.48.1
^ permalink raw reply [flat|nested] 4+ messages in thread
* [PATCH 1/3] app: use cross-platform basename function
2025-08-06 13:38 [PATCH 0/3] Use cross-platform rte_basename function Bruce Richardson
@ 2025-08-06 13:38 ` Bruce Richardson
2025-08-06 13:38 ` [PATCH 2/3] eal: use common " Bruce Richardson
2025-08-06 13:38 ` [PATCH 3/3] dma/idxd: use DPDK " Bruce Richardson
2 siblings, 0 replies; 4+ messages in thread
From: Bruce Richardson @ 2025-08-06 13:38 UTC (permalink / raw)
To: dev; +Cc: Bruce Richardson
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@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
^ permalink raw reply [flat|nested] 4+ messages in thread
* [PATCH 2/3] eal: use common basename function
2025-08-06 13:38 [PATCH 0/3] Use cross-platform rte_basename function Bruce Richardson
2025-08-06 13:38 ` [PATCH 1/3] app: use cross-platform basename function Bruce Richardson
@ 2025-08-06 13:38 ` Bruce Richardson
2025-08-06 13:38 ` [PATCH 3/3] dma/idxd: use DPDK " Bruce Richardson
2 siblings, 0 replies; 4+ messages in thread
From: Bruce Richardson @ 2025-08-06 13:38 UTC (permalink / raw)
To: dev; +Cc: Bruce Richardson
Use the new "rte_basename" function which has common behaviour on all
supported platforms. As extra benefit, it removes the need for
recreating the socket path twice, since rte_basename guarantees not
to modify its argument.
Signed-off-by: Bruce Richardson <bruce.richardson@intel.com>
---
lib/eal/common/eal_common_proc.c | 5 +----
1 file changed, 1 insertion(+), 4 deletions(-)
diff --git a/lib/eal/common/eal_common_proc.c b/lib/eal/common/eal_common_proc.c
index 0dea787e38..62fd4ba88f 100644
--- a/lib/eal/common/eal_common_proc.c
+++ b/lib/eal/common/eal_common_proc.c
@@ -625,10 +625,7 @@ rte_mp_channel_init(void)
/* create filter path */
create_socket_path("*", path, sizeof(path));
- strlcpy(mp_filter, basename(path), sizeof(mp_filter));
-
- /* path may have been modified, so recreate it */
- create_socket_path("*", path, sizeof(path));
+ rte_basename(path, mp_filter, sizeof(mp_filter));
strlcpy(mp_dir_path, dirname(path), sizeof(mp_dir_path));
/* lock the directory */
--
2.48.1
^ permalink raw reply [flat|nested] 4+ messages in thread
* [PATCH 3/3] dma/idxd: use DPDK basename function
2025-08-06 13:38 [PATCH 0/3] Use cross-platform rte_basename function Bruce Richardson
2025-08-06 13:38 ` [PATCH 1/3] app: use cross-platform basename function Bruce Richardson
2025-08-06 13:38 ` [PATCH 2/3] eal: use common " Bruce Richardson
@ 2025-08-06 13:38 ` Bruce Richardson
2 siblings, 0 replies; 4+ messages in thread
From: Bruce Richardson @ 2025-08-06 13:38 UTC (permalink / raw)
To: dev; +Cc: Bruce Richardson
Even though the idxd_bus.c file is linux-only, we can simplify the code
through using rte_basename rather than just basename. Since rte_basename
does not modify its parameter, we can eliminate the strdup and free, and
since it also handles NULL sanely, we can remove an extra NULL check.
Signed-off-by: Bruce Richardson <bruce.richardson@intel.com>
---
drivers/dma/idxd/idxd_bus.c | 12 ++++--------
1 file changed, 4 insertions(+), 8 deletions(-)
diff --git a/drivers/dma/idxd/idxd_bus.c b/drivers/dma/idxd/idxd_bus.c
index ba8076715d..5ae42151e6 100644
--- a/drivers/dma/idxd/idxd_bus.c
+++ b/drivers/dma/idxd/idxd_bus.c
@@ -260,17 +260,14 @@ static int search_devargs(const char *name)
static int
is_for_this_process_use(struct rte_dsa_device *dev, const char *name)
{
- char *runtime_dir = strdup(rte_eal_get_runtime_dir());
+ char prefix[256];
int retval = 0;
- int prefixlen;
- char *prefix;
+ size_t prefixlen;
- if (runtime_dir == NULL)
+ prefixlen = rte_basename(rte_eal_get_runtime_dir(), prefix, sizeof(prefix));
+ if (prefixlen >= sizeof(prefix) || strcmp(prefix, ".") == 0)
return retval;
- prefix = basename(runtime_dir);
- prefixlen = strlen(prefix);
-
if (strncmp(name, "dpdk_", 5) == 0)
retval = 1;
if (strncmp(name, prefix, prefixlen) == 0 && name[prefixlen] == '_')
@@ -283,7 +280,6 @@ is_for_this_process_use(struct rte_dsa_device *dev, const char *name)
retval = !search_devargs(dev->device.name);
}
- free(runtime_dir);
return retval;
}
--
2.48.1
^ permalink raw reply [flat|nested] 4+ messages in thread
end of thread, other threads:[~2025-08-06 13:39 UTC | newest]
Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2025-08-06 13:38 [PATCH 0/3] Use cross-platform rte_basename function Bruce Richardson
2025-08-06 13:38 ` [PATCH 1/3] app: use cross-platform basename function Bruce Richardson
2025-08-06 13:38 ` [PATCH 2/3] eal: use common " Bruce Richardson
2025-08-06 13:38 ` [PATCH 3/3] dma/idxd: use DPDK " Bruce Richardson
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).