A characterization of the invariance of positivity for functional differential equations