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