Cleaned up stout/windows.hpp. Review: https://reviews.apache.org/r/37368
Project: http://git-wip-us.apache.org/repos/asf/mesos/repo Commit: http://git-wip-us.apache.org/repos/asf/mesos/commit/788580cd Tree: http://git-wip-us.apache.org/repos/asf/mesos/tree/788580cd Diff: http://git-wip-us.apache.org/repos/asf/mesos/diff/788580cd Branch: refs/heads/master Commit: 788580cd808c998b6ae472c27bf8728ca37bf280 Parents: 066a5a8 Author: Alex Clemmer <[email protected]> Authored: Thu Sep 10 12:07:46 2015 -0700 Committer: Joris Van Remoortere <[email protected]> Committed: Thu Sep 10 17:15:18 2015 -0700 ---------------------------------------------------------------------- .../3rdparty/stout/include/stout/windows.hpp | 89 ++++++++++---------- 1 file changed, 46 insertions(+), 43 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/mesos/blob/788580cd/3rdparty/libprocess/3rdparty/stout/include/stout/windows.hpp ---------------------------------------------------------------------- diff --git a/3rdparty/libprocess/3rdparty/stout/include/stout/windows.hpp b/3rdparty/libprocess/3rdparty/stout/include/stout/windows.hpp index 5f564d2..50e35f4 100644 --- a/3rdparty/libprocess/3rdparty/stout/include/stout/windows.hpp +++ b/3rdparty/libprocess/3rdparty/stout/include/stout/windows.hpp @@ -15,9 +15,14 @@ #define __STOUT_WINDOWS_HPP__ +#include <fcntl.h> // For file access flags like `_O_CREAT`. + +#include <Windows.h> + + // Definitions and constants used for Windows compat. // -// Gathers most of the Windows-compatibility definitions. This makes it +// Gathers most of the Windows-compatibility definitions. This makes it // possible for files throughout the codebase to remain relatively free of all // the #if's we'd need to make them work. // @@ -27,12 +32,44 @@ // * globally available throughout both the Stout codebase, and any code // that uses it (such as Mesos). -// Normally defined in unistd.h. + +// Define constants used for Windows compat. Allows a lot of code on +// Windows and POSIX systems to be the same, because we can pass the +// same constants to functions we call to do things like file I/O. #define STDIN_FILENO 0 #define STDOUT_FILENO 1 #define STDERR_FILENO 2 +#define R_OK 0x4 +#define W_OK 0x2 +#define X_OK 0x0 // No such permission on Windows. +#define F_OK 0x0 + +#define O_RDONLY _O_RDONLY +#define O_WRONLY _O_WRONLY +#define O_RDWR _O_RDWR +#define O_CREAT _O_CREAT +#define O_TRUNC _O_TRUNC +#define O_APPEND _O_APPEND + +// TODO(hausdorff): (MESOS-3398) Not defined on Windows. This value is +// temporary. +#define MAXHOSTNAMELEN 64 + +#define PATH_MAX _MAX_PATH + +// Corresponds to `mode_t` defined in sys/types.h of the POSIX spec. +// See large "permissions API" comment below for an explanation of +// why this is an int instead of unsigned short (as is common on +// POSIX). +typedef int mode_t; + +// `DWORD` is expected to be the type holding PIDs throughout the Windows API, +// including functions like `OpenProcess`. +typedef DWORD pid_t; +// File I/O function aliases. +// // NOTE: The use of `auto` and the trailing return type in the following // functions are meant to make it easier for Linux developers to use and // maintain the code. It is an explicit marker that we are using the compiler @@ -59,32 +96,14 @@ decltype(_close(fd)) } -// TODO(aclemmer): (MESOS-3398) Not defined on Windows. This value is temporary. -#define MAXHOSTNAMELEN 64 - - -inline auto access(const char* fileName, int accessMode) -> -decltype(_access(fileName, accessMode)) +// Filesystem function aliases. +inline auto mkdir(const char* path, mode_t mode) -> +decltype(_mkdir(path)) { - return _access(fileName, accessMode); + return _mkdir(path); } -#define R_OK 0x4 -#define W_OK 0x2 -#define X_OK 0x0 // No such permission on Windows. -#define F_OK 0x0 - -// Aliases for file access modes. -#include <fcntl.h> -#define O_RDONLY _O_RDONLY -#define O_WRONLY _O_WRONLY -#define O_RDWR _O_RDWR -#define O_CREAT _O_CREAT -#define O_TRUNC _O_TRUNC -#define O_APPEND _O_APPEND -// TODO(josephw): No equivalent for O_NONBLOCK or O_SYNC. -// Alias for mkstemp (requires io.h). inline auto mkstemp(char* path) -> decltype(_mktemp_s(path, strlen(path) + 1)) { @@ -92,9 +111,6 @@ decltype(_mktemp_s(path, strlen(path) + 1)) } -// Alias for realpath. -#define PATH_MAX _MAX_PATH - inline auto realpath(const char* path, char* resolved) -> decltype(_fullpath(resolved, path, PATH_MAX)) @@ -103,17 +119,10 @@ decltype(_fullpath(resolved, path, PATH_MAX)) } -// Corresponds to `mode_t` defined in sys/types.h of the POSIX spec. -// See note above for an explanation of why this is an int instead of -// unsigned short (as is common on POSIX). -typedef int mode_t; - - -// Alias for mkdir (requires direct.h). -inline auto mkdir(const char* path, mode_t mode) -> -decltype(_mkdir(path)) +inline auto access(const char* fileName, int accessMode) -> +decltype(_access(fileName, accessMode)) { - return _mkdir(path); + return _access(fileName, accessMode); } @@ -180,12 +189,6 @@ decltype(_mkdir(path)) // [1] http://www.delorie.com/gnu/docs/glibc/libc_288.html -// Corresponds to `mode_t` defined in sys/types.h of the POSIX spec. -// See note above for an explanation of why this is an int instead of -// unsigned short (as is common on *nix). -typedef int mode_t; - - // User permission flags. const mode_t S_IRUSR = mode_t(_S_IREAD); // Readable by user. const mode_t S_IWUSR = mode_t(_S_IWRITE); // Writeable by user.
