source: box/trunk/infrastructure/m4/ax_check_syscall_lseek.m4 @ 2494

Revision 2494, 2.5 KB checked in by chris, 3 years ago (diff)

Blind fix for autoconf problems introduced by earlier attempt to support
cross-compiling.

  • Property svn:eol-style set to native
Line 
1dnl @synopsis AX_CHECK_SYSCALL_LSEEK([ACTION-IF-TRUE], [ACTION-IF-FALSE])
2dnl
3dnl This macro will find out if the lseek syscall requires a dummy middle
4dnl parameter
5dnl
6dnl The following defines will be set as appropriate:
7dnl HAVE_LSEEK_DUMMY_PARAM
8dnl Also ACTION-IF-TRUE and ACTION-IF-FALSE are run as appropriate
9dnl
10dnl @category C
11dnl @author Martin Ebourne
12dnl @version 2005/07/03
13dnl @license AllPermissive
14
15AC_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
Note: See TracBrowser for help on using the repository browser.