More work on output queue. Memory related routines moved
[ir-tcl-moved-to-github.git] / mem.c
1 /*
2  * IR toolkit for tcl/tk
3  * (c) Index Data 1995
4  * See the file LICENSE for details.
5  * Sebastian Hammer, Adam Dickmeiss
6  *
7  * $Log: mem.c,v $
8  * Revision 1.1  1995-08-04 11:32:40  adam
9  * More work on output queue. Memory related routines moved
10  * to mem.c
11  *
12  */
13
14 #include <stdlib.h>
15 #include <stdio.h>
16 #include <ctype.h>
17 #include <assert.h>
18
19 #include "ir-tclp.h"
20
21 /*
22  * ir_tcl_malloc: Allocate n byte from the heap
23  */
24 void *ir_tcl_malloc (size_t n)
25 {
26     void *p = malloc (n);
27     if (!p)
28     {
29         logf (LOG_FATAL, "Out of memory. %ld bytes requested", (long) n);
30         exit (1);
31     }
32     return p;
33 }
34
35 /*
36  * ir_tcl_strdup: Duplicate string
37  */
38 int ir_tcl_strdup (Tcl_Interp *interp, char** p, const char *s)
39 {
40     if (!s)
41     {
42         *p = NULL;
43         return TCL_OK;
44     }
45     *p = malloc (strlen(s)+1);
46     if (!*p)
47     {
48         interp->result = "strdup fail";
49         return TCL_ERROR;
50     }
51     strcpy (*p, s);
52     return TCL_OK;
53 }
54
55 /*
56  * ir_strdel: Delete string
57  */
58 int ir_tcl_strdel (Tcl_Interp *interp, char **p)
59 {
60     free (*p);
61     *p = NULL;
62     return TCL_OK;
63 }
64