1 # COMPAT_VAR___PROGNAME
2 # ---------------------
3 # Check if libc defines the __progname variable.
4 AC_DEFUN([COMPAT_VAR___PROGNAME], [
5 AC_CACHE_CHECK([if libc defines __progname],
6 [ac_cv_libc_defines___progname],
9 extern char *__progname;
10 printf("%s", __progname);
12 [ac_cv_libc_defines___progname=yes],
13 [ac_cv_libc_defines___progname=no]
16 if test "$ac_cv_libc_defines___progname" = "yes"; then
17 AC_DEFINE([HAVE___PROGNAME], 1,
18 [Define if libc defines the __progname variable])
23 # COMPAT_FUNC_BASENAME
24 # --------------------
25 # Check for working basename() function.
26 AC_DEFUN([COMPAT_FUNC_BASENAME], [
27 AC_DEFINE([NEED_BASENAME], 1,
28 [Define if you want to use the basename function])
29 AC_CHECK_HEADERS([libgen.h])
30 AC_CACHE_CHECK([for working basename],
31 [compat_cv_func_basename_works],
43 const test_t tests[] = {
44 { "/usr/local/foo", "foo" },
45 { "/usr/local/foo/", "foo" },
53 for (i = 0; tests[i].test; i++) {
54 strcpy(test1, tests[i].test);
55 if (strcmp(basename(test1), tests[i].result) ||
56 strcmp(test1, tests[i].test))
63 [compat_cv_func_basename_works=yes],
64 [compat_cv_func_basename_works=no],
65 [compat_cv_func_basename_works=no]
68 if test "$compat_cv_func_basename_works" = "yes"; then
69 AC_DEFINE([HAVE_BASENAME], 1,
70 [Define if your system has a working basename])
79 # Check for working dirname() function.
80 AC_DEFUN([COMPAT_FUNC_DIRNAME], [
81 AC_DEFINE([NEED_DIRNAME], 1,
82 [Define if you want to use the dirname function])
83 AC_CHECK_HEADERS([libgen.h])
84 AC_CACHE_CHECK([for working dirname],
85 [compat_cv_func_dirname_works],
97 const test_t tests[] = {
99 { "/usr/local/foo", "/usr/local" },
100 { "/usr/local/foo/", "/usr/local" },
110 for (i = 0; tests[i].test; i++) {
111 strcpy(test1, tests[i].test);
112 if (strcmp(dirname(test1), tests[i].result) ||
113 strcmp(test1, tests[i].test))
120 [compat_cv_func_dirname_works=yes],
121 [compat_cv_func_dirname_works=no],
122 [compat_cv_func_dirname_works=no]
125 if test "$compat_cv_func_dirname_works" = "yes"; then
126 AC_DEFINE([HAVE_DIRNAME], 1,
127 [Define if your system has a working dirname])
134 # COMPAT_FUNC_FNMATCH
135 # -------------------
136 # Check for working fnmatch() function.
137 AC_DEFUN([COMPAT_FUNC_FNMATCH], [
138 AC_DEFINE([NEED_FNMATCH], 1, [Define if you want to use the fnmatch function])
139 AC_CHECK_HEADERS([fnmatch.h])
140 if test "$ac_cv_header_fnmatch_h" = "yes"; then
143 if test "$ac_cv_func_fnmatch_works" != "yes"; then
144 AC_CHECK_HEADERS([ctype.h])
152 # Check for working glob() function.
153 AC_DEFUN([COMPAT_FUNC_GLOB], [
154 AC_DEFINE([NEED_GLOB], 1, [Define if you want to use the glob function])
155 AC_CHECK_HEADERS([glob.h])
156 AC_CACHE_CHECK([for working glob],
157 [compat_cv_func_glob_works],
165 # define GLOB_ABORTED GLOB_ABEND
172 status = glob("conf*", 0, NULL, &g);
186 [compat_cv_func_glob_works=yes],
187 [compat_cv_func_glob_works=no],
188 [compat_cv_func_glob_works=no]
191 if test "$compat_cv_func_glob_works" = "yes"; then
192 AC_DEFINE([HAVE_GLOB], 1, [Define if your system has a working glob])
195 AC_CHECK_FUNCS([issetugid])
200 # COMPAT_FUNC_MAKEDEV
201 # -------------------
202 # Check for number of arguments expected by makedev().
203 AC_DEFUN([COMPAT_FUNC_MAKEDEV], [
204 AC_REQUIRE([AC_HEADER_MAJOR])
205 AC_DEFINE([NEED_MAKEDEV], 1,
206 [Define if you want to use the makedev function])
207 AC_CACHE_CHECK([whether makedev expects three arguments],
208 [compat_cv_func_makedev_three_args],
211 #include <sys/types.h>
212 #ifdef MAJOR_IN_MKDEV
213 # include <sys/mkdev.h>
215 # ifdef MAJOR_IN_SYSMACROS
216 # include <sys/sysmacros.h>
224 dev = makedev(0, maj, min);
225 if (major(dev) != maj
226 || minor(dev) != min)
230 [compat_cv_func_makedev_three_args=yes],
231 [compat_cv_func_makedev_three_args=no]
234 if test "$compat_cv_func_makedev_three_args" = "yes"; then
235 AC_DEFINE([MAKEDEV_THREE_ARGS], 1,
236 [Define as 1 if makedev expects three arguments])
241 # COMPAT_FUNC_SNPRINTF
242 # --------------------
243 # Check for working snprintf() function.
244 AC_DEFUN([COMPAT_FUNC_SNPRINTF], [
245 AC_DEFINE([NEED_SNPRINTF], 1,
246 [Define if you want to use the snprintf function])
247 AC_CACHE_CHECK([for working snprintf],
248 [compat_cv_func_snprintf_works],
259 const test_t tests[] = {
260 { 10, "12345678901234567890", 20, "123456789" },
262 { 0, "12345678901234567890", 20, NULL },
263 { -1, "12345678901234567890", -1, NULL },
272 for (i = 0; tests[i].test; i++) {
273 memset(test1, 'X', sizeof(test1));
274 if ((snprintf(test1, tests[i].length, "%s", tests[i].test)
275 != tests[i].retval) ||
276 (tests[i].result && strcmp(tests[i].result, test1)))
283 [compat_cv_func_snprintf_works=yes],
284 [compat_cv_func_snprintf_works=no],
285 [compat_cv_func_snprintf_works=no]
288 if test "$compat_cv_func_snprintf_works" = "yes"; then
289 AC_DEFINE([HAVE_SNPRINTF], 1,
290 [Define if your system has a working snprintf])
292 AC_LIBOBJ([snprintf])
297 # COMPAT_PROTO_MACRO(FUNCTION, HEADER, MACRO-LIST, [BODY])
298 # --------------------------------------------------------
299 # Determine which C preprocessor macro is needed to expose prototype of
300 # FUNCTION in HEADER. First, we try with nothing special defined; then we
301 # try with each macro from MACRO-LIST. We stop as soon as it's found
302 # and adjust $CFLAGS appropriately.
303 AC_DEFUN([COMPAT_PROTO_MACRO],
304 [AC_CACHE_CHECK([what to define for $1 prototype],
305 [compat_cv_proto_]$1[_macro],
315 [compat_cv_proto_]$1[_macro="none"],
328 compat_cv_proto_]$1[_macro="$macro"
331 [compat_cv_proto_]$1[_macro="not found"]
336 if test -n "$compat_cv_proto_$1_macro" -a "$compat_cv_proto_$1_macro" != "not found" -a "$compat_cv_proto_$1_macro" != "none"; then
337 CFLAGS="${CFLAGS} -D$compat_cv_proto_$1_macro";
342 # COMPAT_FUNC_STRTOK_R
343 # --------------------
344 # Check for working strtok_r().
345 AC_DEFUN([COMPAT_FUNC_STRTOK_R], [
346 AC_DEFINE([NEED_STRTOK_R], 1,
347 [Define if you want to use the strtok_r function])
348 AC_REPLACE_FUNCS([strtok_r])
349 COMPAT_PROTO_MACRO([strtok_r], [string.h], [_REENTRANT _THREAD_SAFE])
353 # COMPAT_FUNC_GETPWUID_R
354 # ----------------------
355 # Check for POSIX-compliant getpwuid_r().
356 AC_DEFUN([COMPAT_FUNC_GETPWUID_R], [
357 COMPAT_PROTO_MACRO([getpwuid_r], [pwd.h],
358 [_POSIX_PTHREAD_SEMANTICS _REENTRANT],
360 struct passwd pwd, *pwdp;
362 getpwuid_r(0, &pwd, buf, sizeof(buf), &pwdp);
365 if test "$compat_cv_proto_getpwuid_r_macro" != "not found"; then
366 AC_DEFINE([HAVE_GETPWUID_R], 1,
367 [Define if your system has a POSIX-compliant getpwuid_r])
369 AC_MSG_WARN([cannot find usable getpwuid_r - resulting libraries will not be thread-safe])
374 # COMPAT_FUNC_GETHOSTBYNAME_R
375 # ---------------------------
376 # Check for gethostbyname_r().
377 AC_DEFUN([COMPAT_FUNC_GETHOSTBYNAME_R], [
378 AC_REQUIRE([AC_TYPE_SIZE_T])
379 AC_DEFINE([NEED_GETHOSTBYNAME_R], 1,
380 [Define if you want to use the gethostbyname_r function])
381 AC_SEARCH_LIBS([gethostbyname_r], [nsl])
382 if test "$ac_cv_search_gethostbyname_r" != "no"; then
383 COMPAT_PROTO_MACRO([gethostbyname_r], [netdb.h], [_REENTRANT])
385 [for number of arguments to gethostbyname_r],
386 [compat_cv_gethostbyname_r_args],
396 gethostbyname_r("localhost", &hent, buf, sizeof(buf), &herr);
398 [compat_cv_gethostbyname_r_args=5],
404 struct hostent hent, *hp;
408 gethostbyname_r("localhost", &hent, buf, sizeof(buf), &hp, &herr);
410 [compat_cv_gethostbyname_r_args=6],
417 struct hostent_data hdata;
419 gethostbyname_r("localhost", &hent, &hdata);
421 [compat_cv_gethostbyname_r_args=3],
422 [compat_cv_gethostbyname_r_args=no]
427 if test "$compat_cv_gethostbyname_r_args" != "no"; then
428 AC_DEFINE([HAVE_GETHOSTBYNAME_R], 1,
429 [Define if you have the gethostbyname_r function])
430 AC_DEFINE_UNQUOTED([GETHOSTBYNAME_R_NUM_ARGS],
431 [$compat_cv_gethostbyname_r_args],
432 [Define to number of arguments for gethostbyname_r])
433 if test "$compat_cv_gethostbyname_r_args" != "6"; then
434 AC_LIBOBJ([gethostbyname_r])
437 AC_MSG_WARN([unknown form of gethostbyname_r - resulting libraries will not be thread-safe])
440 AC_MSG_WARN([cannot find gethostbyname_r - resulting libraries will not be thread-safe])
445 # COMPAT_FUNC_GETSERVBYNAME_R
446 # ---------------------------
447 # Check for getservbyname_r().
448 AC_DEFUN([COMPAT_FUNC_GETSERVBYNAME_R], [
449 AC_REQUIRE([AC_TYPE_SIZE_T])
450 AC_DEFINE([NEED_GETSERVBYNAME_R], 1,
451 [Define if you want to use the getservbyname_r function])
452 AC_SEARCH_LIBS([getservbyname_r], [socket nsl])
453 if test "$ac_cv_search_getservbyname_r" != "no"; then
454 COMPAT_PROTO_MACRO([getservbyname_r], [netdb.h], [_REENTRANT])
456 [for number of arguments to getservbyname_r],
457 [compat_cv_getservbyname_r_args],
466 getservbyname_r("telnet", "tcp", &sent, buf, sizeof(buf));
468 [compat_cv_getservbyname_r_args=5],
474 struct servent sent, *sp;
477 getservbyname_r("telnet", "tcp", &sent, buf, sizeof(buf), &sp);
479 [compat_cv_getservbyname_r_args=6],
486 struct servent_data sdata;
488 getservbyname_r("telnet", "tcp", &sent, &sdata);
490 [compat_cv_getservbyname_r_args=4],
491 [compat_cv_getservbyname_r_args=no]
496 if test "$compat_cv_getservbyname_r_args" != "no"; then
497 AC_DEFINE([HAVE_GETSERVBYNAME_R], 1,
498 [Define if you have the getservbyname_r function])
499 AC_DEFINE_UNQUOTED([GETSERVBYNAME_R_NUM_ARGS],
500 [$compat_cv_getservbyname_r_args],
501 [Define to number of arguments for getservbyname_r])
502 if test "$compat_cv_getservbyname_r_args" != "6"; then
503 AC_LIBOBJ([getservbyname_r])
506 AC_MSG_WARN([unknown form of getservbyname_r - resulting libraries will not be thread-safe])
509 AC_MSG_WARN([cannot find getservbyname_r - resulting libraries will not be thread-safe])
514 # COMPAT_REPLACE_FUNC(function)
515 # -----------------------------
516 # Replacement for AC_REPLACE_FUNCS.
517 AC_DEFUN([COMPAT_REPLACE_FUNC], [
518 AC_DEFINE([NEED_]translit($1,[a-z],[A-Z]), 1,
519 [Define if you want to use the ]$1[ function])
521 [AC_DEFINE([HAVE_]translit($1,[a-z],[A-Z]), 1,
522 [Define if you have the ]$1[ function])],
528 # COMPAT_FUNC_GETHOSTNAME
529 # -----------------------
530 # Check for gethostname().
531 AC_DEFUN([COMPAT_FUNC_GETHOSTNAME], [
532 COMPAT_REPLACE_FUNC([gethostname])
536 # COMPAT_FUNC_INET_ATON
537 # ---------------------
538 # Check for inet_aton().
539 AC_DEFUN([COMPAT_FUNC_INET_ATON], [
540 COMPAT_REPLACE_FUNC([inet_aton])
546 # Check for strdup().
547 AC_DEFUN([COMPAT_FUNC_STRDUP], [
548 COMPAT_REPLACE_FUNC([strdup])
552 # COMPAT_FUNC_STRLCAT
553 # -------------------
554 # Check for strlcat().
555 AC_DEFUN([COMPAT_FUNC_STRLCAT], [
556 COMPAT_REPLACE_FUNC([strlcat])
560 # COMPAT_FUNC_STRLCPY
561 # -------------------
562 # Check for strlcpy().
563 AC_DEFUN([COMPAT_FUNC_STRLCPY], [
564 COMPAT_REPLACE_FUNC([strlcpy])
568 # COMPAT_FUNC_STRMODE
569 # -------------------
570 # Check for strmode().
571 AC_DEFUN([COMPAT_FUNC_STRMODE], [
572 COMPAT_REPLACE_FUNC([strmode])
576 # COMPAT_FUNC_STRRSTR
577 # -------------------
578 # Check for strrstr().
579 AC_DEFUN([COMPAT_FUNC_STRRSTR], [
580 COMPAT_REPLACE_FUNC([strrstr])
586 # Check for strsep().
587 AC_DEFUN([COMPAT_FUNC_STRSEP], [
588 COMPAT_REPLACE_FUNC([strsep])