home *** CD-ROM | disk | FTP | other *** search
/ Aminet 18 / aminetcdnumber181997.iso / Aminet / misc / emu / AROSdev.lha / AROS / compiler / clib / memset.c < prev    next >
Encoding:
C/C++ Source or Header  |  1997-01-09  |  1.2 KB  |  79 lines

  1. /*
  2.     (C) 1995-96 AROS - The Amiga Replacement OS
  3.     $Id: memset.c,v 1.3 1997/01/01 03:41:10 ldp Exp $
  4.  
  5.     Desc: ANSI C function memcpy()
  6.     Lang: english
  7. */
  8. #include <proto/exec.h>
  9.  
  10. /*****************************************************************************
  11.  
  12.     NAME */
  13. #include <string.h>
  14.  
  15.     void * memset (
  16.  
  17. /*  SYNOPSIS */
  18.     void * dest,
  19.     int    c,
  20.     size_t count)
  21.  
  22. /*  FUNCTION
  23.     Fill the memory at dest with count times c.
  24.  
  25.     INPUTS
  26.     dest - The first byte of the destination area in memory
  27.     c - The byte to fill memory with
  28.     count - How many bytes to write
  29.  
  30.     RESULT
  31.     dest.
  32.  
  33.     NOTES
  34.  
  35.     EXAMPLE
  36.  
  37.     BUGS
  38.  
  39.     SEE ALSO
  40.     memmove(), memcpy()
  41.  
  42.     INTERNALS
  43.  
  44.     HISTORY
  45.     24-12-95    digulla created
  46.  
  47. ******************************************************************************/
  48. {
  49.     UBYTE * ptr = dest;
  50.  
  51.     while (((IPTR)ptr)&(AROS_LONGALIGN-1) && count)
  52.     {
  53.     *ptr ++ = c;
  54.     count --;
  55.     }
  56.  
  57.     if (count > sizeof(ULONG))
  58.     {
  59.     ULONG * ulptr = (ULONG *)ptr;
  60.     ULONG fill;
  61.  
  62.     fill = (ULONG)(c & 0xFF);
  63.     fill = (fill <<  8) | fill;
  64.     fill = (fill << 16) | fill;
  65.  
  66.     while (count > sizeof(ULONG))
  67.     {
  68.         *ulptr ++ = fill;
  69.         count -= sizeof(ULONG);
  70.     }
  71.     }
  72.  
  73.     while (count --)
  74.     *ptr ++ = c;
  75.  
  76.     return dest;
  77. } /* memset */
  78.  
  79.