Closes an open CFILE. Parameters: cfile - the file pointer returned by cfopen()
| 537 | // Closes an open CFILE. |
| 538 | // Parameters: cfile - the file pointer returned by cfopen() |
| 539 | void cfclose(CFILE *cfp) { |
| 540 | // Either give the file back to the library, or close it |
| 541 | if (cfp->lib_handle != -1) { |
| 542 | std::shared_ptr<library> lib; |
| 543 | for (lib = Libraries; lib; lib = lib->next) { |
| 544 | if (lib->handle == cfp->lib_handle) { // found the library |
| 545 | // if library doesn't already have a file, give it this one |
| 546 | if (lib->file == nullptr) { |
| 547 | lib->file = cfp->file; |
| 548 | cfp->file = nullptr; |
| 549 | } |
| 550 | break; |
| 551 | } |
| 552 | } |
| 553 | } |
| 554 | // If the file handle wasn't given back to library, close the file |
| 555 | if (cfp->file) |
| 556 | fclose(cfp->file); |
| 557 | // free the name, if allocated |
| 558 | if (!cfp->lib_offset) |
| 559 | mem_free(cfp->name); |
| 560 | // free the cfile struct |
| 561 | mem_free(cfp); |
| 562 | } |
| 563 | |
| 564 | // Just like stdio fgetc(), except works on a CFILE |
| 565 | // Returns a char or EOF |
no outgoing calls
no test coverage detected