The operative part of the rm command source
is line 343:
enum RM_status status = rm (file, &x);
Checking back to the includes, the most promisingly named is remove.h
which, as hoped, has the rm function declaration. From there it is a short step browsing the git repository tree
where the rm function is defined from line 592 onwards. That source suggests it is non-trivial to do what you want!