+static os_unfair_lock __environ_lock_obj = OS_UNFAIR_LOCK_INIT;
+__private_extern__ void
+__environ_lock(void)
+{
+ os_unfair_lock_lock_with_options(
+ &__environ_lock_obj, OS_UNFAIR_LOCK_DATA_SYNCHRONIZATION);
+}
+__private_extern__ void
+__environ_unlock(void)
+{
+ os_unfair_lock_unlock(&__environ_lock_obj);
+}
+__private_extern__ void
+__environ_lock_fork_child(void)
+{
+ __environ_lock_obj = OS_UNFAIR_LOCK_INIT;
+}
+
+/*
+ * _getenvp -- SPI using an arbitrary pointer to string array (the array must
+ * have been created with malloc) and an env state, created by _allocenvstate().
+ * Returns ptr to value associated with name, if any, else NULL.
+ */
+char *
+_getenvp(const char *name, char ***envp, void *state __unused)
+{
+ // envp is passed as an argument, so the lock is not protecting everything
+ int offset;
+ __environ_lock();
+ char *result = (__findenv_locked(name, &offset, *envp));
+ __environ_unlock();
+ return result;
+}
+