winstorecompat: provide getpid
It's forbidden in any UWP app.
Signed-off-by: Martin Storsjö <martin@martin.st>
diff --git a/mingw-w64-headers/crt/process.h b/mingw-w64-headers/crt/process.h
index 462a902..e5ff999 100644
--- a/mingw-w64-headers/crt/process.h
+++ b/mingw-w64-headers/crt/process.h
@@ -152,6 +152,12 @@
#define WAIT_CHILD _WAIT_CHILD
#define WAIT_GRANDCHILD _WAIT_GRANDCHILD
+#if defined(_CRT_USE_WINAPI_FAMILY_DESKTOP_APP) || defined(WINSTORECOMPAT)
+#ifndef _CRT_GETPID_DEFINED
+#define _CRT_GETPID_DEFINED /* Also in unistd.h */
+ int __cdecl getpid(void) __MINGW_ATTRIB_DEPRECATED_MSVC2005;
+#endif
+#endif /* _CRT_USE_WINAPI_FAMILY_DESKTOP_APP || WINSTORECOMPAT */
#ifdef _CRT_USE_WINAPI_FAMILY_DESKTOP_APP
intptr_t __cdecl cwait(int *_TermStat,intptr_t _ProcHandle,int _Action) __MINGW_ATTRIB_DEPRECATED_MSVC2005;
#ifdef __GNUC__
@@ -169,10 +175,6 @@
intptr_t __cdecl spawnle(int,const char *_Filename,const char *_ArgList,...) __MINGW_ATTRIB_DEPRECATED_MSVC2005;
intptr_t __cdecl spawnlp(int,const char *_Filename,const char *_ArgList,...) __MINGW_ATTRIB_DEPRECATED_MSVC2005;
intptr_t __cdecl spawnlpe(int,const char *_Filename,const char *_ArgList,...) __MINGW_ATTRIB_DEPRECATED_MSVC2005;
-#ifndef _CRT_GETPID_DEFINED
-#define _CRT_GETPID_DEFINED /* Also in unistd.h */
- int __cdecl getpid(void) __MINGW_ATTRIB_DEPRECATED_MSVC2005;
-#endif
#ifdef __GNUC__
/* Those methods are predefined by gcc builtins to return int. So to prevent
stupid warnings, define them in POSIX way. This is save, because those
diff --git a/mingw-w64-headers/crt/unistd.h b/mingw-w64-headers/crt/unistd.h
index 05512c5..af59cb9 100644
--- a/mingw-w64-headers/crt/unistd.h
+++ b/mingw-w64-headers/crt/unistd.h
@@ -93,12 +93,12 @@
void __cdecl swab(char *_Buf1,char *_Buf2,int _SizeInBytes) __MINGW_ATTRIB_DEPRECATED_MSVC2005;
#endif
-#ifdef _CRT_USE_WINAPI_FAMILY_DESKTOP_APP
+#if defined(_CRT_USE_WINAPI_FAMILY_DESKTOP_APP) || defined(WINSTORECOMPAT)
#ifndef _CRT_GETPID_DEFINED
-#define _CRT_GETPID_DEFINED /* Also in process.h */
+#define _CRT_GETPID_DEFINED /* Also in process.h */
int __cdecl getpid(void) __MINGW_ATTRIB_DEPRECATED_MSVC2005;
#endif
-#endif /* _CRT_USE_WINAPI_FAMILY_DESKTOP_APP */
+#endif /* _CRT_USE_WINAPI_FAMILY_DESKTOP_APP || WINSTORECOMPAT */
#ifdef __cplusplus
}
diff --git a/mingw-w64-libraries/winstorecompat/Makefile.am b/mingw-w64-libraries/winstorecompat/Makefile.am
index 028ac14..e25359f 100644
--- a/mingw-w64-libraries/winstorecompat/Makefile.am
+++ b/mingw-w64-libraries/winstorecompat/Makefile.am
@@ -43,6 +43,7 @@
src/RtlVirtualUnwind.c \
src/RtlRestoreContext.c \
src/GetUserName.c \
+ src/getpid.c \
$(NULL)
libwindowsappcompat_a_SOURCES = \
@@ -64,5 +65,6 @@
src/RtlVirtualUnwind.c \
src/RtlRestoreContext.c \
src/GetUserName.c \
+ src/getpid.c \
$(NULL)
libwindowsappcompat_a_CFLAGS = $(AM_CFLAGS) -D_WIN32_WINNT=_WIN32_WINNT_WIN10
diff --git a/mingw-w64-libraries/winstorecompat/src/getpid.c b/mingw-w64-libraries/winstorecompat/src/getpid.c
new file mode 100644
index 0000000..8343d1e
--- /dev/null
+++ b/mingw-w64-libraries/winstorecompat/src/getpid.c
@@ -0,0 +1,41 @@
+/*
+ Copyright (c) 2020 mingw-w64 project
+
+ Contributing authors: Steve Lhomme
+
+ Permission is hereby granted, free of charge, to any person obtaining a
+ copy of this software and associated documentation files (the "Software"),
+ to deal in the Software without restriction, including without limitation
+ the rights to use, copy, modify, merge, publish, distribute, sublicense,
+ and/or sell copies of the Software, and to permit persons to whom the
+ Software is furnished to do so, subject to the following conditions:
+
+ The above copyright notice and this permission notice shall be included in
+ all copies or substantial portions of the Software.
+
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
+ FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
+ DEALINGS IN THE SOFTWARE.
+*/
+
+#define getpid __getpid
+#include <windows.h>
+#include <process.h>
+#undef getpid
+
+int getpid( void );
+
+int getpid( void )
+{
+ return (int)GetCurrentProcessId();
+}
+
+#ifdef _X86_
+int (__cdecl *__MINGW_IMP_SYMBOL(getpid))(void) __asm__("__imp__getpid") = getpid;
+#else
+int (__cdecl *__MINGW_IMP_SYMBOL(getpid))(void) __asm__("__imp_getpid") = getpid;
+#endif