sd_xplatform.h 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137
  1. /* $Id$
  2. *
  3. * sd_xplatform.h
  4. *
  5. * See the COPYING file for the terms of usage and distribution.
  6. */
  7. #ifndef __sd_xplatform_h
  8. #define __sd_xplatform_h
  9. #ifndef _WIN32
  10. #include <unistd.h>
  11. #include <sys/time.h>
  12. #include <sys/stat.h>
  13. #else
  14. #include <time.h>
  15. #include <io.h> /* needed for _access */
  16. #define WIN32_LEAN_AND_MEAN
  17. #include <windows.h>
  18. #include <winsock2.h>
  19. #include <process.h>
  20. #endif
  21. #ifdef HAVE_STDINT_H
  22. # include <stdint.h>
  23. #define XP_UINT64 uint64_t
  24. #define XP_INT64 int64_t
  25. #else
  26. #ifndef _WIN32
  27. #define XP_UINT64 unsigned long long
  28. #define XP_INT64 long long
  29. #else
  30. #define XP_UINT64 DWORD64
  31. #define XP_INT64 __int64
  32. #endif
  33. #endif
  34. #include <log4c/defs.h>
  35. #include <sd/defs.h>
  36. /*extern int sd_optind; */
  37. LOG4C_DATA int sd_optind;
  38. extern void getopt_reset(void);
  39. extern int sd_getopt(int argc, char *const *argv, const char *opts);
  40. #ifdef _WIN32
  41. #define SD_GETOPT(a,b,c) sd_getopt(a,b,c)
  42. #define SD_OPTIND sd_optind
  43. #else
  44. #define SD_GETOPT(a,b,c) getopt(a,b,c)
  45. #define SD_OPTIND optind
  46. #endif
  47. #ifdef _WIN32
  48. #define SD_GETTIMEOFDAY(a,b) sd_gettimeofday(a,b)
  49. extern int sd_gettimeofday(LPFILETIME lpft, void* tzp);
  50. #else
  51. #define SD_GETTIMEOFDAY(a,b) gettimeofday(a,b)
  52. extern int sd_gettimeofday(struct timeval* tp, void* tzp);
  53. #endif
  54. #ifdef _WIN32
  55. #define FILE_SEP "\\"
  56. #else
  57. #define FILE_SEP "/"
  58. #endif
  59. #ifdef _WIN32
  60. #define SD_ACCESS_READ(a) _access(a,04)
  61. #else
  62. #define SD_ACCESS_READ(a) access(a,R_OK)
  63. #endif
  64. int sd_stat_ctime(const char* path, time_t* time);
  65. #define SD_STAT_CTIME(path, time) sd_stat_ctime(path, time)
  66. #ifndef _WIN32
  67. #define DIFF_CMD "/usr/bin/diff -q"
  68. #else
  69. #define DIFF_CMD "comp.exe"
  70. #endif
  71. #ifdef _WIN32
  72. #define snprintf _snprintf
  73. #define vsnprintf _vsnprintf
  74. #define alloca _alloca
  75. #define strncasecmp _strnicmp
  76. #define strcasecmp _stricmp
  77. #define YY_NO_UNISTD_H
  78. #define sleep(x) Sleep(x*1000)
  79. #endif
  80. /* Maybe should be using this for to mean
  81. * MS compiler #if defined(_MSC_VER)
  82. */
  83. #ifdef _WIN32
  84. #define pthread_t HANDLE
  85. #define pthread_mutex_t HANDLE
  86. #define pthread_attr_t DWORD
  87. #define THREAD_FUNCTION DWORD (WINAPI *)(void *)
  88. /*
  89. * This one not obvious: you would have naturally thought of mapping to
  90. * CreateThread()--turns out that to be safe using CRT functions
  91. * you need to use _begintheadex().
  92. * cf. http://msdn2.microsoft.com/en-us/library/7t9ha0zh.aspx
  93. * http://groups.google.com/group/comp.os.ms-windows.programmer.win32/browse_thread/thread/86d8624e7ee38c5d/f947ac76cd10f397?lnk=st&q=when+to+use+_beginthreadex&rnum=1#f947ac76cd10f397
  94. *
  95. */
  96. #define pthread_create(thhandle,attr,thfunc,tharg) \
  97. (int)((*thhandle=(HANDLE)_beginthreadex(NULL,0,(THREAD_FUNCTION)thfunc,tharg,0,NULL))==NULL)
  98. #define pthread_join(thread, result) \
  99. ((WaitForSingleObject((thread),INFINITE)!=WAIT_OBJECT_0) || !CloseHandle(thread))
  100. #define pthread_exit() _endthreadex(0)
  101. #define pthread_cancel(thread) TerminateThread(thread,0)
  102. #define pthread_mutex_init(pobject,pattr) (*pobject=CreateMutex(NULL,FALSE,NULL))
  103. #define pthread_mutex_lock(pobject) WaitForSingleObject(*pobject,INFINITE)
  104. #define pthread_mutex_unlock(pobject) ReleaseMutex(*pobject)
  105. #define pthread_mutex_destroy(pobject) CloseHandle(*pobject)
  106. #endif
  107. #ifdef __HP_cc
  108. #define inline __inline
  109. #endif
  110. #endif