Initial import of the CDE 2.1.30 sources from the Open Group.
[oweals/cde.git] / cde / lib / tt / mini_isam / isalloc.c
1 /*%%  (c) Copyright 1993, 1994 Hewlett-Packard Company                   */
2 /*%%  (c) Copyright 1993, 1994 International Business Machines Corp.     */
3 /*%%  (c) Copyright 1993, 1994 Sun Microsystems, Inc.                    */
4 /*%%  (c) Copyright 1993, 1994 Novell, Inc.                              */
5 /*%%  $XConsortium: isalloc.c /main/3 1995/10/23 11:33:43 rswiston $                                                     */
6 #ifndef lint
7 static char sccsid[] = "@(#)isalloc.c 1.3 89/07/17 Copyr 1988 Sun Micro";
8 #endif
9 /*
10  * Copyright (c) 1988 by Sun Microsystems, Inc.
11  */
12
13 /*
14  * isalloc.c
15  *
16  * Description:
17  *      Functions that allocate and deallocate memory.
18  *      All errors are treated as fatal.
19  */
20
21 #include "isam_impl.h"
22 #include <malloc.h>
23
24 /* strdup is not defined in Ultrix' string.h, so it is implemented in a separate
25  * file named strdup.ultrix.c
26  */
27 #ifdef __ultrix__
28 extern char *strdup();
29 #endif
30
31 /*
32  * _ismalloc(nbytes)
33  *
34  * Allocate nbytes.
35  */
36
37 char *_ismalloc(nbytes)
38     unsigned int        nbytes;
39 {
40     register char       *p;
41     
42     if ((p = (char *) malloc (nbytes)) == NULL)
43         _isfatal_error("malloc() failed");
44
45     return (p);
46 }
47
48 char *_isrealloc(oldaddr, nbytes)
49     char                *oldaddr;
50     unsigned int        nbytes;
51 {
52     register char       *p;
53     
54     if ((p = (char *) realloc (oldaddr, nbytes)) == NULL)
55         _isfatal_error("realloc() failed");
56
57     return (p);
58 }
59
60
61 /*
62  * _isallocstring(str)
63  *
64  * Create a duplicate of string in dynamic memory.
65  */
66
67 char *
68 _isallocstring(str)
69     char        *str;
70 {
71     register char       *p;
72
73     if ((p = strdup(str)) == NULL) 
74         _isfatal_error("strdup() failed");
75
76     return (p);
77 }
78
79 /*
80  * _isfreestring(str)
81  *
82  * Free dynamically allocated string.
83  */
84
85 void
86 _isfreestring(str)
87     char        *str;
88 {
89     assert(str != NULL);
90     free(str);
91 }