Commit 678e9e045becdc5d75f2ce2259ed01c3531ee181

Vicent Marti 2011-07-03T13:33:43

build: Move OS-specific compat to their own folders

diff --git a/CMakeLists.txt b/CMakeLists.txt
index 30df62d..82208dc 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -71,18 +71,19 @@ IF (THREADSAFE)
 	ADD_DEFINITIONS(-DGIT_THREADS)
 ENDIF()
 
+ADD_DEFINITIONS(-D_FILE_OFFSET_BITS=64)
+
 # Collect sourcefiles
-FILE(GLOB SRC src/*.c)
 FILE(GLOB SRC_H include/git2/*.h)
 
 # On Windows use specific platform sources
 IF (WIN32 AND NOT CYGWIN)
     ADD_DEFINITIONS(-DWIN32 -D_DEBUG -D_LIB)
 	FILE(GLOB SRC src/*.c src/win32/*.c)
+ELSE()
+	FILE(GLOB SRC src/*.c src/unix/*.c)
 ENDIF ()
 
-ADD_DEFINITIONS(-D_FILE_OFFSET_BITS=64)
-
 # Compile and link libgit2
 ADD_LIBRARY(git2 ${SRC} ${SRC_ZLIB})
 TARGET_LINK_LIBRARIES(git2 ${CMAKE_THREAD_LIBS_INIT})
diff --git a/src/common.h b/src/common.h
index b6d8ae3..e1e7f00 100644
--- a/src/common.h
+++ b/src/common.h
@@ -23,8 +23,8 @@
 # include <io.h>
 # include <direct.h>
 # include <windows.h>
-# include "msvc-compat.h"
-# include "mingw-compat.h"
+# include "win32/msvc-compat.h"
+# include "win32/mingw-compat.h"
 # ifdef GIT_THREADS
 #  include "win32/pthread.h"
 #endif
diff --git a/src/map_posix.c b/src/map_posix.c
deleted file mode 100644
index 1f50bcf..0000000
--- a/src/map_posix.c
+++ /dev/null
@@ -1,64 +0,0 @@
-#include <git2/common.h>
-
-#ifndef GIT_WIN32
-
-#include "map.h"
-#include <sys/mman.h>
-#include <errno.h>
-
-int git__mmap(git_map *out, size_t len, int prot, int flags, int fd, git_off_t offset)
-{
-	int mprot = 0;
-	int mflag = 0;
-
-	assert((out != NULL) && (len > 0));
-
-	if ((out == NULL) || (len == 0)) {
-		errno = EINVAL;
-		return git__throw(GIT_ERROR, "Failed to mmap. No map or zero length");
-	}
-
-	out->data = NULL;
-	out->len = 0;
-
-	if (prot & GIT_PROT_WRITE)
-		mprot = PROT_WRITE;
-	else if (prot & GIT_PROT_READ)
-		mprot = PROT_READ;
-	else {
-		errno = EINVAL;
-		return git__throw(GIT_ERROR, "Failed to mmap. Invalid protection parameters");
-	}
-
-	if ((flags & GIT_MAP_TYPE) == GIT_MAP_SHARED)
-		mflag = MAP_SHARED;
-	else if ((flags & GIT_MAP_TYPE) == GIT_MAP_PRIVATE)
-		mflag = MAP_PRIVATE;
-
-	if (flags & GIT_MAP_FIXED) {
-		errno = EINVAL;
-		return git__throw(GIT_ERROR, "Failed to mmap. FIXED not set");
-	}
-
-	out->data = mmap(NULL, len, mprot, mflag, fd, offset);
-	if (!out->data || out->data == MAP_FAILED)
-		return git__throw(GIT_EOSERR, "Failed to mmap. Could not write data");
-	out->len = len;
-
-	return GIT_SUCCESS;
-}
-
-int git__munmap(git_map *map)
-{
-	assert(map != NULL);
-
-	if (!map)
-		return git__throw(GIT_ERROR, "Failed to munmap. Map does not exist");
-
-	munmap(map->data, map->len);
-
-	return GIT_SUCCESS;
-}
-
-#endif
-
diff --git a/src/mingw-compat.h b/src/mingw-compat.h
deleted file mode 100644
index 64d780b..0000000
--- a/src/mingw-compat.h
+++ /dev/null
@@ -1,18 +0,0 @@
-#ifndef INCLUDE_mingw_compat__
-#define INCLUDE_mingw_compat__
-
-#if defined(__MINGW32__)
-
-/* use a 64-bit file offset type */
-# define lseek _lseeki64
-# define stat _stati64
-# define fstat _fstati64
-
-/* stat: file mode type testing macros */
-# define _S_IFLNK 0120000
-# define S_IFLNK _S_IFLNK
-# define S_ISLNK(m)  (((m) & _S_IFMT) == _S_IFLNK)
-
-#endif
-
-#endif /* INCLUDE_mingw_compat__ */
diff --git a/src/msvc-compat.h b/src/msvc-compat.h
deleted file mode 100644
index df3e62d..0000000
--- a/src/msvc-compat.h
+++ /dev/null
@@ -1,52 +0,0 @@
-#ifndef INCLUDE_msvc_compat__
-#define INCLUDE_msvc_compat__
-
-#if defined(_MSC_VER)
-
-/* access() mode parameter #defines   */
-# define F_OK 0  /* existence  check */
-# define W_OK 2  /* write mode check */
-# define R_OK 4  /* read  mode check */
-
-# define lseek _lseeki64
-# define stat _stat64
-# define fstat _fstat64
-
-/* stat: file mode type testing macros */
-# define _S_IFLNK 0120000
-# define S_IFLNK _S_IFLNK
-
-# define S_ISDIR(m)   (((m) & _S_IFMT) == _S_IFDIR)
-# define S_ISREG(m)   (((m) & _S_IFMT) == _S_IFREG)
-# define S_ISFIFO(m)  (((m) & _S_IFMT) == _S_IFIFO)
-# define S_ISLNK(m)  (((m) & _S_IFMT) == _S_IFLNK)
-
-# define mode_t unsigned short
-
-/* case-insensitive string comparison */
-# define strcasecmp   _stricmp
-# define strncasecmp  _strnicmp
-
-#if (_MSC_VER >= 1600)
-#	include <stdint.h>
-#else
-/* add some missing <stdint.h> typedef's */
-typedef signed char int8_t;
-typedef unsigned char uint8_t;
-
-typedef short int16_t;
-typedef unsigned short uint16_t;
-
-typedef long int32_t;
-typedef unsigned long uint32_t;
-
-typedef long long int64_t;
-typedef unsigned long long uint64_t;
-
-typedef long long intmax_t;
-typedef unsigned long long uintmax_t;
-#endif
-
-#endif
-
-#endif /* INCLUDE_msvc_compat__ */
diff --git a/src/unix/map.c b/src/unix/map.c
new file mode 100644
index 0000000..1f50bcf
--- /dev/null
+++ b/src/unix/map.c
@@ -0,0 +1,64 @@
+#include <git2/common.h>
+
+#ifndef GIT_WIN32
+
+#include "map.h"
+#include <sys/mman.h>
+#include <errno.h>
+
+int git__mmap(git_map *out, size_t len, int prot, int flags, int fd, git_off_t offset)
+{
+	int mprot = 0;
+	int mflag = 0;
+
+	assert((out != NULL) && (len > 0));
+
+	if ((out == NULL) || (len == 0)) {
+		errno = EINVAL;
+		return git__throw(GIT_ERROR, "Failed to mmap. No map or zero length");
+	}
+
+	out->data = NULL;
+	out->len = 0;
+
+	if (prot & GIT_PROT_WRITE)
+		mprot = PROT_WRITE;
+	else if (prot & GIT_PROT_READ)
+		mprot = PROT_READ;
+	else {
+		errno = EINVAL;
+		return git__throw(GIT_ERROR, "Failed to mmap. Invalid protection parameters");
+	}
+
+	if ((flags & GIT_MAP_TYPE) == GIT_MAP_SHARED)
+		mflag = MAP_SHARED;
+	else if ((flags & GIT_MAP_TYPE) == GIT_MAP_PRIVATE)
+		mflag = MAP_PRIVATE;
+
+	if (flags & GIT_MAP_FIXED) {
+		errno = EINVAL;
+		return git__throw(GIT_ERROR, "Failed to mmap. FIXED not set");
+	}
+
+	out->data = mmap(NULL, len, mprot, mflag, fd, offset);
+	if (!out->data || out->data == MAP_FAILED)
+		return git__throw(GIT_EOSERR, "Failed to mmap. Could not write data");
+	out->len = len;
+
+	return GIT_SUCCESS;
+}
+
+int git__munmap(git_map *map)
+{
+	assert(map != NULL);
+
+	if (!map)
+		return git__throw(GIT_ERROR, "Failed to munmap. Map does not exist");
+
+	munmap(map->data, map->len);
+
+	return GIT_SUCCESS;
+}
+
+#endif
+
diff --git a/src/win32/mingw-compat.h b/src/win32/mingw-compat.h
new file mode 100644
index 0000000..64d780b
--- /dev/null
+++ b/src/win32/mingw-compat.h
@@ -0,0 +1,18 @@
+#ifndef INCLUDE_mingw_compat__
+#define INCLUDE_mingw_compat__
+
+#if defined(__MINGW32__)
+
+/* use a 64-bit file offset type */
+# define lseek _lseeki64
+# define stat _stati64
+# define fstat _fstati64
+
+/* stat: file mode type testing macros */
+# define _S_IFLNK 0120000
+# define S_IFLNK _S_IFLNK
+# define S_ISLNK(m)  (((m) & _S_IFMT) == _S_IFLNK)
+
+#endif
+
+#endif /* INCLUDE_mingw_compat__ */
diff --git a/src/win32/msvc-compat.h b/src/win32/msvc-compat.h
new file mode 100644
index 0000000..df3e62d
--- /dev/null
+++ b/src/win32/msvc-compat.h
@@ -0,0 +1,52 @@
+#ifndef INCLUDE_msvc_compat__
+#define INCLUDE_msvc_compat__
+
+#if defined(_MSC_VER)
+
+/* access() mode parameter #defines   */
+# define F_OK 0  /* existence  check */
+# define W_OK 2  /* write mode check */
+# define R_OK 4  /* read  mode check */
+
+# define lseek _lseeki64
+# define stat _stat64
+# define fstat _fstat64
+
+/* stat: file mode type testing macros */
+# define _S_IFLNK 0120000
+# define S_IFLNK _S_IFLNK
+
+# define S_ISDIR(m)   (((m) & _S_IFMT) == _S_IFDIR)
+# define S_ISREG(m)   (((m) & _S_IFMT) == _S_IFREG)
+# define S_ISFIFO(m)  (((m) & _S_IFMT) == _S_IFIFO)
+# define S_ISLNK(m)  (((m) & _S_IFMT) == _S_IFLNK)
+
+# define mode_t unsigned short
+
+/* case-insensitive string comparison */
+# define strcasecmp   _stricmp
+# define strncasecmp  _strnicmp
+
+#if (_MSC_VER >= 1600)
+#	include <stdint.h>
+#else
+/* add some missing <stdint.h> typedef's */
+typedef signed char int8_t;
+typedef unsigned char uint8_t;
+
+typedef short int16_t;
+typedef unsigned short uint16_t;
+
+typedef long int32_t;
+typedef unsigned long uint32_t;
+
+typedef long long int64_t;
+typedef unsigned long long uint64_t;
+
+typedef long long intmax_t;
+typedef unsigned long long uintmax_t;
+#endif
+
+#endif
+
+#endif /* INCLUDE_msvc_compat__ */