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
MFC after:	1 week


git-svn-id: svn+ssh://svn.freebsd.org/base/head@272139 ccf9f872-aa2e-dd11-9fc8-001c23d0bc1f
Plug a file descriptor leak.

Reported by:	Coverity
CID:		1238916
MFC after:	1 week


git-svn-id: svn+ssh://svn.freebsd.org/base/head@272140 ccf9f872-aa2e-dd11-9fc8-001c23d0bc1f
Refactor the code a little bit to avoid NULL deference when
allocation was failed.

Reported by:	Coverity
CID:		1238915
MFC after:	1 week


git-svn-id: svn+ssh://svn.freebsd.org/base/head@272141 ccf9f872-aa2e-dd11-9fc8-001c23d0bc1f
Use strlcpy(). I don't believe these are real problems but it's better
to use a safe idiom.

Reported by:	Coverity
CID:		1238914
MFC after:	1 week


git-svn-id: svn+ssh://svn.freebsd.org/base/head@272142 ccf9f872-aa2e-dd11-9fc8-001c23d0bc1f
Use a char * as iterator over a bounded string.

MFC after:	1 week


git-svn-id: svn+ssh://svn.freebsd.org/base/head@272143 ccf9f872-aa2e-dd11-9fc8-001c23d0bc1f
The strtol(3) family of functions would set errno when it hits one.
Check errno and handle it as invalid input.

Obtained from:	HardenedBSD
Submitted by:	David CARLIER <devnexen@gmail.com>
MFC after:	2 weeks


git-svn-id: svn+ssh://svn.freebsd.org/base/head@272144 ccf9f872-aa2e-dd11-9fc8-001c23d0bc1f