Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

libc: minimal: add qsort routine #31107

Closed
cfriedt opened this issue Jan 5, 2021 · 2 comments
Closed

libc: minimal: add qsort routine #31107

cfriedt opened this issue Jan 5, 2021 · 2 comments
Labels
Enhancement Changes/Updates/Additions to existing features

Comments

@cfriedt
Copy link
Member

cfriedt commented Jan 5, 2021

Is your enhancement proposal related to a problem? Please describe.
It would be nice if the minimal libc supported qsort() within the stdlib area.

Implementation it via qsort_s() (C11) would probably make sense.

Since it's a global / standard C symbol, it could be enabled by default, as the linker would discard it if unused.

Describe the solution you'd like
A simple implementation of qsort_s() and qsort() via the former.

It might also make sense to define qsort() in terms of C11 generics so that e.g. an 8-bit, 16-bit, 32-bit, or 64-bit optimized version could be used when appropriate, and a generic memcpy() version could be used for objects beyond the size of normal integers. If so, then there would likely need to be a caveat, that any elements would be required to be aligned to their natural boundaries, if there is not one already.

Describe alternatives you've considered
There is a BSD-licensed implementation available from NuttX. I'm currently using it in Greybus for Zephyr, although I think it would be fine to write a less cryptic version.

Additional context

@cfriedt cfriedt added the Enhancement Changes/Updates/Additions to existing features label Jan 5, 2021
@JonBruchim
Copy link

I've actually opened a PR about this.

#29804

@cfriedt
Copy link
Member Author

cfriedt commented Sep 29, 2021

duplicates #28896

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Enhancement Changes/Updates/Additions to existing features
Projects
None yet
Development

No branches or pull requests

2 participants