git/list[1] front-page[2] threads[3] people[4] search[5] about
 

Re: [PATCH 08/14] help.c: Fix detection of custom merge strategy on cygwin

From
Erik Faye-Lund <kusmabite@gmail.com>
Date
Dec 16, 2010, 23:06 UTC
Message-ID
<AANLkTi=9rSEK=7JyS6w50Hr=mrVttmjeqnBrbYsSR=6K@mail.gmail.com>
In-Reply-To
<4D0A7E87.3020203@ramsay1.demon.co.uk>

On Thu, Dec 16, 2010 at 10:03 PM, Ramsay Jones <ramsay@ramsay1.demon.co.uk> wrote:

Show 59 quoted lines
> Erik Faye-Lund wrote:
>>> diff --git a/help.c b/help.c
>>> index 7f4928e..eabadc9 100644
>>> --- a/help.c
>>> +++ b/help.c
>>> @@ -126,7 +126,10 @@ static int is_executable(const char *name)
>>>            !S_ISREG(st.st_mode))
>>>                return 0;
>>>
>>> -#ifdef WIN32
>>> +#if defined(WIN32) || defined(__CYGWIN__)
>>> +#if defined(__CYGWIN__)
>>> +if ((st.st_mode & S_IXUSR) == 0)
>>> +#endif
>>
>> Perhaps the first check should simply be changed to check for _WIN32
>> instead of WIN32? IIRC _WIN32 is set on Cygwin, but I could be
>> mistaken...
>
> No, neither WIN32 or _WIN32 will be defined here (and they should not be).
> It's actually quite tricky, particularly when #including <windows.h>, viz:
>
>    $ cat -n test.c
>     1  #include <stdio.h>
>     2
>     3  #ifdef IW
>     4  # include <windows.h>
>     5  #endif
>     6
>     7  int main(int argc, char *argv[])
>     8  {
>     9  #ifdef WIN32
>    10          printf("WIN32 ");
>    11  #endif
>    12  #ifdef _WIN32
>    13          printf("_WIN32 ");
>    14  #endif
>    15  #ifdef __CYGWIN__
>    16          printf("__CYGWIN__ ");
>    17  #endif
>    18  #ifdef __MINGW32__
>    19          printf("__MINGW32__ ");
>    20  #endif
>    21          printf("\n");
>    22          return 0;
>    23  }
>
>    $ gcc -o test test.c
>    $ ./test
>    __CYGWIN__
>
>    $ gcc -o test -DIW test.c
>    $ ./test
>    WIN32 _WIN32 __CYGWIN__
>
>    $ gcc -o test -mno-cygwin test.c
>    $ ./test
>    WIN32 _WIN32 __MINGW32__
>

Hmm, I thought _WIN32 was always defined when targeting Windows, and that WIN32 was defined when windows.h was included (or usually in the preprocessor flags when compiling GUI programs) - that's what MSVC does anyway. MinGW seems to always define both _WIN32 and WIN32, but as you've shown Cygwin doesn't define either until windows.h is included.

So sorry for leading you onto the wrong path, a check for __CYGWIN__ seems to be necessary indeed.

Previous: Ramsay JonesNext: Johannes Sixt
Message 4 of 8 in “help.c: Fix detection of custom merge strategy on cygwin”
  1. 08/14 help.c: Fix detection of custom merge strategy on cygwinRamsay Jones, Dec 14, 2010
  2. Erik Faye-LundDec 14, 2010
  3. Ramsay JonesDec 16, 2010
  4. Erik Faye-LundDec 16, 2010
  5. Johannes SixtDec 14, 2010
  6. Ramsay JonesDec 16, 2010
  7. Johannes SixtDec 17, 2010
  8. Ramsay JonesDec 18, 2010

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.