bcmp.c: Fix warnings and implement using memcmp.

* bcmp.c: Fix warnings and implement using memcmp.
	* bcopy.c: Fix warnings.
	* bzero.c: Fix warnings and implement using memset.

From-SVN: r97457
This commit is contained in:
Kaveh R. Ghazi 2005-04-02 20:28:00 +00:00 committed by Kaveh Ghazi
parent f9a9ac80d6
commit 291387970d
4 changed files with 26 additions and 23 deletions

View File

@ -1,5 +1,9 @@
2005-04-02 Kaveh R. Ghazi <ghazi@caip.rutgers.edu> 2005-04-02 Kaveh R. Ghazi <ghazi@caip.rutgers.edu>
* bcmp.c: Fix warnings and implement using memcmp.
* bcopy.c: Fix warnings.
* bzero.c: Fix warnings and implement using memset.
* configure.ac (ac_libiberty_warn_cflags): Add -Wwrite-strings * configure.ac (ac_libiberty_warn_cflags): Add -Wwrite-strings
-Wstrict-prototypes. -Wstrict-prototypes.
* configure, config.in: Regenerate. * configure, config.in: Regenerate.

View File

@ -15,20 +15,13 @@ result mean @var{x} sorts before @var{y}).
*/ */
#include <stddef.h>
extern int memcmp(const void *, const void *, size_t);
int int
bcmp (char *from, char *to, int count) bcmp (const void *s1, const void *s2, size_t count)
{ {
int rtnval = 0; return memcmp (s1, s2, count);
while (count-- > 0)
{
if (*from++ != *to++)
{
rtnval = 1;
break;
}
}
return (rtnval);
} }

View File

@ -9,17 +9,23 @@ Copies @var{length} bytes from memory region @var{in} to region
*/ */
#include <stddef.h>
void void
bcopy (register char *src, register char *dest, int len) bcopy (const void *src, void *dest, size_t len)
{ {
if (dest < src) if (dest < src)
while (len--) {
*dest++ = *src++; const char *firsts = src;
char *firstd = dest;
while (len--)
*firstd++ = *firsts++;
}
else else
{ {
char *lasts = src + (len-1); const char *lasts = (const char *)src + (len-1);
char *lastd = dest + (len-1); char *lastd = (char *)dest + (len-1);
while (len--) while (len--)
*(char *)lastd-- = *(char *)lasts--; *lastd-- = *lasts--;
} }
} }

View File

@ -12,12 +12,12 @@ is deprecated in favor of @code{memset}.
*/ */
#include <stddef.h>
extern void *memset(void *, int, size_t);
void void
bzero (char *to, int count) bzero (void *to, size_t count)
{ {
while (count-- > 0) memset (to, 0, count);
{
*to++ = 0;
}
} }