2 * Copyright (c) 2003-2005 Greg Parker. All rights reserved.
4 * Redistribution and use in source and binary forms, with or without
5 * modification, are permitted provided that the following conditions
7 * 1. Redistributions of source code must retain the above copyright
8 * notice, this list of conditions and the following disclaimer.
9 * 2. Redistributions in binary form must reproduce the above copyright
10 * notice, this list of conditions and the following disclaimer in the
11 * documentation and/or other materials provided with the distribution.
13 * THIS SOFTWARE IS PROVIDED BY GREG PARKER ``AS IS'' AND ANY EXPRESS OR
14 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
15 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
16 * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
17 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
18 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
19 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
20 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
21 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
22 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
28 #include <PalmOSGlue.h>
30 // #define DEBUG_ARENA
31 // #define DEBUG_NONARENA
33 // arena allocator is intended for use if pssh ever supports multiple
34 // simultaneous connections. An error in one connection would trigger
35 // destruction of its arena during cleanup.
36 // Currently, arena and non-arena allocators are identical.
38 void *arena_malloc(size_t s)
41 if (s == 0) s = 1; // fixme openssh is expecting fatal for size 0
44 debug_printf("%ld bytes", s);
45 fatal("arena_malloc: out of memory");
50 void arena_free(void *p)
52 if (!p) return; // needed by PuTTY?
56 void *arena_calloc(size_t s)
64 void *arena_realloc(void *oldp, size_t newsize)
68 newp = arena_malloc(newsize);
73 oldsize = MemPtrSize(oldp);
74 memcpy(newp, oldp, MIN(newsize, oldsize));
75 arena_free(oldp); // fixme reallocf?
80 char *arena_strdup(const char *s)
82 size_t len = 1+strlen(s);
84 news = arena_malloc(len);