This is the mail archive of the
gcc-patches@gcc.gnu.org
mailing list for the GCC project.
Re: [libgfortran,patch] MinGW wrapper for getlogin,gethostname and getpid functions
- From: Danny Smith <dannysmith at clear dot net dot nz>
- To: FX Coudert <fxcoudert at gmail dot com>, gfortran <fortran at gcc dot gnu dot org>,patch <gcc-patches at gcc dot gnu dot org>
- Date: Sun, 25 Sep 2005 19:51:48 +1200
- Subject: Re: [libgfortran,patch] MinGW wrapper for getlogin,gethostname and getpid functions
- References: <43354AA3.4080106@gmail.com>
- Reply-to: Danny Smith <dannysmith at users dot sourceforge dot net>
----- Original Message -----
From: "FX Coudert"
Sent: Sunday, 25 September 2005 00:46
> Index: 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
> --- intrinsics/getlog.c 17 Aug 2005 02:48:53 -0000 1.3
> +++ intrinsics/getlog.c 24 Sep 2005 12:42:44 -0000
> @@ -38,6 +38,24 @@ Boston, MA 02110-1301, USA. */
> #include <unistd.h>
> #endif
>
> +#ifdef __MINGW32__
> +#define HAVE_GETLOGIN
> +#include <windows.h>
> +
> +char *getlogin (void);
> +
> +char *
> +getlogin (void)
> +{
> + char *p;
> + DWORD dum = 100;
> +
> + p = gfc_alloca (dum);
> + GetUserName (p, &dum);
> + return p;
> +}
> +#endif
> +
>
Returning memory allocated by __builtin_alloca is not a good idea.
This would be safer:
/* Windows32 version */
#if defined _WIN32 && !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