int32 ReadInt32(IO::ISequentialByteStream* stream) { int32 v; if (stream->Read(&v, 4) != 4) throw std::exception("End of stream"); return LittleEndian32(v); }
int CChunk::Create(IO::Stream& m_stream) { m_dwFlags = 1; // Created ULONG id = LittleEndian32(m_id); ULONG size = LittleEndian32(m_size); m_stream.Write(&id, 4); m_stream.Write(&size, 4); m_pos = m_stream.Seek(0, IO::STREAM_SEEK_CUR); if (m_id == mmioFOURCC('R','I','F','F') || m_id == mmioFOURCC('L','I','S','T')) { ULONG grpID = LittleEndian32(m_grpid); m_stream.Write(&grpID, 4); } return 0; }
int CChunk::Ascend(IO::Stream& stream) { // int hr; LONGLONG curpos; curpos = stream.Seek(0, IO::STREAM_SEEK_CUR); if (m_dwFlags == 0) { // if (FAILED(hr)) return hr; LONGLONG li = m_pos+m_size; if (m_size & 1) li++; // Word-aligned chunks if (curpos > li) { DebugTrace("Read past chunk"); ASSERT(0); return -1; } stream.Seek(li, IO::STREAM_SEEK_SET); } else { ULONG cksize = (ULONG)(curpos - m_pos); if (m_size == 0) // Unknown size data at time of chunk creation { m_size = cksize; cksize = LittleEndian32(cksize); stream.Seek(m_pos-4, IO::STREAM_SEEK_SET); stream.Write(&cksize, 4); // Write the chunk length stream.Seek(curpos, System::IO::STREAM_SEEK_SET); } if (cksize & 1) { uint8 padbyte = 0; stream.Write(&padbyte, 1); } } return 0; }
void WriteSymbolsToFile(char *fname) { int i, fd, step; SymbolFile_t symfile = { { 0 } }; Symbol_t symbol; SymbolLine_t Line; // Open the symbol table file step = 1; #ifdef MSC_VS if ((fd = _sopen_s(&fd, fname, _O_BINARY | _O_WRONLY | _O_CREAT | _O_TRUNC, _SH_DENYWR, _S_IREAD | _S_IWRITE)) < 0) goto error; #else if ((fd = open(fname, O_BINARY | O_WRONLY | O_CREAT | O_TRUNC, 0666)) < 0) goto error; #endif // Write the SymbolFile_t header to the symbol file, filling its // members first. step = 2; if (NULL == getcwd(symfile.SourcePath, MAX_PATH_LENGTH)) goto error; symfile.NumberSymbols = SymbolTableSize; symfile.NumberLines = LineTableSize; // JMS: 07.28 LittleEndian32(&symfile.NumberSymbols); LittleEndian32(&symfile.NumberLines); step = 3; if (write(fd, (void *) &symfile, sizeof(SymbolFile_t)) < 0) goto error; // Loop and write the symbols to a file step = 4; for (i = 0; i < SymbolTableSize; i++) { memcpy(&symbol, (void *) &SymbolTable[i], sizeof(Symbol_t)); LittleEndian32(&symbol); LittleEndian32(&symbol.Value.Value); LittleEndian32(&symbol.Type); LittleEndian32(&symbol.LineNumber); if (write(fd, (void *) &symbol, sizeof(Symbol_t)) < 0) goto error; } // JMS: 07.28 // Loop and write the symbol lines to a file step = 5; for (i = 0; i < LineTableSize; i++) { memcpy(&Line, (void *) &LineTable[i], sizeof(SymbolLine_t)); LittleEndian32(&Line); LittleEndian32(&Line.CodeAddress.Value); LittleEndian32(&Line.LineNumber); if (write(fd, (void *) &Line, sizeof(SymbolLine_t)) < 0) goto error; } if (0) { char *s; error: ; s = strerror(errno); printf("\nFile error (symbol-table write, step %d): %s.\n", step, s); } else printf("\nSymbol-table file written.\n"); close(fd); }
int32 Archive::getint32() { int32 v; if (m_p->m_stream->Read(&v, 4) != 4) raise(IO::IOException("IO Error")); return LittleEndian32(v); }