bcopy => memcpy (safe in all these cases) for ANSI (sigh)
authorChris Torek <torek@ucbvax.Berkeley.EDU>
Fri, 5 Mar 1993 07:36:39 +0000 (23:36 -0800)
committerChris Torek <torek@ucbvax.Berkeley.EDU>
Fri, 5 Mar 1993 07:36:39 +0000 (23:36 -0800)
SCCS-vsn: lib/libc/stdio/fread.c 5.6
SCCS-vsn: lib/libc/stdio/fvwrite.c 5.4
SCCS-vsn: lib/libc/stdio/fgets.c 5.5
SCCS-vsn: lib/libc/stdio/tmpfile.c 5.5
SCCS-vsn: lib/libc/stdio/fgetln.c 5.4
SCCS-vsn: lib/libc/stdio/ungetc.c 5.7

usr/src/lib/libc/stdio/fgetln.c
usr/src/lib/libc/stdio/fgets.c
usr/src/lib/libc/stdio/fread.c
usr/src/lib/libc/stdio/fvwrite.c
usr/src/lib/libc/stdio/tmpfile.c
usr/src/lib/libc/stdio/ungetc.c

index 6e813be..2feafb2 100644 (file)
@@ -9,7 +9,7 @@
  */
 
 #if defined(LIBC_SCCS) && !defined(lint)
  */
 
 #if defined(LIBC_SCCS) && !defined(lint)
-static char sccsid[] = "@(#)fgetln.c   5.3 (Berkeley) %G%";
+static char sccsid[] = "@(#)fgetln.c   5.4 (Berkeley) %G%";
 #endif /* LIBC_SCCS and not lint */
 
 #include <stdio.h>
 #endif /* LIBC_SCCS and not lint */
 
 #include <stdio.h>
@@ -102,7 +102,7 @@ fgetline(fp, lenp)
                 */
                if (__slbexpand(fp, len + OPTIMISTIC))
                        goto error;
                 */
                if (__slbexpand(fp, len + OPTIMISTIC))
                        goto error;
-               (void)bcopy((void *)fp->_p, (void *)(fp->_lb._base + off),
+               (void)memcpy((void *)(fp->_lb._base + off), (void *)fp->_p,
                    len - off);
                off = len;
                if (__srefill(fp))
                    len - off);
                off = len;
                if (__srefill(fp))
@@ -116,7 +116,7 @@ fgetline(fp, lenp)
                len += diff;
                if (__slbexpand(fp, len))
                        goto error;
                len += diff;
                if (__slbexpand(fp, len))
                        goto error;
-               (void)bcopy((void *)fp->_p, (void *)(fp->_lb._base + off),
+               (void)memcpy((void *)(fp->_lb._base + off), (void *)fp->_p,
                    diff);
                fp->_r -= diff;
                fp->_p = p;
                    diff);
                fp->_r -= diff;
                fp->_p = p;
index fa7ebd3..179ef95 100644 (file)
@@ -9,7 +9,7 @@
  */
 
 #if defined(LIBC_SCCS) && !defined(lint)
  */
 
 #if defined(LIBC_SCCS) && !defined(lint)
-static char sccsid[] = "@(#)fgets.c    5.4 (Berkeley) %G%";
+static char sccsid[] = "@(#)fgets.c    5.5 (Berkeley) %G%";
 #endif /* LIBC_SCCS and not lint */
 
 #include <stdio.h>
 #endif /* LIBC_SCCS and not lint */
 
 #include <stdio.h>
@@ -63,13 +63,13 @@ fgets(buf, n, fp)
                        len = ++t - p;
                        fp->_r -= len;
                        fp->_p = t;
                        len = ++t - p;
                        fp->_r -= len;
                        fp->_p = t;
-                       (void) bcopy((void *)p, (void *)s, len);
+                       (void)memcpy((void *)s, (void *)p, len);
                        s[len] = 0;
                        return (buf);
                }
                fp->_r -= len;
                fp->_p += len;
                        s[len] = 0;
                        return (buf);
                }
                fp->_r -= len;
                fp->_p += len;
-               (void) bcopy((void *)p, (void *)s, len);
+               (void)memcpy((void *)s, (void *)p, len);
                s += len;
        } while ((n -= len) != 0);
        *s = 0;
                s += len;
        } while ((n -= len) != 0);
        *s = 0;
index b52c4ec..0a6c053 100644 (file)
@@ -9,7 +9,7 @@
  */
 
 #if defined(LIBC_SCCS) && !defined(lint)
  */
 
 #if defined(LIBC_SCCS) && !defined(lint)
-static char sccsid[] = "@(#)fread.c    5.5 (Berkeley) %G%";
+static char sccsid[] = "@(#)fread.c    5.6 (Berkeley) %G%";
 #endif /* LIBC_SCCS and not lint */
 
 #include <stdio.h>
 #endif /* LIBC_SCCS and not lint */
 
 #include <stdio.h>
