1 /* lkstore.c - Allocated string storage module.
3 Copyright (C) 1989-1995 Alan R. Baldwin
4 721 Berkeley St., Kent, Ohio 44240
6 This program is free software; you can redistribute it and/or modify it
7 under the terms of the GNU General Public License as published by the
8 Free Software Foundation; either version 3, or (at your option) any
11 This program is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 GNU General Public License for more details.
16 You should have received a copy of the GNU General Public License
17 along with this program. If not, see <http://www.gnu.org/licenses/>. */
20 * Allocated string storage module.
22 * 31-Oct-1997 by John Hartman
31 * Allocate space for "str", copy str into new space
32 * Return a pointer to the allocated name, or NULL if out of memory
34 char *StoreString( char *str )
36 /* To avoid wasting memory headers on small allocations, we
37 / allocate a big chunk and parcel it out as required.
38 / These static variables remember our hunk
40 #define STR_STORE_HUNK 2000
41 static char *pNextFree = NULL;
42 static int bytesLeft = 0;
47 length = strlen( str ) + 1; /* what we need, including null */
49 if (length > bytesLeft)
51 /* no space. Allocate a new hunk. We lose the pointer to any
52 / old hunk. We don't care, as the names are never deleted.
54 pNextFree = (char*)new( STR_STORE_HUNK );
55 bytesLeft = STR_STORE_HUNK;
58 /* Copy the name and terminating null into the name store */
59 pStoredString = pNextFree;
60 memcpy( pStoredString, str, length );