xref: /dflybsd-src/contrib/gcc-4.7/libiberty/spaces.c (revision 04febcfb30580676d3e95f58a16c5137ee478b32)
1*e4b17023SJohn Marino /* Allocate memory region filled with spaces.
2*e4b17023SJohn Marino    Copyright (C) 1991 Free Software Foundation, Inc.
3*e4b17023SJohn Marino 
4*e4b17023SJohn Marino This file is part of the libiberty library.
5*e4b17023SJohn Marino Libiberty is free software; you can redistribute it and/or
6*e4b17023SJohn Marino modify it under the terms of the GNU Library General Public
7*e4b17023SJohn Marino License as published by the Free Software Foundation; either
8*e4b17023SJohn Marino version 2 of the License, or (at your option) any later version.
9*e4b17023SJohn Marino 
10*e4b17023SJohn Marino Libiberty is distributed in the hope that it will be useful,
11*e4b17023SJohn Marino but WITHOUT ANY WARRANTY; without even the implied warranty of
12*e4b17023SJohn Marino MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
13*e4b17023SJohn Marino Library General Public License for more details.
14*e4b17023SJohn Marino 
15*e4b17023SJohn Marino You should have received a copy of the GNU Library General Public
16*e4b17023SJohn Marino License along with libiberty; see the file COPYING.LIB.  If
17*e4b17023SJohn Marino not, write to the Free Software Foundation, Inc., 51 Franklin Street - Fifth Floor,
18*e4b17023SJohn Marino Boston, MA 02110-1301, USA.  */
19*e4b17023SJohn Marino 
20*e4b17023SJohn Marino /*
21*e4b17023SJohn Marino 
22*e4b17023SJohn Marino @deftypefn Extension char* spaces (int @var{count})
23*e4b17023SJohn Marino 
24*e4b17023SJohn Marino Returns a pointer to a memory region filled with the specified
25*e4b17023SJohn Marino number of spaces and null terminated.  The returned pointer is
26*e4b17023SJohn Marino valid until at least the next call.
27*e4b17023SJohn Marino 
28*e4b17023SJohn Marino @end deftypefn
29*e4b17023SJohn Marino 
30*e4b17023SJohn Marino */
31*e4b17023SJohn Marino 
32*e4b17023SJohn Marino #ifdef HAVE_CONFIG_H
33*e4b17023SJohn Marino #include "config.h"
34*e4b17023SJohn Marino #endif
35*e4b17023SJohn Marino #include "ansidecl.h"
36*e4b17023SJohn Marino #include "libiberty.h"
37*e4b17023SJohn Marino 
38*e4b17023SJohn Marino #if VMS
39*e4b17023SJohn Marino #include <stdlib.h>
40*e4b17023SJohn Marino #include <unixlib.h>
41*e4b17023SJohn Marino #else
42*e4b17023SJohn Marino /* For systems with larger pointers than ints, these must be declared.  */
43*e4b17023SJohn Marino extern PTR malloc (size_t);
44*e4b17023SJohn Marino extern void free (PTR);
45*e4b17023SJohn Marino #endif
46*e4b17023SJohn Marino 
47*e4b17023SJohn Marino const char *
spaces(int count)48*e4b17023SJohn Marino spaces (int count)
49*e4b17023SJohn Marino {
50*e4b17023SJohn Marino   register char *t;
51*e4b17023SJohn Marino   static char *buf;
52*e4b17023SJohn Marino   static int maxsize;
53*e4b17023SJohn Marino 
54*e4b17023SJohn Marino   if (count > maxsize)
55*e4b17023SJohn Marino     {
56*e4b17023SJohn Marino       free (buf);
57*e4b17023SJohn Marino       buf = (char *) malloc (count + 1);
58*e4b17023SJohn Marino       if (buf == (char *) 0)
59*e4b17023SJohn Marino 	return 0;
60*e4b17023SJohn Marino       for (t = buf + count ; t != buf ; )
61*e4b17023SJohn Marino 	{
62*e4b17023SJohn Marino 	  *--t = ' ';
63*e4b17023SJohn Marino 	}
64*e4b17023SJohn Marino       maxsize = count;
65*e4b17023SJohn Marino       buf[count] = '\0';
66*e4b17023SJohn Marino     }
67*e4b17023SJohn Marino   return (const char *) (buf + maxsize - count);
68*e4b17023SJohn Marino }
69*e4b17023SJohn Marino 
70