The link error handling isn't ideal. It should probably be checking to see if errno is ENOENT before attempting to create the directory structure for the path. Your code should do something similar, maybe like this:
if (( destfd = open( dest, O_WRONLY, mode )) < 0 ) {
if ( errno == ENOENT ) {
rc = errno;
goto cleanup; /* close fds, etc. */
}
rc = -1;...