Use access() instead of stat().