diff options
author | Alin Serdean <aserdean@cloudbasesolutions.com> | 2017-05-22 11:56:50 +0000 |
---|---|---|
committer | Ben Pfaff <blp@ovn.org> | 2017-05-25 14:33:13 -0700 |
commit | 2eed4f18938244d4797c8248846c41ec48de1006 (patch) | |
tree | fe30ae90c741ce54650f6b5703d4c6546e19d6ac /include/windows/unistd.h | |
parent | 13f4d25a6aa086306bc65752b3232a5091fbf3ea (diff) | |
download | openvswitch-2eed4f18938244d4797c8248846c41ec48de1006.tar.gz |
windows: add definition of getpid and getcwd
getcwd - is used in lib/util.c. getcwd is deprecated on Windows but has
_getcwd which is defined in <direct.h>:
https://msdn.microsoft.com/en-us/library/sf98bd4y(v=vs.120).aspx
getpid - is used in several files (i.e. lib/vlog.c). getpid
is also and deprecated and _getpid should be used:
https://msdn.microsoft.com/en-us/library/t2y34y40(v=vs.120).aspx
The problem using _getpid is that the definition is in <process.h>.
A file called process.h also exists in the lib folder. This will mess up
includes.
An option would be to use a wrapper like we use for lib/string.h(.in) but
that would mean to also add it to the automake chain.
A simple solution would be to map it to GetCurrentProcessId
https://msdn.microsoft.com/en-us/library/windows/desktop/ms683180(v=vs.85).aspx
_getpid uses GetCurrentProcessId behind the scenes, casting the result
is not required.
Signed-off-by: Alin Gabriel Serdean <aserdean@cloudbasesolutions.com>
Co-authored-by: Ben Pfaff <blp@ovn.org>
Signed-off-by: Ben Pfaff <blp@ovn.org>
Diffstat (limited to 'include/windows/unistd.h')
-rw-r--r-- | include/windows/unistd.h | 12 |
1 files changed, 12 insertions, 0 deletions
diff --git a/include/windows/unistd.h b/include/windows/unistd.h index 8629f7e11..2e9f0aef1 100644 --- a/include/windows/unistd.h +++ b/include/windows/unistd.h @@ -18,8 +18,11 @@ #define WIN32_LEAN_AND_MEAN #include <windows.h> +#include <direct.h> +#include <windefs.h> #define fsync _commit +#define getcwd _getcwd /* Standard file descriptors. */ #define STDIN_FILENO 0 /* Standard input. */ @@ -33,6 +36,15 @@ #define _SC_NPROCESSORS_ONLN 0x2 #define _SC_PHYS_PAGES 0x4 + +static __inline pid_t getpid(void) +{ + /* Since _getpid: https://msdn.microsoft.com/en-us/library/t2y34y40.aspx + * uses GetCurrentProcessId behind the scenes it is safe to assume no + * casting is required */ + return GetCurrentProcessId(); +} + __inline int GetNumLogicalProcessors(void) { SYSTEM_INFO info_temp; |