From fcdae0a1129886e78f1ed7933f8e300f6a4be9a8 Mon Sep 17 00:00:00 2001 From: Erik Faye-Lund Date: Mon, 23 Aug 2010 16:52:29 +0200 Subject: [PATCH] mingw: implement getppid --- compat/mingw.c | 32 ++++++++++++++++++++++++++++++++ compat/mingw.h | 3 +-- 2 files changed, 33 insertions(+), 2 deletions(-) diff --git a/compat/mingw.c b/compat/mingw.c index 9a8e336582..8fa561964a 100644 --- a/compat/mingw.c +++ b/compat/mingw.c @@ -1431,6 +1431,38 @@ char *getpass(const char *prompt) return strbuf_detach(&buf, NULL); } +pid_t getppid(void) +{ + typedef ULONG (WINAPI *pfnNTQIP)(HANDLE, ULONG, PVOID, ULONG, PULONG); + + static int first = 1; + static pfnNTQIP NtQueryInformationProcess; + + if (first) { + first = 0; + + NtQueryInformationProcess = (pfnNTQIP)GetProcAddress( + GetModuleHandle("NTDLL.DLL"), + "NtQueryInformationProcess"); + } + + if (NtQueryInformationProcess) { + struct { + long ExitStatus; + void* PebBaseAddress; + ULONG AffinityMask; + ULONG BasePriority; + ULONG UniqueProcessId; + ULONG ParentProcessId; + } pbi; + if (!NtQueryInformationProcess(GetCurrentProcess(), + 0, &pbi, sizeof(pbi), 0)) + return pbi.ParentProcessId; + } + + return 0; +} + #ifndef NO_MINGW_REPLACE_READDIR /* MinGW readdir implementation to avoid extra lstats for Git */ struct mingw_DIR diff --git a/compat/mingw.h b/compat/mingw.h index 3b2477be5f..d79943099e 100644 --- a/compat/mingw.h +++ b/compat/mingw.h @@ -81,8 +81,7 @@ static inline unsigned int alarm(unsigned int seconds) { return 0; } static inline int fsync(int fd) { return _commit(fd); } -static inline int getppid(void) -{ return 1; } +pid_t getppid(void); static inline void sync(void) {} static inline int getuid() -- 2.11.4.GIT