コード例 #1
0
ファイル: Reference.cpp プロジェクト: cpascal/fbx-conv
bool Reference::updateOffset(FILE* file, long newOffset)
{
	if(getFilePosition() > 0)
	{
		// save the current offset
		long saveOffset = ftell(file);

		// update the offset data for us
		_offset = newOffset;
		// seek this Reference object in the file.
		fseek(file, getFilePosition(), SEEK_SET);

		//Skip over the id string
		skipString(file);

		// Skip
		skipUint(file);

		// write over the old offset.
		write(_offset, file);

		// restore the offset.
		fseek(file, saveOffset, SEEK_SET);
		return true;
	}

	return false;
}
コード例 #2
0
ファイル: lists.c プロジェクト: billev/literacybridge
char *getPreviousList(ListItem *list) {
	char *ret;
	char buffer[READ_LENGTH+1];
	int fileHandle;
	char *line, *tempCursor;
	int attempt,goodPass;
	const int MAX_ATTEMPTS = 3;
	
	if (list->currentFilePosition == -1)
		ret = getCurrentList(list); 
	else {
		for (attempt=0,goodPass=0;attempt < MAX_ATTEMPTS && !goodPass;attempt++) {
			fileHandle = openList(list,NULL);
			lseek(fileHandle,list->currentFilePosition,SEEK_SET);
			buffer[READ_LENGTH] = '\0'; //prevents readLine from searching for \n past buffer
			getLine(-1,0); // resets DONE
			line = getLine(fileHandle,buffer);
			if (!line)
				line[0] = 0; //empty list
			else {
				do {
					line = getLine(fileHandle,buffer);
				} while (line && strspn(line," \x0a\x0d\x00"));
				if (!line) {
					// end of file -- move to start
					line = getLine(fileHandle,0); // to reset DONE and move to BOF
					list->currentFilePosition = 0;
					line = getLine(fileHandle,buffer);
					if (!line)
						logException(9,0,RESET); //todo: format problem with list
				}
				list->currentFilePosition += getFilePosition();
			}
			close(fileHandle);
			for (tempCursor = line;*tempCursor != 0x0a && *tempCursor != 0x0d && *tempCursor != 0x00;tempCursor++);
			*tempCursor = 0x00;
			strcpy(list->currentString,line);
			ret = list->currentString;
			if ((goodPass = goodString(ret,1)))
				break;
			else 
				logException(30,0,0);
		}
		if (!goodPass)
			logException(30,0,RESET);
	}
	return ret;
}