| 1 |
|
|---|
| 2 | /***********************************************************************
|
|---|
| 3 |
|
|---|
| 4 | $Id: wrappers.c 395 2006-07-28 18:37:43Z root $
|
|---|
| 5 |
|
|---|
| 6 | Wrappers with error checking
|
|---|
| 7 |
|
|---|
| 8 | Copyright (c) 2006 Steven H.Levine
|
|---|
| 9 |
|
|---|
| 10 | 22 Jul 06 SHL Baseline
|
|---|
| 11 |
|
|---|
| 12 | ***********************************************************************/
|
|---|
| 13 |
|
|---|
| 14 | #define INCL_WIN
|
|---|
| 15 | #include <os2.h>
|
|---|
| 16 |
|
|---|
| 17 | #include <stdio.h>
|
|---|
| 18 | #include <stdlib.h>
|
|---|
| 19 | #include <string.h>
|
|---|
| 20 |
|
|---|
| 21 | #include "fm3dll.h"
|
|---|
| 22 | #include "fm3str.h"
|
|---|
| 23 |
|
|---|
| 24 | #pragma alloc_text(WRAPPERS1,xfree,xfopen,xfsopen,xmalloc,xrealloc)
|
|---|
| 25 |
|
|---|
| 26 | FILE *xfopen(PCSZ pszFileName, PCSZ pszMode, PCSZ pszSrcFile, UINT uiLineNumber)
|
|---|
| 27 | {
|
|---|
| 28 | FILE* fp = fopen(pszFileName, pszMode);
|
|---|
| 29 | if (!fp)
|
|---|
| 30 | Runtime_Error(pszSrcFile, uiLineNumber, "fopen");
|
|---|
| 31 | return fp;
|
|---|
| 32 | }
|
|---|
| 33 |
|
|---|
| 34 | FILE *xfsopen(PCSZ pszFileName,PCSZ pszMode,INT fSharemode, PCSZ pszSrcFile, UINT uiLineNumber)
|
|---|
| 35 | {
|
|---|
| 36 | FILE* fp = _fsopen((PSZ)pszFileName, (PSZ)pszMode, fSharemode);
|
|---|
| 37 | if (!fp)
|
|---|
| 38 | Runtime_Error(pszSrcFile, uiLineNumber, "_fsopen");
|
|---|
| 39 | return fp;
|
|---|
| 40 | }
|
|---|
| 41 |
|
|---|
| 42 |
|
|---|
| 43 | //== xfree - safe free ==
|
|---|
| 44 |
|
|---|
| 45 | VOID xfree (PVOID pv)
|
|---|
| 46 | {
|
|---|
| 47 | if (pv)
|
|---|
| 48 | free(pv);
|
|---|
| 49 | }
|
|---|
| 50 |
|
|---|
| 51 | //== xmalloc() malloc with error checking ==
|
|---|
| 52 |
|
|---|
| 53 | PVOID xmalloc(size_t cBytes, PCSZ pszSrcFile, UINT uiLineNumber)
|
|---|
| 54 | {
|
|---|
| 55 | PVOID pv = malloc(cBytes);
|
|---|
| 56 |
|
|---|
| 57 | if (!pv)
|
|---|
| 58 | Runtime_Error(pszSrcFile,uiLineNumber,GetPString(IDS_OUTOFMEMORY));
|
|---|
| 59 |
|
|---|
| 60 | return pv;
|
|---|
| 61 | }
|
|---|
| 62 |
|
|---|
| 63 | //== xmallocz() malloc and zero with error checking ==
|
|---|
| 64 |
|
|---|
| 65 | PVOID xmallocz(size_t cBytes, PCSZ pszSrcFile, UINT uiLineNumber)
|
|---|
| 66 | {
|
|---|
| 67 | PVOID pv = malloc(cBytes);
|
|---|
| 68 |
|
|---|
| 69 | if (!pv)
|
|---|
| 70 | Runtime_Error(pszSrcFile,uiLineNumber,GetPString(IDS_OUTOFMEMORY));
|
|---|
| 71 | else
|
|---|
| 72 | memset(pv, 0, cBytes);
|
|---|
| 73 |
|
|---|
| 74 | return pv;
|
|---|
| 75 | }
|
|---|
| 76 |
|
|---|
| 77 | //== xrealloc() realloc with error checking ==
|
|---|
| 78 |
|
|---|
| 79 | PVOID xrealloc(PVOID pvIn, size_t cBytes, PCSZ pszSrcFile, UINT uiLineNumber)
|
|---|
| 80 | {
|
|---|
| 81 | PVOID pv = realloc(pvIn, cBytes);
|
|---|
| 82 |
|
|---|
| 83 | if (!pv && cBytes)
|
|---|
| 84 | Runtime_Error(pszSrcFile,uiLineNumber,GetPString(IDS_OUTOFMEMORY));
|
|---|
| 85 |
|
|---|
| 86 | return pv;
|
|---|
| 87 |
|
|---|
| 88 | }
|
|---|
| 89 |
|
|---|
| 90 | //== xstrdup() strdup with error checking ==
|
|---|
| 91 |
|
|---|
| 92 | PVOID xstrdup(PCSZ pszIn, PCSZ pszSrcFile, UINT uiLineNumber)
|
|---|
| 93 | {
|
|---|
| 94 | PSZ psz = strdup(pszIn);
|
|---|
| 95 |
|
|---|
| 96 | if (!psz)
|
|---|
| 97 | Runtime_Error(pszSrcFile, uiLineNumber,GetPString(IDS_OUTOFMEMORY));
|
|---|
| 98 |
|
|---|
| 99 | return psz;
|
|---|
| 100 | }
|
|---|
| 101 |
|
|---|