#!/bin/sh # have-func --- check for existence of library function # Author: Noah Friedman # Created: 1996-09-30 # Public domain. # $Id: have-func,v 2.2 2011/10/03 18:55:21 friedman Exp $ # Commentary: # Zero exit status if the named function exists, 1 otherwise. # Note: this script may lie if there are unrelated compilation problems. # Code: case "$#" in 1 ) : ;; 2 ) progname=`echo "$0" | sed -e 's/[^\/]*\///g'` echo "Usage: $progname [function name]" 1>&2 exit 1 ;; esac func="$1" file="functest$$" trap 'exitstat=$?; rm -f $file.c $file.o $file; exit $exitstat' 0 1 2 3 15 cat > "$file.c" <<__EOF__ /* System header to define __stub macros and hopefully few prototypes, which can conflict with char $ac_func(); below. */ #include /* Override any gcc2 internal prototype to avoid an error. */ /* We use char because int might match the return type of a gcc2 builtin and then its argument prototype would still apply. */ char $func (); int t () { /* The GNU C library defines this for functions which it implements * to always fail with ENOSYS. Some functions are actually named * something starting with __ and the normal name is an alias. */ #if defined (__stub_$func) || defined (__stub___$func) choke me #else $func (); #endif return 0; } int main () { t (); return 0; } __EOF__ if ${CC-cc} ${CFLAGS} $file.c -o $file ${LOADLIBES} && test -f "$file" then exit 0 fi exit 1 # have-func ends here