| 1 | dnl @synopsis AX_CHECK_SYSCALL_LSEEK([ACTION-IF-TRUE], [ACTION-IF-FALSE]) |
|---|
| 2 | dnl |
|---|
| 3 | dnl This macro will find out if the lseek syscall requires a dummy middle |
|---|
| 4 | dnl parameter |
|---|
| 5 | dnl |
|---|
| 6 | dnl The following defines will be set as appropriate: |
|---|
| 7 | dnl HAVE_LSEEK_DUMMY_PARAM |
|---|
| 8 | dnl Also ACTION-IF-TRUE and ACTION-IF-FALSE are run as appropriate |
|---|
| 9 | dnl |
|---|
| 10 | dnl @category C |
|---|
| 11 | dnl @author Martin Ebourne |
|---|
| 12 | dnl @version 2005/07/03 |
|---|
| 13 | dnl @license AllPermissive |
|---|
| 14 | |
|---|
| 15 | AC_DEFUN([AX_CHECK_SYSCALL_LSEEK], [ |
|---|
| 16 | AC_REQUIRE([AX_FUNC_SYSCALL])dnl |
|---|
| 17 | if test "x$ac_cv_header_sys_syscall_h" = "xyes"; then |
|---|
| 18 | AC_CACHE_CHECK([[whether syscall lseek requires dummy parameter]], [box_cv_have_lseek_dummy_param], |
|---|
| 19 | [AC_TRY_RUN( |
|---|
| 20 | [ |
|---|
| 21 | $ac_includes_default |
|---|
| 22 | #include <fcntl.h> |
|---|
| 23 | #include <sys/syscall.h> |
|---|
| 24 | #ifdef HAVE___SYSCALL_NEED_DEFN |
|---|
| 25 | extern "C" off_t __syscall(quad_t number, ...); |
|---|
| 26 | #endif |
|---|
| 27 | #ifdef HAVE___SYSCALL // always use it if we have it |
|---|
| 28 | #undef syscall |
|---|
| 29 | #define syscall __syscall |
|---|
| 30 | #endif |
|---|
| 31 | int main() |
|---|
| 32 | { |
|---|
| 33 | int fh = creat("lseektest", 0600); |
|---|
| 34 | int res = 0; |
|---|
| 35 | if(fh>=0) |
|---|
| 36 | { |
|---|
| 37 | // This test tries first to seek to position 0, with NO |
|---|
| 38 | // "dummy argument". If lseek does actually require a dummy |
|---|
| 39 | // argument, then it will eat SEEK_SET for the offset and |
|---|
| 40 | // try to use 99 as whence, which is invalid, so res will be |
|---|
| 41 | // -1, the program will return zero and |
|---|
| 42 | // have_lseek_dummy_param=yes |
|---|
| 43 | // (whew! that took 1 hour to figure out) |
|---|
| 44 | // The "dummy argument" probably means that it takes a 64-bit |
|---|
| 45 | // offset, so this was probably a bug anyway, and now that |
|---|
| 46 | // we cast the offset to off_t, it should never be needed |
|---|
| 47 | // (if my reasoning is correct). |
|---|
| 48 | res = syscall(SYS_lseek, fh, (off_t)0, SEEK_SET, 99); |
|---|
| 49 | close(fh); |
|---|
| 50 | } |
|---|
| 51 | unlink("lseektest"); |
|---|
| 52 | return res!=-1; |
|---|
| 53 | } |
|---|
| 54 | ], |
|---|
| 55 | [box_cv_have_lseek_dummy_param=yes], |
|---|
| 56 | [box_cv_have_lseek_dummy_param=no], |
|---|
| 57 | [box_cv_have_lseek_dummy_param=no # assume not for cross-compiling] |
|---|
| 58 | )]) |
|---|
| 59 | if test "x$box_cv_have_lseek_dummy_param" = "xyes"; then |
|---|
| 60 | AC_DEFINE([HAVE_LSEEK_DUMMY_PARAM], 1, |
|---|
| 61 | [Define to 1 if syscall lseek requires a dummy middle parameter]) |
|---|
| 62 | fi |
|---|
| 63 | fi |
|---|
| 64 | if test "x$box_cv_have_lseek_dummy_param" = "xno" |
|---|
| 65 | then |
|---|
| 66 | m4_ifvaln([$1],[$1],[:])dnl |
|---|
| 67 | m4_ifvaln([$2],[else $2])dnl |
|---|
| 68 | fi |
|---|
| 69 | ])dnl |
|---|