likle / cwalk

Path library for C/C++. Cross-Platform for Linux, FreeBSD, Windows and MacOS. Supports UNIX and Windows path styles on those platforms.
https://likle.github.io/cwalk/
MIT License
250 stars 39 forks source link

incorrect basename #33

Closed freevryheid closed 1 year ago

freevryheid commented 1 year ago

Thanks for the library, got a question:

Perhaps I'm misunderstanding the concept of basename - the following returns a basename of 'my' with length 2 - I was expecting a null string with length 0.

#include <cwalk.h>
#include <stdio.h>
#include <stddef.h>
#include <stdlib.h>

int main(int argc, char *argv[])
{
  const·char·*basename;
  size_t length;
  cwk_path_set_style(CWK_STYLE_UNIX);  
  cwk_path_get_basename("/my/", &basename, &length);
  printf("The basename is: '%.*s'", length, basename);
  return EXIT_SUCCESS;
}
likle commented 1 year ago

Hi @freevryheid

Thanks for asking. The basename is the last segment of the path. Maybe you are looking for cwk_path_get_dirname instead?

freevryheid commented 1 year ago

Got it - thanks!