int extract(FILE *f, ArchFileInfo *info, char *fileName) { LOGGING_FUNC_START; int _error = 0; FILE *fOut = NULL; char *buf = malloc(BUF_SIZE*sizeof(char)); char *buf2Write = malloc(BUF_SIZE*sizeof(char)*8); size_t lenBits = 0; size_t readBytes = 0; size_t returnBytes = 0; size_t readedBytes = 0; size_t howManyBytesRead = 0; Tree *haffTree = NULL; if (NULL == (fOut = fopen(fileName, "wb"))) { IO(L"Couldnt open file `%s`", fileName); __forErrorFileName = fileName; LOGGING_FUNC_STOP; return FILE_OPEN_ERROR; } haffTree = decodeTree(info->haffTree,info->haffTreeSize); initDecoding(haffTree); for (readedBytes=0; readedBytes < info->dataSize;) { howManyBytesRead = min(BUF_SIZE, (info->dataSize - readedBytes)); _error = readNBytes(f, howManyBytesRead, buf, &readBytes); readedBytes += readBytes; if (_error) { IO(L"Error reading archive file"); LOGGING_FUNC_STOP; return ARCHIVE_ERROR; } lenBits = (howManyBytesRead < BUF_SIZE) ? readBytes*8 - info->endUnusedBits : readBytes*8; decode(buf,lenBits,buf2Write,&returnBytes); _error = writeNBytes(fOut, returnBytes, buf2Write); if (_error) { IO("Write error to `%s`", fileName); __forErrorFileName = fileName; return _error; } } fclose(fOut); free(haffTree); LOGGING_FUNC_STOP; return 0; }
int checkingData(FILE *arch, ArchFileInfo *info, crc *real, crc *should){ initRdCrc(); size_t read_bytes; char *str = (char *)malloc(info->dataSize); readNBytes(arch, info->dataSize, str, &read_bytes); *real = getRdCrc(); readCrc(arch, should, &read_bytes); free(str); if (*real == *should){ return 0; } else { return 1; } }
PMDInternalStream::PMDInternalStream(const RVNGInputStreamPtr &input, unsigned long size) : librevenge::RVNGInputStream() , m_offset(0) , m_size(0) , m_data(0) , m_tmpBuf(0) , m_dataOwner(true) { const unsigned char *const bytes = readNBytes(input, size); unsigned char *const data = new unsigned char[size]; m_data = data; m_dataOwner = true; m_size = size; std::uninitialized_copy(bytes, bytes + size, data); }
void Source_scheduler(schedinfo_t *si) { int i = 0; write_Stream(); write_EOF(); // jump to FSM state switch (_FSM_state) { case my_state_ReadFile: goto l_ReadFile; case my_state_ReadFileDone: goto l_ReadFileDone; case my_state_ReadInit: goto l_ReadInit; case my_state_SendData: goto l_SendData; case my_state_SendLastData: goto l_SendLastData; default: printf("unknown state in Source.c : %s\n", stateNames[_FSM_state]); exit(1); } // FSM transitions l_ReadFile: if (isSchedulable_readNBytes()) { readNBytes(); i++; goto l_SendData; } else if (isSchedulable_sendData_done()) { sendData_done(); i++; goto l_ReadFileDone; } else { si->num_firings = i; si->reason = starved; _FSM_state = my_state_ReadFile; goto finished; } l_ReadFileDone: if (isSchedulable_closeFile()) { int stop = 0; if (1 > SIZE_EOF - index_EOF + Source_EOF->read_inds[0]) { stop = 1; } if (stop != 0) { _FSM_state = my_state_ReadFileDone; si->num_firings = i; si->reason = full; goto finished; } closeFile(); i++; goto l_ReadFileDone; } else { si->num_firings = i; si->reason = starved; _FSM_state = my_state_ReadFileDone; goto finished; } l_ReadInit: if (isSchedulable_getFileSize()) { getFileSize(); i++; goto l_ReadFile; } else { si->num_firings = i; si->reason = starved; _FSM_state = my_state_ReadInit; goto finished; } l_SendData: if (isSchedulable_sendData_launch()) { int stop = 0; if (221 > SIZE_Stream - index_Stream + Source_Stream->read_inds[0]) { stop = 1; } if (1 > SIZE_EOF - index_EOF + Source_EOF->read_inds[0]) { stop = 1; } if (stop != 0) { _FSM_state = my_state_SendData; si->num_firings = i; si->reason = full; goto finished; } { int isAligned = 1; isAligned &= ((index_Stream % SIZE_Stream) < ((index_Stream + 221) % SIZE_Stream)); if (isAligned) { sendData_launch_aligned(); } else { sendData_launch(); } } i++; goto l_SendData; } else if (isSchedulable_sendData_done()) { sendData_done(); i++; goto l_ReadFile; } else { si->num_firings = i; si->reason = starved; _FSM_state = my_state_SendData; goto finished; } l_SendLastData: if (isSchedulable_sendData_launch()) { int stop = 0; if (221 > SIZE_Stream - index_Stream + Source_Stream->read_inds[0]) { stop = 1; } if (1 > SIZE_EOF - index_EOF + Source_EOF->read_inds[0]) { stop = 1; } if (stop != 0) { _FSM_state = my_state_SendLastData; si->num_firings = i; si->reason = full; goto finished; } { int isAligned = 1; isAligned &= ((index_Stream % SIZE_Stream) < ((index_Stream + 221) % SIZE_Stream)); if (isAligned) { sendData_launch_aligned(); } else { sendData_launch(); } } i++; goto l_SendLastData; } else if (isSchedulable_sendData_done()) { sendData_done(); i++; goto l_ReadFileDone; } else { si->num_firings = i; si->reason = starved; _FSM_state = my_state_SendLastData; goto finished; } finished: write_end_Stream(); write_end_EOF(); }