198b9484cSchristos /* Allocate memory region filled with spaces. 2*7e120ff0Schristos Copyright (C) 1991-2024 Free Software Foundation, Inc. 398b9484cSchristos 498b9484cSchristos This file is part of the libiberty library. 598b9484cSchristos Libiberty is free software; you can redistribute it and/or 698b9484cSchristos modify it under the terms of the GNU Library General Public 798b9484cSchristos License as published by the Free Software Foundation; either 898b9484cSchristos version 2 of the License, or (at your option) any later version. 998b9484cSchristos 1098b9484cSchristos Libiberty is distributed in the hope that it will be useful, 1198b9484cSchristos but WITHOUT ANY WARRANTY; without even the implied warranty of 1298b9484cSchristos MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 1398b9484cSchristos Library General Public License for more details. 1498b9484cSchristos 1598b9484cSchristos You should have received a copy of the GNU Library General Public 1698b9484cSchristos License along with libiberty; see the file COPYING.LIB. If 1798b9484cSchristos not, write to the Free Software Foundation, Inc., 51 Franklin Street - Fifth Floor, 1898b9484cSchristos Boston, MA 02110-1301, USA. */ 1998b9484cSchristos 2098b9484cSchristos /* 2198b9484cSchristos 2298b9484cSchristos @deftypefn Extension char* spaces (int @var{count}) 2398b9484cSchristos 2498b9484cSchristos Returns a pointer to a memory region filled with the specified 2598b9484cSchristos number of spaces and null terminated. The returned pointer is 2698b9484cSchristos valid until at least the next call. 2798b9484cSchristos 2898b9484cSchristos @end deftypefn 2998b9484cSchristos 3098b9484cSchristos */ 3198b9484cSchristos 3298b9484cSchristos #ifdef HAVE_CONFIG_H 3398b9484cSchristos #include "config.h" 3498b9484cSchristos #endif 3598b9484cSchristos #include "ansidecl.h" 3698b9484cSchristos #include "libiberty.h" 3798b9484cSchristos 3898b9484cSchristos #if VMS 3998b9484cSchristos #include <stdlib.h> 4098b9484cSchristos #include <unixlib.h> 4198b9484cSchristos #else 4298b9484cSchristos /* For systems with larger pointers than ints, these must be declared. */ 434b169a6bSchristos extern void *malloc (size_t); 444b169a6bSchristos extern void free (void *); 4598b9484cSchristos #endif 4698b9484cSchristos 4798b9484cSchristos const char * 4898b9484cSchristos spaces (int count) 4998b9484cSchristos { 5098b9484cSchristos register char *t; 5198b9484cSchristos static char *buf; 5298b9484cSchristos static int maxsize; 5398b9484cSchristos 5498b9484cSchristos if (count > maxsize) 5598b9484cSchristos { 5698b9484cSchristos free (buf); 5798b9484cSchristos buf = (char *) malloc (count + 1); 5898b9484cSchristos if (buf == (char *) 0) 5998b9484cSchristos return 0; 6098b9484cSchristos for (t = buf + count ; t != buf ; ) 6198b9484cSchristos { 6298b9484cSchristos *--t = ' '; 6398b9484cSchristos } 6498b9484cSchristos maxsize = count; 6598b9484cSchristos buf[count] = '\0'; 6698b9484cSchristos } 6798b9484cSchristos return (const char *) (buf + maxsize - count); 6898b9484cSchristos } 6998b9484cSchristos 70