summaryrefslogtreecommitdiff
path: root/src/SDK/OS/OSAlloc.c
diff options
context:
space:
mode:
authorRevo <projectrevotpp@hotmail.com>2020-09-13 12:35:03 -0400
committerGitHub <noreply@github.com>2020-09-13 12:35:03 -0400
commit8a7bfac7d3a81b34be131c76a98cac1f4cf9cb82 (patch)
treed2a503a323ae06264ebab085d9e3108f7c5eb33c /src/SDK/OS/OSAlloc.c
parent11effce5c0a8c617662608d05cdf906ff8e73d2c (diff)
parent9c1b7dcd0a71137bd1193e5753a92607e2b301ad (diff)
Merge pull request #39 from red031000/master
split OSAudioSystem and decomp first func
Diffstat (limited to 'src/SDK/OS/OSAlloc.c')
-rw-r--r--src/SDK/OS/OSAlloc.c49
1 files changed, 49 insertions, 0 deletions
diff --git a/src/SDK/OS/OSAlloc.c b/src/SDK/OS/OSAlloc.c
new file mode 100644
index 0000000..090233e
--- /dev/null
+++ b/src/SDK/OS/OSAlloc.c
@@ -0,0 +1,49 @@
+#include "types.h"
+#include "OS/OSAlloc.h"
+
+Cell *DLInsert(Cell *original, Cell *inserted)
+{
+ Cell *prevCell = NULL;
+ Cell *nextCell = original;
+
+ for (nextCell = original, prevCell = NULL; nextCell; prevCell = nextCell, nextCell = nextCell->next)
+ {
+ if (inserted <= nextCell)
+ break;
+ }
+
+ inserted->next = nextCell;
+ inserted->prev = prevCell;
+
+ if (nextCell != NULL)
+ {
+ nextCell->prev = inserted;
+ Cell * temp = (Cell *)((char *)inserted + inserted->size);
+ if (temp == nextCell)
+ {
+ inserted->size += nextCell->size;
+ nextCell = nextCell->next;
+ inserted->next = nextCell;
+ if (nextCell != NULL)
+ nextCell->prev = inserted;
+ }
+ }
+
+ if (prevCell != NULL)
+ {
+ prevCell->next = inserted;
+ Cell * temp = (Cell *)((char *)prevCell + prevCell->size);
+
+ if (temp != inserted)
+ return original;
+
+ prevCell->size += inserted->size;
+ prevCell->next = nextCell;
+ if (nextCell != NULL)
+ nextCell->prev = prevCell;
+
+ return original;
+ }
+
+ return inserted;
+}