move openat to common code