compat.h 2.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394
  1. /*****************************************************************************
  2. * __________________ _________ _____ _____ .__ ._.
  3. * \______ \______ \ / _____/ / \ / _ \ |__| ____ | |
  4. * | | _/| | \ \_____ \ / \ / \ / /_\ \| _/ __ \ | |
  5. * | | \| ` \/ / Y \ / | | \ ___/ \|
  6. * |______ /_______ /_______ \____|__ / /\ \____|__ |__|\___ | __
  7. * \/ \/ \/ \/ )/ \/ \/ \/
  8. *
  9. * This file is part of liBDSM. Copyright © 2014-2015 VideoLabs SAS
  10. *
  11. * Author: Julien 'Lta' BALLET <contact@lta.io>
  12. *
  13. * liBDSM is released under LGPLv2.1 (or later) and is also available
  14. * under a commercial license.
  15. *****************************************************************************
  16. * This program is free software; you can redistribute it and/or modify it
  17. * under the terms of the GNU Lesser General Public License as published by
  18. * the Free Software Foundation; either version 2.1 of the License, or
  19. * (at your option) any later version.
  20. *
  21. * This program is distributed in the hope that it will be useful,
  22. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  23. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  24. * GNU Lesser General Public License for more details.
  25. *
  26. * You should have received a copy of the GNU Lesser General Public License
  27. * along with this program; if not, write to the Free Software Foundation,
  28. * Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA.
  29. *****************************************************************************/
  30. #ifndef BDSM_COMPAT_H
  31. # define BDSM_COMPAT_H
  32. #include <stdlib.h>
  33. #if !defined HAVE_STRLCPY && !defined HAVE_LIBBSD
  34. size_t strlcpy(char *dst, const char *src, size_t siz);
  35. #endif
  36. #ifndef HAVE_CLOCKID_T
  37. typedef int clockid_t;
  38. #endif
  39. #if !HAVE_DECL_CLOCK_MONOTONIC
  40. enum {
  41. CLOCK_REALTIME,
  42. CLOCK_MONOTONIC,
  43. CLOCK_PROCESS_CPUTIME_ID,
  44. CLOCK_THREAD_CPUTIME_ID
  45. };
  46. #endif
  47. #if !defined HAVE_CLOCK_GETTIME
  48. // We need a proper struct timespec definition
  49. #include <time.h>
  50. int clock_gettime(clockid_t clk_id, struct timespec *tp);
  51. #endif
  52. #if !defined HAVE_STRNDUP
  53. char *strndup(const char *str, size_t n);
  54. #endif
  55. #ifndef O_NONBLOCK
  56. # define O_NONBLOCK 0
  57. #endif
  58. #if !defined HAVE_SYS_QUEUE_H
  59. # include "queue.h"
  60. #endif
  61. #if !defined(HAVE_PIPE) && defined(HAVE__PIPE)
  62. # ifdef _WIN32
  63. # include <winapifamily.h>
  64. # endif
  65. # if !defined(_WIN32) || WINAPI_FAMILY_PARTITION(WINAPI_PARTITION_DESKTOP)
  66. # include <fcntl.h>
  67. # define HAVE_PIPE
  68. static inline int pipe(int fds[2])
  69. {
  70. return _pipe(fds, 32768, O_NOINHERIT | O_BINARY);
  71. }
  72. #endif
  73. #endif
  74. #ifndef _WIN32
  75. #define closesocket(fd) close(fd)
  76. #endif
  77. #ifndef HAVE_STRUCT_TIMESPEC
  78. struct timespec {
  79. time_t tv_sec; /* Seconds */
  80. long tv_nsec; /* Nanoseconds */
  81. };
  82. #endif /* HAVE_STRUCT_TIMESPEC */
  83. #endif