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

Bad scandir prototype #16

Closed
JayFoxRox opened this issue May 8, 2018 · 2 comments
Closed

Bad scandir prototype #16

JayFoxRox opened this issue May 8, 2018 · 2 comments

Comments

@JayFoxRox
Copy link

JayFoxRox commented May 8, 2018

My installation of Linux has the following prototype for scandir:

extern int scandir (const char *__restrict __dir,
		    struct dirent ***__restrict __namelist,
		    int (*__selector) (const struct dirent *),
		    int (*__cmp) (const struct dirent **,
				  const struct dirent **))

The difference between void (your dirent) and dirent (Linux) pointers for compare causes problems in our project. Depending on the enabled warnings, you can't even pass alphasort (which uses dirent pointers in your code) to scandir. A Visual Studio warning recommends to cast it, and that includes the __cdecl convention - a macro which does not exist on other compilers.
So people patch this code for Visual Studio and by adding the cast, they break other platforms.

This cast should not be necessary in the first place - why is the prototype like this?
Can the prototype in your dirent.h be changed to use dirent pointers (on this repo)?

@tronkko
Copy link
Owner

tronkko commented May 8, 2018

Thanks for your thorough error report! The prototype is truly different from Linux and cast only makes matters worse!

Could you please try the version 1.23.2 at https://github.com/tronkko/dirent/releases/tag/1.23.2 to see it fixes the issue? The same code is also on master branch.

@JayFoxRox
Copy link
Author

Yes, this seems to work fine for us.
Thanks for the quickfix!

(Also: brave move to tag unverified changes for a release)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants