lib_slk_wset.c revision 262685
156657Smckusick/**************************************************************************** 21541Srgrimes * Copyright (c) 2003-2002,2011 Free Software Foundation, Inc. * 31541Srgrimes * * 491369Salfred * Permission is hereby granted, free of charge, to any person obtaining a * 51541Srgrimes * copy of this software and associated documentation files (the * 644344Smckusick * "Software"), to deal in the Software without restriction, including * 744344Smckusick * without limitation the rights to use, copy, modify, merge, publish, * 81541Srgrimes * distribute, distribute with modifications, sublicense, and/or sell * 944344Smckusick * copies of the Software, and to permit persons to whom the Software is * 1044344Smckusick * furnished to do so, subject to the following conditions: * 1144344Smckusick * * 1244344Smckusick * The above copyright notice and this permission notice shall be included * 1387373Smckusick * in all copies or substantial portions of the Software. * 1444344Smckusick * * 1544344Smckusick * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS * 1644344Smckusick * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF * 1744344Smckusick * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. * 1844344Smckusick * IN NO EVENT SHALL THE ABOVE COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, * 1944344Smckusick * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR * 2044344Smckusick * OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR * 2144344Smckusick * THE USE OR OTHER DEALINGS IN THE SOFTWARE. * 2244344Smckusick * * 2344344Smckusick * Except as contained in this notice, the name(s) of the above copyright * 2444344Smckusick * holders shall not be used in advertising or otherwise to promote the * 2544344Smckusick * sale, use or other dealings in this Software without prior written * 26169532Smckusick * authorization. * 2777031Sru ****************************************************************************/ 28169532Smckusick 2977031Sru/**************************************************************************** 3077031Sru * Author: Thomas E. Dickey * 31169532Smckusick ****************************************************************************/ 3277162Sru 33169532Smckusick/* 3477031Sru * lib_slk_wset.c 35169532Smckusick * Set soft label text. 3677031Sru */ 3777031Sru#include <curses.priv.h> 38169532Smckusick 39169532Smckusick#if HAVE_WCTYPE_H 4077031Sru#include <wctype.h> 4144344Smckusick#endif 4244344Smckusick 4344344SmckusickMODULE_ID("$Id: lib_slk_wset.c,v 1.13 2011/10/22 15:52:20 tom Exp $") 4444344Smckusick 4544344SmckusickNCURSES_EXPORT(int) 46171245Sbzslk_wset(int i, const wchar_t *astr, int format) 47171245Sbz{ 4844344Smckusick int result = ERR; 4944344Smckusick size_t arglen; 5044344Smckusick const wchar_t *str; 51169532Smckusick char *mystr; 52169532Smckusick mbstate_t state; 5344344Smckusick 5444344Smckusick T((T_CALLED("slk_wset(%d, %s, %d)"), i, _nc_viswbuf(astr), format)); 5544344Smckusick 5644344Smckusick if (astr != 0) { 5744344Smckusick init_mb(state); 5844344Smckusick str = astr; 5944344Smckusick if ((arglen = wcsrtombs(NULL, &str, (size_t) 0, &state)) != (size_t) -1) { 6044344Smckusick if ((mystr = (char *) _nc_doalloc(0, arglen + 1)) != 0) { 6144344Smckusick str = astr; 6244344Smckusick if (wcsrtombs(mystr, &str, arglen, &state) != (size_t) -1) { 6344344Smckusick /* glibc documentation claims that the terminating L'\0' 6444344Smckusick * is written, but it is not... 65171245Sbz */ 66171245Sbz mystr[arglen] = 0; 6744344Smckusick result = slk_set(i, mystr, format); 6844344Smckusick } 6944344Smckusick free(mystr); 7044344Smckusick } 7144344Smckusick } 7244344Smckusick } 7344344Smckusick returnCode(result); 7462491Smckusick} 7544344Smckusick