| 1 | /* $Id: kHlpCRTAlloc.cpp 3552 2007-08-26 02:15:22Z bird $ */
|
|---|
| 2 | /** @file
|
|---|
| 3 | * kHlpAlloc - Memory Allocation, CRT based implementation.
|
|---|
| 4 | */
|
|---|
| 5 |
|
|---|
| 6 | /*
|
|---|
| 7 | * Copyright (c) 2007 knut st. osmundsen <bird-src-spam@anduin.net>
|
|---|
| 8 | *
|
|---|
| 9 | * This file is part of kStuff.
|
|---|
| 10 | *
|
|---|
| 11 | * kStuff is free software; you can redistribute it and/or
|
|---|
| 12 | * modify it under the terms of the GNU Lesser General Public
|
|---|
| 13 | * License as published by the Free Software Foundation; either
|
|---|
| 14 | * version 2.1 of the License, or (at your option) any later version.
|
|---|
| 15 | *
|
|---|
| 16 | * kStuff is distributed in the hope that it will be useful,
|
|---|
| 17 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|---|
| 18 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|---|
| 19 | * Lesser General Public License for more details.
|
|---|
| 20 | *
|
|---|
| 21 | * You should have received a copy of the GNU Lesser General Public
|
|---|
| 22 | * License along with kStuff; if not, write to the Free Software
|
|---|
| 23 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
|
|---|
| 24 | *
|
|---|
| 25 | */
|
|---|
| 26 |
|
|---|
| 27 | /*******************************************************************************
|
|---|
| 28 | * Header Files *
|
|---|
| 29 | *******************************************************************************/
|
|---|
| 30 | #include <k/kHlpAlloc.h>
|
|---|
| 31 | #include <stdlib.h>
|
|---|
| 32 | #include <string.h>
|
|---|
| 33 |
|
|---|
| 34 | KHLP_DECL(void *) kHlpAlloc(KSIZE cb)
|
|---|
| 35 | {
|
|---|
| 36 | return malloc(cb);
|
|---|
| 37 | }
|
|---|
| 38 |
|
|---|
| 39 |
|
|---|
| 40 | KHLP_DECL(void *) kHlpAllocZ(KSIZE cb)
|
|---|
| 41 | {
|
|---|
| 42 | return calloc(1, cb);
|
|---|
| 43 | }
|
|---|
| 44 |
|
|---|
| 45 |
|
|---|
| 46 | KHLP_DECL(void *) kHlpDup(const void *pv, KSIZE cb)
|
|---|
| 47 | {
|
|---|
| 48 | void *pvDup = kHlpAlloc(cb);
|
|---|
| 49 | if (pvDup)
|
|---|
| 50 | return memcpy(pvDup, pv, cb);
|
|---|
| 51 | return NULL;
|
|---|
| 52 | }
|
|---|
| 53 |
|
|---|
| 54 |
|
|---|
| 55 | KHLP_DECL(char *) kHlpStrDup(const char *psz)
|
|---|
| 56 | {
|
|---|
| 57 | size_t cb = strlen(psz) + 1;
|
|---|
| 58 | return (char *)kHlpDup(psz, cb);
|
|---|
| 59 | }
|
|---|
| 60 |
|
|---|
| 61 |
|
|---|
| 62 | KHLP_DECL(void *) kHlpRealloc(void *pv, KSIZE cb)
|
|---|
| 63 | {
|
|---|
| 64 | return realloc(pv, cb);
|
|---|
| 65 | }
|
|---|
| 66 |
|
|---|
| 67 |
|
|---|
| 68 | KHLP_DECL(void) kHlpFree(void *pv)
|
|---|
| 69 | {
|
|---|
| 70 | if (pv)
|
|---|
| 71 | free(pv);
|
|---|
| 72 | }
|
|---|
| 73 |
|
|---|
| 74 |
|
|---|
| 75 | KHLP_DECL(int) kHlpPageAlloc(void **ppv, KSIZE cb, KPROT enmProt, KBOOL fFixed)
|
|---|
| 76 | {
|
|---|
| 77 | return -1;
|
|---|
| 78 | }
|
|---|
| 79 |
|
|---|
| 80 |
|
|---|
| 81 | KHLP_DECL(int) kHlpPageProtect(void *pv, KSIZE cb, KPROT enmProt)
|
|---|
| 82 | {
|
|---|
| 83 | return -1;
|
|---|
| 84 | }
|
|---|
| 85 |
|
|---|
| 86 |
|
|---|
| 87 | KHLP_DECL(int) kHlpPageFree(void *pv, KSIZE cb)
|
|---|
| 88 | {
|
|---|
| 89 | return -1;
|
|---|
| 90 | }
|
|---|
| 91 |
|
|---|