示例#1
0
char *fileMgr_readLine(file_t *file)
{
	// todo: optimize this..
	DWORD currentSeek = SetFilePointer(file->hFile, 0, NULL, FILE_CURRENT);
	DWORD fileSize = GetFileSize(file->hFile, NULL);
	DWORD maxLen = fileSize - currentSeek;
	if( maxLen == 0 )
		return NULL; // eof reached
	// begin parsing
	char *cstr = (char*)memMgr_alloc(NULL, 512);
	int size = 0;
	int limit = 512;
	while( maxLen )
	{
		maxLen--;
		char n = fileMgr_readS8(file);
		if( n == '\r' )
			continue; // skip
		if( n == '\n' )
			break; // line end
		cstr[size] = n;
		size++;
		if( size == limit )
			__debugbreak();
	}
	cstr[size] = '\0';
	return cstr;
}
示例#2
0
stream_t *fileMgr_openWriteable(char *name)
{
	HANDLE hFile = CreateFile(name, FILE_GENERIC_READ|FILE_GENERIC_WRITE, FILE_SHARE_READ, 0, OPEN_EXISTING, 0, 0);
	if( hFile == INVALID_HANDLE_VALUE )
		return NULL;
	file_t *file = (file_t*)memMgr_alloc(NULL, sizeof(file_t));
	file->hFile = hFile;
	stream_t* stream = stream_create(&fileStreamSettings, file);
	file->stream = stream;
	return file->stream;
}
void hashTable_init(HashTable_stringSynced_t *hashTable, int itemLimit)
{
    InitializeCriticalSection(&hashTable->cs);
    hashTable->size = itemLimit;
    hashTable->entrys = (_HashTable_string_entry_t*)memMgr_alloc(NULL, sizeof(_HashTable_string_entry_t)*itemLimit);
    // reset all items
    for(int i=0; i<itemLimit; i++)
    {
        hashTable->entrys[i].hashB = 0xFFFFFFFF;
        hashTable->entrys[i].hashC = 0xFFFFFFFF;
        hashTable->entrys[i].item = NULL;
    }
}
示例#4
0
stream_t *fileMgr_create(char *name)
{
	HANDLE hFile = CreateFile(name, GENERIC_WRITE | GENERIC_READ, FILE_SHARE_READ, 0, CREATE_ALWAYS, 0, 0);
	if( hFile == INVALID_HANDLE_VALUE )
		return NULL;
	file_t *file = (file_t*)memMgr_alloc(NULL, sizeof(file_t));
	file->hFile = hFile;
	file->stream = NULL;
	if( file->stream == NULL )
	{
		stream_t* stream = stream_create(&fileStreamSettings, file);
		file->stream = stream;
	}
	return file->stream;
}
示例#5
0
stream_t *fileMgr_openForAppend(char *name)
{
	HANDLE hFile = CreateFile(name, FILE_GENERIC_READ|FILE_GENERIC_WRITE, FILE_SHARE_READ, 0, OPEN_ALWAYS, 0, 0);
	if( hFile == INVALID_HANDLE_VALUE )
		return NULL;
	file_t *file = (file_t*)memMgr_alloc(NULL, sizeof(file_t));
	file->hFile = hFile;
	file->stream = NULL;
	SetFilePointer(file->hFile, 0, 0, FILE_END);
	if( file->stream == NULL )
	{
		stream_t* stream = stream_create(&fileStreamSettings, file);
		file->stream = stream;
	}
	return file->stream;
}