summaryrefslogtreecommitdiff
path: root/libgfortran/intrinsics
diff options
context:
space:
mode:
authorfxcoudert <fxcoudert@138bc75d-0d04-0410-961f-82ee72b054a4>2007-04-25 07:36:20 +0000
committerfxcoudert <fxcoudert@138bc75d-0d04-0410-961f-82ee72b054a4>2007-04-25 07:36:20 +0000
commitc0e8efbe78a70b723ceb20fe02b1bea81b674fad (patch)
tree8203328c54bf2042dd9ae6ad2ea9e5d9f9d0cea8 /libgfortran/intrinsics
parenta106dabe8c6a7d9a8bfa0b45e7ba6cf4f1364312 (diff)
downloadgcc-c0e8efbe78a70b723ceb20fe02b1bea81b674fad.tar.gz
PR libfortran/31299
* intrinsics/getlog.c: Use getpwuid and geteuid instead of getlogin if they are available. * configure.ac: Add checks for getpwuid and geteuid. * configure: Regenerate. * config.h.in: Regenerate. git-svn-id: svn+ssh://gcc.gnu.org/svn/gcc/trunk@124143 138bc75d-0d04-0410-961f-82ee72b054a4
Diffstat (limited to 'libgfortran/intrinsics')
-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