Update.
[glibc.git] / sysdeps / generic / bzero.c
blob7fda7c3b5e20ff949079835bbe679fc6139780e1
1 /* Copyright (C) 1991, 1997 Free Software Foundation, Inc.
2 This file is part of the GNU C Library.
3 Contributed by Torbjorn Granlund (tege@sics.se).
5 The GNU C Library is free software; you can redistribute it and/or
6 modify it under the terms of the GNU Library General Public License as
7 published by the Free Software Foundation; either version 2 of the
8 License, or (at your option) any later version.
10 The GNU C Library 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.
15 You should have received a copy of the GNU Library General Public
16 License along with the GNU C Library; see the file COPYING.LIB. If not,
17 write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
18 Boston, MA 02111-1307, USA. */
20 #include <string.h>
21 #include <memcopy.h>
23 /* Set N bytes of S to 0. */
24 void
25 bzero (s, len)
26 void *s;
27 size_t len;
29 long int dstp = (long int) s;
30 const op_t zero = 0;
32 if (len >= 8)
34 size_t xlen;
36 /* There are at least some bytes to zero. No need to test
37 for LEN == 0 in this alignment loop. */
38 while (dstp % OPSIZ != 0)
40 ((byte *) dstp)[0] = 0;
41 dstp += 1;
42 len -= 1;
45 /* Write 8 op_t per iteration until less than 8 op_t remain. */
46 xlen = len / (OPSIZ * 8);
47 while (xlen != 0)
49 ((op_t *) dstp)[0] = zero;
50 ((op_t *) dstp)[1] = zero;
51 ((op_t *) dstp)[2] = zero;
52 ((op_t *) dstp)[3] = zero;
53 ((op_t *) dstp)[4] = zero;
54 ((op_t *) dstp)[5] = zero;
55 ((op_t *) dstp)[6] = zero;
56 ((op_t *) dstp)[7] = zero;
57 dstp += 8 * OPSIZ;
58 xlen -= 1;
60 len %= OPSIZ * 8;
62 /* Write 1 op_t per iteration until less than op_t remain. */
63 xlen = len / OPSIZ;
64 while (xlen != 0)
66 ((op_t *) dstp)[0] = zero;
67 dstp += OPSIZ;
68 xlen -= 1;
70 len %= OPSIZ;
73 /* Write the last few bytes. */
74 while (len != 0)
76 ((byte *) dstp)[0] = 0;
77 dstp += 1;
78 len -= 1;