code checked */
| 1645 | |
| 1646 | /* code checked */ |
| 1647 | int rtpstream_cache_file(char* filename, |
| 1648 | int mode /* 0: FILE -- 1: PATTERN */, |
| 1649 | int id, |
| 1650 | int bytes_per_packet, |
| 1651 | int stream_type) |
| 1652 | { |
| 1653 | int count = 0; |
| 1654 | cached_file_t *newfilecachelist; |
| 1655 | cached_pattern_t *newpatterncachelist; |
| 1656 | char *filecontents; |
| 1657 | struct stat statbuffer; |
| 1658 | FILE *f; |
| 1659 | |
| 1660 | debugprint("rtpstream_cache_file filename = %s mode = %d id = %d bytes_per_packet = %d stream_type = %d\n", filename, mode, id, bytes_per_packet, stream_type); |
| 1661 | |
| 1662 | if ((debugafile == nullptr) && |
| 1663 | rtpcheck_debug && |
| 1664 | (stream_type == 0)) |
| 1665 | { |
| 1666 | debugafile = fopen("debugafile", "w"); |
| 1667 | if (debugafile == nullptr) |
| 1668 | { |
| 1669 | /* error encountered opening audio debug file */ |
| 1670 | return -1; |
| 1671 | } |
| 1672 | } |
| 1673 | |
| 1674 | if ((debugvfile == nullptr) && |
| 1675 | rtpcheck_debug && |
| 1676 | (stream_type == 1)) |
| 1677 | { |
| 1678 | debugvfile = fopen("debugvfile", "w"); |
| 1679 | if (debugvfile == nullptr) |
| 1680 | { |
| 1681 | /* error encountered opening video debug file */ |
| 1682 | return -1; |
| 1683 | } |
| 1684 | } |
| 1685 | |
| 1686 | if (mode == 1) |
| 1687 | { |
| 1688 | if ((id < 1) || (id > NUMPATTERNS)) |
| 1689 | { |
| 1690 | /* invalid pattern ID specified */ |
| 1691 | return -1; |
| 1692 | } |
| 1693 | |
| 1694 | /* cached pattern entries are stored in a dynamically grown array. */ |
| 1695 | /* could use a binary (or avl) tree but number of files should */ |
| 1696 | /* be small and doesn't really justify the effort. */ |
| 1697 | while (count < num_cached_files) |
| 1698 | { |
| 1699 | count++; |
| 1700 | } |
| 1701 | |
| 1702 | if (!(num_cached_files%RTPSTREAM_FILESPERBLOCK)) { |
| 1703 | /* Time to allocate more memory for the next block of files */ |
| 1704 | newpatterncachelist = (cached_pattern_t*) realloc(cached_patterns, sizeof(*cached_patterns) * (num_cached_files + RTPSTREAM_FILESPERBLOCK)); |
no test coverage detected