summaryrefslogtreecommitdiff
path: root/infrastructure/m4/ax_check_syscall_lseek.m4
blob: 6bf93c23a167e6eb59466dc847c0cd3fd0ac35fa (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
dnl @synopsis AX_CHECK_SYSCALL_LSEEK([ACTION-IF-TRUE], [ACTION-IF-FALSE])
dnl
dnl This macro will find out if the lseek syscall requires a dummy middle
dnl parameter
dnl
dnl The following defines will be set as appropriate:
dnl HAVE_LSEEK_DUMMY_PARAM
dnl Also ACTION-IF-TRUE and ACTION-IF-FALSE are run as appropriate
dnl
dnl @category C
dnl @author Martin Ebourne
dnl @version 2005/07/03
dnl @license AllPermissive

AC_DEFUN([AX_CHECK_SYSCALL_LSEEK], [
  AC_REQUIRE([AX_FUNC_SYSCALL])dnl
  if test "x$ac_cv_header_sys_syscall_h" = "xyes"; then
    AC_CACHE_CHECK([[whether syscall lseek requires dummy parameter]], [have_lseek_dummy_param],
      [AC_RUN_IFELSE(
        [AC_LANG_PROGRAM([[
          $ac_includes_default
          #include <fcntl.h>
          #include <sys/syscall.h>
          #ifdef HAVE___SYSCALL_NEED_DEFN
            extern "C" off_t __syscall(quad_t number, ...);
          #endif
          #ifndef HAVE_SYSCALL
            #undef syscall
            #define syscall __syscall
          #endif
          ]], [[
          int fh = creat("lseektest", 0600);
          int res = 0;
          if(fh>=0)
          {
            res = syscall(SYS_lseek, fh, 0, SEEK_SET, 99);
            close(fh);
          }
          unlink("lseektest");
          return res!=-1;
        ]])],
        [have_lseek_dummy_param=yes], [have_lseek_dummy_param=no]
      )])
    if test "x$have_lseek_dummy_param" = "xyes"; then
      AC_DEFINE([HAVE_LSEEK_DUMMY_PARAM], 1,
                [Define to 1 if syscall lseek requires a dummy middle parameter])
    fi
  fi
  if test "x$have_lseek_dummy_param" = "xno"
  then
    m4_ifvaln([$1],[$1],[:])dnl
    m4_ifvaln([$2],[else $2])dnl
  fi
  ])dnl