Port ReadEnv to modern API