You have a bogus \0
in your dirname_
. When you print the directory name inside the loop and run through strace, the output looks like
write(2, "dirname : ", 10) = 10
write(2, "./zLOZ2nOXpP\0/7U20o0J90x\0", 25) = 25
write(2, "\n", 1) = 1
stat("./zLOZ2nOXpP", {st_mode=S_IFDIR|0755, st_size=4096, ...}) = 0
So, cerr
or cout
correctly print the string (using its length), but when converting to a C-String with c_str()
the result is only the first directory name, which is then passed to stat()
.