summaryrefslogtreecommitdiff
path: root/sysutils/user/patches/patch-aa
blob: 1fd09c9871750a8f79db490183d7cfe354aeb21e (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
$NetBSD: patch-aa,v 1.1.1.1 1999/12/16 16:28:31 agc Exp $

Bring in strlcpy(3) from -current for those versions of NetBSD which
don't have it.

--- user.c	Thu Dec 16 15:46:16 1999
+++ user.c	Thu Dec 16 16:17:17 1999
@@ -92,6 +92,47 @@
 	return ret;
 }
 
+#if __NetBSD_Version__ < 104110000
+#undef _DIAGASSERT
+#define _DIAGASSERT(x)
+/*
+ * 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;
+{
+	register char *d = dst;
+	register const char *s = src;
+	register size_t n = siz;
+
+	_DIAGASSERT(dst != NULL);
+	_DIAGASSERT(src != NULL);
+
+	/* 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 */
+}
+#endif
+
 /* copy any dot files into the user's home directory */
 static int
 copydotfiles(char *skeldir, int uid, int gid, char *dir)