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
115 #define FOLLOW_DOUBLE_CALL_STRATEGY 1
117 int owner_of_object_returned_by_realpath()
119 void *r; /* any pointer is just fine */
120 char p[8] = "/bin/sh\000";
122 r = (void*)realpath(p, NULL);
123 #if FOLLOW_DOUBLE_CALL_STRATEGY
125 char p[8] = "/bin/cp\000";
127 if (r == (void*)realpath(p, NULL)) {
128 /* System owns when 2 calls yield same pointer */
133 #if FOLLOW_REALLOC_STRATEGY
134 /* reallocation would help already */
135 r = realloc(r, 4096);
137 #if FOLLOW_FREE_STRATEGY
138 /* if r was ours we should be able to free it */
141 #if FOLLOW_FREE_STRATEGY || FOLLOW_REALLOC_STRATEGY
150 return owner_of_object_returned_by_realpath();
157 AC_MSG_RESULT([$]resvar)
159 if test "$[]resvar[]" = "user"; then
160 AC_DEFINE([REALPATH_USER_OWNS_RETVAL], [1],
161 [Whether the user space owns the retval of realpath()])
162 elif test "$[]resvar[]" = "sys"; then
163 AC_DEFINE([REALPATH_SYS_OWNS_RETVAL], [1],
164 [Whether the system owns the retval of realpath()])
168 ])dnl _SXE_CHECK_REALPATH_RETVAL_OWNER
170 AC_DEFUN([_SXE_CHECK_REALPATH_ON_PROTECTED_MEMORY], [dnl
171 ## defines sxe_func_realpath_accepts_protmem
172 pushdef([resvar], [sxe_func_realpath_accepts_protmem])
174 AC_MSG_CHECKING([whether realpath can operate on protected mem blocks])
175 if test "$opsys" = "darwin"; then
178 AC_RUN_IFELSE([AC_LANG_SOURCE([[
184 #define PATH_MAX 4096
187 int realpath_can_operate_on_protected_mem_blocks()
190 realpath("/bin/sh", NULL);
191 realpath("/bin/sh", resv);
197 return realpath_can_operate_on_protected_mem_blocks();
204 AC_MSG_RESULT([$]resvar)
206 if test "$[]resvar[]" = "yes"; then
207 AC_DEFINE([REALPATH_ACCEPTS_PROTMEM], [1],
208 [Whether realpath() accepts protected memory blocks])
212 ])dnl _SXE_CHECK_REALPATH_ON_PROTECTED_MEMORY
214 AC_DEFUN([_SXE_CHECK_REALPATH_SANE_ON_NON_EXISTENT], [dnl
215 ## defines sxe_func_realpath_
216 pushdef([resvar], [sxe_func_realpath_sane_on_non_existent])
218 AC_MSG_CHECKING([whether realpath survives if we pass non-existent stuff])
219 AC_RUN_IFELSE([AC_LANG_SOURCE([[
225 #define PATH_MAX 4096
228 static char p[24] = "/nobody/has/this/file\000";
230 int realpath_survives_non_existent_path()
234 r = realpath((char*)p, resv);
236 return ((r == NULL) == 0);
241 return realpath_survives_non_existent_path();
247 AC_MSG_RESULT([$]resvar)
249 if test "$[]resvar[]" = "yes"; then
250 AC_DEFINE([REALPATH_SANE_ON_NON_EXISTENT], [1],
251 [Whether realpath() accepts and handles non-existent files])
255 ])dnl _SXE_CHECK_REALPATH_SANE_ON_NON_EXISTENT
257 AC_DEFUN([SXE_CHECK_BROKEN_REALPATH], [dnl
258 ## defines 3 vars, look in the sub macros to see which ones
259 _SXE_CHECK_REALPATH_ON_PROTECTED_MEMORY
260 _SXE_CHECK_REALPATH_SANE_ON_NON_EXISTENT
261 _SXE_CHECK_REALPATH_RETVAL
262 _SXE_CHECK_REALPATH_RETVAL_OWNER
264 AC_MSG_CHECKING([if realpath is considered broken])
265 if test "$sxe_func_realpath_returns" = "char*" -a \
266 "$sxe_func_realpath_sane_on_non_existent" = "yes" -a \
267 "$sxe_func_realpath_retval_owner" = "user"; then
268 sxe_func_realpath_broken="no"
270 sxe_func_realpath_broken="yes"
272 AC_MSG_RESULT([$sxe_func_realpath_broken])
273 ])dnl SXE_CHECK_BROKEN_REALPATH
276 AC_DEFUN([SXE_CHECK_DIRNAME], [dnl
277 ## defines have_dirname
279 ## of course posix standards are just rough draughts
280 ## and by no means obliging in any way ...
281 ## and since we all hate working systems we do our best
282 ## to break these so called standards wherever we can
284 ## Passage from coreutils:
285 ## In general, we can't use the builtin `dirname' function if available,
286 ## since it has different meanings in different environments. In some
287 ## environments the builtin `dirname' modifies its argument.
289 ## for the dirname proto
290 SXE_CHECK_HEADERS([libgen.h])
291 AC_CHECK_DECLS([dirname], [], [], [
296 AC_CHECK_FUNCS([dirname]) dnl should be part of glibc
297 AC_CHECK_LIB([c], [dirname])
299 if test "$ac_cv_func_dirname" = "yes"; then
300 SXE_CHECK_BROKEN_DIRNAME
301 elif test "$ac_cv_lib_c_dirname" = "yes"; then
302 LDFLAGS="$LDFLAGS -lc"
303 SXE_CHECK_BROKEN_DIRNAME
307 ])dnl SXE_CHECK_DIRNAME
309 AC_DEFUN([_SXE_CHECK_DIRNAME_RETVAL], [dnl
310 ## arg #1 is the return type, char* by default
311 ## arg #2 is the final test,
312 ## pass something that is expected to be true here
313 ## the return value is stored in a variable `r'
314 ## defines sxe_func_dirname_returns_<ret_t> and
315 ## sxe_func_dirname_returns=$1 if true
316 pushdef([ret_t], ifelse($1, [], [char*],$1))
317 pushdef([resvar_body], [sxe_func_dirname_returns])
318 pushdef([resvar], resvar_body[_]translit(ret_t, [ -*], [__X]))
319 pushdef([rettest], ifelse($2, [], [[[[r[0] == '.' && r[1] == '\000']]]],$2))
321 AC_MSG_CHECKING([whether dirname returns ]ret_t)
322 AC_RUN_IFELSE([AC_LANG_SOURCE([[
330 char p[11] = "somefile\000";
334 res = ((]]rettest[[) == 0);
341 AC_MSG_RESULT([$]resvar)
343 if test "$[]resvar[]" = "yes"; then
345 AC_DEFINE_UNQUOTED([DIRNAME_RET_T], ret_t,
346 [return type of dirname()])
349 popdef([resvar_body])
353 ])dnl _SXE_CHECK_DIRNAME_RETVAL
355 AC_DEFUN([_SXE_CHECK_DIRNAME_ON_C99_RESTRICT_MEMORY], [dnl
356 ## defines sxe_func_dirname_accepts_restrmem
357 pushdef([resvar], [sxe_func_dirname_accepts_restrmem])
359 AC_MSG_CHECKING([whether dirname can operate on C99 restrict mem blocks])
360 AC_RUN_IFELSE([AC_LANG_SOURCE([[
368 static char f[11] = "./somefile\000";
370 int dirname_can_operate_on_c99_restrict()
372 const char *restrict p = &f;
379 return dirname_can_operate_on_c99_restrict();
385 AC_MSG_RESULT([$]resvar)
387 if test "$[]resvar[]" = "yes"; then
388 AC_DEFINE([DIRNAME_ACCEPTS_RESTRMEM], [1],
389 [Whether dirname() accepts restricted memory blocks])
393 ])dnl _SXE_CHECK_DIRNAME_ON_C99_RESTRICT_MEMORY
395 AC_DEFUN([SXE_CHECK_BROKEN_DIRNAME], [dnl
396 ## defines 3 vars, look in the sub macros to see which ones
397 _SXE_CHECK_DIRNAME_ON_C99_RESTRICT_MEMORY
398 _SXE_CHECK_DIRNAME_RETVAL
399 ])dnl SXE_CHECK_BROKEN_DIRNAME
402 AC_DEFUN([SXE_CHECK_FILE_LOCK], [dnl
403 ## Determine type of mail locking from configure args and s&m headers
404 AC_MSG_CHECKING([for a type of mail spool file locking])
407 AC_CHECK_FUNCS([lockf flock locking])
408 ## The mail_use_xxx variables are set according to the s&m headers.
409 if test "$with_mail_locking" != "no" -a \
410 "$mail_use_flock" = "yes"; then
411 with_mail_locking=flock
412 elif test "$with_mail_locking" != "no" -a \
413 "$mail_use_lockf" = "yes"; then
414 with_mail_locking=lockf
415 elif test "$with_mail_locking" != "no" -a \
416 "$mail_use_locking" = "yes"; then
417 with_mail_locking=locking
420 if test "$with_mail_locking" = "lockf"; then
421 AC_DEFINE([MAIL_LOCK_LOCKF], [1], [Description here!])
422 elif test "$with_mail_locking" = "flock"; then
423 AC_DEFINE([MAIL_LOCK_FLOCK], [1], [Description here!])
424 elif test "$with_mail_locking" = "locking"; then
425 AC_DEFINE([MAIL_LOCK_LOCKING], [1], [Description here!])
426 elif test "$with_mail_locking" = "pop"; then
429 elif test "$with_mail_locking" = "mmdf"; then
430 AC_DEFINE([MAIL_LOCK_MMDF], [1], [Description here!])
432 with_mail_locking="file"
433 AC_DEFINE([MAIL_LOCK_DOT], [1], [Description here!])
436 if test "$with_mail_locking" = "lockf" -a \
437 "$ac_cv_func_lockf" != "yes"; then
438 SXE_DIE([lockf mail locking requested but not available.])
439 elif test "$with_mail_locking" = "flock" -a \
440 "$ac_cv_func_flock" != "yes"; then
441 SXE_DIE([flock mail locking requested but not available.])
442 elif test "$with_mail_locking" = "locking" -a \
443 "$ac_cv_func_locking" != "yes"; then
444 SXE_DIE([locking mail locking requested but not available.])
446 ])dnl SXE_CHECK_FILE_LOCK
449 dnl sxe-fs-funs.m4 ends here