#!/usr/bin/env bash
# Fake flock for tools/test-tools.sh (Git Bash has none): only `flock -n <fd>`, via perl's flock(2) on the inherited descriptor.
[ "${1:-}" = -n ] && [ -n "${2:-}" ] || { echo "fake flock: unsupported arguments $*" >&2; exit 64; }
exec perl -e 'use Fcntl qw(:flock); open(my $f, "+<&=", $ARGV[0]) or exit 2; exit(flock($f, LOCK_EX | LOCK_NB) ? 0 : 1)' "$2"
