arkq / bluez-alsa

Bluetooth Audio ALSA Backend
MIT License
856 stars 188 forks source link

Use basename implementation from glib-2.0 #726

Closed kraj closed 1 month ago

kraj commented 1 month ago

This is portable across various platforms and system C libraries e.g. basename differs between glibc and musl, where glibc provides a GNU implementation and POSIX version, and musl provides posix version only and Newer version of musl have removed prototype for basename in string.h [1] which caused build failures with gcc-14 on musl systems.

g_path_get_basename() is implemented in glib-2.0 and is portable across these systems. It allocates a new string for the returned value which should be free'd by user, however, all our usecases here are in main() functions, so technically we are not going to leak any memory.

[1] https://git.musl-libc.org/cgit/musl/commit/?id=725e17ed6dff4d0cd22487bb64470881e86a92e7

arkq commented 1 month ago

Could you please verify whether simple solution like that will work: https://github.com/arkq/bluez-alsa/tree/basename ?

If possible I would like to avoid pulling in glib-2.0 dependency on bluealsa clients.

kraj commented 1 month ago

Could you please verify whether simple solution like that will work: https://github.com/arkq/bluez-alsa/tree/basename ?

If possible I would like to avoid pulling in glib-2.0 dependency on bluealsa clients.

yes that works too, although posix basename does not guarantee that input string will be unmodified. Thats the reason why I was trying to use something thats compatible with GNU basename implementation because unknowingly lot of software on linux assumes glibc and hence GNU implementation.

arkq commented 1 month ago

although posix basename does not guarantee that input string will be unmodified

With the bluez-alsa usage of basename it's guaranteed that the argument will not be modified.

Many thanks for reporting the issue!