PERFORCE change 39788 for review

Andrew Reisse areisse at FreeBSD.org
Thu Oct 16 14:21:05 GMT 2003


http://perforce.freebsd.org/chv.cgi?CH=39788

Change 39788 by areisse at areisse_ibook on 2003/10/16 07:20:07

	add strlcpy to darwin

Affected files ...

.. //depot/projects/trustedbsd/sedarwin/apsl/xnu/osfmk/device/subrs.c#2 edit
.. //depot/projects/trustedbsd/sedarwin/apsl/xnu/osfmk/libsa/string.h#2 edit

Differences ...

==== //depot/projects/trustedbsd/sedarwin/apsl/xnu/osfmk/device/subrs.c#2 (text+ko) ====

@@ -330,3 +330,34 @@
 	return (old);
 }
 
+/* Copy src to string dst of size siz.  At most siz-1 characters
+ * will be copied.  Always NUL terminates (unless siz == 0).
+ * Returns strlen(src); if retval >= siz, truncation occurred.
+ */
+size_t strlcpy(dst, src, siz)
+	char *dst;
+	const char *src;
+	size_t siz;
+{
+	char *d = dst;
+	const char *s = src;
+	size_t n = siz;
+
+	/* Copy as many bytes as will fit */
+	if (n != 0 && --n != 0) {
+		do {
+			if ((*d++ = *s++) == 0)
+				break;
+		} while (--n != 0);
+	}
+
+	/* Not enough room in dst, add NUL and traverse rest of src */
+	if (n == 0) {
+		if (siz != 0)
+			*d = '\0';		/* NUL-terminate dst */
+		while (*s++)
+			;
+	}
+
+	return(s - src - 1);	/* count does not include NUL */
+}

==== //depot/projects/trustedbsd/sedarwin/apsl/xnu/osfmk/libsa/string.h#2 (text+ko) ====

@@ -84,6 +84,7 @@
 extern int	strncmp(const char *,const char *, size_t);
 extern char	*strchr(const char *s, int c);
 extern size_t	strspn(const char *, const char *);
+extern size_t	strlcpy(char *, const char *, size_t);
 
 #ifdef __cplusplus
 }
To Unsubscribe: send mail to majordomo at trustedbsd.org
with "unsubscribe trustedbsd-cvs" in the body of the message



More information about the trustedbsd-cvs mailing list