Open madebr opened 1 year ago
Yeah, that sounds reasonable.
@madebr, did you want to take a pass on this?
Sure. Looks like posix basename and dirname do in-string modifications, and return a pointer pointing somewhere in the input string. I suppose SDL should model the same behavior, and not return a newly allocated string?
Maybe instead we want SDL_splitpath(const char *path, char **dir, char **base); SDL_free(dir); SDL_free(base);
@icculus, what do you think?
What's the use case for these in SDL?
basename is used in testapp.c of SDL_ttf for building the filename when saving to a bmp. In https://github.com/libsdl-org/SDL_ttf/pull/289, I added a poor man's non-compliant basename implementation, which made me wondering whether a proper implementation would be useful for SDL3.
Huh, it's more complicated than I thought it would be:
My plan was to implement https://pubs.opengroup.org/onlinepubs/9699919799/utilities/dirname.html and https://pubs.opengroup.org/onlinepubs/9699919799/utilities/basename.html
Here are some free test cases: https://pubs.opengroup.org/onlinepubs/9699919799/functions/basename.html#tag_16_32_06_02
And do the necessary to support windows dos and UNC paths.
My plan was to implement https://pubs.opengroup.org/onlinepubs/9699919799/utilities/dirname.html and https://pubs.opengroup.org/onlinepubs/9699919799/utilities/basename.html
Here are some free test cases: https://pubs.opengroup.org/onlinepubs/9699919799/functions/basename.html#tag_16_32_06_02
And do the necessary to support windows dos and UNC paths.
Okay, sounds good.
@madebr, just double checking, did you want this in for the SDL 3.0 ABI milestone?
Getting into 3.0 (3.2 release) is not absolutely needed. I prefer a well-defined, well-tested API.
I think these functions could be useful, with an implementation close to the posix standard.
It should probably deviate by also treating the Windows backslash as a path separator. The SDL implementation should probably not modify its arguments and return a new allocated buffer, or an optional buffer passed as input.
If the SDL implementation differs from the posix standard, this will also mean basename and dirname from the C library will never be used, even when configuring SDL with
-DSDL_LIBC=ON
.