1169695Skan/* Allocate memory region filled with spaces.
2169695Skan   Copyright (C) 1991 Free Software Foundation, Inc.
3169695Skan
4169695SkanThis file is part of the libiberty library.
5169695SkanLibiberty is free software; you can redistribute it and/or
6169695Skanmodify it under the terms of the GNU Library General Public
7169695SkanLicense as published by the Free Software Foundation; either
8169695Skanversion 2 of the License, or (at your option) any later version.
9169695Skan
10169695SkanLibiberty is distributed in the hope that it will be useful,
11169695Skanbut WITHOUT ANY WARRANTY; without even the implied warranty of
12169695SkanMERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
13169695SkanLibrary General Public License for more details.
14169695Skan
15169695SkanYou should have received a copy of the GNU Library General Public
16169695SkanLicense along with libiberty; see the file COPYING.LIB.  If
17169695Skannot, write to the Free Software Foundation, Inc., 51 Franklin Street - Fifth Floor,
18169695SkanBoston, MA 02110-1301, USA.  */
19169695Skan
20169695Skan/*
21169695Skan
22169695Skan@deftypefn Extension char* spaces (int @var{count})
23169695Skan
24169695SkanReturns a pointer to a memory region filled with the specified
25169695Skannumber of spaces and null terminated.  The returned pointer is
26169695Skanvalid until at least the next call.
27169695Skan
28169695Skan@end deftypefn
29169695Skan
30169695Skan*/
31169695Skan
32169695Skan#ifdef HAVE_CONFIG_H
33169695Skan#include "config.h"
34169695Skan#endif
35169695Skan#include "ansidecl.h"
36169695Skan#include "libiberty.h"
37169695Skan
38169695Skan#if VMS
39169695Skan#include <stdlib.h>
40169695Skan#include <unixlib.h>
41169695Skan#else
42169695Skan/* For systems with larger pointers than ints, these must be declared.  */
43169695Skanextern PTR malloc (size_t);
44169695Skanextern void free (PTR);
45169695Skan#endif
46169695Skan
47169695Skanconst char *
48169695Skanspaces (int count)
49169695Skan{
50169695Skan  register char *t;
51169695Skan  static char *buf;
52169695Skan  static int maxsize;
53169695Skan
54169695Skan  if (count > maxsize)
55169695Skan    {
56169695Skan      if (buf)
57169695Skan	{
58169695Skan	  free (buf);
59169695Skan	}
60169695Skan      buf = (char *) malloc (count + 1);
61169695Skan      if (buf == (char *) 0)
62169695Skan	return 0;
63169695Skan      for (t = buf + count ; t != buf ; )
64169695Skan	{
65169695Skan	  *--t = ' ';
66169695Skan	}
67169695Skan      maxsize = count;
68169695Skan      buf[count] = '\0';
69169695Skan    }
70169695Skan  return (const char *) (buf + maxsize - count);
71169695Skan}
72169695Skan
73