-
-
Notifications
You must be signed in to change notification settings - Fork 3.1k
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
Build Error on Cygwin #2529
Comments
I just saw that this has already been reported in #2511. |
Just a simple workaround that could easily be extended to other platforms: inline std::size_t catch_strnlen(const char *str, std::size_t n)
{
#ifdef __CYGWIN__
if (str == nullptr || n == 0) {
return 0;
}
std::size_t len = 0;
while (len < n && str[len] != '\0') {
++len;
}
return len;
#else
return strnlen(str, n);
#endif
} |
There is a better solution with |
So then this can be written portably in C++11 using inline std::size_t catch_strnlen(const char *str, std::size_t n)
{
auto ret = std::memchr(str, '\0', n);
if (ret != nullptr) {
return ret - str;
}
return n;
} without resorting to macros. |
you sure it's not hidden behind _GNU_SOURCE? |
It is part of the strings library: https://en.cppreference.com/w/cpp/string/byte/memchr. |
Describe the bug
A clear and concise description of what the bug is.
I get the following error using gcc 11.3.0 on cygwin:
What about using
strnlen_s
instead? The only problem I see is that additional macros would have to be defined but since the templates are fully instantiated, the required code could be moved to the source file.There might also be another header providing a
strnlen
. I could dig a little deeper if help is required.Platform information:
The text was updated successfully, but these errors were encountered: