Back to index

glibc  2.9
bzero.c
Go to the documentation of this file.
00001 /* Copyright (C) 1991, 1997, 1999 Free Software Foundation, Inc.
00002    This file is part of the GNU C Library.
00003    Contributed by Torbjorn Granlund (tege@sics.se).
00004 
00005    The GNU C Library is free software; you can redistribute it and/or
00006    modify it under the terms of the GNU Lesser General Public
00007    License as published by the Free Software Foundation; either
00008    version 2.1 of the License, or (at your option) any later version.
00009 
00010    The GNU C Library is distributed in the hope that it will be useful,
00011    but WITHOUT ANY WARRANTY; without even the implied warranty of
00012    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00013    Lesser General Public License for more details.
00014 
00015    You should have received a copy of the GNU Lesser General Public
00016    License along with the GNU C Library; if not, write to the Free
00017    Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
00018    02111-1307 USA.  */
00019 
00020 #include <string.h>
00021 #include <memcopy.h>
00022 
00023 #undef __bzero
00024 
00025 /* Set N bytes of S to 0.  */
00026 void
00027 __bzero (s, len)
00028      void *s;
00029      size_t len;
00030 {
00031   long int dstp = (long int) s;
00032   const op_t zero = 0;
00033 
00034   if (len >= 8)
00035     {
00036       size_t xlen;
00037 
00038       /* There are at least some bytes to zero.  No need to test
00039         for LEN == 0 in this alignment loop.  */
00040       while (dstp % OPSIZ != 0)
00041        {
00042          ((byte *) dstp)[0] = 0;
00043          dstp += 1;
00044          len -= 1;
00045        }
00046 
00047       /* Write 8 op_t per iteration until less than 8 op_t remain.  */
00048       xlen = len / (OPSIZ * 8);
00049       while (xlen != 0)
00050        {
00051          ((op_t *) dstp)[0] = zero;
00052          ((op_t *) dstp)[1] = zero;
00053          ((op_t *) dstp)[2] = zero;
00054          ((op_t *) dstp)[3] = zero;
00055          ((op_t *) dstp)[4] = zero;
00056          ((op_t *) dstp)[5] = zero;
00057          ((op_t *) dstp)[6] = zero;
00058          ((op_t *) dstp)[7] = zero;
00059          dstp += 8 * OPSIZ;
00060          xlen -= 1;
00061        }
00062       len %= OPSIZ * 8;
00063 
00064       /* Write 1 op_t per iteration until less than op_t remain.  */
00065       xlen = len / OPSIZ;
00066       while (xlen != 0)
00067        {
00068          ((op_t *) dstp)[0] = zero;
00069          dstp += OPSIZ;
00070          xlen -= 1;
00071        }
00072       len %= OPSIZ;
00073     }
00074 
00075   /* Write the last few bytes.  */
00076   while (len != 0)
00077     {
00078       ((byte *) dstp)[0] = 0;
00079       dstp += 1;
00080       len -= 1;
00081     }
00082 }
00083 weak_alias (__bzero, bzero)