this repo has no description
at main 121 lines 2.0 kB view raw
1/* 2 PBUFSTDC.h 3 4 Copyright (C) 2018 Paul C. Pratt 5 6 You can redistribute this file and/or modify it under the terms 7 of version 2 of the GNU General Public License as published by 8 the Free Software Foundation. You should have received a copy 9 of the license along with this file; see the file COPYING. 10 11 This file is distributed in the hope that it will be useful, 12 but WITHOUT ANY WARRANTY; without even the implied warranty of 13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 license for more details. 15*/ 16 17/* 18 Parameter BUFfers implemented with STanDard C library 19*/ 20 21 22#if IncludePbufs 23LOCALVAR void *PbufDat[NumPbufs]; 24#endif 25 26#if IncludePbufs 27LOCALFUNC tMacErr PbufNewFromPtr(void *p, ui5b count, tPbuf *r) 28{ 29 tPbuf i; 30 tMacErr err; 31 32 if (! FirstFreePbuf(&i)) { 33 free(p); 34 err = mnvm_miscErr; 35 } else { 36 *r = i; 37 PbufDat[i] = p; 38 PbufNewNotify(i, count); 39 err = mnvm_noErr; 40 } 41 42 return err; 43} 44#endif 45 46#if IncludePbufs 47LOCALPROC PbufKillToPtr(void **p, ui5r *count, tPbuf r) 48{ 49 *p = PbufDat[r]; 50 *count = PbufSize[r]; 51 52 PbufDisposeNotify(r); 53} 54#endif 55 56#if IncludePbufs 57GLOBALOSGLUFUNC tMacErr PbufNew(ui5b count, tPbuf *r) 58{ 59 tMacErr err = mnvm_miscErr; 60 61 void *p = calloc(1, count); 62 if (NULL != p) { 63 err = PbufNewFromPtr(p, count, r); 64 } 65 66 return err; 67} 68#endif 69 70#if IncludePbufs 71GLOBALOSGLUPROC PbufDispose(tPbuf i) 72{ 73 void *p; 74 ui5r count; 75 76 PbufKillToPtr(&p, &count, i); 77 78 free(p); 79} 80#endif 81 82#if IncludePbufs 83LOCALPROC UnInitPbufs(void) 84{ 85 tPbuf i; 86 87 for (i = 0; i < NumPbufs; ++i) { 88 if (PbufIsAllocated(i)) { 89 PbufDispose(i); 90 } 91 } 92} 93#endif 94 95#if IncludePbufs 96#define PbufHaveLock 1 97#endif 98 99#if IncludePbufs 100LOCALFUNC ui3p PbufLock(tPbuf i) 101{ 102 return (ui3p)PbufDat[i]; 103} 104#endif 105 106#if IncludePbufs 107#define PbufUnlock(i) 108#endif 109 110#if IncludePbufs 111GLOBALOSGLUPROC PbufTransfer(ui3p Buffer, 112 tPbuf i, ui5r offset, ui5r count, blnr IsWrite) 113{ 114 void *p = ((ui3p)PbufDat[i]) + offset; 115 if (IsWrite) { 116 (void) memcpy(p, Buffer, count); 117 } else { 118 (void) memcpy(Buffer, p, count); 119 } 120} 121#endif