IntelliSense error: identifier "strlcpy" is undefined

Hello!

I just started working with PlatformIO and migrated over my project from VisualMicro (Arduino extension for Visual Studio). My code compiles and running fine however I’m getting an Intellisense error for strlcat and strlcpy. I’m using a Wemos D1 mini board (ESP8266).

identifier "strlcpy" is undefinedC/C++(20)

Is there a way to getting rid of this error? The other IDE was not giving me one.

Thanks!

Indeed,

#include <Arduino.h>

void setup() {}
void loop() {
 const char *s = "test";
 char buf[64];
 strlcpy(buf, s, sizeof(buf));    
}

does compile but show a VSCode intellisense ‘error’. The source of error is the same as in Identifier is undefined - setenv tzset. PlatformIO does not seem to define _BSD_SOURCE as a macro in the intellisense config, and so some non-standard functions are not found.

From string.h:

#if __BSD_VISIBLE
size_t	strlcat (char *, const char *, size_t);
size_t	strlcpy (char *, const char *, size_t);
#endif

(_BSD_SOURCE enables a lot of other macros, such as __BSD_VISIBLE).

So the fix, adding build_flags = -D_BSD_SOURCE to the platformio.ini, is also valid there.

EDIT: Enabling _GNU_SOURCE also does the trick.

A fix for this on the PlatformIO builder side is in Move _GNU_SOURCE from CCFLAGS to CPPDEFINES by maxgerhardt · Pull Request #8579 · esp8266/Arduino · GitHub.

Thanks a lot @maxgerhardt ! Indeed, setting the build flag got rid of the error.