Question: * * * please keep the main.c file same. try to fix fscMalloc.c file * File: fscMalloc.h #ifndef FSCMALLOC _ H #define FSCMALLOC _ H
please keep the main.c file same.
try to fix fscMalloc.c file
File: fscMalloc.h
#ifndef FSCMALLOCH
#define FSCMALLOCH
#ifdef cplusplus
extern C
#endif
#include for sizet
#include for FILE
typedef struct
sizet size;
int magic;
fscallocheadert;
typedef struct fscnodet
sizet size;
struct fscnodet next;
fscfreenodet;
typedef struct
fscfreenodet head;
int magicNumber;
memoryStructure;
typedef enum
FIRSTFITRETURNFIRST,
FIRSTFITRETURNSECOND,
BESTFITRETURNFIRST,
BESTFITRETURNSECOND,
WORSTFITRETURNFIRST,
WORSTFITRETURNSECOND,
NEXTFITRETURNFIRST,
NEXTFITRETURNSECOND
fscAllocationMethod;
enum MBToB ;
void fscMemorySetupmemoryStructure fscAllocationMethod, sizet sizeInBytes;
void fscMallocmemoryStructure sizet sizeInBytes; returns memory, if failure
void fscFreememoryStructure void ; returns memory to the pool
void fscMemoryCleanupmemoryStructure;
void printFreeListFILE out, fscfreenodet head;
#ifdef cplusplus
#endif
#endif FSCMALLOCH
File: memoryTest.h
#ifndef MEMORYTESTH
#define MEMORYTESTH
#ifdef cplusplus
extern C
#endif
int memoryTestOne;
int memoryTestTwo;
int memoryTestThree;
#ifdef cplusplus
#endif
#endif MEMORYTESTH
file: fscMalloc.c
void fscMemorySetupmemoryStructure m fscAllocationMethod am sizet sizeInBytes
if am FIRSTFITRETURNFIRST
fprintfstderr "This code only supports the FIRSTFITRETURNFIRST allocation method
;
return NULL;
mhead mallocsizeoffscfreenodet;
if mhead NULL
fprintfstderr "Memory allocation failed
;
return NULL;
mheadsize sizeInBytes;
mheadnext NULL;
mmagicNumber ; Example magic number
return m;
void fscMallocmemoryStructure m sizet requestedSizeInBytes
fscfreenodet current mhead;
fscfreenodet prev NULL;
while current NULL
if currentsize requestedSizeInBytes
void allocatedMemory void char current sizeoffscfreenodet;
sizet remainingSize currentsize requestedSizeInBytes;
if remainingSize
fscfreenodet newNode fscfreenodet char allocatedMemory requestedSizeInBytes;
newNodesize remainingSize;
newNodenext currentnext;
if prev NULL
prevnext newNode;
else
mhead newNode;
else
if prev NULL
prevnext currentnext;
else
mhead currentnext;
return allocatedMemory;
prev current;
current currentnext;
fprintfstderr "Failed to allocate memory
;
return NULL;
void fscFreememoryStructure m void returnedMemory
fscfreenodet newFreeNode fscfreenodet char returnedMemory sizeoffscfreenodet;
newFreeNodenext mhead;
mhead newFreeNode;
void fscMemoryCleanupmemoryStructure m
fscfreenodet current mhead;
while current NULL
fscfreenodet temp current;
current currentnext;
freetemp;
mhead NULL;
mmagicNumber ;
void printFreeListFILE out fscfreenodet head
fprintfout "About to dump the free list:
;
fscfreenodet current head;
while current NULL
fprintfout "Node address: ptNode size stored: lutNode size actual: lutNode next: p
current, currentsize, currentsize sizeoffscfreenodet currentnext;
current currentnext;
File: main.c
int mainint argc, char argv
setlocaleLCNUMERIC,"";
if memoryTestOne
fprintfstderr"Failure in memory test one";
exit EXITFAILURE;
if memoryTestTwo
fprintfstderr"Failure in memory test two";
exit EXITFAILURE;
if memoryTestThree
fprintfstderr"Failure in memory test three";
exit EXITFAILURE;
printfTests Succeeded";
return EXITSUCCESS;
output:
About to dump the free list:
Node address: xae ode s z s o ed: ode size actual: o e n x : i
Error on line
Failure in memory test one
RUN FINISHED; exit value ; real time: ms; user: ms; system: ms
Step by Step Solution
There are 3 Steps involved in it
1 Expert Approved Answer
Step: 1 Unlock
Question Has Been Solved by an Expert!
Get step-by-step solutions from verified subject matter experts
Step: 2 Unlock
Step: 3 Unlock
