xref: /openbsd-src/gnu/lib/libiberty/src/spaces.c (revision 20fce977aadac3358da45d5027d7d19cdc03b0fe)
100bf4279Sespie /* Allocate memory region filled with spaces.
200bf4279Sespie    Copyright (C) 1991 Free Software Foundation, Inc.
300bf4279Sespie 
400bf4279Sespie This file is part of the libiberty library.
500bf4279Sespie Libiberty is free software; you can redistribute it and/or
600bf4279Sespie modify it under the terms of the GNU Library General Public
700bf4279Sespie License as published by the Free Software Foundation; either
800bf4279Sespie version 2 of the License, or (at your option) any later version.
900bf4279Sespie 
1000bf4279Sespie Libiberty is distributed in the hope that it will be useful,
1100bf4279Sespie but WITHOUT ANY WARRANTY; without even the implied warranty of
1200bf4279Sespie MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
1300bf4279Sespie Library General Public License for more details.
1400bf4279Sespie 
1500bf4279Sespie You should have received a copy of the GNU Library General Public
1600bf4279Sespie License along with libiberty; see the file COPYING.LIB.  If
17*20fce977Smiod not, write to the Free Software Foundation, Inc., 51 Franklin Street - Fifth Floor,
18*20fce977Smiod Boston, MA 02110-1301, USA.  */
1900bf4279Sespie 
2000bf4279Sespie /*
2100bf4279Sespie 
229588ddcfSespie @deftypefn Extension char* spaces (int @var{count})
2300bf4279Sespie 
2400bf4279Sespie Returns a pointer to a memory region filled with the specified
2500bf4279Sespie number of spaces and null terminated.  The returned pointer is
2600bf4279Sespie valid until at least the next call.
2700bf4279Sespie 
289588ddcfSespie @end deftypefn
2900bf4279Sespie 
3000bf4279Sespie */
3100bf4279Sespie 
32*20fce977Smiod #ifdef HAVE_CONFIG_H
33*20fce977Smiod #include "config.h"
34*20fce977Smiod #endif
3500bf4279Sespie #include "ansidecl.h"
3600bf4279Sespie #include "libiberty.h"
3700bf4279Sespie 
3800bf4279Sespie #if VMS
3900bf4279Sespie #include <stdlib.h>
4000bf4279Sespie #include <unixlib.h>
4100bf4279Sespie #else
4200bf4279Sespie /* For systems with larger pointers than ints, these must be declared.  */
43*20fce977Smiod extern PTR malloc (size_t);
44*20fce977Smiod extern void free (PTR);
4500bf4279Sespie #endif
4600bf4279Sespie 
4700bf4279Sespie const char *
spaces(int count)48*20fce977Smiod spaces (int count)
4900bf4279Sespie {
5000bf4279Sespie   register char *t;
5100bf4279Sespie   static char *buf;
5200bf4279Sespie   static int maxsize;
5300bf4279Sespie 
5400bf4279Sespie   if (count > maxsize)
5500bf4279Sespie     {
5600bf4279Sespie       if (buf)
5700bf4279Sespie 	{
5800bf4279Sespie 	  free (buf);
5900bf4279Sespie 	}
60*20fce977Smiod       buf = (char *) malloc (count + 1);
6100bf4279Sespie       if (buf == (char *) 0)
6200bf4279Sespie 	return 0;
6300bf4279Sespie       for (t = buf + count ; t != buf ; )
6400bf4279Sespie 	{
6500bf4279Sespie 	  *--t = ' ';
6600bf4279Sespie 	}
6700bf4279Sespie       maxsize = count;
6800bf4279Sespie       buf[count] = '\0';
6900bf4279Sespie     }
7000bf4279Sespie   return (const char *) (buf + maxsize - count);
7100bf4279Sespie }
7200bf4279Sespie 
73