summaryrefslogtreecommitdiff
path: root/libgfortran/intrinsics/getlog.c
diff options
context:
space:
mode:
Diffstat (limited to 'libgfortran/intrinsics/getlog.c')
-rw-r--r--libgfortran/intrinsics/getlog.c26
1 files changed, 22 insertions, 4 deletions
diff --git a/libgfortran/intrinsics/getlog.c b/libgfortran/intrinsics/getlog.c
index 9b73ec21078..417b0f28f99 100644
--- a/libgfortran/intrinsics/getlog.c
+++ b/libgfortran/intrinsics/getlog.c
@@ -37,7 +37,12 @@ Boston, MA 02110-1301, USA. */
#ifdef HAVE_UNISTD_H
#include <unistd.h>
#endif
-
+#ifdef HAVE_SYS_TYPES_H
+#include <sys/types.h>
+#endif
+#ifdef HAVE_PWD_H
+#include <pwd.h>
+#endif
/* Windows32 version */
#if defined __MINGW32__ && !defined HAVE_GETLOGIN
@@ -66,7 +71,6 @@ w32_getlogin (void)
process.
CHARACTER(len=*), INTENT(OUT) :: LOGIN */
-#ifdef HAVE_GETLOGIN
void PREFIX(getlog) (char *, gfc_charlen_type);
export_proto_np(PREFIX(getlog));
@@ -78,7 +82,22 @@ PREFIX(getlog) (char * login, gfc_charlen_type login_len)
memset (login, ' ', login_len); /* Blank the string. */
- p = getlogin ();
+#if defined(HAVE_GETPWUID) && defined(HAVE_GETEUID)
+ {
+ struct passwd *pw = getpwuid (geteuid ());
+ if (pw)
+ p = pw->pw_name;
+ else
+ return;
+ }
+#else
+# ifdef HAVE_GETLOGIN
+ p = getlogin();
+# else
+ return;
+# endif
+#endif
+
if (p == NULL)
return;
@@ -88,4 +107,3 @@ PREFIX(getlog) (char * login, gfc_charlen_type login_len)
else
memcpy (login, p, p_len);
}
-#endif