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