Create generic function for getting resource struct from rd

Unfortunately, close() can't use this, as it needs a pointer to the
resource pointer.
Resource comments and whitespace fixup
Remove unused resource function