compat.h 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145
  1. /*
  2. * libcompat - system compatibility library
  3. * compat.h - system compatibility declarations
  4. *
  5. * Copyright © 1995 Ian Jackson <ian@chiark.greenend.org.uk>
  6. * Copyright © 2008, 2009 Guillem Jover <guillem@debian.org>
  7. *
  8. * This is free software; you can redistribute it and/or modify
  9. * it under the terms of the GNU General Public License as published by
  10. * the Free Software Foundation; either version 2 of the License, or
  11. * (at your option) any later version.
  12. *
  13. * This is distributed in the hope that it will be useful,
  14. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  15. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  16. * GNU General Public License for more details.
  17. *
  18. * You should have received a copy of the GNU General Public License
  19. * along with this program. If not, see <https://www.gnu.org/licenses/>.
  20. */
  21. #ifndef COMPAT_H
  22. #define COMPAT_H
  23. #ifndef TEST_LIBCOMPAT
  24. #define TEST_LIBCOMPAT 0
  25. #endif
  26. #if TEST_LIBCOMPAT || !defined(HAVE_STRNLEN) || !defined(HAVE_STRNDUP) || \
  27. !defined(HAVE_C99_SNPRINTF)
  28. #include <stddef.h>
  29. #endif
  30. #if TEST_LIBCOMPAT || !defined(HAVE_ASPRINTF) || !defined(HAVE_C99_SNPRINTF)
  31. #include <stdarg.h>
  32. #endif
  33. #if TEST_LIBCOMPAT || !defined(HAVE_VA_COPY)
  34. #include <string.h>
  35. #endif
  36. #ifdef __cplusplus
  37. extern "C" {
  38. #endif
  39. #ifndef HAVE_OFFSETOF
  40. #define offsetof(st, m) ((size_t)&((st *)NULL)->m)
  41. #endif
  42. #ifndef HAVE_MAKEDEV
  43. #define makedev(maj, min) ((((maj) & 0xff) << 8) | ((min) & 0xff))
  44. #endif
  45. #ifndef HAVE_O_NOFOLLOW
  46. #define O_NOFOLLOW 0
  47. #endif
  48. #ifndef HAVE_P_TMPDIR
  49. #define P_tmpdir "/tmp"
  50. #endif
  51. /*
  52. * Define WCOREDUMP if we don't have it already, coredumps won't be
  53. * detected, though.
  54. */
  55. #ifndef HAVE_WCOREDUMP
  56. #define WCOREDUMP(x) 0
  57. #endif
  58. #ifndef HAVE_VA_COPY
  59. #define va_copy(dest, src) memcpy(&(dest), &(src), sizeof(va_list))
  60. #endif
  61. #if TEST_LIBCOMPAT
  62. #undef snprintf
  63. #define snprintf test_snprintf
  64. #undef vsnprintf
  65. #define vsnprintf test_vsnprintf
  66. #undef asprintf
  67. #define asprintf test_asprintf
  68. #undef vasprintf
  69. #define vasprintf test_vasprintf
  70. #undef strndup
  71. #define strndup test_strndup
  72. #undef strnlen
  73. #define strnlen test_strnlen
  74. #undef strerror
  75. #define strerror test_strerror
  76. #undef strsignal
  77. #define strsignal test_strsignal
  78. #undef scandir
  79. #define scandir test_scandir
  80. #undef alphasort
  81. #define alphasort test_alphasort
  82. #undef unsetenv
  83. #define unsetenv test_unsetenv
  84. #endif
  85. #if TEST_LIBCOMPAT || !defined(HAVE_C99_SNPRINTF)
  86. int snprintf(char *str, size_t n, char const *fmt, ...);
  87. int vsnprintf(char *buf, size_t maxsize, const char *fmt, va_list args);
  88. #endif
  89. #if TEST_LIBCOMPAT || !defined(HAVE_ASPRINTF)
  90. int asprintf(char **str, char const *fmt, ...);
  91. int vasprintf(char **str, const char *fmt, va_list args);
  92. #endif
  93. #if TEST_LIBCOMPAT || !defined(HAVE_STRNLEN)
  94. size_t strnlen(const char *s, size_t n);
  95. #endif
  96. #if TEST_LIBCOMPAT || !defined(HAVE_STRNDUP)
  97. char *strndup(const char *s, size_t n);
  98. #endif
  99. #if TEST_LIBCOMPAT || !defined(HAVE_STRERROR)
  100. const char *strerror(int);
  101. #endif
  102. #if TEST_LIBCOMPAT || !defined(HAVE_STRSIGNAL)
  103. const char *strsignal(int);
  104. #endif
  105. #if TEST_LIBCOMPAT || !defined(HAVE_SCANDIR)
  106. struct dirent;
  107. int scandir(const char *dir, struct dirent ***namelist,
  108. int (*filter)(const struct dirent *),
  109. int (*cmp)(const void *, const void *));
  110. #endif
  111. #if TEST_LIBCOMPAT || !defined(HAVE_ALPHASORT)
  112. int alphasort(const void *a, const void *b);
  113. #endif
  114. #if TEST_LIBCOMPAT || !defined(HAVE_UNSETENV)
  115. int unsetenv(const char *x);
  116. #endif
  117. #ifdef __cplusplus
  118. }
  119. #endif
  120. #endif /* COMPAT_H */