This is the mail archive of the fortran@gcc.gnu.org mailing list for the GNU Fortran 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 and getpid functions


----- Original Message -----
From: "FX Coudert
Sent: Sunday, 25 September 2005 22:40


> > 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?
>

Yes

This
+#define WIN32_MEAN_AND_LEAN
in getlog,  was a typo on my part.  It should be:
#define WIN32_LEAN_AND_MEAN
.
and yes defining trhis reallu does have a noticeable effect on slower machines.

RE gethostname, a comment or two would be helpful  Also need to be careful with
win9x:

/* Windows32 version */
#if defined _WIN32 && !defined  HAVE_GETHOSTNAME
#define WIN32_LEAN_AND_MEAN
#include <windows.h>
#include <errno.h>

static int
w32_gethostname (char *name, size_t len)
{
  /* We could try the WinSock API gethostname, but that will
     fail if WSAStartup function has has not been called.  We don't
    really need a name that will be understood by socket API, so avoid
    unnecessary dependence on WinSock libraries by using
    GetComputerName instead.  */

  /* On Win9x GetComputerName fails if the input size is less
     than MAX_COMPUTERNAME_LENGTH + 1.  */
  char buffer[MAX_COMPUTERNAME_LENGTH + 1];
  DWORD size =  sizeof (buffer);

  if (!GetComputerName (buffer, &size))
    return -1;

  if ((size = strlen (buffer) + 1)  > len)
    {
      errno = EINVAL;
      /* Truncate as per POSIX spec.  We do not NUL-terminate. */
      size = len;
    }
  memcpy (name, buffer, (size_t) size);

  return 0;
}

#undef gethostname
#define gethostname w32_gethostname
#define  HAVE_GETHOSTNAME 1

#endif




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