1 /* $OpenBSD: lib_slk_wset.c,v 1.1 2010/09/06 17:26:17 nicm Exp $ */ 2 3 /**************************************************************************** 4 * Copyright (c) 2003-2004,2005 Free Software Foundation, Inc. * 5 * * 6 * Permission is hereby granted, free of charge, to any person obtaining a * 7 * copy of this software and associated documentation files (the * 8 * "Software"), to deal in the Software without restriction, including * 9 * without limitation the rights to use, copy, modify, merge, publish, * 10 * distribute, distribute with modifications, sublicense, and/or sell * 11 * copies of the Software, and to permit persons to whom the Software is * 12 * furnished to do so, subject to the following conditions: * 13 * * 14 * The above copyright notice and this permission notice shall be included * 15 * in all copies or substantial portions of the Software. * 16 * * 17 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS * 18 * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF * 19 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. * 20 * IN NO EVENT SHALL THE ABOVE COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, * 21 * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR * 22 * OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR * 23 * THE USE OR OTHER DEALINGS IN THE SOFTWARE. * 24 * * 25 * Except as contained in this notice, the name(s) of the above copyright * 26 * holders shall not be used in advertising or otherwise to promote the * 27 * sale, use or other dealings in this Software without prior written * 28 * authorization. * 29 ****************************************************************************/ 30 31 /**************************************************************************** 32 * Author: Thomas E. Dickey * 33 ****************************************************************************/ 34 35 /* 36 * lib_slk_wset.c 37 * Set soft label text. 38 */ 39 #include <curses.priv.h> 40 41 #if HAVE_WCTYPE_H 42 #include <wctype.h> 43 #endif 44 45 MODULE_ID("$Id: lib_slk_wset.c,v 1.1 2010/09/06 17:26:17 nicm Exp $") 46 47 NCURSES_EXPORT(int) 48 slk_wset(int i, const wchar_t *astr, int format) 49 { 50 int result = ERR; 51 size_t arglen; 52 const wchar_t *str; 53 char *mystr; 54 mbstate_t state; 55 56 T((T_CALLED("slk_wset(%d, %s, %d)"), i, _nc_viswbuf(astr), format)); 57 58 init_mb(state); 59 str = astr; 60 if ((arglen = wcsrtombs(NULL, &str, 0, &state)) != (size_t) -1) { 61 if ((mystr = (char *) _nc_doalloc(0, arglen + 1)) != 0) { 62 str = astr; 63 if (wcsrtombs(mystr, &str, arglen, &state) != (size_t) -1) { 64 /* glibc documentation claims that the terminating L'\0' 65 * is written, but it is not... 66 */ 67 mystr[arglen] = 0; 68 result = slk_set(i, mystr, format); 69 } 70 free(mystr); 71 } 72 } 73 returnCode(result); 74 } 75