On some platforms, the 'd_name' field of struct dirent is not a static
fixed-sized array but a "flexarray" (i.e. a single character); in this
situation, 'd_name' points to a buffer allocated somewhere, usually
at the end of the buffer used for dirent (which is then allocated in a
bigger memory). Because of this, creating a struct dirent on stack as
buffer for readdir_r is not enough to store all the memory needed for
a dirent on those platforms.
As result, create an helper union with all the needed space, calculated
statically at build time. NAME_MAX+1 is still not a perfect option, but
it will do the job in the vast majority of cases.