Previous implementation could not be realiable for embedded applications
since it used recursion and allocated a buffer for each folder in the
tree. Now, one single allocation is made, duplicating the original string so
it can be tokenized.
A check which ensures each element from the tree is a directory has also
been added. On the other hand, errno is now set when standard functions don't.