home *** CD-ROM | disk | FTP | other *** search
/ linuxmafia.com 2016 / linuxmafia.com.tar / linuxmafia.com / pub / linux / backup / star-1.3.1.tar.gz / star-1.3.1.tar / star-1.3.1 / lib / fillbytes.c < prev    next >
C/C++ Source or Header  |  2000-05-07  |  2KB  |  95 lines

  1. /* @(#)fillbytes.c    1.11 00/05/07 Copyright 1987 J. Schilling */
  2. /*
  3.  *    fill memory with data
  4.  *
  5.  *    Copyright (c) 1987 J. Schilling
  6.  */
  7. /*
  8.  * This program is free software; you can redistribute it and/or modify
  9.  * it under the terms of the GNU General Public License as published by
  10.  * the Free Software Foundation; either version 2, or (at your option)
  11.  * any later version.
  12.  *
  13.  * This program is distributed in the hope that it will be useful,
  14.  * but WITHOUT ANY WARRANTY; without even the implied warranty of
  15.  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  16.  * GNU General Public License for more details.
  17.  *
  18.  * You should have received a copy of the GNU General Public License
  19.  * along with this program; see the file COPYING.  If not, write to
  20.  * the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.
  21.  */
  22.  
  23. #include <standard.h>
  24. #include <align.h>
  25. #include <schily.h>
  26.  
  27. #define    DO8(a)    a;a;a;a;a;a;a;a;
  28.  
  29. #define    cval    ((char) lval)
  30.  
  31. #ifdef    PROTOTYPES
  32. char *fillbytes(void *tov, int cnt, char val)
  33. #else
  34. char *fillbytes(tov, cnt, val)
  35.     void    *tov;
  36.     int    cnt;
  37.     char    val;
  38. #endif
  39. {
  40.     register char    *to = (char *)tov;
  41.     register int    n;
  42.     register long    lval;
  43.  
  44.     /*
  45.      * If we change cnt to be unsigned, check for == instead of <=
  46.      */
  47.     if ((n = cnt) <= 0)
  48.         return (to);
  49.  
  50.     lval = val & 0xFF;
  51.  
  52.     while (!laligned(to)) {
  53.         *to++ = cval;
  54.         n--;
  55.     }
  56.  
  57.     if (n >= (int)(8 * sizeof(long))) {
  58.         register int rem = n % (8 * sizeof (long));
  59.  
  60.         lval |= (lval<<8);
  61.         lval |= (lval<<16);
  62. #if SIZE_LONG > SIZE_INT
  63.         lval |= (lval<<32);
  64. #endif
  65.  
  66.         n /= (8 * sizeof (long));
  67.         {
  68.             register long *tol = (long *)to;
  69.  
  70.             do {
  71.                 DO8 (*tol++ = lval);
  72.             } while (--n > 0);
  73.  
  74.             to = (char *)tol;
  75.         }
  76.         n = rem;
  77.  
  78.         if (n >= 8) {
  79.             n -= 8;
  80.             do {
  81.                 DO8 (*to++ = cval);
  82.             } while ((n -= 8) >= 0);
  83.             n += 8;
  84.         }
  85.         if (n > 0) do {
  86.             *to++ = cval;
  87.         } while (--n > 0);
  88.         return (to);
  89.     }
  90.     if (n > 0) do {
  91.         *to++ = cval;
  92.     } while (--n > 0);
  93.     return (to);
  94. }
  95.