Commit ed9408bf authored by Christoph Purrer's avatar Christoph Purrer Committed by Facebook Github Bot

Fix <folly/portability/Windows.h> on Windows SDK 1903 / 10.0.18362.0

Summary:
Folly does not compile with Windows SDK 1903. The issues is in folly/portability/Windows.h and surfaces when compiling files including it, e.g.: xplat/folly.portability/Stdlib.cpp
```
xplat\folly/portability/SysStat.h:47:5: error: conflicting types for 'mkdir'
int mkdir(const char* fn, int mode);
    ^
C:\Program Files (x86)\Windows Kits\10\Include\10.0.18362.0\ucrt\direct.h:111:26: note: previous declaration is here
    _ACRTIMP int __cdecl mkdir(
                         ^
xplat\folly\portability\Stdlib.cpp:47:11: error: no matching function for call to 'mkdir'
    ret = mkdir(ptr, 0700);
          ^~~~~
C:\Program Files (x86)\Windows Kits\10\Include\10.0.18362.0\ucrt\direct.h:111:26: note: candidate function not viable:
      requires single argument '_Path', but 2 arguments were provided
    _ACRTIMP int __cdecl mkdir(
                         ^
2 errors generated.
```
Now internal Windows functions collide with folly portability ones defined in https://github.com/facebook/folly/blob/master/folly/portability/Unistd.h#L61-L93

C:\Program Files (x86)\Windows Kits\10\Include\10.0.18362.0\ucrt\direct.h defines a Windows ```mkdir``` function when
```
#if defined(_CRT_INTERNAL_NONSTDC_NAMES) && _CRT_INTERNAL_NONSTDC_NAMES
//...
    _Check_return_ _CRT_NONSTDC_DEPRECATE(_mkdir)
    _ACRTIMP int __cdecl mkdir(
        _In_z_ char const* _Path
        );

    _Check_return_ _CRT_NONSTDC_DEPRECATE(_rmdir)
    _ACRTIMP int __cdecl rmdir(
        _In_z_ char const* _Path
        );

#endif // _CRT_INTERNAL_NONSTDC_NAMES
```

When diffing the current Windows SDK 1903 version: C:\Program Files (x86)\Windows Kits\10\Include\10.0.18362.0\ucrt\corecrt.h
with a previous one, e.g.: 1809 C:\tools\toolchains\vs2017_15.9\WindowsSdk\Include\10.0.17763.0\ucrt\corecrt.h
we see a fundamental change:

## SDK 1903
```
#if ( defined _CRT_DECLARE_NONSTDC_NAMES && _CRT_DECLARE_NONSTDC_NAMES) || \
    (!defined _CRT_DECLARE_NONSTDC_NAMES && !__STDC__                 )
    #define _CRT_INTERNAL_NONSTDC_NAMES 1
#else
    #define _CRT_INTERNAL_NONSTDC_NAMES 0
#endif
```

## SDK 1809
```
#define _CRT_INTERNAL_NONSTDC_NAMES                                            \
    (                                                                          \
        ( defined _CRT_DECLARE_NONSTDC_NAMES && _CRT_DECLARE_NONSTDC_NAMES) || \
        (!defined _CRT_DECLARE_NONSTDC_NAMES && !__STDC__                 )    \
    )
```

Reviewed By: Orvid

Differential Revision: D19804183

fbshipit-source-id: cbbe32c611a3c011175145329c29de4a9597868c
parent 5ee564ba
...@@ -33,10 +33,12 @@ ...@@ -33,10 +33,12 @@
#ifdef _CRT_DECLARE_NONSTDC_NAMES #ifdef _CRT_DECLARE_NONSTDC_NAMES
#undef _CRT_DECLARE_NONSTDC_NAMES #undef _CRT_DECLARE_NONSTDC_NAMES
#endif #endif
#define _CRT_DECLARE_NONSTDC_NAMES 0 #pragma push_macro("_CRT_INTERNAL_NONSTDC_NAMES")
#undef _CRT_INTERNAL_NONSTDC_NAMES
#include <direct.h> // @manual nolint #include <direct.h> // @manual nolint
#include <io.h> // @manual nolint #include <io.h> // @manual nolint
#undef __STDC__ #undef __STDC__
#pragma pop_macro("_CRT_INTERNAL_NONSTDC_NAMES")
#pragma pop_macro("_CRT_DECLARE_NONSTDC_NAMES") #pragma pop_macro("_CRT_DECLARE_NONSTDC_NAMES")
#else #else
#include <direct.h> // @manual nolint #include <direct.h> // @manual nolint
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment