Browse code

fix portability issues for fseeko, sysconf(_SC_PAGESIZE), getpagesize() (bb#1658)

aCaB authored on 2009/07/16 20:22:28
Showing 9 changed files
... ...
@@ -1,3 +1,8 @@
1
+Thu Jul 16 14:20:01 CEST 2009 (acab)
2
+------------------------------------
3
+ * libclamav, build system: fix portability issues for fseeko, sysconf(_SC_PAGESIZE),
4
+			    getpagesize() (bb#1658)
5
+
1 6
 Wed Jul 15 23:36:09 EEST 2009 (edwin)
2 7
 -------------------------------------
3 8
  * libclamav/pe.c, yc.c: Make yC able to handle more samples and variants.
... ...
@@ -196,6 +196,9 @@
196 196
 /* gethostbyname_r takes 6 arguments */
197 197
 #undef HAVE_GETHOSTBYNAME_R_6
198 198
 
199
+/* Define to 1 if getpagesize() is available */
200
+#undef HAVE_GETPAGESIZE
201
+
199 202
 /* Define to 1 if you have the <grp.h> header file. */
200 203
 #undef HAVE_GRP_H
201 204
 
... ...
@@ -356,6 +359,9 @@
356 356
 /* Define to 1 if you have the `strlcpy' function. */
357 357
 #undef HAVE_STRLCPY
358 358
 
359
+/* Define to 1 if sysconf(_SC_PAGESIZE) is available */
360
+#undef HAVE_SYSCONF_SC_PAGESIZE
361
+
359 362
 /* link against system-wide libtommath */
360 363
 #undef HAVE_SYSTEM_TOMMATH
361 364
 
... ...
@@ -16384,6 +16384,139 @@ _ACEOF
16384 16384
 fi
16385 16385
 done
16386 16386
 
16387
+{ $as_echo "$as_me:$LINENO: checking for _LARGEFILE_SOURCE value needed for large files" >&5
16388
+$as_echo_n "checking for _LARGEFILE_SOURCE value needed for large files... " >&6; }
16389
+if test "${ac_cv_sys_largefile_source+set}" = set; then
16390
+  $as_echo_n "(cached) " >&6
16391
+else
16392
+  while :; do
16393
+  cat >conftest.$ac_ext <<_ACEOF
16394
+/* confdefs.h.  */
16395
+_ACEOF
16396
+cat confdefs.h >>conftest.$ac_ext
16397
+cat >>conftest.$ac_ext <<_ACEOF
16398
+/* end confdefs.h.  */
16399
+#include <sys/types.h> /* for off_t */
16400
+     #include <stdio.h>
16401
+int
16402
+main ()
16403
+{
16404
+int (*fp) (FILE *, off_t, int) = fseeko;
16405
+     return fseeko (stdin, 0, 0) && fp (stdin, 0, 0);
16406
+  ;
16407
+  return 0;
16408
+}
16409
+_ACEOF
16410
+rm -f conftest.$ac_objext conftest$ac_exeext
16411
+if { (ac_try="$ac_link"
16412
+case "(($ac_try" in
16413
+  *\"* | *\`* | *\\*) ac_try_echo=\$ac_try;;
16414
+  *) ac_try_echo=$ac_try;;
16415
+esac
16416
+eval ac_try_echo="\"\$as_me:$LINENO: $ac_try_echo\""
16417
+$as_echo "$ac_try_echo") >&5
16418
+  (eval "$ac_link") 2>conftest.er1
16419
+  ac_status=$?
16420
+  grep -v '^ *+' conftest.er1 >conftest.err
16421
+  rm -f conftest.er1
16422
+  cat conftest.err >&5
16423
+  $as_echo "$as_me:$LINENO: \$? = $ac_status" >&5
16424
+  (exit $ac_status); } && {
16425
+	 test -z "$ac_c_werror_flag" ||
16426
+	 test ! -s conftest.err
16427
+       } && test -s conftest$ac_exeext && {
16428
+	 test "$cross_compiling" = yes ||
16429
+	 $as_test_x conftest$ac_exeext
16430
+       }; then
16431
+  ac_cv_sys_largefile_source=no; break
16432
+else
16433
+  $as_echo "$as_me: failed program was:" >&5
16434
+sed 's/^/| /' conftest.$ac_ext >&5
16435
+
16436
+
16437
+fi
16438
+
16439
+rm -rf conftest.dSYM
16440
+rm -f core conftest.err conftest.$ac_objext conftest_ipa8_conftest.oo \
16441
+      conftest$ac_exeext conftest.$ac_ext
16442
+  cat >conftest.$ac_ext <<_ACEOF
16443
+/* confdefs.h.  */
16444
+_ACEOF
16445
+cat confdefs.h >>conftest.$ac_ext
16446
+cat >>conftest.$ac_ext <<_ACEOF
16447
+/* end confdefs.h.  */
16448
+#define _LARGEFILE_SOURCE 1
16449
+#include <sys/types.h> /* for off_t */
16450
+     #include <stdio.h>
16451
+int
16452
+main ()
16453
+{
16454
+int (*fp) (FILE *, off_t, int) = fseeko;
16455
+     return fseeko (stdin, 0, 0) && fp (stdin, 0, 0);
16456
+  ;
16457
+  return 0;
16458
+}
16459
+_ACEOF
16460
+rm -f conftest.$ac_objext conftest$ac_exeext
16461
+if { (ac_try="$ac_link"
16462
+case "(($ac_try" in
16463
+  *\"* | *\`* | *\\*) ac_try_echo=\$ac_try;;
16464
+  *) ac_try_echo=$ac_try;;
16465
+esac
16466
+eval ac_try_echo="\"\$as_me:$LINENO: $ac_try_echo\""
16467
+$as_echo "$ac_try_echo") >&5
16468
+  (eval "$ac_link") 2>conftest.er1
16469
+  ac_status=$?
16470
+  grep -v '^ *+' conftest.er1 >conftest.err
16471
+  rm -f conftest.er1
16472
+  cat conftest.err >&5
16473
+  $as_echo "$as_me:$LINENO: \$? = $ac_status" >&5
16474
+  (exit $ac_status); } && {
16475
+	 test -z "$ac_c_werror_flag" ||
16476
+	 test ! -s conftest.err
16477
+       } && test -s conftest$ac_exeext && {
16478
+	 test "$cross_compiling" = yes ||
16479
+	 $as_test_x conftest$ac_exeext
16480
+       }; then
16481
+  ac_cv_sys_largefile_source=1; break
16482
+else
16483
+  $as_echo "$as_me: failed program was:" >&5
16484
+sed 's/^/| /' conftest.$ac_ext >&5
16485
+
16486
+
16487
+fi
16488
+
16489
+rm -rf conftest.dSYM
16490
+rm -f core conftest.err conftest.$ac_objext conftest_ipa8_conftest.oo \
16491
+      conftest$ac_exeext conftest.$ac_ext
16492
+  ac_cv_sys_largefile_source=unknown
16493
+  break
16494
+done
16495
+fi
16496
+{ $as_echo "$as_me:$LINENO: result: $ac_cv_sys_largefile_source" >&5
16497
+$as_echo "$ac_cv_sys_largefile_source" >&6; }
16498
+case $ac_cv_sys_largefile_source in #(
16499
+  no | unknown) ;;
16500
+  *)
16501
+cat >>confdefs.h <<_ACEOF
16502
+#define _LARGEFILE_SOURCE $ac_cv_sys_largefile_source
16503
+_ACEOF
16504
+;;
16505
+esac
16506
+rm -rf conftest*
16507
+
16508
+# We used to try defining _XOPEN_SOURCE=500 too, to work around a bug
16509
+# in glibc 2.1.3, but that breaks too many other things.
16510
+# If you want fseeko and ftello with glibc, upgrade to a fixed glibc.
16511
+if test $ac_cv_sys_largefile_source != unknown; then
16512
+
16513
+cat >>confdefs.h <<\_ACEOF
16514
+#define HAVE_FSEEKO 1
16515
+_ACEOF
16516
+
16517
+fi
16518
+
16519
+
16387 16520
 
16388 16521
 	{ $as_echo "$as_me:$LINENO: checking for working mmap" >&5
16389 16522
 $as_echo_n "checking for working mmap... " >&6; }
... ...
@@ -16508,25 +16641,29 @@ _ACEOF
16508 16508
 fi
16509 16509
 rm -f conftest.mmap
16510 16510
 
16511
-{ $as_echo "$as_me:$LINENO: checking for _LARGEFILE_SOURCE value needed for large files" >&5
16512
-$as_echo_n "checking for _LARGEFILE_SOURCE value needed for large files... " >&6; }
16513
-if test "${ac_cv_sys_largefile_source+set}" = set; then
16511
+
16512
+ac_cv_c_can_get_pagesize="no"
16513
+{ $as_echo "$as_me:$LINENO: checking for sysconf(_SC_PAGESIZE)" >&5
16514
+$as_echo_n "checking for sysconf(_SC_PAGESIZE)... " >&6; }
16515
+if test "${ac_cv_c_sysconf_sc_pagesize+set}" = set; then
16514 16516
   $as_echo_n "(cached) " >&6
16515 16517
 else
16516
-  while :; do
16517
-  cat >conftest.$ac_ext <<_ACEOF
16518
+
16519
+	cat >conftest.$ac_ext <<_ACEOF
16518 16520
 /* confdefs.h.  */
16519 16521
 _ACEOF
16520 16522
 cat confdefs.h >>conftest.$ac_ext
16521 16523
 cat >>conftest.$ac_ext <<_ACEOF
16522 16524
 /* end confdefs.h.  */
16523
-#include <sys/types.h> /* for off_t */
16524
-     #include <stdio.h>
16525
+
16526
+#include <sys/types.h>
16527
+#if HAVE_UNISTD_H
16528
+#include <unistd.h>
16529
+#endif
16525 16530
 int
16526 16531
 main ()
16527 16532
 {
16528
-int (*fp) (FILE *, off_t, int) = fseeko;
16529
-     return fseeko (stdin, 0, 0) && fp (stdin, 0, 0);
16533
+int x = sysconf(_SC_PAGESIZE);
16530 16534
   ;
16531 16535
   return 0;
16532 16536
 }
... ...
@@ -16552,31 +16689,49 @@ $as_echo "$ac_try_echo") >&5
16552 16552
 	 test "$cross_compiling" = yes ||
16553 16553
 	 $as_test_x conftest$ac_exeext
16554 16554
        }; then
16555
-  ac_cv_sys_largefile_source=no; break
16555
+  ac_cv_c_sysconf_sc_pagesize=yes
16556 16556
 else
16557 16557
   $as_echo "$as_me: failed program was:" >&5
16558 16558
 sed 's/^/| /' conftest.$ac_ext >&5
16559 16559
 
16560
-
16560
+	ac_cv_c_sysconf_sc_pagesize=no
16561 16561
 fi
16562 16562
 
16563 16563
 rm -rf conftest.dSYM
16564 16564
 rm -f core conftest.err conftest.$ac_objext conftest_ipa8_conftest.oo \
16565 16565
       conftest$ac_exeext conftest.$ac_ext
16566
-  cat >conftest.$ac_ext <<_ACEOF
16566
+
16567
+fi
16568
+{ $as_echo "$as_me:$LINENO: result: $ac_cv_c_sysconf_sc_pagesize" >&5
16569
+$as_echo "$ac_cv_c_sysconf_sc_pagesize" >&6; }
16570
+if test "$ac_cv_c_sysconf_sc_pagesize" = "yes"; then
16571
+
16572
+cat >>confdefs.h <<\_ACEOF
16573
+#define HAVE_SYSCONF_SC_PAGESIZE 1
16574
+_ACEOF
16575
+
16576
+	ac_cv_c_can_get_pagesize="yes"
16577
+fi
16578
+{ $as_echo "$as_me:$LINENO: checking for getpagesize()" >&5
16579
+$as_echo_n "checking for getpagesize()... " >&6; }
16580
+if test "${ac_cv_c_getpagesize+set}" = set; then
16581
+  $as_echo_n "(cached) " >&6
16582
+else
16583
+
16584
+	cat >conftest.$ac_ext <<_ACEOF
16567 16585
 /* confdefs.h.  */
16568 16586
 _ACEOF
16569 16587
 cat confdefs.h >>conftest.$ac_ext
16570 16588
 cat >>conftest.$ac_ext <<_ACEOF
16571 16589
 /* end confdefs.h.  */
16572
-#define _LARGEFILE_SOURCE 1
16573
-#include <sys/types.h> /* for off_t */
16574
-     #include <stdio.h>
16590
+
16591
+#if HAVE_UNISTD_H
16592
+#include <unistd.h>
16593
+#endif
16575 16594
 int
16576 16595
 main ()
16577 16596
 {
16578
-int (*fp) (FILE *, off_t, int) = fseeko;
16579
-     return fseeko (stdin, 0, 0) && fp (stdin, 0, 0);
16597
+int x = getpagesize();
16580 16598
   ;
16581 16599
   return 0;
16582 16600
 }
... ...
@@ -16602,45 +16757,30 @@ $as_echo "$ac_try_echo") >&5
16602 16602
 	 test "$cross_compiling" = yes ||
16603 16603
 	 $as_test_x conftest$ac_exeext
16604 16604
        }; then
16605
-  ac_cv_sys_largefile_source=1; break
16605
+  ac_cv_c_getpagesize=yes
16606 16606
 else
16607 16607
   $as_echo "$as_me: failed program was:" >&5
16608 16608
 sed 's/^/| /' conftest.$ac_ext >&5
16609 16609
 
16610
-
16610
+	ac_cv_c_getpagesize=no
16611 16611
 fi
16612 16612
 
16613 16613
 rm -rf conftest.dSYM
16614 16614
 rm -f core conftest.err conftest.$ac_objext conftest_ipa8_conftest.oo \
16615 16615
       conftest$ac_exeext conftest.$ac_ext
16616
-  ac_cv_sys_largefile_source=unknown
16617
-  break
16618
-done
16619
-fi
16620
-{ $as_echo "$as_me:$LINENO: result: $ac_cv_sys_largefile_source" >&5
16621
-$as_echo "$ac_cv_sys_largefile_source" >&6; }
16622
-case $ac_cv_sys_largefile_source in #(
16623
-  no | unknown) ;;
16624
-  *)
16625
-cat >>confdefs.h <<_ACEOF
16626
-#define _LARGEFILE_SOURCE $ac_cv_sys_largefile_source
16627
-_ACEOF
16628
-;;
16629
-esac
16630
-rm -rf conftest*
16631 16616
 
16632
-# We used to try defining _XOPEN_SOURCE=500 too, to work around a bug
16633
-# in glibc 2.1.3, but that breaks too many other things.
16634
-# If you want fseeko and ftello with glibc, upgrade to a fixed glibc.
16635
-if test $ac_cv_sys_largefile_source != unknown; then
16617
+fi
16618
+{ $as_echo "$as_me:$LINENO: result: $ac_cv_c_getpagesize" >&5
16619
+$as_echo "$ac_cv_c_getpagesize" >&6; }
16620
+if test "$ac_cv_c_getpagesize" = "yes"; then
16636 16621
 
16637 16622
 cat >>confdefs.h <<\_ACEOF
16638
-#define HAVE_FSEEKO 1
16623
+#define HAVE_GETPAGESIZE 1
16639 16624
 _ACEOF
16640 16625
 
16626
+	ac_cv_c_can_get_pagesize="yes"
16641 16627
 fi
16642 16628
 
16643
-
16644 16629
 # Check whether --enable-mempool was given.
16645 16630
 if test "${enable_mempool+set}" = set; then
16646 16631
   enableval=$enable_mempool; enable_mempool=$enableval
... ...
@@ -16653,93 +16793,10 @@ if test "$enable_mempool" = "yes"; then
16653 16653
 		{ $as_echo "$as_me:$LINENO: ****** mempool support disabled (mmap not available or not usable)" >&5
16654 16654
 $as_echo "$as_me: ****** mempool support disabled (mmap not available or not usable)" >&6;}
16655 16655
 	else
16656
-		{ $as_echo "$as_me:$LINENO: checking for getpagesize" >&5
16657
-$as_echo_n "checking for getpagesize... " >&6; }
16658
-if test "${ac_cv_func_getpagesize+set}" = set; then
16659
-  $as_echo_n "(cached) " >&6
16660
-else
16661
-  cat >conftest.$ac_ext <<_ACEOF
16662
-/* confdefs.h.  */
16663
-_ACEOF
16664
-cat confdefs.h >>conftest.$ac_ext
16665
-cat >>conftest.$ac_ext <<_ACEOF
16666
-/* end confdefs.h.  */
16667
-/* Define getpagesize to an innocuous variant, in case <limits.h> declares getpagesize.
16668
-   For example, HP-UX 11i <limits.h> declares gettimeofday.  */
16669
-#define getpagesize innocuous_getpagesize
16670
-
16671
-/* System header to define __stub macros and hopefully few prototypes,
16672
-    which can conflict with char getpagesize (); below.
16673
-    Prefer <limits.h> to <assert.h> if __STDC__ is defined, since
16674
-    <limits.h> exists even on freestanding compilers.  */
16675
-
16676
-#ifdef __STDC__
16677
-# include <limits.h>
16678
-#else
16679
-# include <assert.h>
16680
-#endif
16681
-
16682
-#undef getpagesize
16683
-
16684
-/* Override any GCC internal prototype to avoid an error.
16685
-   Use char because int might match the return type of a GCC
16686
-   builtin and then its argument prototype would still apply.  */
16687
-#ifdef __cplusplus
16688
-extern "C"
16689
-#endif
16690
-char getpagesize ();
16691
-/* The GNU C library defines this for functions which it implements
16692
-    to always fail with ENOSYS.  Some functions are actually named
16693
-    something starting with __ and the normal name is an alias.  */
16694
-#if defined __stub_getpagesize || defined __stub___getpagesize
16695
-choke me
16696
-#endif
16697
-
16698
-int
16699
-main ()
16700
-{
16701
-return getpagesize ();
16702
-  ;
16703
-  return 0;
16704
-}
16705
-_ACEOF
16706
-rm -f conftest.$ac_objext conftest$ac_exeext
16707
-if { (ac_try="$ac_link"
16708
-case "(($ac_try" in
16709
-  *\"* | *\`* | *\\*) ac_try_echo=\$ac_try;;
16710
-  *) ac_try_echo=$ac_try;;
16711
-esac
16712
-eval ac_try_echo="\"\$as_me:$LINENO: $ac_try_echo\""
16713
-$as_echo "$ac_try_echo") >&5
16714
-  (eval "$ac_link") 2>conftest.er1
16715
-  ac_status=$?
16716
-  grep -v '^ *+' conftest.er1 >conftest.err
16717
-  rm -f conftest.er1
16718
-  cat conftest.err >&5
16719
-  $as_echo "$as_me:$LINENO: \$? = $ac_status" >&5
16720
-  (exit $ac_status); } && {
16721
-	 test -z "$ac_c_werror_flag" ||
16722
-	 test ! -s conftest.err
16723
-       } && test -s conftest$ac_exeext && {
16724
-	 test "$cross_compiling" = yes ||
16725
-	 $as_test_x conftest$ac_exeext
16726
-       }; then
16727
-  ac_cv_func_getpagesize=yes
16728
-else
16729
-  $as_echo "$as_me: failed program was:" >&5
16730
-sed 's/^/| /' conftest.$ac_ext >&5
16731
-
16732
-	ac_cv_func_getpagesize=no
16733
-fi
16734
-
16735
-rm -rf conftest.dSYM
16736
-rm -f core conftest.err conftest.$ac_objext conftest_ipa8_conftest.oo \
16737
-      conftest$ac_exeext conftest.$ac_ext
16738
-fi
16739
-{ $as_echo "$as_me:$LINENO: result: $ac_cv_func_getpagesize" >&5
16740
-$as_echo "$ac_cv_func_getpagesize" >&6; }
16741
-if test "x$ac_cv_func_getpagesize" = x""yes; then
16742
-
16656
+		if test "$ac_cv_c_can_get_pagesize" != "yes"; then
16657
+			{ $as_echo "$as_me:$LINENO: ****** mempool support disabled (pagesize cannot be determined)" >&5
16658
+$as_echo "$as_me: ****** mempool support disabled (pagesize cannot be determined)" >&6;}
16659
+		else
16743 16660
 
16744 16661
 	{ $as_echo "$as_me:$LINENO: checking for MAP_ANON(YMOUS)" >&5
16745 16662
 $as_echo_n "checking for MAP_ANON(YMOUS)... " >&6; }
... ...
@@ -16867,12 +16924,7 @@ cat >>confdefs.h <<\_ACEOF
16867 16867
 _ACEOF
16868 16868
 
16869 16869
 			fi
16870
-
16871
-else
16872
-  { $as_echo "$as_me:$LINENO: ****** mempool support disabled (getpagesize not available)" >&5
16873
-$as_echo "$as_me: ****** mempool support disabled (getpagesize not available)" >&6;}
16874
-fi
16875
-
16870
+		fi
16876 16871
 	fi
16877 16872
 fi
16878 16873
 
... ...
@@ -424,22 +424,26 @@ AC_CHECK_LIB([socket], [bind], [LIBS="$LIBS -lsocket"; CLAMAV_MILTER_LIBS="$CLAM
424 424
 AC_SEARCH_LIBS([gethostent],[nsl], [(LIBS="$LIBS -lnsl"; CLAMAV_MILTER_LIBS="$CLAMAV_MILTER_LIBS -lnsl"; FRESHCLAM_LIBS="$FRESHCLAM_LIBS -lnsl"; CLAMD_LIBS="$CLAMD_LIBS -lnsl")])
425 425
 
426 426
 AC_CHECK_FUNCS([poll setsid memcpy snprintf vsnprintf strerror_r strlcpy strlcat strcasestr inet_ntop setgroups initgroups ctime_r mkstemp mallinfo])
427
-AC_C_FUNC_MMAP_PRIVATE
428 427
 AC_FUNC_FSEEKO
429 428
 
429
+dnl Check if anon maps are available, check if we can determine the page size
430
+AC_C_FUNC_MMAP_PRIVATE
431
+AC_C_FUNC_PAGESIZE
430 432
 AC_ARG_ENABLE([mempool],[  --disable-mempool       disable memory pools], enable_mempool=$enableval, enable_mempool="yes")
431 433
 if test "$enable_mempool" = "yes"; then
432 434
 	if test "$ac_cv_c_mmap_private" != "yes"; then
433 435
 		AC_MSG_NOTICE([****** mempool support disabled (mmap not available or not usable)])
434 436
 	else
435
-		AC_CHECK_FUNC([getpagesize], [
437
+		if test "$ac_cv_c_can_get_pagesize" != "yes"; then
438
+			AC_MSG_NOTICE([****** mempool support disabled (pagesize cannot be determined)])
439
+		else
436 440
 			AC_C_FUNC_MMAP_ANONYMOUS
437 441
 			if test "$ac_cv_c_mmap_anonymous" = "no"; then
438 442
 				AC_MSG_NOTICE([****** mempool support disabled (anonymous mmap not available)])
439 443
 			else
440 444
 				AC_DEFINE([USE_MPOOL],1,[enable memory pools])
441 445
 			fi
442
-		], [AC_MSG_NOTICE([****** mempool support disabled (getpagesize not available)])])
446
+		fi
443 447
 	fi
444 448
 fi
445 449
 
... ...
@@ -181,7 +181,7 @@ blobGetFilename(const blob *b)
181 181
 int
182 182
 blobAddData(blob *b, const unsigned char *data, size_t len)
183 183
 {
184
-#ifdef	HAVE_GETPAGESIZE
184
+#if	HAVE_CLI_GETPAGESIZE
185 185
 	static int pagesize;
186 186
 	int growth;
187 187
 #endif
... ...
@@ -210,9 +210,9 @@ blobAddData(blob *b, const unsigned char *data, size_t len)
210 210
 	 * size of a blob before you start adding data, use blobGrow() that's
211 211
 	 * the most optimum
212 212
 	 */
213
-#ifdef	HAVE_GETPAGESIZE
213
+#if	HAVE_CLI_GETPAGESIZE
214 214
 	if(pagesize == 0) {
215
-		pagesize = getpagesize();
215
+		pagesize = cli_getpagesize();
216 216
 		if(pagesize == 0)
217 217
 			pagesize = 4096;
218 218
 	}
... ...
@@ -41,7 +41,9 @@
41 41
 #include <string.h>
42 42
 #endif
43 43
 #include <limits.h>
44
+#if HAVE_STRINGS_H
44 45
 #include <strings.h>
46
+#endif
45 47
 #include <zlib.h>
46 48
 
47 49
 #include "scanners.h"
... ...
@@ -514,8 +516,8 @@ static int is_parse_hdr(int desc, cli_ctx *ctx, struct IS_CABSTUFF *c) {
514 514
 	    return CL_EREAD; /* hdr must be within bounds, it's k to hard fail here */
515 515
 	}
516 516
     } else {
517
-#if HAVE_MMAP
518
-	int psz = getpagesize();
517
+#if HAVE_MMAP && HAVE_CLI_GETPAGESIZE
518
+	int psz = cli_getpagesize();
519 519
 	off_t mp_hdr = (c->hdr / psz) * psz;
520 520
 	mp_hdrsz = c->hdrsz + c->hdr - mp_hdr;
521 521
 	if((map = mmap(NULL, mp_hdrsz, PROT_READ, MAP_PRIVATE, desc, mp_hdr))==MAP_FAILED) {
... ...
@@ -524,7 +526,7 @@ static int is_parse_hdr(int desc, cli_ctx *ctx, struct IS_CABSTUFF *c) {
524 524
 	}
525 525
 	hdr = map + c->hdr - mp_hdr;
526 526
 #else
527
-	cli_warnmsg("is_parse_hdr: hdr too big and mmap unavailable\n");
527
+	cli_warnmsg("is_parse_hdr: hdr too big and mmap is not usable\n");
528 528
 	return CL_CLEAN
529 529
 #endif
530 530
     }
... ...
@@ -716,7 +718,12 @@ static int is_extract_cab(int desc, cli_ctx *ctx, uint64_t off, uint64_t size, u
716 716
 	close(ofd);
717 717
 	return CL_EOPEN;
718 718
     }
719
-    if(fseeko(in, off, SEEK_SET)) {
719
+#if HAVE_FSEEKO
720
+    if(fseeko(in, (off_t)off, SEEK_SET))
721
+#else
722
+    if(fseek(in, (long)off, SEEK_SET))
723
+#endif
724
+    {
720 725
 	cli_dbgmsg("is_extract_cab: fseek failed\n");
721 726
 	fclose(in);
722 727
 	return CL_ESEEK;
... ...
@@ -349,7 +349,7 @@ struct MP *mpool_create() {
349 349
   struct MP mp, *mpool_p;
350 350
   unsigned int sz;
351 351
   memset(&mp, 0, sizeof(mp));
352
-  mp.psize = getpagesize();
352
+  mp.psize = cli_getpagesize();
353 353
   sz = align_to_pagesize(&mp, MIN_FRAGSIZE);
354 354
   mp.mpm.usize = align_to_voidptr(sizeof(struct MPMAP));
355 355
   mp.mpm.size = sz - align_to_voidptr(sizeof(mp));
... ...
@@ -365,6 +365,17 @@ void cli_dbgmsg_internal(const char *str, ...) __attribute__((format(printf, 1,
365 365
 void cli_dbgmsg_internal(const char *str, ...);
366 366
 #endif
367 367
 
368
+#if HAVE_SYSCONF_SC_PAGESIZE
369
+static inline int cli_getpagesize() { return sysconf(_SC_PAGESIZE); }
370
+#define HAVE_CLI_GETPAGESIZE 1
371
+#else
372
+#if HAVE_GETPAGESIZE
373
+static inline int cli_getpagesize() { return getpagesize(); }
374
+#define HAVE_CLI_GETPAGESIZE 1
375
+#endif
376
+#define HAVE_CLI_GETPAGESIZE 0
377
+#endif
378
+
368 379
 void *cli_malloc(size_t nmemb);
369 380
 void *cli_calloc(size_t nmemb, size_t size);
370 381
 void *cli_realloc(void *ptr, size_t size);
... ...
@@ -100,3 +100,32 @@ AC_DEFUN([AC_C_FUNC_MMAP_ANONYMOUS],
100 100
 		AC_DEFINE_UNQUOTED([ANONYMOUS_MAP],[$ac_cv_c_mmap_anonymous],[mmap flag for anonymous maps])
101 101
 	fi
102 102
 ])
103
+
104
+AC_DEFUN([AC_C_FUNC_PAGESIZE],
105
+[
106
+ac_cv_c_can_get_pagesize="no"
107
+AC_CACHE_CHECK([for sysconf(_SC_PAGESIZE)], [ac_cv_c_sysconf_sc_pagesize], [
108
+	AC_LINK_IFELSE([AC_LANG_PROGRAM([[
109
+#include <sys/types.h>
110
+#if HAVE_UNISTD_H
111
+#include <unistd.h>
112
+#endif]], [[int x = sysconf(_SC_PAGESIZE);]])],
113
+	[ac_cv_c_sysconf_sc_pagesize=yes], [ac_cv_c_sysconf_sc_pagesize=no])
114
+])
115
+if test "$ac_cv_c_sysconf_sc_pagesize" = "yes"; then
116
+	AC_DEFINE([HAVE_SYSCONF_SC_PAGESIZE], 1, [Define to 1 if sysconf(_SC_PAGESIZE) is available])
117
+	ac_cv_c_can_get_pagesize="yes"
118
+fi
119
+AC_CACHE_CHECK([for getpagesize()], [ac_cv_c_getpagesize], [
120
+	AC_LINK_IFELSE([AC_LANG_PROGRAM([[
121
+#if HAVE_UNISTD_H
122
+#include <unistd.h>
123
+#endif]], [[int x = getpagesize();]])], 
124
+	[ac_cv_c_getpagesize=yes], [ac_cv_c_getpagesize=no])
125
+])
126
+if test "$ac_cv_c_getpagesize" = "yes"; then
127
+	AC_DEFINE([HAVE_GETPAGESIZE], 1, [Define to 1 if getpagesize() is available])
128
+	ac_cv_c_can_get_pagesize="yes"
129
+fi
130
+])
131
+