gpgme fails to compile with mingw due to wrong macro

Biswapriyo Nath nathbappai at gmail.com
Sat May 20 16:11:19 CEST 2023


* compiler:

gcc version 13.1.0 (Rev6, Built by MSYS2 project)
Target: x86_64-w64-mingw32
Thread model: posix

* compiler error:

python3.10-gpg/helpers.h:30:28: error: expected expression before '{' token
   30 | #define write(fd, str, sz) {DWORD written; WriteFile((HANDLE)
fd, str, sz, &written, 0);}
      |                            ^
python3.10-gpg/helpers.c:407:11: note: in expansion of macro 'write'
  407 |       if (write(fd, "\n", 1) < 0) {
      |           ^~~~~

* suggestion:
1. Disable the write() macro with `#ifdef _MSC_VER` (true for msvc
only). I am not sure if Microsoft Windows' write function is
equivalent with *nix's one.
2. Rewrite the write() macro as following.

static ssize_t gpgme_win32_write(int fd, const void *str, size_t sz)
{
    DWORD written;
    return WriteFile((HANDLE) fd, str, sz, &written, 0);
}

#define write(fd, str, sz) gpgme_win32_write(fd, str, sz)

I can provide further information if required. Thank you.



More information about the Gnupg-devel mailing list