1 /* $Id$ $Revision$ */
2 /* vim:set shiftwidth=4 ts=8: */
3 
4 /*************************************************************************
5  * Copyright (c) 2011 AT&T Intellectual Property
6  * All rights reserved. This program and the accompanying materials
7  * are made available under the terms of the Eclipse Public License v1.0
8  * which accompanies this distribution, and is available at
9  * http://www.eclipse.org/legal/epl-v10.html
10  *
11  * Contributors: See CVS logs. Details at http://www.graphviz.org/
12  *************************************************************************/
13 
14 
15 #include <ast.h>
16 
17 /*
18  * return small format buffer chunk of size n
19  * spin lock for thread access
20  * format buffers are short lived
21  */
22 
23 static char buf[16 * 1024];
24 static char *nxt = buf;
25 static int lck = -1;
26 
fmtbuf(size_t n)27 char *fmtbuf(size_t n)
28 {
29     register char *cur;
30 
31     while (++lck)
32 	lck--;
33     if (n > (&buf[elementsof(buf)] - nxt))
34 	nxt = buf;
35     cur = nxt;
36     nxt += n;
37     lck--;
38     return cur;
39 }
40