| 1690 | */ |
| 1691 | |
| 1692 | int FS_FileIsInPAK(const char *filename ) { |
| 1693 | searchpath_t *search; |
| 1694 | pack_t *pak; |
| 1695 | fileInPack_t *pakFile; |
| 1696 | long hash = 0; |
| 1697 | |
| 1698 | FS_AssertInitialised(); |
| 1699 | |
| 1700 | if ( !filename ) { |
| 1701 | Com_Error( ERR_FATAL, "FS_FOpenFileRead: NULL 'filename' parameter passed\n" ); |
| 1702 | } |
| 1703 | |
| 1704 | // qpaths are not supposed to have a leading slash |
| 1705 | if ( filename[0] == '/' || filename[0] == '\\' ) { |
| 1706 | filename++; |
| 1707 | } |
| 1708 | |
| 1709 | // make absolutely sure that it can't back up the path. |
| 1710 | // The searchpaths do guarantee that something will always |
| 1711 | // be prepended, so we don't need to worry about "c:" or "//limbo" |
| 1712 | if ( strstr( filename, ".." ) || strstr( filename, "::" ) ) { |
| 1713 | return -1; |
| 1714 | } |
| 1715 | |
| 1716 | // |
| 1717 | // search through the path, one element at a time |
| 1718 | // |
| 1719 | |
| 1720 | for ( search = fs_searchpaths ; search ; search = search->next ) { |
| 1721 | // |
| 1722 | if (search->pack) { |
| 1723 | hash = FS_HashFileName(filename, search->pack->hashSize); |
| 1724 | } |
| 1725 | // is the element a pak file? |
| 1726 | if ( search->pack && search->pack->hashTable[hash] ) { |
| 1727 | // look through all the pak file elements |
| 1728 | pak = search->pack; |
| 1729 | pakFile = pak->hashTable[hash]; |
| 1730 | do { |
| 1731 | // case and separator insensitive comparisons |
| 1732 | if ( !FS_FilenameCompare( pakFile->name, filename ) ) { |
| 1733 | return 1; |
| 1734 | } |
| 1735 | pakFile = pakFile->next; |
| 1736 | } while(pakFile != NULL); |
| 1737 | } |
| 1738 | } |
| 1739 | return -1; |
| 1740 | } |
| 1741 | |
| 1742 | /* |
| 1743 | ============ |
nothing calls this directly
no test coverage detected