From 444dc90322fcd1e4ea1cb9c6a46372fa28d8ef9d Mon Sep 17 00:00:00 2001 From: Dmitry Potapov Date: Sat, 27 Sep 2008 12:43:01 +0400 Subject: mingw: move common functionality to win32.h Some small Win32 specific functions will be shared by MinGW and Cygwin compatibility layer. Place them into a separate header. Signed-off-by: Dmitry Potapov Signed-off-by: Shawn O. Pearce --- compat/win32.h | 34 ++++++++++++++++++++++++++++++++++ 1 file changed, 34 insertions(+) create mode 100644 compat/win32.h (limited to 'compat/win32.h') diff --git a/compat/win32.h b/compat/win32.h new file mode 100644 index 0000000000..c26384e595 --- /dev/null +++ b/compat/win32.h @@ -0,0 +1,34 @@ +/* common Win32 functions for MinGW and Cygwin */ +#include + +static inline int file_attr_to_st_mode (DWORD attr) +{ + int fMode = S_IREAD; + if (attr & FILE_ATTRIBUTE_DIRECTORY) + fMode |= S_IFDIR; + else + fMode |= S_IFREG; + if (!(attr & FILE_ATTRIBUTE_READONLY)) + fMode |= S_IWRITE; + return fMode; +} + +static inline int get_file_attr(const char *fname, WIN32_FILE_ATTRIBUTE_DATA *fdata) +{ + if (GetFileAttributesExA(fname, GetFileExInfoStandard, fdata)) + return 0; + + switch (GetLastError()) { + case ERROR_ACCESS_DENIED: + case ERROR_SHARING_VIOLATION: + case ERROR_LOCK_VIOLATION: + case ERROR_SHARING_BUFFER_EXCEEDED: + return EACCES; + case ERROR_BUFFER_OVERFLOW: + return ENAMETOOLONG; + case ERROR_NOT_ENOUGH_MEMORY: + return ENOMEM; + default: + return ENOENT; + } +} -- cgit v1.2.3 From 627735f9bf322c5c964b396f4a55d14e18d34aa2 Mon Sep 17 00:00:00 2001 From: Marius Storm-Olsen Date: Wed, 16 Sep 2009 10:20:18 +0200 Subject: Add include guards to compat/win32.h Signed-off-by: Marius Storm-Olsen Acked-by: Johannes Sixt Signed-off-by: Junio C Hamano --- compat/win32.h | 5 +++++ 1 file changed, 5 insertions(+) (limited to 'compat/win32.h') diff --git a/compat/win32.h b/compat/win32.h index c26384e595..e8c178d8cd 100644 --- a/compat/win32.h +++ b/compat/win32.h @@ -1,3 +1,6 @@ +#ifndef WIN32_H +#define WIN32_H + /* common Win32 functions for MinGW and Cygwin */ #include @@ -32,3 +35,5 @@ static inline int get_file_attr(const char *fname, WIN32_FILE_ATTRIBUTE_DATA *fd return ENOENT; } } + +#endif -- cgit v1.2.3 From 435bdf8c7ffa493f8f6f2e8f329f8cc22db16ce6 Mon Sep 17 00:00:00 2001 From: Marius Storm-Olsen Date: Wed, 16 Sep 2009 10:20:26 +0200 Subject: Make usage of windows.h lean and mean Centralize the include of windows.h in git-compat-util.h, turn on WIN32_LEAN_AND_MEAN to avoid including plenty of other header files which is not needed in Git. Also ensure we load winsock2.h first, so we don't load the older winsock definitions at a later stage, since they contain duplicate definitions. When moving windows.h into git-compat-util.h, we need to protect the definition of struct pollfd in mingw.h, since this file is used by both MinGW and MSVC, and the latter defines this struct in winsock2.h. We need to keep the windows.h include in compat/win32.h, since its shared by both MinGW and Cygwin, and we're not touching Cygwin in this commit. The include in git-compat-util.h is protected with an ifdef WIN32, which is not the case when compiling for Cygwin. Signed-off-by: Marius Storm-Olsen Acked-by: Johannes Sixt Signed-off-by: Junio C Hamano --- compat/win32.h | 2 ++ 1 file changed, 2 insertions(+) (limited to 'compat/win32.h') diff --git a/compat/win32.h b/compat/win32.h index e8c178d8cd..8ce91048de 100644 --- a/compat/win32.h +++ b/compat/win32.h @@ -2,7 +2,9 @@ #define WIN32_H /* common Win32 functions for MinGW and Cygwin */ +#ifndef WIN32 /* Not defined by Cygwin */ #include +#endif static inline int file_attr_to_st_mode (DWORD attr) { -- cgit v1.2.3