- Main Page
- Data Structures
- Files
- Directories

- Search for |

- File List
- Globals

# memset.c

Go to the documentation of this file.

    00001 /*****************************************************************************************
    00002  Copyright (c) 2002 The UbixOS Project
    00003  All rights reserved.
    00004
    00005 Redistribution and use in source and binary forms, with or without modification, are
    00006 permitted provided that the following conditions are met:
    00007
    00008 Redistributions of source code must retain the above copyright notice, this list of
    00009 conditions, the following disclaimer and the list of authors.  Redistributions in binary
    00010 form must reproduce the above copyright notice, this list of conditions, the following
    00011 disclaimer and the list of authors in the documentation and/or other materials provided
    00012 with the distribution. Neither the name of the UbixOS Project nor the names of its
    00013 contributors may be used to endorse or promote products derived from this software
    00014 without specific prior written permission.
    00015
    00016 THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY
    00017 EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
    00018 MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL
    00019 THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
    00020 SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT
    00021 OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
    00022 HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR
    00023 TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
    00024 SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
    00025
    00026  $Id: memset_8c-source.html 88 2016-01-12 00:11:29Z reddawg $
    00027
    00028 *****************************************************************************************/
    00029
    00030 #include <string.h>
    00031
    00032 #define wsize   sizeof(uInt)
    00033 #define wmask   (wsize - 1)
    00034 #define VAL     c0
    00035 #define WIDEVAL c
    00036
    00037 void *memset(void *dst0, int c0, size_t length) {
    00038   size_t t;
    00039   uInt c;
    00040   uInt8 *dst;
    00041
    00042   dst = dst0;
    00043
    00044         if (length < 3 * wsize) {
    00045                 while (length != 0) {
    00046                         *dst++ = VAL;
    00047                         --length;
    00048                 }
    00049                 return(dst0);
    00050         }
    00051
    00052         if ((c = (uInt8)c0) != 0) {    /* Fill the word. */
    00053                 c = (c << 8) | c;       /* u_int is 16 bits. */
    00054                 c = (c << 16) | c;      /* u_int is 32 bits. */
    00055         }
    00056
    00057         /* Align destination by filling in bytes. */
    00058         if ((t = (long)dst & wmask) != 0) {
    00059                 t = wsize - t;
    00060                 length -= t;
    00061                 do {
    00062                         *dst++ = VAL;
    00063                 } while (--t != 0);
    00064         }
    00065
    00066         /* Fill words.  Length was >= 2*words so we know t >= 1 here. */
    00067         t = length / wsize;
    00068         do {
    00069                 *(u_int *)dst = WIDEVAL;
    00070                 dst += wsize;
    00071         } while (--t != 0);
    00072
    00073         /* Mop up trailing bytes, if any. */
    00074         t = length & wmask;
    00075         if (t != 0)
    00076                 do {
    00077                         *dst++ = VAL;
    00078                 } while (--t != 0);
    00079         return(dst0);
    00080   }
    00081
    00082
    00083 /***
    00084  $Log: memset_8c-source.html,v $
    00084  Revision 1.7  2006/12/15 17:47:06  reddawg
    00084  Updates
    00084
    00085  Revision 1.1.1.1  2006/06/01 12:46:16  reddawg
    00086  ubix2
    00087
    00088  Revision 1.2  2005/10/12 00:13:37  reddawg
    00089  Removed
    00090
    00091  Revision 1.1.1.1  2005/09/26 17:24:12  reddawg
    00092  no message
    00093
    00094  Revision 1.1  2004/07/28 16:20:10  reddawg
    00095  forgot this file
    00096
    00097  END
    00098  ***/
    00099