diff --git a/libgfortran/configure.ac b/libgfortran/configure.ac
index 97b337e..86cb330 100644
--- a/libgfortran/configure.ac
+++ b/libgfortran/configure.ac
@@ -266,7 +266,8 @@ ftruncate chsize chdir getlogin gethostname kill link symlink sleep ttyname \
 alarm access fork execl wait setmode execve pipe dup2 close \
 strcasestr getrlimit gettimeofday stat fstat lstat getpwuid vsnprintf dup \
 getcwd localtime_r gmtime_r getpwuid_r ttyname_r clock_gettime \
-readlink getgid getpid getppid getuid geteuid umask getegid __secure_getenv)
+readlink getgid getpid getppid getuid geteuid umask getegid \
+secure_getenv __secure_getenv)
 
 # Check strerror_r, cannot be above as versions with two and three arguments exist
 LIBGFOR_CHECK_STRERROR_R
diff --git a/libgfortran/libgfortran.h b/libgfortran/libgfortran.h
index 7dafd94..a8c3363 100644
--- a/libgfortran/libgfortran.h
+++ b/libgfortran/libgfortran.h
@@ -772,6 +772,7 @@ unit_convert get_unformatted_convert (int);
 internal_proto(get_unformatted_convert);
 
 /* Secure getenv() which returns NULL if running as SUID/SGID.  */
+#ifndef HAVE_SECURE_GETENV
 #ifdef HAVE___SECURE_GETENV
 #define secure_getenv __secure_getenv
 #elif defined(HAVE_GETUID) && defined(HAVE_GETEUID) \
@@ -782,6 +783,7 @@ internal_proto(secure_getenv);
 #else
 #define secure_getenv getenv
 #endif
+#endif
 
 /* string.c */
 
