Allow YAZ 2 series only
[ir-tcl-moved-to-github.git] / mem.c
1 /*
2  * IR toolkit for tcl/tk
3  * (c) Index Data 1995-1998
4  * See the file LICENSE for details.
5  * Sebastian Hammer, Adam Dickmeiss
6  *
7  * $Log: mem.c,v $
8  * Revision 1.4  1998-10-13 21:23:37  adam
9  * Fixed log message.
10  *
11  * Revision 1.3  1996/07/03 13:31:14  adam
12  * The xmalloc/xfree functions from YAZ are used to manage memory.
13  *
14  * Revision 1.2  1995/08/29  15:30:15  adam
15  * Work on GRS records.
16  *
17  * Revision 1.1  1995/08/04  11:32:40  adam
18  * More work on output queue. Memory related routines moved
19  * to mem.c
20  *
21  */
22
23 #include <stdlib.h>
24 #include <stdio.h>
25 #include <ctype.h>
26 #include <assert.h>
27
28 #include "ir-tclp.h"
29
30 /*
31  * ir_tcl_malloc: Allocate n byte from the heap
32  */
33 void *ir_tcl_malloc (size_t n)
34 {
35     void *p = xmalloc (n);
36     if (!p)
37     {
38         logf (LOG_FATAL, "Out of memory. %ld bytes requested", (long) n);
39         exit (1);
40     }
41     return p;
42 }
43
44 /*
45  * ir_tcl_strdup: Duplicate string
46  */
47 int ir_tcl_strdup (Tcl_Interp *interp, char** p, const char *s)
48 {
49     size_t len;
50
51     if (!s)
52     {
53         *p = NULL;
54         return TCL_OK;
55     }
56     len = strlen(s)+1;
57     *p = xmalloc (len);
58     if (!*p)
59     {
60         if (!interp) 
61         {
62             logf (LOG_FATAL, "Out of memory in strdup. %d bytes", len);
63             exit (1);
64         }
65         interp->result = "strdup fail";
66         return TCL_ERROR;
67     }
68     strcpy (*p, s);
69     return TCL_OK;
70 }
71
72 /*
73  * ir_strdel: Delete string
74  */
75 int ir_tcl_strdel (Tcl_Interp *interp, char **p)
76 {
77     xfree (*p);
78     *p = NULL;
79     return TCL_OK;
80 }
81