diff options
| author | comex <comexk@gmail.com> | 2009-04-20 17:06:38 -0400 |
|---|---|---|
| committer | comex <comexk@gmail.com> | 2009-04-20 17:06:38 -0400 |
| commit | b440e369ed1a68337101f3258c44ee91765284e9 (patch) | |
| tree | 63e53ca8f02d3a0cf4e82cba7bb3239921401ace /memfile.c | |
| parent | cd6b21e3db3b05417b4e7ba662941c433d363bd0 (diff) | |
brlan.h and shit
Diffstat (limited to '')
| -rw-r--r-- | memfile.c | 112 |
1 files changed, 56 insertions, 56 deletions
@@ -15,96 +15,96 @@ void ReadMemory(void* dst, size_t size, size_t count, MEMORY* src) { - if((src->mode & 0x1) == 0) { - printf("Invalid mode for reading!\n"); - return; - } - u8* data = (u8*)dst; - if(((size * count) + src->position) > src->memorysize) { - printf("Tried to over read.\n"); - return; - } - memcpy(data, ((u8*)src->memory) + src->position, size * count); - src->position += size * count; + if((src->mode & 0x1) == 0) { + printf("Invalid mode for reading!\n"); + return; + } + u8* data = (u8*)dst; + if(((size * count) + src->position) > src->memorysize) { + printf("Tried to over read.\n"); + return; + } + memcpy(data, ((u8*)src->memory) + src->position, size * count); + src->position += size * count; } char ReadMemoryChar(MEMORY* src) { - char ret; - ReadMemory(&ret, 1, 1, src); - return ret; + char ret; + ReadMemory(&ret, 1, 1, src); + return ret; } void WriteMemory(void* dst, size_t size, size_t count, MEMORY* src) { - if((src->mode & 0x2) == 0) { - printf("Invalid mode for writing!\n"); - return; - } - u8* data = (u8*)dst; - if(((size * count) + src->position) > src->memorysize) { - printf("Tried to over read.\n"); - return; - } - memcpy(((u8*)src->memory) + src->position, data, size * count); - src->position += size * count; + if((src->mode & 0x2) == 0) { + printf("Invalid mode for writing!\n"); + return; + } + u8* data = (u8*)dst; + if(((size * count) + src->position) > src->memorysize) { + printf("Tried to over read.\n"); + return; + } + memcpy(((u8*)src->memory) + src->position, data, size * count); + src->position += size * count; } void WriteMemoryChar(char inchar, MEMORY* src) { - WriteMemory(&inchar, 1, 1, src); + WriteMemory(&inchar, 1, 1, src); } MEMORY* OpenMemory(void* indata, size_t size, char mode) { - MEMORY* mem = malloc(sizeof(MEMORY)); - if((mode & 0x2) == 0x0) - mem->memory = indata; - else - mem->memory = calloc(size, 1); - if(mem->memory == NULL) - return NULL; - mem->memorysize = size; - mem->position = 0; - mem->mode = mode; - return mem; + MEMORY* mem = malloc(sizeof(MEMORY)); + if((mode & 0x2) == 0x0) + mem->memory = indata; + else + mem->memory = calloc(size, 1); + if(mem->memory == NULL) + return NULL; + mem->memorysize = size; + mem->position = 0; + mem->mode = mode; + return mem; } void* CloseMemory(MEMORY* mem) { - void* ret = mem->memory; - mem->memory = NULL; - mem->memorysize = 0; - mem->position = 0; - mem->mode = 0; - free(mem); - return ret; + void* ret = mem->memory; + mem->memory = NULL; + mem->memorysize = 0; + mem->position = 0; + mem->mode = 0; + free(mem); + return ret; } void* GetMemory(MEMORY* mem) { - return mem->memory; + return mem->memory; } void SeekMemory(MEMORY* mem, size_t location, int type) { - switch(type) { - case SEEK_SET: - mem->position = location; - break; - - case SEEK_END: - mem->position = mem->memorysize - location; - break; - } + switch(type) { + case SEEK_SET: + mem->position = location; + break; + + case SEEK_END: + mem->position = mem->memorysize - location; + break; + } } size_t TellMemory(MEMORY* mem) { - return mem->position; + return mem->position; } size_t SizeMemory(MEMORY* mem) { - return mem->memorysize; + return mem->memorysize; } |
