1 dnl sxe-fs-funs.m4 -- Functions for file system access
3 AC_DEFUN([SXE_CHECK_REALPATH], [dnl
4 ## defines have_realpath
6 ## for the dirname proto
7 AC_CHECK_DECLS([realpath], [], [], [
12 AC_CHECK_FUNCS([realpath])
13 AC_CHECK_LIB([c], [realpath])
15 if test "$ac_cv_func_realpath" = "yes"; then
16 SXE_CHECK_BROKEN_REALPATH
17 elif test "$ac_cv_lib_c_realpath" = "yes"; then
18 LDFLAGS="$LDFLAGS -lc"
19 SXE_CHECK_BROKEN_REALPATH
24 if test "$sxe_func_realpath_broken" != "no"; then
25 SXE_ADD_CORE_OBJS([realpath.o])
27 ])dnl SXE_CHECK_REALPATH
29 AC_DEFUN([_SXE_CHECK_REALPATH_RETVAL], [dnl
30 ## arg #1 is the return type, char* by default
31 ## arg #2 is the final test,
32 ## pass something that is expected to be true here
33 ## the return value is stored in a variable `r'
34 ## defines sxe_func_realpath_returns_<ret_t> and
35 ## sxe_func_realpath_returns=$1 if true
36 pushdef([ret_t], ifelse($1, [], [char*],$1))
37 pushdef([resvar_body], [sxe_func_realpath_returns])
38 pushdef([resvar], resvar_body[_]translit(ret_t, [ -*], [__X]))
39 pushdef([rettest], ifelse($2, [], [[[[r[0] == '/']]]],$2))
41 AC_MSG_CHECKING([whether realpath returns ]ret_t)
42 AC_RUN_IFELSE([AC_LANG_SOURCE([[
51 int realpath_returns_]]ret_t[[() {
53 char p[8] = "/bin/sh\000";
58 r = realpath(p, resv);
60 res = ((]]rettest[[) == 0);
69 return realpath_returns_]]ret_t[[();
75 AC_MSG_RESULT([$]resvar)
77 if test "$[]resvar[]" = "yes"; then
79 AC_DEFINE_UNQUOTED([REALPATH_RET_T], ret_t,
80 [return type of realpath()])
87 ])dnl _SXE_CHECK_REALPATH_RETVAL
89 AC_DEFUN([_SXE_CHECK_REALPATH_RETVAL_OWNER], [dnl
90 ## defines sxe_func_realpath_retval_owner,
91 ## values are either "sys" or "user"
92 pushdef([resvar], [sxe_func_realpath_retval_owner])
94 ## this test is especially critical, because some systems do not
95 ## allocate memory for the user when the return value is "."
96 ## instead they point to a static const char somewhere in their
97 ## guts which, of course, must not be furtherly modified, free'd or
98 ## anything ... took me fucking ages to find out what's going on
99 ## so let's drink to the morons responsible for THAT!
100 AC_MSG_CHECKING([to whom belongs the object returned by realpath])
101 if test "$opsys" = "darwin"; then
104 AC_RUN_IFELSE([AC_LANG_SOURCE([[
110 #define PATH_MAX 4096
113 #define FOLLOW_FREE_STRATEGY 1
114 #define FOLLOW_REALLOC_STRATEGY 1
116 int owner_of_object_returned_by_realpath()
118 void *r; /* any pointer is just fine */
119 char p[8] = "/bin/sh\000";
121 r = (void*)realpath(p, NULL);
122 #if FOLLOW_REALLOC_STRATEGY
123 /* reallocation would help already */
124 r = realloc(r, 4096);
126 #if FOLLOW_FREE_STRATEGY
127 /* if r was ours we should be able to free it */
130 #if FOLLOW_FREE_STRATEGY || FOLLOW_REALLOC_STRATEGY
139 return owner_of_object_returned_by_realpath();
146 AC_MSG_RESULT([$]resvar)
148 if test "$[]resvar[]" = "user"; then
149 AC_DEFINE([REALPATH_USER_OWNS_RETVAL], [1],
150 [Whether the user space owns the retval of realpath()])
151 elif test "$[]resvar[]" = "sys"; then
152 AC_DEFINE([REALPATH_SYS_OWNS_RETVAL], [1],
153 [Whether the system owns the retval of realpath()])
157 ])dnl _SXE_CHECK_REALPATH_RETVAL_OWNER
159 AC_DEFUN([_SXE_CHECK_REALPATH_ON_PROTECTED_MEMORY], [dnl
160 ## defines sxe_func_realpath_accepts_protmem
161 pushdef([resvar], [sxe_func_realpath_accepts_protmem])
163 AC_MSG_CHECKING([whether realpath can operate on protected mem blocks])
164 if test "$opsys" = "darwin"; then
167 AC_RUN_IFELSE([AC_LANG_SOURCE([[
173 #define PATH_MAX 4096
176 int realpath_can_operate_on_protected_mem_blocks()
179 realpath("/bin/sh", NULL);
180 realpath("/bin/sh", resv);
186 return realpath_can_operate_on_protected_mem_blocks();
193 AC_MSG_RESULT([$]resvar)
195 if test "$[]resvar[]" = "yes"; then
196 AC_DEFINE([REALPATH_ACCEPTS_PROTMEM], [1],
197 [Whether realpath() accepts protected memory blocks])
201 ])dnl _SXE_CHECK_REALPATH_ON_PROTECTED_MEMORY
203 AC_DEFUN([_SXE_CHECK_REALPATH_SANE_ON_NON_EXISTENT], [dnl
204 ## defines sxe_func_realpath_
205 pushdef([resvar], [sxe_func_realpath_sane_on_non_existent])
207 AC_MSG_CHECKING([whether realpath survives if we pass non-existent stuff])
208 AC_RUN_IFELSE([AC_LANG_SOURCE([[
214 #define PATH_MAX 4096
217 static char p[24] = "/nobody/has/this/file\000";
219 int realpath_survives_non_existent_path()
223 r = realpath((char*)p, resv);
225 return ((r == NULL) == 0);
230 return realpath_survives_non_existent_path();
236 AC_MSG_RESULT([$]resvar)
238 if test "$[]resvar[]" = "yes"; then
239 AC_DEFINE([REALPATH_SANE_ON_NON_EXISTENT], [1],
240 [Whether realpath() accepts and handles non-existent files])
244 ])dnl _SXE_CHECK_REALPATH_SANE_ON_NON_EXISTENT
246 AC_DEFUN([SXE_CHECK_BROKEN_REALPATH], [dnl
247 ## defines 3 vars, look in the sub macros to see which ones
248 _SXE_CHECK_REALPATH_ON_PROTECTED_MEMORY
249 _SXE_CHECK_REALPATH_SANE_ON_NON_EXISTENT
250 _SXE_CHECK_REALPATH_RETVAL
251 _SXE_CHECK_REALPATH_RETVAL_OWNER
253 AC_MSG_CHECKING([if realpath is considered broken])
254 if test "$sxe_func_realpath_returns" = "char*" -a \
255 "$sxe_func_realpath_sane_on_non_existent" = "yes" -a \
256 "$sxe_func_realpath_retval_owner" = "user"; then
257 sxe_func_realpath_broken="no"
259 sxe_func_realpath_broken="yes"
261 AC_MSG_RESULT([$sxe_func_realpath_broken])
262 ])dnl SXE_CHECK_BROKEN_REALPATH
265 AC_DEFUN([SXE_CHECK_DIRNAME], [dnl
266 ## defines have_dirname
268 ## of course posix standards are just rough draughts
269 ## and by no means obliging in any way ...
270 ## and since we all hate working systems we do our best
271 ## to break these so called standards wherever we can
273 ## Passage from coreutils:
274 ## In general, we can't use the builtin `dirname' function if available,
275 ## since it has different meanings in different environments. In some
276 ## environments the builtin `dirname' modifies its argument.
278 ## for the dirname proto
279 SXE_CHECK_HEADERS([libgen.h])
280 AC_CHECK_DECLS([dirname], [], [], [
285 AC_CHECK_FUNCS([dirname]) dnl should be part of glibc
286 AC_CHECK_LIB([c], [dirname])
288 if test "$ac_cv_func_dirname" = "yes"; then
289 SXE_CHECK_BROKEN_DIRNAME
290 elif test "$ac_cv_lib_c_dirname" = "yes"; then
291 LDFLAGS="$LDFLAGS -lc"
292 SXE_CHECK_BROKEN_DIRNAME
296 ])dnl SXE_CHECK_DIRNAME
298 AC_DEFUN([_SXE_CHECK_DIRNAME_SIDE_EFFECT], [dnl
299 ## defines sxe_func_dirname_side_effect
300 ## and DIRNAME_SIDE_EFFECT
301 pushdef([resvar], [sxe_func_dirname_side_effect])
303 AC_MSG_CHECKING([whether dirname modifies its argument by side-effect])
304 AC_RUN_IFELSE([AC_LANG_SOURCE([[
309 int dirname_modifies_argument()
311 char p[11] = "somefile\000";
313 return ((p[0] == '.' && p[1] == '\0') == 0);
318 return dirname_modifies_argument();
324 AC_MSG_RESULT([$]resvar)
326 if test "$[]resvar[]" = "yes"; then
327 AC_DEFINE([DIRNAME_SIDE_EFFECT], [1],
328 [Whether dirname() operates by side effect])
332 ])dnl _SXE_CHECK_DIRNAME_SIDE_EFFECT
334 AC_DEFUN([_SXE_CHECK_DIRNAME_RETVAL], [dnl
335 ## arg #1 is the return type, char* by default
336 ## arg #2 is the final test,
337 ## pass something that is expected to be true here
338 ## the return value is stored in a variable `r'
339 ## defines sxe_func_dirname_returns_<ret_t> and
340 ## sxe_func_dirname_returns=$1 if true
341 pushdef([ret_t], ifelse($1, [], [char*],$1))
342 pushdef([resvar_body], [sxe_func_dirname_returns])
343 pushdef([resvar], resvar_body[_]translit(ret_t, [ -*], [__X]))
344 pushdef([rettest], ifelse($2, [], [[[[r[0] == '.' && r[1] == '\000']]]],$2))
346 AC_MSG_CHECKING([whether dirname returns ]ret_t)
347 AC_RUN_IFELSE([AC_LANG_SOURCE([[
355 char p[11] = "somefile\000";
359 res = ((]]rettest[[) == 0);
366 AC_MSG_RESULT([$]resvar)
368 if test "$[]resvar[]" = "yes"; then
370 AC_DEFINE_UNQUOTED([DIRNAME_RET_T], ret_t,
371 [return type of dirname()])
374 popdef([resvar_body])
378 ])dnl _SXE_CHECK_DIRNAME_RETVAL
380 AC_DEFUN([_SXE_CHECK_DIRNAME_RETVAL_OWNER], [dnl
381 ## defines sxe_func_dirname_retval_owner,
382 ## values are either "sys" or "user"
383 pushdef([resvar], [sxe_func_dirname_retval_owner])
385 malloc_check=${MALLOC_CHECK_}
386 ## Turn off the stupid glibc 2.5 stack trace check. We *know* we may
387 ## do something bad here :-)
390 ## this test is especially critical, because some systems do not
391 ## allocate memory for the user when the return value is "."
392 ## instead they point to a static const char somewhere in their
393 ## guts which, of course, must not be furtherly modified, free'd or
394 ## anything ... took me fucking ages to find out what's going on
395 ## so let's drink to the morons responsible for THAT!
396 AC_MSG_CHECKING([to whom belongs the object returned by dirname])
397 if test "$opsys" = "darwin" ; then
400 AC_RUN_IFELSE([AC_LANG_SOURCE([[
405 #define FOLLOW_FREE_STRATEGY 1
406 #define FOLLOW_REALLOC_STRATEGY 1
408 int owner_of_object_returned_by_dirname()
410 void *r; /* any pointer is just fine */
411 char p[11] = "./somefile\000";
413 r = (void*)dirname(p);
414 #if FOLLOW_REALLOC_STRATEGY
415 /* reallocation would help already */
416 r = realloc(r, 4096);
418 #if FOLLOW_FREE_STRATEGY
419 /* if r was ours we should be able to free it */
422 #if FOLLOW_FREE_STRATEGY || FOLLOW_REALLOC_STRATEGY
431 return owner_of_object_returned_by_dirname();
438 if test "${malloc_check}" = "" ; then
441 MALLOC_CHECK_=${malloc_check}
443 AC_MSG_RESULT([$]resvar)
445 if test "$[]resvar[]" = "user"; then
446 AC_DEFINE([DIRNAME_USER_OWNS_RETVAL], [1],
447 [Whether the user space owns the retval of dirname()])
448 elif test "$[]resvar[]" = "sys"; then
449 AC_DEFINE([DIRNAME_SYS_OWNS_RETVAL], [1],
450 [Whether the system owns the retval of dirname()])
454 ])dnl _SXE_CHECK_DIRNAME_RETVAL_OWNER
456 AC_DEFUN([_SXE_CHECK_DIRNAME_ON_PROTECTED_MEMORY], [dnl
457 ## defines sxe_func_dirname_accepts_protmem
458 pushdef([resvar], [sxe_func_dirname_accepts_protmem])
460 AC_MSG_CHECKING([whether dirname can operate on protected mem blocks])
461 AC_RUN_IFELSE([AC_LANG_SOURCE([[
466 int dirname_can_operate_on_protected_mem_blocks()
468 dirname("./somefile");
474 return dirname_can_operate_on_protected_mem_blocks();
480 AC_MSG_RESULT([$]resvar)
482 if test "$[]resvar[]" = "yes"; then
483 AC_DEFINE([DIRNAME_ACCEPTS_PROTMEM], [1],
484 [Whether dirname() accepts protected memory blocks])
488 ])dnl _SXE_CHECK_DIRNAME_ON_PROTECTED_MEMORY
490 AC_DEFUN([_SXE_CHECK_DIRNAME_ON_C99_RESTRICT_MEMORY], [dnl
491 ## defines sxe_func_dirname_accepts_restrmem
492 pushdef([resvar], [sxe_func_dirname_accepts_restrmem])
494 AC_MSG_CHECKING([whether dirname can operate on C99 restrict mem blocks])
495 AC_RUN_IFELSE([AC_LANG_SOURCE([[
503 static char f[11] = "./somefile\000";
505 int dirname_can_operate_on_c99_restrict()
507 const char *restrict p = &f;
514 return dirname_can_operate_on_c99_restrict();
520 AC_MSG_RESULT([$]resvar)
522 if test "$[]resvar[]" = "yes"; then
523 AC_DEFINE([DIRNAME_ACCEPTS_RESTRMEM], [1],
524 [Whether dirname() accepts restricted memory blocks])
528 ])dnl _SXE_CHECK_DIRNAME_ON_C99_RESTRICT_MEMORY
530 AC_DEFUN([SXE_CHECK_BROKEN_DIRNAME], [dnl
531 ## defines 3 vars, look in the sub macros to see which ones
532 _SXE_CHECK_DIRNAME_SIDE_EFFECT
533 _SXE_CHECK_DIRNAME_ON_PROTECTED_MEMORY
534 _SXE_CHECK_DIRNAME_ON_C99_RESTRICT_MEMORY
535 _SXE_CHECK_DIRNAME_RETVAL
536 _SXE_CHECK_DIRNAME_RETVAL_OWNER
537 ])dnl SXE_CHECK_BROKEN_DIRNAME
540 AC_DEFUN([SXE_CHECK_FILE_LOCK], [dnl
541 ## Determine type of mail locking from configure args and s&m headers
542 AC_MSG_CHECKING([for a type of mail spool file locking])
545 AC_CHECK_FUNCS([lockf flock locking])
546 ## The mail_use_xxx variables are set according to the s&m headers.
547 if test "$with_mail_locking" != "no" -a \
548 "$mail_use_flock" = "yes"; then
549 with_mail_locking=flock
550 elif test "$with_mail_locking" != "no" -a \
551 "$mail_use_lockf" = "yes"; then
552 with_mail_locking=lockf
553 elif test "$with_mail_locking" != "no" -a \
554 "$mail_use_locking" = "yes"; then
555 with_mail_locking=locking
558 if test "$with_mail_locking" = "lockf"; then
559 AC_DEFINE([MAIL_LOCK_LOCKF], [1], [Description here!])
560 elif test "$with_mail_locking" = "flock"; then
561 AC_DEFINE([MAIL_LOCK_FLOCK], [1], [Description here!])
562 elif test "$with_mail_locking" = "locking"; then
563 AC_DEFINE([MAIL_LOCK_LOCKING], [1], [Description here!])
564 elif test "$with_mail_locking" = "pop"; then
567 elif test "$with_mail_locking" = "mmdf"; then
568 AC_DEFINE([MAIL_LOCK_MMDF], [1], [Description here!])
570 with_mail_locking="file"
571 AC_DEFINE([MAIL_LOCK_DOT], [1], [Description here!])
574 if test "$with_mail_locking" = "lockf" -a \
575 "$ac_cv_func_lockf" != "yes"; then
576 SXE_DIE([lockf mail locking requested but not available.])
577 elif test "$with_mail_locking" = "flock" -a \
578 "$ac_cv_func_flock" != "yes"; then
579 SXE_DIE([flock mail locking requested but not available.])
580 elif test "$with_mail_locking" = "locking" -a \
581 "$ac_cv_func_locking" != "yes"; then
582 SXE_DIE([locking mail locking requested but not available.])
584 ])dnl SXE_CHECK_FILE_LOCK
587 dnl sxe-fs-funs.m4 ends here