summaryrefslogtreecommitdiff
path: root/command_line/CmdLine/Src/MacEmul/Memory.c
diff options
context:
space:
mode:
authorAsh Wolf <ninji@wuffs.org>2022-10-13 15:30:47 +0100
committerAsh Wolf <ninji@wuffs.org>2022-10-13 15:30:47 +0100
commit59a724bd4cc7a543686c633572510e6763b34d39 (patch)
tree8a29e94d9ca50a7f175f10b7f22290d6948b59cf /command_line/CmdLine/Src/MacEmul/Memory.c
parentc198d1135a80d607161c62ec43c1d1182f62bbf7 (diff)
downloadMWCC-59a724bd4cc7a543686c633572510e6763b34d39.tar.gz
MWCC-59a724bd4cc7a543686c633572510e6763b34d39.zip
fix issues in OSLib Memory and ErrMgr, fully match OSLib Files
Diffstat (limited to 'command_line/CmdLine/Src/MacEmul/Memory.c')
-rw-r--r--command_line/CmdLine/Src/MacEmul/Memory.c38
1 files changed, 19 insertions, 19 deletions
diff --git a/command_line/CmdLine/Src/MacEmul/Memory.c b/command_line/CmdLine/Src/MacEmul/Memory.c
index 8b956a0..0aa5d24 100644
--- a/command_line/CmdLine/Src/MacEmul/Memory.c
+++ b/command_line/CmdLine/Src/MacEmul/Memory.c
@@ -14,13 +14,13 @@ OSHandle *OS_PeekMacHandle(Handle h) {
}
static void FixHandlePtr(Handle h, void *ptr) {
- HS(h)->hand.addr = ptr;
+ HS(h)->addr = ptr;
}
Handle OS_CreateMacHandle(OSHandle *h) {
HandleStructure *hs = malloc(sizeof(HandleStructure));
if (!hs) {
- memError = -108;
+ memError = memFullErr;
return 0;
};
@@ -34,7 +34,7 @@ Handle OS_CreateMacHandle(OSHandle *h) {
Handle OS_CreateMacHandleDup(OSHandle *h) {
HandleStructure *hs = malloc(sizeof(HandleStructure));
if (!hs) {
- memError = -108;
+ memError = memFullErr;
return 0;
};
@@ -45,7 +45,7 @@ Handle OS_CreateMacHandleDup(OSHandle *h) {
}
void OS_DestroyMacHandle(Handle h, OSHandle *ret) {
- *ret = HS(h)->hand;
+ *ret = *OS_PeekMacHandle(h);
free(h);
}
@@ -80,8 +80,10 @@ Handle NewHandleClear(UInt32 dataSize) {
}
Handle TempNewHandle(UInt32 dataSize, OSErr *resultCode) {
+ Handle hdl;
+
*resultCode = 0;
- Handle hdl = NewHandle(dataSize);
+ hdl = NewHandle(dataSize);
if (!hdl)
*resultCode = memError;
return hdl;
@@ -92,7 +94,7 @@ void DisposeHandle(Handle h) {
memError = OS_MacError(OS_FreeHandle(&HS(h)->hand));
FixHandlePtr(h, 0);
} else {
- memError = -109;
+ memError = nilHandleErr;
}
}
@@ -104,7 +106,7 @@ void HLock(Handle h) {
FixHandlePtr(h, buffer);
memError = 0;
} else {
- memError = -109;
+ memError = nilHandleErr;
}
}
@@ -117,7 +119,7 @@ void HUnlock(Handle h) {
memError = 0;
OS_UnlockHandle(&HS(h)->hand);
} else {
- memError = -109;
+ memError = nilHandleErr;
}
}
@@ -145,7 +147,7 @@ SInt32 GetHandleSize(Handle h) {
memError = OS_MacError(OS_GetHandleSize(&HS(h)->hand, &sz));
} else {
sz = 0;
- memError = -109;
+ memError = nilHandleErr;
}
return sz;
@@ -161,15 +163,14 @@ OSErr PtrAndHand(const void *srcPtr, Handle destHandle, SInt32 size) {
OSErr err;
err = OS_MacError(OS_AppendHandle(&HS(destHandle)->hand, srcPtr, size));
- FixHandlePtr(h, OS_LockHandle(&HS(destHandle)->hand));
- OS_UnlockHandle(&HS(h)->hand);
+ FixHandlePtr(destHandle, OS_LockHandle(&HS(destHandle)->hand));
+ OS_UnlockHandle(&HS(destHandle)->hand);
return err;
}
OSErr PtrToHand(const void *srcPtr, Handle *destHandle, SInt32 size) {
- *destHandle = NewHandle(size);
- if (!*destHandle)
+ if (!(*destHandle = NewHandle(size)))
return MemError();
HLock(*destHandle);
@@ -184,8 +185,7 @@ OSErr HandToHand(Handle *destHandle) {
SInt32 size;
size = GetHandleSize(srcHandle);
- *destHandle = NewHandle(size);
- if (!*destHandle)
+ if (!(*destHandle = NewHandle(size)))
return MemError();
HLock(*destHandle);
@@ -209,7 +209,7 @@ OSErr HandAndHand(Handle src, Handle dst) {
}
void MoveHHi(Handle theHandle) {
- memError = theHandle ? 0 : -109;
+ memError = theHandle ? noErr : nilHandleErr;
}
void BlockMove(const void *srcPtr, void *destPtr, UInt32 byteCount) {
@@ -227,7 +227,7 @@ Ptr NewPtr(SInt32 dataSize) {
dataSize = 1;
p = malloc(dataSize);
- memError = p ? 0 : -108;
+ memError = p ? noErr : memFullErr;
return p;
}
@@ -240,7 +240,7 @@ void DisposePtr(Ptr p) {
Ptr NewPtrClear(SInt32 dataSize) {
Ptr p;
- memError = -108;
+ memError = memFullErr;
if (!dataSize)
dataSize = 1;
@@ -254,7 +254,7 @@ Ptr NewPtrClear(SInt32 dataSize) {
}
void DebugStr(ConstStringPtr str) {
- fprintf(stderr, "*.*s", str[0], str[1], &str[1]);
+ fprintf(stderr, "%*.*s", str[0], str[0], &str[1]);
}
struct Zone *HandleZone() {