MCPcopy Create free account
hub / github.com/assaultcube/AC / open

Method open

source/src/stream.cpp:724–750  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

722 }
723
724 bool open(stream *f, const char *mode, bool needclose, int level)
725 {
726 if(file) return false;
727 for(; *mode; mode++)
728 {
729 if(*mode=='r') { reading = true; break; }
730 else if(*mode=='w') { writing = true; break; }
731 }
732 if(reading)
733 {
734 if(inflateInit2(&zfile, -MAX_WBITS) != Z_OK) reading = false;
735 }
736 else if(writing && deflateInit2(&zfile, level, Z_DEFLATED, -MAX_WBITS, min(MAX_MEM_LEVEL, 8), Z_DEFAULT_STRATEGY) != Z_OK) writing = false;
737 if(!reading && !writing) return false;
738
739 autoclose = needclose;
740 file = f;
741 crc = crc32(0, NULL, 0);
742 buf = new uchar[BUFSIZE];
743
744 if(reading)
745 {
746 if(!checkheader()) { stopreading(); file = NULL; return false; }
747 }
748 else if(writing) writeheader();
749 return true;
750 }
751
752 uint getcrc() { return crc; }
753

Callers 2

openrawfileFunction · 0.45
opengzfileFunction · 0.45

Calls 1

minFunction · 0.85

Tested by

no test coverage detected