pass correct flags when opening a file