From 73506d1ba11490a495e9b4f7a7bd2d74ccf41c40 Mon Sep 17 00:00:00 2001 From: nicm <> Date: Fri, 8 Jul 2011 17:46:45 +0000 Subject: [PATCH] After a certain amount of fighting with the mbstowcs API, remove L from the wcsdup example. ok stsp --- src/lib/libc/string/wcsdup.3 | 16 ++++++++++++---- 1 file changed, 12 insertions(+), 4 deletions(-) diff --git a/src/lib/libc/string/wcsdup.3 b/src/lib/libc/string/wcsdup.3 index 4d29ac21..6588f149 100644 --- a/src/lib/libc/string/wcsdup.3 +++ b/src/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); }