1*4a9058f9Skre /* $NetBSD: memalloc.h,v 1.20 2021/10/26 10:07:20 kre Exp $ */ 249f0ad86Scgd 361f28255Scgd /*- 437ed7877Sjtc * Copyright (c) 1991, 1993 537ed7877Sjtc * The Regents of the University of California. All rights reserved. 661f28255Scgd * 761f28255Scgd * This code is derived from software contributed to Berkeley by 861f28255Scgd * Kenneth Almquist. 961f28255Scgd * 1061f28255Scgd * Redistribution and use in source and binary forms, with or without 1161f28255Scgd * modification, are permitted provided that the following conditions 1261f28255Scgd * are met: 1361f28255Scgd * 1. Redistributions of source code must retain the above copyright 1461f28255Scgd * notice, this list of conditions and the following disclaimer. 1561f28255Scgd * 2. Redistributions in binary form must reproduce the above copyright 1661f28255Scgd * notice, this list of conditions and the following disclaimer in the 1761f28255Scgd * documentation and/or other materials provided with the distribution. 18b5b29542Sagc * 3. Neither the name of the University nor the names of its contributors 1961f28255Scgd * may be used to endorse or promote products derived from this software 2061f28255Scgd * without specific prior written permission. 2161f28255Scgd * 2261f28255Scgd * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND 2361f28255Scgd * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 2461f28255Scgd * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 2561f28255Scgd * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE 2661f28255Scgd * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 2761f28255Scgd * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 2861f28255Scgd * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 2961f28255Scgd * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 3061f28255Scgd * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 3161f28255Scgd * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 3261f28255Scgd * SUCH DAMAGE. 3361f28255Scgd * 3407bae7edSchristos * @(#)memalloc.h 8.2 (Berkeley) 5/4/95 3561f28255Scgd */ 3661f28255Scgd 3761f28255Scgd struct stackmark { 3861f28255Scgd struct stack_block *stackp; 3961f28255Scgd char *stacknxt; 4061f28255Scgd int stacknleft; 41ee3b307fSkre int sstrnleft; 428e2797bcSchristos struct stackmark *marknext; 4361f28255Scgd }; 4461f28255Scgd 4561f28255Scgd 4661f28255Scgd extern char *stacknxt; 4761f28255Scgd extern int stacknleft; 4861f28255Scgd extern int sstrnleft; 4961f28255Scgd extern int herefd; 5061f28255Scgd 514498b1feSmatt pointer ckmalloc(size_t); 52c02b3bbdSchristos pointer ckrealloc(pointer, int); 53e314f958Sdsl char *savestr(const char *); 54c02b3bbdSchristos pointer stalloc(int); 55c02b3bbdSchristos void stunalloc(pointer); 56c02b3bbdSchristos void setstackmark(struct stackmark *); 57c02b3bbdSchristos void popstackmark(struct stackmark *); 5870696c01Skre void rststackmark(struct stackmark *); 59c02b3bbdSchristos void growstackblock(void); 60c02b3bbdSchristos void grabstackblock(int); 61c02b3bbdSchristos char *growstackstr(void); 62c02b3bbdSchristos char *makestrspace(void); 63c02b3bbdSchristos void ungrabstackstr(char *, char *); 64*4a9058f9Skre 654ca0efa9Skre char *ststrcat(size_t *, ...); 66*4a9058f9Skre #define STSTRC_END ((const char *)0) 6761f28255Scgd 6861f28255Scgd 6961f28255Scgd 7061f28255Scgd #define stackblock() stacknxt 7161f28255Scgd #define stackblocksize() stacknleft 7261f28255Scgd #define STARTSTACKSTR(p) p = stackblock(), sstrnleft = stackblocksize() 7361f28255Scgd #define STPUTC(c, p) (--sstrnleft >= 0? (*p++ = (c)) : (p = growstackstr(), *p++ = (c))) 7407bae7edSchristos #define CHECKSTRSPACE(n, p) { if (sstrnleft < n) p = makestrspace(); } 7561f28255Scgd #define USTPUTC(c, p) (--sstrnleft, *p++ = (c)) 76ee3b307fSkre #define STACKSTRNUL(p) (sstrnleft == 0? (p = growstackstr(), sstrnleft++, *p = '\0') : (*p = '\0')) 7761f28255Scgd #define STUNPUTC(p) (++sstrnleft, --p) 7861f28255Scgd #define STTOPC(p) p[-1] 7961f28255Scgd #define STADJUST(amount, p) (p += (amount), sstrnleft -= (amount)) 80ee3b307fSkre #define grabstackstr(p) stalloc((p) - stackblock()) 8161f28255Scgd 8261f28255Scgd #define ckfree(p) free((pointer)(p)) 83