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([[
54 char p[8] = "/bin/sh\000";
59 r = realpath(p, resv);
61 res = ((]]rettest[[) == 0);
71 AC_MSG_RESULT([$]resvar)
73 if test "$[]resvar[]" = "yes"; then
75 AC_DEFINE_UNQUOTED([REALPATH_RET_T], ret_t,
76 [return type of realpath()])
83 ])dnl _SXE_CHECK_REALPATH_RETVAL
85 AC_DEFUN([_SXE_CHECK_REALPATH_RETVAL_OWNER], [dnl
86 ## defines sxe_func_realpath_retval_owner,
87 ## values are either "sys" or "user"
88 pushdef([resvar], [sxe_func_realpath_retval_owner])
90 ## this test is especially critical, because some systems do not
91 ## allocate memory for the user when the return value is "."
92 ## instead they point to a static const char somewhere in their
93 ## guts which, of course, must not be furtherly modified, free'd or
94 ## anything ... took me fucking ages to find out what's going on
95 ## so let's drink to the morons responsible for THAT!
96 AC_MSG_CHECKING([to whom belongs the object returned by realpath])
97 if test "$opsys" = "darwin"; then
100 AC_RUN_IFELSE([AC_LANG_SOURCE([[
106 #define PATH_MAX 4096
109 #define FOLLOW_FREE_STRATEGY 1
110 #define FOLLOW_REALLOC_STRATEGY 1
114 void *r; /* any pointer is just fine */
115 char p[8] = "/bin/sh\000";
117 r = (void*)realpath(p, NULL);
118 #if FOLLOW_REALLOC_STRATEGY
119 /* reallocation would help already */
120 r = realloc(r, 4096);
122 #if FOLLOW_FREE_STRATEGY
123 /* if r was ours we should be able to free it */
126 #if FOLLOW_FREE_STRATEGY || FOLLOW_REALLOC_STRATEGY
137 AC_MSG_RESULT([$]resvar)
139 if test "$[]resvar[]" = "user"; then
140 AC_DEFINE([REALPATH_USER_OWNS_RETVAL], [1],
141 [Whether the user space owns the retval of realpath()])
142 elif test "$[]resvar[]" = "sys"; then
143 AC_DEFINE([REALPATH_SYS_OWNS_RETVAL], [1],
144 [Whether the system owns the retval of realpath()])
148 ])dnl _SXE_CHECK_REALPATH_RETVAL_OWNER
150 AC_DEFUN([_SXE_CHECK_REALPATH_ON_PROTECTED_MEMORY], [dnl
151 ## defines sxe_func_realpath_accepts_protmem
152 pushdef([resvar], [sxe_func_realpath_accepts_protmem])
154 AC_MSG_CHECKING([whether realpath can operate on protected mem blocks])
155 if test "$opsys" = "darwin"; then
158 AC_RUN_IFELSE([AC_LANG_SOURCE([[
164 #define PATH_MAX 4096
170 realpath("/bin/sh", NULL);
171 realpath("/bin/sh", resv);
179 AC_MSG_RESULT([$]resvar)
181 if test "$[]resvar[]" = "yes"; then
182 AC_DEFINE([REALPATH_ACCEPTS_PROTMEM], [1],
183 [Whether realpath() accepts protected memory blocks])
187 ])dnl _SXE_CHECK_REALPATH_ON_PROTECTED_MEMORY
189 AC_DEFUN([_SXE_CHECK_REALPATH_SANE_ON_NON_EXISTENT], [dnl
190 ## defines sxe_func_realpath_
191 pushdef([resvar], [sxe_func_realpath_sane_on_non_existent])
193 AC_MSG_CHECKING([whether realpath survives if we pass non-existent stuff])
194 AC_RUN_IFELSE([AC_LANG_SOURCE([[
200 #define PATH_MAX 4096
203 static char p[24] = "/nobody/has/this/file\000";
209 r = realpath((char*)p, resv);
211 return ((r == NULL) == 0);
217 AC_MSG_RESULT([$]resvar)
219 if test "$[]resvar[]" = "yes"; then
220 AC_DEFINE([REALPATH_SANE_ON_NON_EXISTENT], [1],
221 [Whether realpath() accepts and handles non-existent files])
225 ])dnl _SXE_CHECK_REALPATH_SANE_ON_NON_EXISTENT
227 AC_DEFUN([SXE_CHECK_BROKEN_REALPATH], [dnl
228 ## defines 3 vars, look in the sub macros to see which ones
229 _SXE_CHECK_REALPATH_ON_PROTECTED_MEMORY
230 _SXE_CHECK_REALPATH_SANE_ON_NON_EXISTENT
231 _SXE_CHECK_REALPATH_RETVAL
232 _SXE_CHECK_REALPATH_RETVAL_OWNER
234 AC_MSG_CHECKING([if realpath is considered broken])
235 if test "$sxe_func_realpath_returns" = "char*" -a \
236 "$sxe_func_realpath_sane_on_non_existent" = "yes" -a \
237 "$sxe_func_realpath_retval_owner" = "user"; then
238 sxe_func_realpath_broken="no"
240 sxe_func_realpath_broken="yes"
242 AC_MSG_RESULT([$sxe_func_realpath_broken])
243 ])dnl SXE_CHECK_BROKEN_REALPATH
246 AC_DEFUN([SXE_CHECK_DIRNAME], [dnl
247 ## defines have_dirname
249 ## of course posix standards are just rough draughts
250 ## and by no means obliging in any way ...
251 ## and since we all hate working systems we do our best
252 ## to break these so called standards wherever we can
254 ## Passage from coreutils:
255 ## In general, we can't use the builtin `dirname' function if available,
256 ## since it has different meanings in different environments. In some
257 ## environments the builtin `dirname' modifies its argument.
259 ## for the dirname proto
260 SXE_CHECK_HEADERS([libgen.h])
261 AC_CHECK_DECLS([dirname], [], [], [
266 AC_CHECK_FUNCS([dirname]) dnl should be part of glibc
267 AC_CHECK_LIB([c], [dirname])
269 if test "$ac_cv_func_dirname" = "yes"; then
270 SXE_CHECK_BROKEN_DIRNAME
271 elif test "$ac_cv_lib_c_dirname" = "yes"; then
272 LDFLAGS="$LDFLAGS -lc"
273 SXE_CHECK_BROKEN_DIRNAME
277 ])dnl SXE_CHECK_DIRNAME
279 AC_DEFUN([_SXE_CHECK_DIRNAME_SIDE_EFFECT], [dnl
280 ## defines sxe_func_dirname_side_effect
281 ## and DIRNAME_SIDE_EFFECT
282 pushdef([resvar], [sxe_func_dirname_side_effect])
284 AC_MSG_CHECKING([whether dirname modifies its argument by side-effect])
285 AC_RUN_IFELSE([AC_LANG_SOURCE([[
292 char p[11] = "somefile\000";
294 return ((p[0] == '.' && p[1] == '\0') == 0);
300 AC_MSG_RESULT([$]resvar)
302 if test "$[]resvar[]" = "yes"; then
303 AC_DEFINE([DIRNAME_SIDE_EFFECT], [1],
304 [Whether dirname() operates by side effect])
308 ])dnl _SXE_CHECK_DIRNAME_SIDE_EFFECT
310 AC_DEFUN([_SXE_CHECK_DIRNAME_RETVAL], [dnl
311 ## arg #1 is the return type, char* by default
312 ## arg #2 is the final test,
313 ## pass something that is expected to be true here
314 ## the return value is stored in a variable `r'
315 ## defines sxe_func_dirname_returns_<ret_t> and
316 ## sxe_func_dirname_returns=$1 if true
317 pushdef([ret_t], ifelse($1, [], [char*],$1))
318 pushdef([resvar_body], [sxe_func_dirname_returns])
319 pushdef([resvar], resvar_body[_]translit(ret_t, [ -*], [__X]))
320 pushdef([rettest], ifelse($2, [], [[[[r[0] == '.' && r[1] == '\000']]]],$2))
322 AC_MSG_CHECKING([whether dirname returns ]ret_t)
323 AC_RUN_IFELSE([AC_LANG_SOURCE([[
331 char p[11] = "somefile\000";
335 res = ((]]rettest[[) == 0);
342 AC_MSG_RESULT([$]resvar)
344 if test "$[]resvar[]" = "yes"; then
346 AC_DEFINE_UNQUOTED([DIRNAME_RET_T], ret_t,
347 [return type of dirname()])
350 popdef([resvar_body])
354 ])dnl _SXE_CHECK_DIRNAME_RETVAL
356 AC_DEFUN([_SXE_CHECK_DIRNAME_RETVAL_OWNER], [dnl
357 ## defines sxe_func_dirname_retval_owner,
358 ## values are either "sys" or "user"
359 pushdef([resvar], [sxe_func_dirname_retval_owner])
361 malloc_check=${MALLOC_CHECK_}
362 ## Turn off the stupid glibc 2.5 stack trace check. We *know* we may
363 ## do something bad here :-)
366 ## this test is especially critical, because some systems do not
367 ## allocate memory for the user when the return value is "."
368 ## instead they point to a static const char somewhere in their
369 ## guts which, of course, must not be furtherly modified, free'd or
370 ## anything ... took me fucking ages to find out what's going on
371 ## so let's drink to the morons responsible for THAT!
372 AC_MSG_CHECKING([to whom belongs the object returned by dirname])
373 AC_RUN_IFELSE([AC_LANG_SOURCE([[
378 #define FOLLOW_FREE_STRATEGY 1
379 #define FOLLOW_REALLOC_STRATEGY 1
383 void *r; /* any pointer is just fine */
384 char p[11] = "./somefile\000";
386 r = (void*)dirname(p);
387 #if FOLLOW_REALLOC_STRATEGY
388 /* reallocation would help already */
389 r = realloc(r, 4096);
391 #if FOLLOW_FREE_STRATEGY
392 /* if r was ours we should be able to free it */
395 #if FOLLOW_FREE_STRATEGY || FOLLOW_REALLOC_STRATEGY
405 if test "${malloc_check}" = "" ; then
408 MALLOC_CHECK_=${malloc_check}
410 AC_MSG_RESULT([$]resvar)
412 if test "$[]resvar[]" = "user"; then
413 AC_DEFINE([DIRNAME_USER_OWNS_RETVAL], [1],
414 [Whether the user space owns the retval of dirname()])
415 elif test "$[]resvar[]" = "sys"; then
416 AC_DEFINE([DIRNAME_SYS_OWNS_RETVAL], [1],
417 [Whether the system owns the retval of dirname()])
421 ])dnl _SXE_CHECK_DIRNAME_RETVAL_OWNER
423 AC_DEFUN([_SXE_CHECK_DIRNAME_ON_PROTECTED_MEMORY], [dnl
424 ## defines sxe_func_dirname_accepts_protmem
425 pushdef([resvar], [sxe_func_dirname_accepts_protmem])
427 AC_MSG_CHECKING([whether dirname can operate on protected mem blocks])
428 AC_RUN_IFELSE([AC_LANG_SOURCE([[
435 dirname("./somefile");
442 AC_MSG_RESULT([$]resvar)
444 if test "$[]resvar[]" = "yes"; then
445 AC_DEFINE([DIRNAME_ACCEPTS_PROTMEM], [1],
446 [Whether dirname() accepts protected memory blocks])
450 ])dnl _SXE_CHECK_DIRNAME_ON_PROTECTED_MEMORY
452 AC_DEFUN([_SXE_CHECK_DIRNAME_ON_C99_RESTRICT_MEMORY], [dnl
453 ## defines sxe_func_dirname_accepts_restrmem
454 pushdef([resvar], [sxe_func_dirname_accepts_restrmem])
456 AC_MSG_CHECKING([whether dirname can operate on C99 restrict mem blocks])
457 AC_RUN_IFELSE([AC_LANG_SOURCE([[
465 static char f[11] = "./somefile\000";
469 const char *restrict p = &f;
477 AC_MSG_RESULT([$]resvar)
479 if test "$[]resvar[]" = "yes"; then
480 AC_DEFINE([DIRNAME_ACCEPTS_RESTRMEM], [1],
481 [Whether dirname() accepts restricted memory blocks])
485 ])dnl _SXE_CHECK_DIRNAME_ON_C99_RESTRICT_MEMORY
487 AC_DEFUN([SXE_CHECK_BROKEN_DIRNAME], [dnl
488 ## defines 3 vars, look in the sub macros to see which ones
489 _SXE_CHECK_DIRNAME_SIDE_EFFECT
490 _SXE_CHECK_DIRNAME_ON_PROTECTED_MEMORY
491 _SXE_CHECK_DIRNAME_ON_C99_RESTRICT_MEMORY
492 _SXE_CHECK_DIRNAME_RETVAL
493 _SXE_CHECK_DIRNAME_RETVAL_OWNER
494 ])dnl SXE_CHECK_BROKEN_DIRNAME
497 AC_DEFUN([SXE_CHECK_FILE_LOCK], [dnl
498 ## Determine type of mail locking from configure args and s&m headers
499 AC_MSG_CHECKING([for a type of mail spool file locking])
502 AC_CHECK_FUNCS([lockf flock locking])
503 ## The mail_use_xxx variables are set according to the s&m headers.
504 if test "$with_mail_locking" != "no" -a \
505 "$mail_use_flock" = "yes"; then
506 with_mail_locking=flock
507 elif test "$with_mail_locking" != "no" -a \
508 "$mail_use_lockf" = "yes"; then
509 with_mail_locking=lockf
510 elif test "$with_mail_locking" != "no" -a \
511 "$mail_use_locking" = "yes"; then
512 with_mail_locking=locking
515 if test "$with_mail_locking" = "lockf"; then
516 AC_DEFINE([MAIL_LOCK_LOCKF], [1], [Description here!])
517 elif test "$with_mail_locking" = "flock"; then
518 AC_DEFINE([MAIL_LOCK_FLOCK], [1], [Description here!])
519 elif test "$with_mail_locking" = "locking"; then
520 AC_DEFINE([MAIL_LOCK_LOCKING], [1], [Description here!])
521 elif test "$with_mail_locking" = "pop"; then
524 elif test "$with_mail_locking" = "mmdf"; then
525 AC_DEFINE([MAIL_LOCK_MMDF], [1], [Description here!])
527 with_mail_locking="file"
528 AC_DEFINE([MAIL_LOCK_DOT], [1], [Description here!])
531 if test "$with_mail_locking" = "lockf" -a \
532 "$ac_cv_func_lockf" != "yes"; then
533 SXE_DIE([lockf mail locking requested but not available.])
534 elif test "$with_mail_locking" = "flock" -a \
535 "$ac_cv_func_flock" != "yes"; then
536 SXE_DIE([flock mail locking requested but not available.])
537 elif test "$with_mail_locking" = "locking" -a \
538 "$ac_cv_func_locking" != "yes"; then
539 SXE_DIE([locking mail locking requested but not available.])
541 ])dnl SXE_CHECK_FILE_LOCK
544 dnl sxe-fs-funs.m4 ends here