/* Copyright (C) 1991, 1997 Free Software Foundation, Inc.1This file is part of the GNU C Library.23The GNU C Library is free software; you can redistribute it and/or4modify it under the terms of the GNU Lesser General Public5License as published by the Free Software Foundation; either6version 2.1 of the License, or (at your option) any later version.78The GNU C Library is distributed in the hope that it will be useful,9but WITHOUT ANY WARRANTY; without even the implied warranty of10MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU11Lesser General Public License for more details.1213You should have received a copy of the GNU Lesser General Public14License along with the GNU C Library; if not, write to the Free15Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA1602111-1307 USA. */1718/* Slight modifications for pa-risc linux - Paul Bame <[email protected]> */1920#include <linux/types.h>21#include <asm/string.h>2223#define OPSIZ (BITS_PER_LONG/8)24typedef unsigned long op_t;2526void *27memset (void *dstpp, int sc, size_t len)28{29unsigned int c = sc;30long int dstp = (long int) dstpp;3132if (len >= 8)33{34size_t xlen;35op_t cccc;3637cccc = (unsigned char) c;38cccc |= cccc << 8;39cccc |= cccc << 16;40if (OPSIZ > 4)41/* Do the shift in two steps to avoid warning if long has 32 bits. */42cccc |= (cccc << 16) << 16;4344/* There are at least some bytes to set.45No need to test for LEN == 0 in this alignment loop. */46while (dstp % OPSIZ != 0)47{48((unsigned char *) dstp)[0] = c;49dstp += 1;50len -= 1;51}5253/* Write 8 `op_t' per iteration until less than 8 `op_t' remain. */54xlen = len / (OPSIZ * 8);55while (xlen > 0)56{57((op_t *) dstp)[0] = cccc;58((op_t *) dstp)[1] = cccc;59((op_t *) dstp)[2] = cccc;60((op_t *) dstp)[3] = cccc;61((op_t *) dstp)[4] = cccc;62((op_t *) dstp)[5] = cccc;63((op_t *) dstp)[6] = cccc;64((op_t *) dstp)[7] = cccc;65dstp += 8 * OPSIZ;66xlen -= 1;67}68len %= OPSIZ * 8;6970/* Write 1 `op_t' per iteration until less than OPSIZ bytes remain. */71xlen = len / OPSIZ;72while (xlen > 0)73{74((op_t *) dstp)[0] = cccc;75dstp += OPSIZ;76xlen -= 1;77}78len %= OPSIZ;79}8081/* Write the last few bytes. */82while (len > 0)83{84((unsigned char *) dstp)[0] = c;85dstp += 1;86len -= 1;87}8889return dstpp;90}919293