fix errno for writing and tracin