require '_h2ph_pre.ph';

no warnings qw(redefine misc);

unless(defined(&_BLUETOOTH_H_)) {
    eval 'sub _BLUETOOTH_H_ () {1;}' unless defined(&_BLUETOOTH_H_);
    require 'sys/types.ph';
    require 'sys/endian.ph';
    require 'sys/socket.ph';
    require 'netbt/bluetooth.ph';
    require 'netbt/hci.ph';
    require 'netbt/l2cap.ph';
    require 'netdb.ph';
    require 'stdio.ph';
    require 'time.ph';
    eval 'sub BTOPT_DIRECTION () {(1<< 0);}' unless defined(&BTOPT_DIRECTION);
    eval 'sub BTOPT_TIMESTAMP () {(1<< 1);}' unless defined(&BTOPT_TIMESTAMP);
    eval 'sub bt_devclose {
        my($s) = @_;
	    eval q( &close($s));
    }' unless defined(&bt_devclose);
    eval 'sub BTHCID_SOCKET_NAME () {"/var/run/bthcid";}' unless defined(&BTHCID_SOCKET_NAME);
    if(defined(&COMPAT_BLUEZ)) {
	eval 'sub bacmp {
	    my($ba1, $ba2) = @_;
    	    eval q( &memcmp(($ba1), ($ba2), $sizeof{ &bdaddr_t}));
	}' unless defined(&bacmp);
	eval 'sub bacpy {
	    my($dst, $src) = @_;
    	    eval q( &memcpy(($dst), ($src), $sizeof{ &bdaddr_t}));
	}' unless defined(&bacpy);
	eval 'sub ba2str {
	    my($ba, $str) = @_;
    	    eval q( &bt_ntoa(($ba), ($str)));
	}' unless defined(&ba2str);
	eval 'sub str2ba {
	    my($str, $ba) = @_;
    	    eval q(( &bt_aton(($str), ($ba)) == 1? 0: -1));
	}' unless defined(&str2ba);
	eval 'sub htobs {
	    my($x) = @_;
    	    eval q( &htole16($x));
	}' unless defined(&htobs);
	eval 'sub htobl {
	    my($x) = @_;
    	    eval q( &htole32($x));
	}' unless defined(&htobl);
	eval 'sub btohs {
	    my($x) = @_;
    	    eval q( &le16toh($x));
	}' unless defined(&btohs);
	eval 'sub btohl {
	    my($x) = @_;
    	    eval q( &le32toh($x));
	}' unless defined(&btohl);
	eval 'sub bt_malloc {
	    my($n) = @_;
    	    eval q( &malloc($n));
	}' unless defined(&bt_malloc);
	eval 'sub bt_free {
	    my($p) = @_;
    	    eval q( &free($p));
	}' unless defined(&bt_free);
    }
}
1;
