On Fri, Aug 01, 2025 at 02:56:11PM -0700, Stephen Hemminger wrote:
> On Thu, 31 Jul 2025 16:00:38 +0000
> Bruce Richardson <bruce.richard...@intel.com> wrote:
> 
> > There is no standard, cross-platform function to get the basename of a
> > file path across all the supported DPDK platforms, Linux, BSD and
> > Windows. Both Linux and BSD have a "basename" function in standard
> > library, except:
> > * Linux has two different basename functions, a POSIX version (which may
> >   or may not modify args), and a GNU one which is guaranteed *not* to
> >   modify the input arg and returns pointer to internal storage.
> > * FreeBSD has just the one basename function, but, to be different, it is
> >   guaranteed *always* to modify the argument and re-use it for output.
> > * Windows just doesn't have a basename function, but provides _split_path
> >   as a similar function, but with many differences over basename, e.g.
> >   splitting off extension, returning empty basename if path ends in "/"
> >   etc. etc.
> > 
> > Therefore, rather than just trying to implement basename for windows,
> > which opens the question as to whether to emulate GNU and *never* modify
> > arg, or emulate BSD and *always* modify arg, this patchset introduces
> > "rte_basename" which should have defined behaviour on all platforms. The
> > patch also introduces a set of test cases to confirm consistent behaviour
> > on all platforms too.
> > 
> > The behaviour is as in doxygen docs. Essentially:
> > - does not modify input path buffer
> > - returns output in a separate output buffer
> > - uses snprintf and strlcpy style return value to indicate truncation
> > 
> > Signed-off-by: Bruce Richardson <bruce.richard...@intel.com>
> 
> What about existing uses of basename()
> 
> 0 main.c                  main                       553 char *token = 
> strtok(basename(rst_path),
>                                                          ".");
> 1 process.h               get_current_prefix         220 snprintf(prefix, 
> size, "%s",
>                                                          
> basename(dirname(buf)));
> 2 mlx5_common_auxiliary.c mlx5_auxiliary_get_pci_str  85 base = 
> basename(sysfs_pci);
> 3 idxd_bus.c              is_for_this_process_use    271 prefix = 
> basename(runtime_dir);
> 4 bnxt_tf_pmd_shim.c      ulp_pmd_get_mac_by_pci     156 intf_name = 
> basename(gres.gl_pathv[0]);
> 5 eal_common_proc.c       rte_mp_channel_init        628 strlcpy(mp_filter, 
> basename(path),
>

I wasn't planning on updating existing uses unless necessary, but I'll take
a look.

/Bruce

Reply via email to