build bzero(3) out of the same sources
authorKeith Bostic <bostic@ucbvax.Berkeley.EDU>
Thu, 13 May 1993 02:00:29 +0000 (18:00 -0800)
committerKeith Bostic <bostic@ucbvax.Berkeley.EDU>
Thu, 13 May 1993 02:00:29 +0000 (18:00 -0800)
SCCS-vsn: lib/libc/string/memset.c 5.8

usr/src/lib/libc/string/memset.c

index 42900d8..2e3ea15 100644 (file)
@@ -9,7 +9,7 @@
  */
 
 #if defined(LIBC_SCCS) && !defined(lint)
  */
 
 #if defined(LIBC_SCCS) && !defined(lint)
-static char sccsid[] = "@(#)memset.c   5.7 (Berkeley) %G%";
+static char sccsid[] = "@(#)memset.c   5.8 (Berkeley) %G%";
 #endif /* LIBC_SCCS and not lint */
 
 #include <sys/types.h>
 #endif /* LIBC_SCCS and not lint */
 
 #include <sys/types.h>
@@ -20,17 +20,24 @@ static char sccsid[] = "@(#)memset.c        5.7 (Berkeley) %G%";
 #define        wsize   sizeof(u_int)
 #define        wmask   (wsize - 1)
 
 #define        wsize   sizeof(u_int)
 #define        wmask   (wsize - 1)
 
+#ifdef BZERO
+void
+bzero(dst0, length)
+       void *dst0;
+       register size_t length;
+#else
 void *
 memset(dst0, c0, length)
        void *dst0;
        register int c0;
        register size_t length;
 void *
 memset(dst0, c0, length)
        void *dst0;
        register int c0;
        register size_t length;
+#endif
 {
        register size_t t;
        register u_int c;
 {
        register size_t t;
        register u_int c;
-       register char *dst;
+       register u_char *dst;
 
 
-       dst = (char *)dst0;
+       dst = dst0;
        /*
         * If not enough words, just fill bytes.  A length >= 2 words
         * guarantees that at least one of them is `complete' after
        /*
         * If not enough words, just fill bytes.  A length >= 2 words
         * guarantees that at least one of them is `complete' after
@@ -46,35 +53,52 @@ memset(dst0, c0, length)
         */ 
        if (length < 3 * wsize) {
                while (length != 0) {
         */ 
        if (length < 3 * wsize) {
                while (length != 0) {
+#ifdef BZERO
+                       *dst++ = 0;
+#else
                        *dst++ = c0;
                        *dst++ = c0;
+#endif
                        --length;
                }
                        --length;
                }
+#ifdef BZERO
+               return;
+#else
                return (dst0);
                return (dst0);
+#endif
        }
 
        }
 
-       if ((c = (u_char)c0) != 0) {    /* Copy value into the word. */
+#ifndef BZERO
+       if ((c = (u_char)c0) != 0) {    /* Fill the word. */
                c = (c << 8) | c;       /* u_int is 16 bits. */
                c = (c << 8) | c;       /* u_int is 16 bits. */
-#if UINT_MAX > 65535
+#if UINT_MAX > 0xffff
                c = (c << 16) | c;      /* u_int is 32 bits. */
 #endif
                c = (c << 16) | c;      /* u_int is 32 bits. */
 #endif
-#if UINT_MAX > 0xffffffff              /* GCC will bitch, otherwise. */
+#if UINT_MAX > 0xffffffff
                c = (c << 32) | c;      /* u_int is 64 bits. */
 #endif
        }
                c = (c << 32) | c;      /* u_int is 64 bits. */
 #endif
        }
-
+#endif
        /* Align destination by filling in bytes. */
        if ((t = (int)dst & wmask) != 0) {
                t = wsize - t;
                length -= t;
                do {
        /* Align destination by filling in bytes. */
        if ((t = (int)dst & wmask) != 0) {
                t = wsize - t;
                length -= t;
                do {
+#ifdef BZERO
+                       *dst++ = 0;
+#else
                        *dst++ = c0;
                        *dst++ = c0;
+#endif
                } while (--t != 0);
        }
 
        /* Fill words.  Length was >= 2*words so we know t >= 1 here. */
        t = length / wsize;
        do {
                } while (--t != 0);
        }
 
        /* Fill words.  Length was >= 2*words so we know t >= 1 here. */
        t = length / wsize;
        do {
+#ifdef BZERO
+               *(u_int *)dst = 0;
+#else
                *(u_int *)dst = c;
                *(u_int *)dst = c;
+#endif
                dst += wsize;
        } while (--t != 0);
 
                dst += wsize;
        } while (--t != 0);
 
@@ -82,7 +106,15 @@ memset(dst0, c0, length)
        t = length & wmask;
        if (t != 0)
                do {
        t = length & wmask;
        if (t != 0)
                do {
+#ifdef BZERO
+                       *dst++ = 0;
+#else
                        *dst++ = c0;
                        *dst++ = c0;
+#endif
                } while (--t != 0);
                } while (--t != 0);
+#ifdef BZERO
+       return;
+#else
        return (dst0);
        return (dst0);
+#endif
 }
 }