MCPcopy Create free account
hub / github.com/ClusterLabs/pacemaker / decompress_file

Function decompress_file

lib/common/xml.c:643–697  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

641}
642
643static char *
644decompress_file(const char *filename)
645{
646 char *buffer = NULL;
647#if HAVE_BZLIB_H
648 int rc = 0;
649 size_t length = 0, read_len = 0;
650
651 BZFILE *bz_file = NULL;
652 FILE *input = fopen(filename, "r");
653
654 if(input == NULL) {
655 crm_perror(LOG_ERR,"Could not open %s for reading", filename);
656 return NULL;
657 }
658
659 bz_file = BZ2_bzReadOpen(&rc, input, 0, 0, NULL, 0);
660
661 if ( rc != BZ_OK ) {
662 BZ2_bzReadClose ( &rc, bz_file);
663 return NULL;
664 }
665
666 rc = BZ_OK;
667 while ( rc == BZ_OK ) {
668 buffer = realloc(buffer, XML_BUFFER_SIZE + length + 1);
669 read_len = BZ2_bzRead (
670 &rc, bz_file, buffer + length, XML_BUFFER_SIZE);
671
672 crm_trace("Read %ld bytes from file: %d",
673 (long)read_len, rc);
674
675 if ( rc == BZ_OK || rc == BZ_STREAM_END) {
676 length += read_len;
677 }
678 }
679
680 buffer[length] = '\0';
681 read_len = length;
682
683 if ( rc != BZ_STREAM_END ) {
684 crm_err("Couldnt read compressed xml from file");
685 free(buffer);
686 buffer = NULL;
687 }
688
689 BZ2_bzReadClose (&rc, bz_file);
690 fclose(input);
691
692#else
693 crm_err("Cannot read compressed files:"
694 " bzlib was not available at compile time");
695#endif
696 return buffer;
697}
698
699void strip_text_nodes(xmlNode *xml)
700{

Callers 1

filename2xmlFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected