compatibility

master
Christien Rioux 9 years ago
parent 16143f4b04
commit 75ba1a9f4f

@ -23,9 +23,9 @@
#define MAP_FAILED NULL #define MAP_FAILED NULL
typedef long long tlc_fileoffset_t; typedef long long tlc_fileoffset_t;
#elif defined (__unix__) || (defined (__APPLE__) && defined (__MACH__)) #elif defined(TLC_COMPATIBLE_UNIX)
// POSIX // Compatible Unix
#include<sys/types.h> #include<sys/types.h>
#include<sys/stat.h> #include<sys/stat.h>
#include<sys/fcntl.h> #include<sys/fcntl.h>
@ -36,7 +36,7 @@ typedef off_t tlc_fileoffset_t;
#define MMAP ::mmap #define MMAP ::mmap
#define FSTAT ::fstat #define FSTAT ::fstat
#define STAT ::stat #define STAT ::stat
#elif defined(__linux__) #elif (defined(__linux__) || defined(__cygwin__)) && defined(_LARGEFILE64_SOURCE)
typedef off64_t tlc_fileoffset_t; typedef off64_t tlc_fileoffset_t;
#define MMAP ::mmap64 #define MMAP ::mmap64
#define FSTAT ::fstat64 #define FSTAT ::fstat64
@ -571,7 +571,7 @@ long long turbo_linecount_handle(int fhandle, tlc_error_t * error, char ** error
#ifdef _WIN32 #ifdef _WIN32
long long turbo_linecount_file(const TCHAR *filename, tlc_error_t * error, TCHAR ** errorstring) long long turbo_linecount_file(const TCHAR *filename, tlc_error_t * error, TCHAR ** errorstring)
#else #elif defined(TLC_COMPATIBLE_UNIX)
long long turbo_linecount_file(const char *filename, tlc_error_t * error, char ** errorstring) long long turbo_linecount_file(const char *filename, tlc_error_t * error, char ** errorstring)
#endif #endif
{ {

@ -27,16 +27,32 @@
////////////// Platform specific ////////////// Platform specific
#if defined(_APPLE__) || defined(__CYGWIN__) || defined(__linux__) || defined(__MINGW32__)
#define TLC_COMPATIBLE_UNIX 1
#endif
#if defined(__CYGWIN__) || defined(__linux__) || defined(__MINGW32__)
#ifndef _LARGEFILE64_SOURCE
#define _LARGEFILE64_SOURCE 1
#endif
#endif
#ifdef _WIN32 // Windows #ifdef _WIN32 // Windows
#include<Windows.h> #include<Windows.h>
#include<tchar.h> #include<tchar.h>
typedef errno_t tlc_error_t; typedef errno_t tlc_error_t;
#elif defined (__unix__) || (defined (__APPLE__) && defined (__MACH__)) // POSIX
#elif defined(TLC_COMPATIBLE_UNIX)
#include<unistd.h> #include<unistd.h>
#include<pthread.h> #include<pthread.h>
#define _T(x) x #define _T(x) x
#define TCHAR char #define TCHAR char
typedef tlc_error_t tlc_error_t; typedef tlc_error_t tlc_error_t;
#else
#error Unsupported operating system.
#endif #endif
///////////////////////////////////////////// Line Count Class ///////////////////////////////////////////// Line Count Class
@ -57,14 +73,14 @@ BEGIN_TURBOLINECOUNT_NAMESPACE;
typedef tlc_fileoffset_t tlc_linecount_t; typedef tlc_fileoffset_t tlc_linecount_t;
#define TLC_LINECOUNT_FMT "%I64d" #define TLC_LINECOUNT_FMT "%I64d"
#elif defined (__unix__) || (defined (__APPLE__) && defined (__MACH__)) // POSIX #elif defined(TLC_COMPATIBLE_UNIX) // Unix
typedef std::string tlc_string_t; typedef std::string tlc_string_t;
typedef int tlc_filehandle_t; typedef int tlc_filehandle_t;
#if (defined (__APPLE__) && defined (__MACH__)) #if (defined (__APPLE__) && defined (__MACH__))
typedef off_t tlc_fileoffset_t; typedef off_t tlc_fileoffset_t;
#define TLC_LINECOUNT_FMT "%lld" #define TLC_LINECOUNT_FMT "%lld"
#elif defined(__linux__) #elif defined(_LARGEFILE64_SOURCE)
typedef off64_t tlc_fileoffset_t; typedef off64_t tlc_fileoffset_t;
#define TLC_LINECOUNT_FMT "%lld" #define TLC_LINECOUNT_FMT "%lld"
#else #else
@ -99,7 +115,7 @@ private:
#ifdef _WIN32 #ifdef _WIN32
std::vector<HANDLE> m_threads; std::vector<HANDLE> m_threads;
HANDLE m_filemapping; HANDLE m_filemapping;
#else #elif defined(TLC_COMPATIBLE_UNIX)
std::vector<pthread_t> m_threads; std::vector<pthread_t> m_threads;
#endif #endif
std::vector<tlc_linecount_t> m_threadlinecounts; std::vector<tlc_linecount_t> m_threadlinecounts;
@ -112,7 +128,7 @@ private:
bool createThread(int thread_number); bool createThread(int thread_number);
#ifdef _WIN32 #ifdef _WIN32
friend DWORD WINAPI threadProc(LPVOID ctx); friend DWORD WINAPI threadProc(LPVOID ctx);
#else #elif defined(TLC_COMPATIBLE_UNIX)
friend void *threadProc(void *ctx); friend void *threadProc(void *ctx);
#endif #endif
unsigned int countThread(int thread_number); unsigned int countThread(int thread_number);
@ -155,7 +171,7 @@ extern "C"
#ifdef _WIN32 #ifdef _WIN32
long long turbo_linecount_handle(HANDLE fhandle, tlc_error_t * error = NULL, TCHAR ** errorstring = NULL); long long turbo_linecount_handle(HANDLE fhandle, tlc_error_t * error = NULL, TCHAR ** errorstring = NULL);
long long turbo_linecount_file(const TCHAR *filename, tlc_error_t * error = NULL, TCHAR ** errorstring = NULL); long long turbo_linecount_file(const TCHAR *filename, tlc_error_t * error = NULL, TCHAR ** errorstring = NULL);
#else #elif defined(TLC_COMPATIBLE_UNIX)
long long turbo_linecount_handle(int fhandle, tlc_error_t * tlc_error = NULL, char ** errorstring = NULL); long long turbo_linecount_handle(int fhandle, tlc_error_t * tlc_error = NULL, char ** errorstring = NULL);
long long turbo_linecount_file(const char *filename, tlc_error_t * error = NULL, char ** errorstring = NULL); long long turbo_linecount_file(const char *filename, tlc_error_t * error = NULL, char ** errorstring = NULL);
#endif #endif

Loading…
Cancel
Save