| 1 | /* $Id: kHlpCRTAlloc.cpp 3575 2007-09-02 20:05:39Z 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 |
|
|---|
| 35 | KHLP_DECL(void *) kHlpAlloc(KSIZE cb)
|
|---|
| 36 | {
|
|---|
| 37 | return malloc(cb);
|
|---|
| 38 | }
|
|---|
| 39 |
|
|---|
| 40 |
|
|---|
| 41 | KHLP_DECL(void *) kHlpAllocZ(KSIZE cb)
|
|---|
| 42 | {
|
|---|
| 43 | return calloc(1, cb);
|
|---|
| 44 | }
|
|---|
| 45 |
|
|---|
| 46 |
|
|---|
| 47 | KHLP_DECL(void *) kHlpDup(const void *pv, KSIZE cb)
|
|---|
| 48 | {
|
|---|
| 49 | void *pvDup = kHlpAlloc(cb);
|
|---|
| 50 | if (pvDup)
|
|---|
| 51 | return memcpy(pvDup, pv, cb);
|
|---|
| 52 | return NULL;
|
|---|
| 53 | }
|
|---|
| 54 |
|
|---|
| 55 |
|
|---|
| 56 | KHLP_DECL(char *) kHlpStrDup(const char *psz)
|
|---|
| 57 | {
|
|---|
| 58 | size_t cb = strlen(psz) + 1;
|
|---|
| 59 | return (char *)kHlpDup(psz, cb);
|
|---|
| 60 | }
|
|---|
| 61 |
|
|---|
| 62 |
|
|---|
| 63 | KHLP_DECL(void *) kHlpRealloc(void *pv, KSIZE cb)
|
|---|
| 64 | {
|
|---|
| 65 | return realloc(pv, cb);
|
|---|
| 66 | }
|
|---|
| 67 |
|
|---|
| 68 |
|
|---|
| 69 | KHLP_DECL(void) kHlpFree(void *pv)
|
|---|
| 70 | {
|
|---|
| 71 | if (pv)
|
|---|
| 72 | free(pv);
|
|---|
| 73 | }
|
|---|
| 74 |
|
|---|