Added error checking to mbrwrite()