[3552] | 1 | /* $Id: kHlpCRTAlloc.cpp 3607 2007-10-29 00:48:50Z bird $ */
|
---|
| 2 | /** @file
|
---|
| 3 | * kHlpAlloc - Memory Allocation, CRT based implementation.
|
---|
| 4 | */
|
---|
| 5 |
|
---|
| 6 | /*
|
---|
[3607] | 7 | * Copyright (c) 2006-2007 knut st. osmundsen <bird-kStuff-spam@anduin.net>
|
---|
[3552] | 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 | *
|
---|
[3607] | 16 | * In addition to the permissions in the GNU Lesser General Public
|
---|
| 17 | * License, you are granted unlimited permission to link the compiled
|
---|
| 18 | * version of this file into combinations with other programs, and to
|
---|
| 19 | * distribute those combinations without any restriction coming from
|
---|
| 20 | * the use of this file.
|
---|
| 21 | *
|
---|
[3552] | 22 | * kStuff is distributed in the hope that it will be useful,
|
---|
| 23 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
|
---|
| 24 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
---|
| 25 | * Lesser General Public License for more details.
|
---|
| 26 | *
|
---|
| 27 | * You should have received a copy of the GNU Lesser General Public
|
---|
| 28 | * License along with kStuff; if not, write to the Free Software
|
---|
[3607] | 29 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
|
---|
| 30 | * 02110-1301, USA
|
---|
[3552] | 31 | */
|
---|
| 32 |
|
---|
| 33 | /*******************************************************************************
|
---|
| 34 | * Header Files *
|
---|
| 35 | *******************************************************************************/
|
---|
| 36 | #include <k/kHlpAlloc.h>
|
---|
| 37 | #include <stdlib.h>
|
---|
| 38 | #include <string.h>
|
---|
| 39 |
|
---|
[3575] | 40 |
|
---|
[3552] | 41 | KHLP_DECL(void *) kHlpAlloc(KSIZE cb)
|
---|
| 42 | {
|
---|
| 43 | return malloc(cb);
|
---|
| 44 | }
|
---|
| 45 |
|
---|
| 46 |
|
---|
| 47 | KHLP_DECL(void *) kHlpAllocZ(KSIZE cb)
|
---|
| 48 | {
|
---|
| 49 | return calloc(1, cb);
|
---|
| 50 | }
|
---|
| 51 |
|
---|
| 52 |
|
---|
| 53 | KHLP_DECL(void *) kHlpDup(const void *pv, KSIZE cb)
|
---|
| 54 | {
|
---|
| 55 | void *pvDup = kHlpAlloc(cb);
|
---|
| 56 | if (pvDup)
|
---|
| 57 | return memcpy(pvDup, pv, cb);
|
---|
| 58 | return NULL;
|
---|
| 59 | }
|
---|
| 60 |
|
---|
| 61 |
|
---|
| 62 | KHLP_DECL(char *) kHlpStrDup(const char *psz)
|
---|
| 63 | {
|
---|
| 64 | size_t cb = strlen(psz) + 1;
|
---|
| 65 | return (char *)kHlpDup(psz, cb);
|
---|
| 66 | }
|
---|
| 67 |
|
---|
| 68 |
|
---|
| 69 | KHLP_DECL(void *) kHlpRealloc(void *pv, KSIZE cb)
|
---|
| 70 | {
|
---|
| 71 | return realloc(pv, cb);
|
---|
| 72 | }
|
---|
| 73 |
|
---|
| 74 |
|
---|
| 75 | KHLP_DECL(void) kHlpFree(void *pv)
|
---|
| 76 | {
|
---|
| 77 | if (pv)
|
---|
| 78 | free(pv);
|
---|
| 79 | }
|
---|
| 80 |
|
---|