See man 2 unlink and man 2 rmdir for system calls that will delete files and (empty) directories respectively. All you need to do then in order to handle the recursive case is to traverse the target directory in a post-order depth-first traversal and delete each entry in that order with the correct deletion routine. You can use opendir, readdir, and closedir to traverse the directory structure.