Being able to access a path do not necessarily mean we have access
to a directory.  So instead of doing this, we just call mkdir(2)
directly and test if the returned value is 0 or errno is EISDIR.

Reported by:	Coverity
CID:		1238925
Plug a file descriptor leak.

Reported by:	Coverity
CID:		1238916
Refactor the code a little bit to avoid NULL deference when allocation
was failed.

Reported by:	Coverity
CID:		1238915
Use strlcpy().  I don't believe these are real problems but it's better
to use a safe idiom.

Reported by:	Coverity
CID:		1238914