compat.h 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108
  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. #ifdef __cplusplus
  24. extern "C" {
  25. #endif
  26. #ifndef HAVE_OFFSETOF
  27. #define offsetof(st, m) ((size_t)&((st *)NULL)->m)
  28. #endif
  29. #ifndef HAVE_MAKEDEV
  30. #define makedev(maj, min) ((((maj) & 0xff) << 8) | ((min) & 0xff))
  31. #endif
  32. #ifndef HAVE_O_NOFOLLOW
  33. #define O_NOFOLLOW 0
  34. #endif
  35. /*
  36. * Define WCOREDUMP if we don't have it already, coredumps won't be
  37. * detected, though.
  38. */
  39. #ifndef HAVE_WCOREDUMP
  40. #define WCOREDUMP(x) 0
  41. #endif
  42. #ifndef HAVE_VA_COPY
  43. #include <string.h>
  44. #define va_copy(dest, src) memcpy(&(dest), &(src), sizeof(va_list))
  45. #endif
  46. #ifndef HAVE_C99_SNPRINTF
  47. #include <stddef.h>
  48. #include <stdarg.h>
  49. int snprintf(char *str, size_t n, char const *fmt, ...);
  50. int vsnprintf(char *buf, size_t maxsize, const char *fmt, va_list args);
  51. #endif
  52. #ifndef HAVE_ASPRINTF
  53. #include <stdarg.h>
  54. int asprintf(char **str, char const *fmt, ...);
  55. int vasprintf(char **str, const char *fmt, va_list args);
  56. #endif
  57. #ifndef HAVE_STRNLEN
  58. size_t strnlen(const char *s, size_t n);
  59. #endif
  60. #ifndef HAVE_STRNDUP
  61. #include <stddef.h>
  62. #undef strndup
  63. char *strndup(const char *s, size_t n);
  64. #endif
  65. #ifndef HAVE_STRERROR
  66. const char *strerror(int);
  67. #endif
  68. #ifndef HAVE_STRSIGNAL
  69. const char *strsignal(int);
  70. #endif
  71. #ifndef HAVE_SCANDIR
  72. struct dirent;
  73. int scandir(const char *dir, struct dirent ***namelist,
  74. int (*filter)(const struct dirent *),
  75. int (*cmp)(const void *, const void *));
  76. #endif
  77. #ifndef HAVE_ALPHASORT
  78. int alphasort(const void *a, const void *b);
  79. #endif
  80. #ifndef HAVE_UNSETENV
  81. int unsetenv(const char *x);
  82. #endif
  83. #ifdef __cplusplus
  84. }
  85. #endif
  86. #endif /* COMPAT_H */