This is the mail archive of the gcc-patches@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: [libgfortran,patch] MinGW wrapper for getlogin, gethostname andgetpid functions


Returning memory allocated by __builtin_alloca is not a good idea.

Ouch.


`yes "I will not return memory allocated by alloca()" | head -n 500`

With inclusion of your code and remarks about getpid(), here is an updated patch. Any more comments?

FX

PS: any progress on PR middle-end/21766 ("Bootstrap failure on i686-pc-cygwin")?
2005-09-25  Francois-Xavier Coudert  <coudert@clipper.ens.fr>
            Danny Smith  <dannysmith@users.sourceforge.net>

	PR libfortran/23803
	* intrinsics/getXid.c: Add getpid wrapper for MinGW.
	* intrinsics/getlog.c: Add getlogin wrapper for MinGW.
	* intrinsics/hostnm.c: Add gethostname wrapper for MinGW.
Index: libgfortran/intrinsics/getXid.c
===================================================================
RCS file: /cvs/gcc/gcc/libgfortran/intrinsics/getXid.c,v
retrieving revision 1.4
diff -u -3 -p -r1.4 getXid.c
--- libgfortran/intrinsics/getXid.c	17 Aug 2005 02:48:52 -0000	1.4
+++ libgfortran/intrinsics/getXid.c	25 Sep 2005 10:33:58 -0000
@@ -38,6 +38,11 @@ Boston, MA 02110-1301, USA.  */
 
 #include "libgfortran.h"
 
+#ifdef __MINGW32__
+#define HAVE_GETPID
+#include <process.h>
+#endif
+
 #ifdef HAVE_GETGID
 extern GFC_INTEGER_4 PREFIX(getgid) (void);
 export_proto_np(PREFIX(getgid));
Index: libgfortran/intrinsics/getlog.c
===================================================================
RCS file: /cvs/gcc/gcc/libgfortran/intrinsics/getlog.c,v
retrieving revision 1.3
diff -u -3 -p -r1.3 getlog.c
--- libgfortran/intrinsics/getlog.c	17 Aug 2005 02:48:53 -0000	1.3
+++ libgfortran/intrinsics/getlog.c	25 Sep 2005 10:33:58 -0000
@@ -39,6 +39,29 @@ Boston, MA 02110-1301, USA.  */
 #endif
 
 
+/* Windows32 version */
+#if defined __MINGW32__ && !defined  HAVE_GETLOGIN
+#define WIN32_MEAN_AND_LEAN
+#include <windows.h>
+#include <lmcons.h>  /* for UNLEN */ 
+
+static char *
+w32_getlogin (void)
+{
+  static char name [UNLEN + 1];
+  DWORD namelen = sizeof (name);
+
+  GetUserName (name, &namelen);
+  return (name[0] == 0 ?  NULL : name);
+}
+
+#undef getlogin
+#define getlogin w32_getlogin
+#define HAVE_GETLOGIN 1
+
+#endif
+
+
 /* GETLOG (LOGIN), g77 intrinsic for retrieving the login name for the
    process.
    CHARACTER(len=*), INTENT(OUT) :: LOGIN  */
Index: libgfortran/intrinsics/hostnm.c
===================================================================
RCS file: /cvs/gcc/gcc/libgfortran/intrinsics/hostnm.c,v
retrieving revision 1.2
diff -u -3 -p -r1.2 hostnm.c
--- libgfortran/intrinsics/hostnm.c	17 Aug 2005 02:48:53 -0000	1.2
+++ libgfortran/intrinsics/hostnm.c	25 Sep 2005 10:33:58 -0000
@@ -38,7 +38,21 @@ Boston, MA 02110-1301, USA.  */
 #include <unistd.h> 
 #endif
 
-#include "../io/io.h"
+
+#ifdef __MINGW32__
+#define HAVE_GETHOSTNAME
+#include <windows.h>
+int gethostname_mingw (char *, size_t);
+
+int
+gethostname_mingw (char *name, size_t len)
+{
+  DWORD dlen = len;
+  return (GetComputerName (name, &dlen) ? 0 : -1);
+}
+#define gethostname gethostname_mingw
+#endif
+
 
 /* SUBROUTINE HOSTNM(NAME, STATUS)
    CHARACTER(len=*), INTENT(OUT) :: NAME

Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]