1 |
/* Stupid ass version of memset |
/* memset.c -- set an area of memory to a given value |
2 |
|
Copyright (C) 1991 Free Software Foundation, Inc. |
3 |
|
|
4 |
Copyright (C) 1996, 1997 Free Software Foundation, Inc. |
This program is free software; you can redistribute it and/or modify |
5 |
|
it under the terms of the GNU General Public License as published by |
6 |
Written by Miles Bader <miles@gnu.ai.mit.edu> |
the Free Software Foundation; either version 2, or (at your option) |
7 |
|
any later version. |
8 |
This program is free software; you can redistribute it and/or |
|
9 |
modify it under the terms of the GNU General Public License as |
This program is distributed in the hope that it will be useful, |
10 |
published by the Free Software Foundation; either version 2, or (at |
but WITHOUT ANY WARRANTY; without even the implied warranty of |
11 |
your option) any later version. |
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
12 |
|
GNU General Public License for more details. |
|
This program is distributed in the hope that it will be useful, but |
|
|
WITHOUT ANY WARRANTY; without even the implied warranty of |
|
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
|
|
General Public License for more details. |
|
13 |
|
|
14 |
You should have received a copy of the GNU General Public License |
You should have received a copy of the GNU General Public License |
15 |
along with this program; if not, write to the Free Software |
along with this program; if not, write to the Free Software Foundation, |
16 |
Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. */ |
Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */ |
17 |
|
|
18 |
#ifdef HAVE_CONFIG_H |
char * |
19 |
#include <config.h> |
memset (char *str, int c, unsigned int len) |
|
#endif |
|
|
|
|
|
#ifdef HAVE_STDLIB_H |
|
|
#include <stdlib.h> |
|
|
#endif |
|
|
#ifdef HAVE_STRING_H |
|
|
#include <string.h> |
|
|
#endif |
|
|
|
|
|
void |
|
|
memset (mem, val, sz) |
|
|
void *mem; |
|
|
int val; |
|
|
size_t sz; |
|
20 |
{ |
{ |
21 |
#ifdef HAVE_BZERO |
register char *st = str; |
22 |
if (val == 0) |
|
23 |
bzero (mem, sz); |
while (len-- > 0) |
24 |
else |
*st++ = c; |
25 |
#endif |
return str; |
|
/* Not *too* efficient... */ |
|
|
{ |
|
|
char *p = mem; |
|
|
while (sz-- > 0) |
|
|
*p++ = val; |
|
|
} |
|
26 |
} |
} |