source: trunk/kitgen/8.x/blt/generic/bltAlloc.c

Last change on this file was 175, checked in by demin, 12 years ago

initial commit

File size: 1.4 KB
Line 
1#include "bltInt.h"
2
3#ifndef linux
4#ifdef HAVE_MALLOC_H
5#include <malloc.h>
6#endif /* HAVE_MALLOC_H */
7#endif
8
9/*
10 * Blt_MallocProcPtr, Blt_FreeProcPtr --
11 *
12 * These global variables allow you to override the default
13 * memory allocation/deallocation routines, simply by setting the
14 * pointers to your own C functions. By default, we try to use
15 * the same memory allocation scheme that Tcl is using: generally
16 * that's Tcl_Alloc and Tcl_Free.
17 */
18
19EXTERN Blt_MallocProc TclpAlloc;
20EXTERN Blt_FreeProc TclpFree;
21EXTERN Blt_ReallocProc TclpRealloc;
22
23Blt_MallocProc *Blt_MallocProcPtr = TclpAlloc;
24Blt_FreeProc *Blt_FreeProcPtr = TclpFree;
25Blt_ReallocProc *Blt_ReallocProcPtr = TclpRealloc;
26
27void *
28Blt_Calloc(nElems, sizeOfElem)
29 unsigned int nElems;
30 size_t sizeOfElem;
31{
32 char *ptr;
33 size_t size;
34
35 size = nElems * sizeOfElem;
36 ptr = Blt_Malloc(size);
37 if (ptr != NULL) {
38 memset(ptr, 0, size);
39 }
40 return ptr;
41}
42
43/*
44 *----------------------------------------------------------------------
45 *
46 * Blt_Strdup --
47 *
48 * Create a copy of the string from heap storage.
49 *
50 * Results:
51 * Returns a pointer to the need string copy.
52 *
53 *----------------------------------------------------------------------
54 */
55char *
56Blt_Strdup(string)
57 CONST char *string;
58{
59 size_t size;
60 char *ptr;
61
62 size = strlen(string) + 1;
63 ptr = Blt_Malloc(size * sizeof(char));
64 if (ptr != NULL) {
65 strcpy(ptr, string);
66 }
67 return ptr;
68}
69
Note: See TracBrowser for help on using the repository browser.