source: trunk/minix/lib/ack/libp/new.c@ 9

Last change on this file since 9 was 9, checked in by Mattia Monga, 13 years ago

Minix 3.1.2a

File size: 1.4 KB
Line 
1/* $Header: /cvsup/minix/src/lib/ack/libp/new.c,v 1.1 2005/10/10 15:27:47 beng Exp $ */
2/*
3 * (c) copyright 1983 by the Vrije Universiteit, Amsterdam, The Netherlands.
4 *
5 * This product is part of the Amsterdam Compiler Kit.
6 *
7 * Permission to use, sell, duplicate or disclose this software must be
8 * obtained in writing. Requests for such permissions may be sent to
9 *
10 * Dr. Andrew S. Tanenbaum
11 * Wiskundig Seminarium
12 * Vrije Universiteit
13 * Postbox 7161
14 * 1007 MC Amsterdam
15 * The Netherlands
16 *
17 */
18
19/* Author: J.W. Stevenson */
20
21extern _sav();
22extern _rst();
23
24#define assert(x) /* nothing */
25#define UNDEF 0x8000
26
27struct adm {
28 struct adm *next;
29 int size;
30};
31
32struct adm *_lastp = 0;
33struct adm *_highp = 0;
34
35_new(n,pp) int n; struct adm **pp; {
36 struct adm *p,*q;
37 int *ptmp;
38
39 n = ((n+sizeof(*p)-1) / sizeof(*p)) * sizeof(*p);
40 if ((p = _lastp) != 0)
41 do {
42 q = p->next;
43 if (q->size >= n) {
44 assert(q->size%sizeof(adm) == 0);
45 if ((q->size -= n) == 0) {
46 if (p == q)
47 p = 0;
48 else
49 p->next = q->next;
50 if (q == _highp)
51 _highp = p;
52 }
53 _lastp = p;
54 p = (struct adm *)((char *)q + q->size);
55 q = (struct adm *)((char *)p + n);
56 goto initialize;
57 }
58 p = q;
59 } while (p != _lastp);
60 /*no free block big enough*/
61 _sav(&p);
62 q = (struct adm *)((char *)p + n);
63 _rst(&q);
64initialize:
65 *pp = p;
66 ptmp = (int *)p;
67 while (ptmp < (int *)q)
68 *ptmp++ = UNDEF;
69}
Note: See TracBrowser for help on using the repository browser.