mirror of
https://notabug.org/scuti/lib3ddevil1
synced 2025-05-31 14:11:42 +05:30
Split main.c into separate files and set up directory structure
This commit is contained in:
37
src/devil1pld.c
Normal file
37
src/devil1pld.c
Normal file
@@ -0,0 +1,37 @@
|
||||
#include "devil1pld.h"
|
||||
#include "stdio.h"
|
||||
#include "stdlib.h"
|
||||
#include "string.h"
|
||||
|
||||
void printpldh(struct PldHeader *ph) {
|
||||
if (ph == NULL) {
|
||||
return;
|
||||
}
|
||||
printf("number of offsets = %i\n", ph -> numOffset);
|
||||
unsigned int i;
|
||||
for (i = 0; i < ph -> numOffset; i++) {
|
||||
printf("offset %i = %x\n", i, ph -> offsets[i]);
|
||||
}
|
||||
}
|
||||
|
||||
struct PldHeader *getpldh(const char *buffer) {
|
||||
if (buffer == NULL) {
|
||||
return NULL;
|
||||
}
|
||||
int32_t *n = (int32_t*)buffer;
|
||||
struct PldHeader *ph = (struct PldHeader*)malloc(
|
||||
sizeof(struct PldHeader)
|
||||
);
|
||||
uint32_t size_offsets = sizeof(uint32_t) * n[0];
|
||||
ph -> offsets = (uint32_t*)malloc(size_offsets);
|
||||
if (ph -> offsets == NULL) {
|
||||
perror("Error 4: ");
|
||||
free(ph);
|
||||
free(ph -> offsets);
|
||||
return NULL;
|
||||
}
|
||||
// set data of struct.
|
||||
ph -> numOffset = n[0];
|
||||
memcpy(ph -> offsets, buffer + sizeof(int32_t), size_offsets);
|
||||
return ph;
|
||||
}
|
Reference in New Issue
Block a user