1
0

compat.h 7.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332
  1. /* prototypes for borrowed "compatibility" code */
  2. #include <libtar/config.h>
  3. #include <sys/types.h>
  4. #include <sys/stat.h>
  5. #ifdef STDC_HEADERS
  6. # include <stdarg.h>
  7. # include <stddef.h>
  8. #else
  9. # include <varargs.h>
  10. #endif
  11. #ifdef HAVE_LIBGEN_H
  12. # include <libgen.h>
  13. #endif
  14. #ifdef __cplusplus
  15. extern "C" {
  16. #endif
  17. #if defined(NEED_BASENAME) && !defined(HAVE_BASENAME)
  18. # ifdef basename
  19. # undef basename /* fix glibc brokenness */
  20. # endif
  21. char *openbsd_basename(const char *);
  22. # define basename openbsd_basename
  23. #endif /* NEED_BASENAME && ! HAVE_BASENAME */
  24. #if defined(NEED_DIRNAME) && !defined(HAVE_DIRNAME)
  25. char *openbsd_dirname(const char *);
  26. # define dirname openbsd_dirname
  27. #endif /* NEED_DIRNAME && ! HAVE_DIRNAME */
  28. #ifdef NEED_FNMATCH
  29. # ifndef HAVE_FNMATCH
  30. # define FNM_NOMATCH 1 /* Match failed. */
  31. # define FNM_NOESCAPE 0x01 /* Disable backslash escaping. */
  32. # define FNM_PATHNAME 0x02 /* Slash must be matched by slash. */
  33. # define FNM_PERIOD 0x04 /* Period must be matched by period. */
  34. # define FNM_LEADING_DIR 0x08 /* Ignore /<tail> after Imatch. */
  35. # define FNM_CASEFOLD 0x10 /* Case insensitive search. */
  36. # define FNM_IGNORECASE FNM_CASEFOLD
  37. # define FNM_FILE_NAME FNM_PATHNAME
  38. int openbsd_fnmatch(const char *, const char *, int);
  39. # define fnmatch openbsd_fnmatch
  40. # else /* HAVE_FNMATCH */
  41. # ifdef HAVE_FNMATCH_H
  42. # include <fnmatch.h>
  43. # endif
  44. # endif /* ! HAVE_FNMATCH */
  45. #endif /* NEED_FNMATCH */
  46. #ifdef NEED_GETHOSTBYNAME_R
  47. # include <netdb.h>
  48. # if GETHOSTBYNAME_R_NUM_ARGS != 6
  49. int compat_gethostbyname_r(const char *, struct hostent *,
  50. char *, size_t, struct hostent **, int *);
  51. # define gethostbyname_r compat_gethostbyname_r
  52. # endif /* GETHOSTBYNAME_R_NUM_ARGS != 6 */
  53. #endif /* NEED_GETHOSTBYNAME_R */
  54. #if defined(NEED_GETHOSTNAME) && !defined(HAVE_GETHOSTNAME)
  55. int gethostname(char *, size_t);
  56. #endif /* NEED_GETHOSTNAME && ! HAVE_GETHOSTNAME */
  57. #ifdef NEED_GETSERVBYNAME_R
  58. # include <netdb.h>
  59. # if GETSERVBYNAME_R_NUM_ARGS != 6
  60. int compat_getservbyname_r(const char *, const char *, struct servent *,
  61. char *, size_t, struct servent **);
  62. # define getservbyname_r compat_getservbyname_r
  63. # endif /* GETSERVBYNAME_R_NUM_ARGS != 6 */
  64. #endif /* NEED_GETSERVBYNAME_R */
  65. #ifdef NEED_GLOB
  66. # ifndef HAVE_GLOB
  67. typedef struct {
  68. int gl_pathc; /* Count of total paths so far. */
  69. int gl_matchc; /* Count of paths matching pattern. */
  70. int gl_offs; /* Reserved at beginning of gl_pathv. */
  71. int gl_flags; /* Copy of flags parameter to glob. */
  72. char **gl_pathv; /* List of paths matching pattern. */
  73. /* Copy of errfunc parameter to glob. */
  74. int (*gl_errfunc)(const char *, int);
  75. /*
  76. * Alternate filesystem access methods for glob; replacement
  77. * versions of closedir(3), readdir(3), opendir(3), stat(2)
  78. * and lstat(2).
  79. */
  80. void (*gl_closedir)(void *);
  81. struct dirent *(*gl_readdir)(void *);
  82. void *(*gl_opendir)(const char *);
  83. int (*gl_lstat)(const char *, struct stat *);
  84. int (*gl_stat)(const char *, struct stat *);
  85. } glob_t;
  86. /* Flags */
  87. # define GLOB_APPEND 0x0001 /* Append to output from previous call. */
  88. # define GLOB_DOOFFS 0x0002 /* Use gl_offs. */
  89. # define GLOB_ERR 0x0004 /* Return on error. */
  90. # define GLOB_MARK 0x0008 /* Append / to matching directories. */
  91. # define GLOB_NOCHECK 0x0010 /* Return pattern itself if nothing matches. */
  92. # define GLOB_NOSORT 0x0020 /* Don't sort. */
  93. # define GLOB_ALTDIRFUNC 0x0040 /* Use alternately specified directory funcs. */
  94. # define GLOB_BRACE 0x0080 /* Expand braces ala csh. */
  95. # define GLOB_MAGCHAR 0x0100 /* Pattern had globbing characters. */
  96. # define GLOB_NOMAGIC 0x0200 /* GLOB_NOCHECK without magic chars (csh). */
  97. # define GLOB_QUOTE 0x0400 /* Quote special chars with \. */
  98. # define GLOB_TILDE 0x0800 /* Expand tilde names from the passwd file. */
  99. # define GLOB_NOESCAPE 0x1000 /* Disable backslash escaping. */
  100. /* Error values returned by glob(3) */
  101. # define GLOB_NOSPACE (-1) /* Malloc call failed. */
  102. # define GLOB_ABORTED (-2) /* Unignored error. */
  103. # define GLOB_NOMATCH (-3) /* No match and GLOB_NOCHECK not set. */
  104. # define GLOB_NOSYS (-4) /* Function not supported. */
  105. # define GLOB_ABEND GLOB_ABORTED
  106. int openbsd_glob(const char *, int, int (*)(const char *, int), glob_t *);
  107. void openbsd_globfree(glob_t *);
  108. # define glob openbsd_glob
  109. # define globfree openbsd_globfree
  110. # else /* HAVE_GLOB */
  111. # ifdef HAVE_GLOB_H
  112. # include <glob.h>
  113. # endif
  114. # endif /* ! HAVE_GLOB */
  115. #endif /* NEED_GLOB */
  116. #if defined(NEED_INET_ATON) && !defined(HAVE_INET_ATON)
  117. int inet_aton(const char *, struct in_addr *);
  118. #endif /* NEED_INET_ATON && ! HAVE_INET_ATON */
  119. #ifdef NEED_MAKEDEV
  120. # ifdef MAJOR_IN_MKDEV
  121. # include <sys/mkdev.h>
  122. # else
  123. # ifdef MAJOR_IN_SYSMACROS
  124. # include <sys/sysmacros.h>
  125. # endif
  126. # endif
  127. /*
  128. ** On most systems makedev() has two args.
  129. ** Some weird systems, like QNX6, have makedev() functions that expect
  130. ** an extra first argument for "node", which can be 0 for a local
  131. ** machine.
  132. */
  133. # ifdef MAKEDEV_THREE_ARGS
  134. # define compat_makedev(maj, min) makedev(0, maj, min)
  135. # else
  136. # define compat_makedev makedev
  137. # endif
  138. #endif /* NEED_MAKEDEV */
  139. #ifdef _MSC_VER /* compile snprintf only onwin32 */
  140. #if !defined(HAVE_SNPRINTF)
  141. int mutt_snprintf(char *, size_t, const char *, ...);
  142. # define snprintf mutt_snprintf
  143. #endif
  144. #if !defined(HAVE_VSNPRINTF)
  145. int mutt_vsnprintf(char *, size_t, const char *, va_list);
  146. # define vsnprintf mutt_vsnprintf
  147. #endif /* NEED_SNPRINTF && ! HAVE_SNPRINTF */
  148. #endif
  149. #if defined(NEED_STRLCAT) && !defined(HAVE_STRLCAT)
  150. size_t strlcat(char *, const char *, size_t);
  151. #endif /* NEED_STRLCAT && ! HAVE_STRLCAT */
  152. #if defined(NEED_STRLCPY) && !defined(HAVE_STRLCPY)
  153. size_t strlcpy(char *, const char *, size_t);
  154. #endif /* NEED_STRLCPY && ! HAVE_STRLCPY */
  155. #if defined(NEED_STRDUP) && !defined(HAVE_STRDUP)
  156. char *openbsd_strdup(const char *);
  157. # define strdup openbsd_strdup
  158. #endif /* NEED_STRDUP && ! HAVE_STRDUP */
  159. #if defined(NEED_STRMODE) && !defined(HAVE_STRMODE)
  160. void strmode(register mode_t, register char *);
  161. #endif /* NEED_STRMODE && ! HAVE_STRMODE */
  162. #if defined(NEED_STRRSTR) && !defined(HAVE_STRRSTR)
  163. char *strrstr(char *, char *);
  164. #endif /* NEED_STRRSTR && ! HAVE_STRRSTR */
  165. #ifdef NEED_STRSEP
  166. # ifdef HAVE_STRSEP
  167. # define _LINUX_SOURCE_COMPAT /* needed on AIX 4.3.3 */
  168. # else
  169. char *strsep(register char **, register const char *);
  170. # endif
  171. #endif /* NEED_STRSEP */
  172. #ifdef _MSC_VER
  173. #include <stdlib.h>
  174. #define MAXPATHLEN _MAX_PATH
  175. #ifndef O_ACCMODE
  176. # define O_ACCMODE 0x0003
  177. #endif
  178. #endif
  179. #ifndef S_ISREG
  180. #ifndef S_IFREG
  181. #ifndef _S_IFREG
  182. #define S_IFREG (-1)
  183. #else
  184. #define S_IFREG _S_IFREG
  185. #endif
  186. #endif
  187. #define S_ISREG(m) (((m)&S_IFREG)==S_IFREG)
  188. #endif
  189. #ifndef S_ISDIR
  190. #ifndef S_IFDIR
  191. #ifndef _S_IFDIR
  192. #define S_IFDIR (-1)
  193. #else
  194. #define S_IFDIR _S_IFDIR
  195. #endif
  196. #endif
  197. #define S_ISDIR(m) (((m)&S_IFDIR)==S_IFDIR)
  198. #endif
  199. #ifndef S_ISBLK
  200. #ifndef S_IFBLK
  201. #ifndef _S_IFBLK
  202. #define S_IFBLK (-1)
  203. #else
  204. #define S_IFBLK _S_IFBLK
  205. #endif
  206. #endif
  207. #define S_ISBLK(m) (((m)&S_IFBLK)==S_IFBLK)
  208. #endif
  209. #ifndef S_ISFIFO
  210. #ifndef S_IFFIFO
  211. #ifndef _S_IFFIFO
  212. #define S_IFFIFO (-1)
  213. #else
  214. #define S_IFFIFO _S_IFFIFO
  215. #endif
  216. #endif
  217. #define S_ISFIFO(m) (((m)&S_IFFIFO)==S_IFFIFO)
  218. #endif
  219. #if !defined(TAR_MAXPATHLEN)
  220. # if defined(PATH_MAX)
  221. # define TAR_MAXPATHLEN PATH_MAX
  222. # elif defined(MAXPATHLEN)
  223. # define TAR_MAXPATHLEN MAXPATHLEN
  224. # else
  225. # define TAR_MAXPATHLEN 16384
  226. # endif
  227. #endif
  228. #ifdef __cplusplus
  229. }
  230. #endif