summaryrefslogtreecommitdiff
path: root/lib/libc/string
diff options
context:
space:
mode:
authorNicholas Marriott <nicm@cvs.openbsd.org>2011-07-08 17:46:46 +0000
committerNicholas Marriott <nicm@cvs.openbsd.org>2011-07-08 17:46:46 +0000
commitf4b9987edf15f1c1380b00c0baae4f82831a4a30 (patch)
tree6f213d30f56675851114368c5b75fbc6f83e3ae4 /lib/libc/string
parentf2a091a96dec89129a57a0a235b86035d93484c5 (diff)
After a certain amount of fighting with the mbstowcs API, remove L from
the wcsdup example. ok stsp
Diffstat (limited to 'lib/libc/string')
-rw-r--r--lib/libc/string/wcsdup.316
1 files changed, 12 insertions, 4 deletions
diff --git a/lib/libc/string/wcsdup.3 b/lib/libc/string/wcsdup.3
index 4d29ac218fa..6588f14988d 100644
--- a/lib/libc/string/wcsdup.3
+++ b/lib/libc/string/wcsdup.3
@@ -1,4 +1,4 @@
-.\" $OpenBSD: wcsdup.3,v 1.2 2011/07/05 19:01:31 nicm Exp $
+.\" $OpenBSD: wcsdup.3,v 1.3 2011/07/08 17:46:45 nicm Exp $
.\" $NetBSD: wcsdup.3,v 1.3 2010/12/16 17:42:28 wiz Exp $
.\"
.\" Copyright (c) 1990, 1991, 1993
@@ -30,7 +30,7 @@
.\"
.\" from: @(#)strdup.3 8.1 (Berkeley) 6/9/93
.\"
-.Dd $Mdocdate: July 5 2011 $
+.Dd $Mdocdate: July 8 2011 $
.Dt WCSDUP 3
.Os
.Sh NAME
@@ -61,9 +61,17 @@ The following will point
to an allocated area of memory containing the nul-terminated string
.Qq foobar :
.Bd -literal -offset indent
-wchar_t *p;
+const char *o = "foobar";
+wchar_t *p, b[32];
+size_t blen;
-if ((p = wcsdup(L"foobar")) == NULL) {
+blen = sizeof(b) / sizeof(b[0]);
+if (mbstowcs(b, o, blen) == (size_t)-1) {
+ fprintf(stderr, "Failed to convert string.\en");
+ exit(1);
+}
+b[blen - 1] = 0;
+if ((p = wcsdup(b)) == NULL) {
fprintf(stderr, "Out of memory.\en");
exit(1);
}