1 /* alloca.c
2 A very simplistic alloca routine.
3
4 Copyright (C) 1991, 1992 Ian Lance Taylor
5
6 This file is part of the Taylor UUCP package.
7
8 This program is free software; you can redistribute it and/or
9 modify it under the terms of the GNU General Public License as
10 published by the Free Software Foundation; either version 2 of the
11 License, or (at your option) any later version.
12
13 This program is distributed in the hope that it will be useful, but
14 WITHOUT ANY WARRANTY; without even the implied warranty of
15 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16 General Public License for more details.
17
18 You should have received a copy of the GNU General Public License
19 along with this program; if not, write to the Free Software
20 Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
21
22 The author of the program may be contacted at ian@airs.com or
23 c/o AIRS, P.O. Box 520, Waltham, MA 02254.
24
25 $Log: alloca.c,v $
26 Revision 1.1 1992/02/23 03:26:51 ian
27 Initial revision
28
29 */
30
31 #include "uucp.h"
32
33 #if USE_RCS_ID
34 char alloca_rcsid[] = "$Id: alloca.c,v 1.1 1992/02/23 03:26:51 ian Rel $";
35 #endif
36
37 /* A simplistic implementation of alloca. I could just include Doug
38 Gwyn's alloca, but this is simpler for what I need and it's
39 guaranteed to be portable. It will only work for a simple program
40 like this one. Obviously a real alloca will be preferable. */
41
42 static void uaclear_alloca P((void));
43
44 struct salloca
45 {
46 struct salloca *qnext;
47 pointer pbuf;
48 };
49
50 static struct salloca *qAlloca;
51
52 /* Allocate temporary storage. */
53
54 pointer
alloca(isize)55 alloca (isize)
56 int isize;
57 {
58 struct salloca *q;
59
60 if (isize == 0)
61 {
62 uaclear_alloca ();
63 return NULL;
64 }
65 q = (struct salloca *) malloc (sizeof (struct salloca));
66 if (q == NULL)
67 abort ();
68 q->qnext = qAlloca;
69 qAlloca = q;
70 q->pbuf = malloc (isize);
71 if (q->pbuf == NULL)
72 abort ();
73 return q->pbuf;
74 }
75
76 /* Free up all temporary storage. */
77
78 static void
uaclear_alloca()79 uaclear_alloca ()
80 {
81 struct salloca *q;
82
83 q = qAlloca;
84 while (q != NULL)
85 {
86 struct salloca *qnext;
87
88 free (q->pbuf);
89 qnext = q->qnext;
90 free ((pointer) q);
91 q = qnext;
92 }
93 qAlloca = NULL;
94 }
95