home *** CD-ROM | disk | FTP | other *** search
/ Geek Gadgets 1 / ADE-1.bin / ade-dist / binutils-2.7-src.tgz / tar.out / fsf / binutils / libiberty / spaces.c < prev    next >
C/C++ Source or Header  |  1996-09-28  |  2KB  |  72 lines

  1. /* Allocate memory region filled with spaces.
  2.    Copyright (C) 1991 Free Software Foundation, Inc.
  3.  
  4. This file is part of the libiberty library.
  5. Libiberty is free software; you can redistribute it and/or
  6. modify it under the terms of the GNU Library General Public
  7. License as published by the Free Software Foundation; either
  8. version 2 of the License, or (at your option) any later version.
  9.  
  10. Libiberty is distributed in the hope that it will be useful,
  11. but WITHOUT ANY WARRANTY; without even the implied warranty of
  12. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
  13. Library General Public License for more details.
  14.  
  15. You should have received a copy of the GNU Library General Public
  16. License along with libiberty; see the file COPYING.LIB.  If
  17. not, write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
  18. Boston, MA 02111-1307, USA.  */
  19.  
  20. /*
  21.  
  22. NAME
  23.  
  24.     spaces -- return a pointer to a buffer full of spaces
  25.  
  26. SYNOPSIS
  27.  
  28.     char *spaces (int count)
  29.  
  30. DESCRIPTION
  31.  
  32.     Returns a pointer to a memory region filled with the specified
  33.     number of spaces and null terminated.  The returned pointer is
  34.     valid until at least the next call.
  35.     
  36. BUGS
  37.  
  38. */
  39.  
  40. #include "ansidecl.h"
  41. #include "libiberty.h"
  42.  
  43. const char *
  44. spaces (count)
  45.   int count;
  46. {
  47.   register char *t;
  48.   static char *buf;
  49.   static int maxsize;
  50.   extern char *malloc ();
  51.   extern void free ();
  52.  
  53.   if (count > maxsize)
  54.     {
  55.       if (buf)
  56.     {
  57.       free (buf);
  58.     }
  59.       buf = malloc (count + 1);
  60.       if (buf == (char *) 0)
  61.     return 0;
  62.       for (t = buf + count ; t != buf ; )
  63.     {
  64.       *--t = ' ';
  65.     }
  66.       maxsize = count;
  67.       buf[count] = '\0';
  68.     }
  69.   return (const char *) (buf + maxsize - count);
  70. }
  71.  
  72.