Copy from OS X branch.