$NetBSD: patch-af,v 1.7 2017/08/29 11:26:20 wiz Exp $

Add missing getenv_r() support.
https://dev.gnupg.org/T3376

--- src/get-env.c.orig	2016-11-16 12:22:41.000000000 +0000
+++ src/get-env.c
@@ -53,7 +53,25 @@ _gpgme_getenv (const char *name, char **
 
 #else
 
-/* FIXME: Implement this when we have the specification for it.  */
-#error Use of getenv_r not implemented.
+/* Retrieve the environment variable NAME and return a copy of it in a
+   malloc()'ed buffer in *VALUE.  If the environment variable is not
+   set, return NULL in *VALUE.  */
+gpgme_error_t
+_gpgme_getenv (const char *name, char **value)
+{
+  char env_value[256];
+  if (getenv_r (name, env_value, 256) < 0)
+      *value = NULL;
+  else
+    {
+      *value = strdup (env_value);
+      if (!*value)
+        errno = ENOMEM;
+    }
+  if (!*value && errno != ENOENT)
+      return gpg_error_from_syserror ();
+  else
+      return 0;
+}
 
 #endif