@@ -33,7 +33,7 @@ fread(buf, size, count, fp)
        total = resid;
        p = buf;
        while (resid > (r = fp->_r)) {
        total = resid;
        p = buf;
        while (resid > (r = fp->_r)) {
-               (void) bcopy((void *)fp->_p, (void *)p, (size_t)r);
+               (void)memcpy((void *)p, (void *)fp->_p, (size_t)r);
                fp->_p += r;
                /* fp->_r = 0 ... done in __srefill */
                p += r;
                fp->_p += r;
                /* fp->_r = 0 ... done in __srefill */
                p += r;
@@ -43,7 +43,7 @@ fread(buf, size, count, fp)
                        return ((total - resid) / size);
                }
        }
                        return ((total - resid) / size);
                }
        }
-       (void) bcopy((void *)fp->_p, (void *)p, resid);
+       (void)memcpy((void *)p, (void *)fp->_p, resid);
        fp->_r -= resid;
        fp->_p += resid;
        return (count);
        fp->_r -= resid;
        fp->_p += resid;
        return (count);
index 1b352cc..fe105ad 100644 (file)
@@ -9,7 +9,7 @@
  */
 
 #if defined(LIBC_SCCS) && !defined(lint)
  */
 
 #if defined(LIBC_SCCS) && !defined(lint)
-static char sccsid[] = "@(#)fvwrite.c  5.3 (Berkeley) %G%";
+static char sccsid[] = "@(#)fvwrite.c  5.4 (Berkeley) %G%";
 #endif /* LIBC_SCCS and not lint */
 
 #include <stdio.h>
 #endif /* LIBC_SCCS and not lint */
 
 #include <stdio.h>
@@ -41,7 +41,7 @@ __sfvwrite(fp, uio)
                return (EOF);
 
 #define        MIN(a, b) ((a) < (b) ? (a) : (b))
                return (EOF);
 
 #define        MIN(a, b) ((a) < (b) ? (a) : (b))
-#define        COPY(n)   (void) bcopy((void *)p, (void *)fp->_p, (size_t)(n));
+#define        COPY(n)   (void)memcpy((void *)fp->_p, (void *)p, (size_t)(n))
 
        iov = uio->uio_iov;
        p = iov->iov_base;
 
        iov = uio->uio_iov;
        p = iov->iov_base;
index 1ad75af..bff0679 100644 (file)
@@ -9,7 +9,7 @@
  */
 
 #if defined(LIBC_SCCS) && !defined(lint)
  */
 
 #if defined(LIBC_SCCS) && !defined(lint)
-static char sccsid[] = "@(#)tmpfile.c  5.4 (Berkeley) %G%";
+static char sccsid[] = "@(#)tmpfile.c  5.5 (Berkeley) %G%";
 #endif /* LIBC_SCCS and not lint */
 
 #include <sys/types.h>
 #endif /* LIBC_SCCS and not lint */
 
 #include <sys/types.h>
@@ -28,8 +28,8 @@ tmpfile()
 #define        TRAILER "tmp.XXXXXX"
        char buf[sizeof(_PATH_TMP) + sizeof(TRAILER)];
 
 #define        TRAILER "tmp.XXXXXX"
        char buf[sizeof(_PATH_TMP) + sizeof(TRAILER)];
 
-       bcopy(_PATH_TMP, buf, sizeof(_PATH_TMP) - 1);
-       bcopy(TRAILER, buf + sizeof(_PATH_TMP) - 1, sizeof(TRAILER));
+       (void)memcpy(buf, _PATH_TMP, sizeof(_PATH_TMP) - 1);
+       (void)memcpy(buf + sizeof(_PATH_TMP) - 1, TRAILER, sizeof(TRAILER));
 
        sigfillset(&set);
        (void)sigprocmask(SIG_BLOCK, &set, &oset);
 
        sigfillset(&set);
        (void)sigprocmask(SIG_BLOCK, &set, &oset);
@@ -43,7 +43,7 @@ tmpfile()
        if (fd == -1)
                return (NULL);
 
        if (fd == -1)
                return (NULL);
 
-       if (!(fp = fdopen(fd, "w+"))) {
+       if ((fp = fdopen(fd, "w+")) == NULL) {
                sverrno = errno;
                (void)close(fd);
                errno = sverrno;
                sverrno = errno;
                (void)close(fd);
                errno = sverrno;
index 5b2ef34..f7e97c5 100644 (file)
@@ -9,7 +9,7 @@
  */
 
 #if defined(LIBC_SCCS) && !defined(lint)
  */
 
 #if defined(LIBC_SCCS) && !defined(lint)
-static char sccsid[] = "@(#)ungetc.c   5.6 (Berkeley) %G%";
+static char sccsid[] = "@(#)ungetc.c   5.7 (Berkeley) %G%";
 #endif /* LIBC_SCCS and not lint */
 
 #include <stdio.h>
 #endif /* LIBC_SCCS and not lint */
 
 #include <stdio.h>
@@ -48,7 +48,8 @@ __submore(fp)
        p = realloc(fp->_ub._base, i << 1);
        if (p == NULL)
                return (EOF);
        p = realloc(fp->_ub._base, i << 1);
        if (p == NULL)
                return (EOF);
-       (void) bcopy((void *)p, (void *)(p + i), (size_t)i);
+       /* no overlap (hence can use memcpy) because we doubled the size */
+       (void)memcpy((void *)(p + i), (void *)p, (size_t)i);
        fp->_p = p + i;
        fp->_ub._base = p;
        fp->_ub._size = i << 1;
        fp->_p = p + i;
        fp->_ub._base = p;
        fp->_ub._size = i << 1;