Change th_get_size() macro to return unsigned int
[libtar.git] / compat / module.ac
bloba76cf1c27a4178e6fd799f1457fc1496c096ea37
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],
7     [AC_TRY_LINK([],
8       [
9         extern char *__progname;
10         printf("%s", __progname);
11       ],
12       [ac_cv_libc_defines___progname=yes],
13       [ac_cv_libc_defines___progname=no]
14     )]
15   )
16   if test "$ac_cv_libc_defines___progname" = "yes"; then
17     AC_DEFINE([HAVE___PROGNAME], 1,
18       [Define if libc defines the __progname variable])
19   fi
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],
32     [AC_TRY_RUN([
33 #include <stdio.h>
34 #ifdef HAVE_LIBGEN_H
35 # include <libgen.h>
36 #endif
38 typedef struct {
39   char *test;
40   char *result;
41 } test_t;
43 const test_t tests[] = {
44   { "/usr/local/foo", "foo" },
45   { "/usr/local/foo/", "foo" },
46   { NULL, NULL }
49 int main() {
50   char test1[1024];
51   int i;
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))
57       exit(1);
58   }
60   exit(0);
63       [compat_cv_func_basename_works=yes],
64       [compat_cv_func_basename_works=no],
65       [compat_cv_func_basename_works=no]
66     )]
67   )
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])
71   else
72     AC_LIBOBJ([basename])
73   fi
77 # COMPAT_FUNC_DIRNAME
78 # -------------------
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],
86     [AC_TRY_RUN([
87 #include <stdio.h>
88 #ifdef HAVE_LIBGEN_H
89 # include <libgen.h>
90 #endif
92 typedef struct {
93   char *test;
94   char *result;
95 } test_t;
97 const test_t tests[] = {
98   { "foobar", "." },
99   { "/usr/local/foo", "/usr/local" },
100   { "/usr/local/foo/", "/usr/local" },
101   { "/", "/" },
102   { "", "." },
103   { NULL, NULL }
106 int main() {
107   char test1[1024];
108   int i;
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))
114       exit(1);
115   }
117   exit(0);
120       [compat_cv_func_dirname_works=yes],
121       [compat_cv_func_dirname_works=no],
122       [compat_cv_func_dirname_works=no]
123     )]
124   )
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])
128   else
129     AC_LIBOBJ([dirname])
130   fi
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
141     AC_FUNC_FNMATCH
142   fi
143   if test "$ac_cv_func_fnmatch_works" != "yes"; then
144     AC_CHECK_HEADERS([ctype.h])
145     AC_LIBOBJ([fnmatch])
146   fi
150 # COMPAT_FUNC_GLOB
151 # ----------------
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],
158     [AC_TRY_RUN([
159 #include <stdio.h>
160 #ifdef HAVE_GLOB_H
161 # include <glob.h>
162 #endif
164 #ifndef GLOB_ABORTED
165 # define GLOB_ABORTED GLOB_ABEND
166 #endif
168 int main() {
169   glob_t g;
170   int status;
172   status = glob("conf*", 0, NULL, &g);
173   switch (status) {
174     case 0:
175     case GLOB_NOSPACE:
176     case GLOB_ABORTED:
177     case GLOB_NOMATCH:
178       exit(0);
179       break;
180     default:
181       exit(1);
182       break;
183   }
186       [compat_cv_func_glob_works=yes],
187       [compat_cv_func_glob_works=no],
188       [compat_cv_func_glob_works=no]
189     )]
190   )
191   if test "$compat_cv_func_glob_works" = "yes"; then
192     AC_DEFINE([HAVE_GLOB], 1, [Define if your system has a working glob])
193   else
194     AC_LIBOBJ([glob])
195     AC_CHECK_FUNCS([issetugid])
196   fi
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],
209     [AC_COMPILE_IFELSE([
210       AC_LANG_PROGRAM([[
211 #include <sys/types.h>
212 #ifdef MAJOR_IN_MKDEV
213 # include <sys/mkdev.h>
214 #else
215 # ifdef MAJOR_IN_SYSMACROS
216 #  include <sys/sysmacros.h>
217 # endif
218 #endif
219 ]], [[
220 dev_t dev;
221 major_t maj = 5;
222 minor_t min = 7;
224 dev = makedev(0, maj, min);
225 if (major(dev) != maj
226     || minor(dev) != min)
227   exit(1);
228 exit(0);
229 ]])],
230       [compat_cv_func_makedev_three_args=yes],
231       [compat_cv_func_makedev_three_args=no]
232     )]
233   )
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])
237   fi
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],
249     [AC_TRY_RUN([
250 #include <stdio.h>
252 typedef struct {
253   int length;
254   char *test;
255   int retval;
256   char *result;
257 } test_t;
259 const test_t tests[] = {
260   { 10, "12345678901234567890", 20, "123456789" },
261 #if 0
262   { 0, "12345678901234567890", 20, NULL },
263   { -1, "12345678901234567890", -1, NULL },
264 #endif
265   { 0, NULL, 0, NULL }
268 int main() {
269   char test1[1024];
270   int i;
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)))
277       exit(1);
278   }
280   exit(0);
283       [compat_cv_func_snprintf_works=yes],
284       [compat_cv_func_snprintf_works=no],
285       [compat_cv_func_snprintf_works=no]
286     )]
287   )
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])
291   else
292     AC_LIBOBJ([snprintf])
293   fi
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],
306     [AC_TRY_COMPILE(
307       [
308         #include <$2>
309       ],
310       [
311         void *funcptr;
312         $4
313         funcptr = $1;
314       ],
315       [compat_cv_proto_]$1[_macro="none"],
316       [for macro in $3; do
317         AC_TRY_COMPILE(
318           [
319             #define $macro
320             #include <$2>
321           ],
322           [
323             void *funcptr;
324             $4
325             funcptr = $1;
326           ],
327           [
328             compat_cv_proto_]$1[_macro="$macro"
329             break
330           ],
331           [compat_cv_proto_]$1[_macro="not found"]
332         )
333       done]
334     )]
335   )]
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";
338   fi
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],
359     [
360       struct passwd pwd, *pwdp;
361       char buf[10240];
362       getpwuid_r(0, &pwd, buf, sizeof(buf), &pwdp);
363     ]
364   )
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])
368   else
369     AC_MSG_WARN([cannot find usable getpwuid_r - resulting libraries will not be thread-safe])
370   fi
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])
384     AC_CACHE_CHECK(
385       [for number of arguments to gethostbyname_r],
386       [compat_cv_gethostbyname_r_args],
387       [AC_TRY_COMPILE(
388         [
389           #include <netdb.h>
390         ],
391         [
392           struct hostent hent;
393           char buf[10240];
394           int herr;
396           gethostbyname_r("localhost", &hent, buf, sizeof(buf), &herr);
397         ],
398         [compat_cv_gethostbyname_r_args=5],
399         [AC_TRY_COMPILE(
400           [
401             #include <netdb.h>
402           ],
403           [
404             struct hostent hent, *hp;
405             char buf[10240];
406             int herr;
408             gethostbyname_r("localhost", &hent, buf, sizeof(buf), &hp, &herr);
409           ],
410           [compat_cv_gethostbyname_r_args=6],
411           [AC_TRY_COMPILE(
412             [
413               #include <netdb.h>
414             ],
415             [
416               struct hostent hent;
417               struct hostent_data hdata;
419               gethostbyname_r("localhost", &hent, &hdata);
420             ],
421             [compat_cv_gethostbyname_r_args=3],
422             [compat_cv_gethostbyname_r_args=no]
423           )]
424         )]
425       )]
426     )
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])
435       fi
436     else
437       AC_MSG_WARN([unknown form of gethostbyname_r - resulting libraries will not be thread-safe])
438     fi
439   else
440     AC_MSG_WARN([cannot find gethostbyname_r - resulting libraries will not be thread-safe])
441   fi
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])
455     AC_CACHE_CHECK(
456       [for number of arguments to getservbyname_r],
457       [compat_cv_getservbyname_r_args],
458       [AC_TRY_COMPILE(
459         [
460           #include <netdb.h>
461         ],
462         [
463           struct servent sent;
464           char buf[10240];
466           getservbyname_r("telnet", "tcp", &sent, buf, sizeof(buf));
467         ],
468         [compat_cv_getservbyname_r_args=5],
469         [AC_TRY_COMPILE(
470           [
471             #include <netdb.h>
472           ],
473           [
474             struct servent sent, *sp;
475             char buf[10240];
477             getservbyname_r("telnet", "tcp", &sent, buf, sizeof(buf), &sp);
478           ],
479           [compat_cv_getservbyname_r_args=6],
480           [AC_TRY_COMPILE(
481             [
482               #include <netdb.h>
483             ],
484             [
485               struct servent sent; 
486               struct servent_data sdata;
488               getservbyname_r("telnet", "tcp", &sent, &sdata);
489             ],
490             [compat_cv_getservbyname_r_args=4],
491             [compat_cv_getservbyname_r_args=no]
492           )]
493         )]
494       )]
495     )
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])
504       fi
505     else
506       AC_MSG_WARN([unknown form of getservbyname_r - resulting libraries will not be thread-safe])
507     fi
508   else
509     AC_MSG_WARN([cannot find getservbyname_r - resulting libraries will not be thread-safe])
510   fi
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])
520   AC_CHECK_FUNC($1,
521     [AC_DEFINE([HAVE_]translit($1,[a-z],[A-Z]), 1,
522                [Define if you have the ]$1[ function])],
523     [AC_LIBOBJ(]$1[)]
524   )
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])
544 # COMPAT_FUNC_STRDUP
545 # ------------------
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])
584 # COMPAT_FUNC_STRSEP
585 # ------------------
586 # Check for strsep().
587 AC_DEFUN([COMPAT_FUNC_STRSEP], [
588   COMPAT_REPLACE_FUNC([strsep])