~ Handle open mode and open flags properly.

And  fix warnings also.