ANSI version
authorKeith Bostic <bostic@ucbvax.Berkeley.EDU>
Fri, 18 May 1990 01:38:06 +0000 (17:38 -0800)
committerKeith Bostic <bostic@ucbvax.Berkeley.EDU>
Fri, 18 May 1990 01:38:06 +0000 (17:38 -0800)
SCCS-vsn: lib/libc/string/strlen.c 5.4
SCCS-vsn: lib/libc/string/strncmp.c 5.4

usr/src/lib/libc/string/strlen.c
usr/src/lib/libc/string/strncmp.c

index 183fc7d..dd29032 100644 (file)
@@ -1,29 +1,24 @@
-/*
- * Copyright (c) 1988 Regents of the University of California.
+/*-
+ * Copyright (c) 1990 The Regents of the University of California.
  * All rights reserved.
  *
  * All rights reserved.
  *
- * Redistribution and use in source and binary forms are permitted
- * provided that the above copyright notice and this paragraph are
- * duplicated in all such forms and that any documentation,
- * advertising materials, and other materials related to such
- * distribution and use acknowledge that the software was developed
- * by the University of California, Berkeley.  The name of the
- * University may not be used to endorse or promote products derived
- * from this software without specific prior written permission.
- * THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR
- * IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED
- * WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR A PARTICULAR PURPOSE.
+ * %sccs.include.redist.c%
  */
 
 #if defined(LIBC_SCCS) && !defined(lint)
  */
 
 #if defined(LIBC_SCCS) && !defined(lint)
-static char sccsid[] = "@(#)strlen.c   5.3 (Berkeley) %G%";
+static char sccsid[] = "@(#)strlen.c   5.4 (Berkeley) %G%";
 #endif /* LIBC_SCCS and not lint */
 
 #endif /* LIBC_SCCS and not lint */
 
+#include <sys/stdc.h>
+#include <string.h>
+
+size_t
 strlen(str)
 strlen(str)
-       register char *str;
+       const char *str;
 {
 {
-       register int cnt;
+       register const char *s;
 
 
-       for (cnt = 0; *str; ++cnt, ++str);
-       return(cnt);
+       for (s = str; *s; ++s);
+       return(s - str);
 }
 }
+
index d172cfe..218680d 100644 (file)
@@ -1,5 +1,5 @@
 /*
 /*
- * Copyright (c) 1988 Regents of the University of California.
+ * Copyright (c) 1989 The Regents of the University of California.
  * All rights reserved.
  *
  * Redistribution and use in source and binary forms are permitted
  * All rights reserved.
  *
  * Redistribution and use in source and binary forms are permitted
  * from this software without specific prior written permission.
  * THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR
  * IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED
  * from this software without specific prior written permission.
  * THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR
  * IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED
- * WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR A PARTICULAR PURPOSE.
+ * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
  */
 
 #if defined(LIBC_SCCS) && !defined(lint)
  */
 
 #if defined(LIBC_SCCS) && !defined(lint)
-static char sccsid[] = "@(#)strncmp.c  5.3 (Berkeley) %G%";
+static char sccsid[] = "@(#)strncmp.c  5.4 (Berkeley) %G%";
 #endif /* LIBC_SCCS and not lint */
 
 #endif /* LIBC_SCCS and not lint */
 
-strncmp(s1, s2, cnt)
-       register char *s1, *s2;
-       register int cnt;
+#include <sys/stdc.h>
+#include <string.h>
+
+int
+strncmp(s1, s2, n)
+       register const char *s1, *s2;
+       register size_t n;
 {
 {
-       for (; cnt && *s1 == *s2; --cnt, ++s1, ++s2)
-               if (!*s1)
-                       return(0);
-       return(cnt ? *s1 - *s2 : 0);
+
+       if (n == 0)
+               return (0);
+       do {
+               if (*s1 != *s2++)
+                       return (*(unsigned char *)s1 - *(unsigned char *)--s2);
+               if (*s1++ == 0)
+                       break;
+       } while (--n != 0);
+       return (0);
 }
 }