#!/usr/bin/env bash src_dir=lib/src allocation_functions=(malloc calloc realloc free) for function in "${allocation_functions[@]}"; do usages=$(grep -n -E "\b${function}\(" -r $src_dir --exclude alloc.c --exclude stdlib.c) if [[ -n $usages ]]; then printf 'The %s function should not be called directly, but is called here:\n%s\n' "$function" "$usages" >&2 exit 1 fi done