compat.h 2.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889
  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. #include <fcntl.h>
  63. #define HAVE_PIPE
  64. static inline int pipe(int fds[2])
  65. {
  66. return _pipe(fds, 32768, O_NOINHERIT | O_BINARY);
  67. }
  68. #endif
  69. #ifndef _WIN32
  70. #define closesocket(fd) close(fd)
  71. #endif
  72. #ifndef HAVE_STRUCT_TIMESPEC
  73. struct timespec {
  74. time_t tv_sec; /* Seconds */
  75. long tv_nsec; /* Nanoseconds */
  76. };
  77. #endif /* HAVE_STRUCT_TIMESPEC */
  78. #endif