compat.h 7.4 KB

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