my_wsagetlasterror (void)
{
  int wsaerr;
  gpg_err_code_t ec;

  wsaerr = WSAGetLastError ();
  switch (wsaerr)
    {
    case WSAENOTSOCK:        ec = GPG_ERR_EINVAL;       break;
    case WSAEWOULDBLOCK:     ec = GPG_ERR_EAGAIN;       break;
    case ERROR_BROKEN_PIPE:  ec = GPG_ERR_EPIPE;        break;
    case WSANOTINITIALISED:  ec = GPG_ERR_ENOSYS;       break;
    case WSAENOBUFS:         ec = GPG_ERR_ENOBUFS;      break;
    case WSAEMSGSIZE:        ec = GPG_ERR_EMSGSIZE;     break;
    case WSAECONNREFUSED:    ec = GPG_ERR_ECONNREFUSED; break;
    case WSAEISCONN:         ec = GPG_ERR_EISCONN;      break;
    case WSAEALREADY:        ec = GPG_ERR_EALREADY;     break;
    case WSAETIMEDOUT:       ec = GPG_ERR_ETIMEDOUT;    break;
    default:                 ec = GPG_ERR_EIO;          break;
    }

  return gpg_err_make (default_errsource, ec);
}
my_wsagetlasterror (void)
{
  int wsaerr;
  gpg_err_code_t ec;

  wsaerr = WSAGetLastError ();
  switch (wsaerr)
    {
    case WSAENOTSOCK:        ec = GPG_ERR_EINVAL;       break;
    case WSAEWOULDBLOCK:     ec = GPG_ERR_EAGAIN;       break;
    case ERROR_BROKEN_PIPE:  ec = GPG_ERR_EPIPE;        break;
    case WSANOTINITIALISED:  ec = GPG_ERR_ENOSYS;       break;
    case WSAENOBUFS:         ec = GPG_ERR_ENOBUFS;      break;
    case WSAEMSGSIZE:        ec = GPG_ERR_EMSGSIZE;     break;
    case WSAECONNREFUSED:    ec = GPG_ERR_ECONNREFUSED; break;
    case WSAEISCONN:         ec = GPG_ERR_EISCONN;      break;
    case WSAEALREADY:        ec = GPG_ERR_EALREADY;     break;
    case WSAETIMEDOUT:       ec = GPG_ERR_ETIMEDOUT;    break;
    default:                 ec = GPG_ERR_EIO;          break;
    }

  return gpg_err_make (default_errsource, ec);
}