|
| 1 | +/**************************************************************************** |
| 2 | + * libs/libc/stdio/lib_fputws.c |
| 3 | + * |
| 4 | + * Copyright © 2005-2014 Rich Felker, et al. |
| 5 | + * |
| 6 | + * Permission is hereby granted, free of charge, to any person obtaining |
| 7 | + * a 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, sublicense, and/or sell copies of the Software, and to |
| 11 | + * permit persons to whom the Software is furnished to do so, subject to |
| 12 | + * the following conditions: |
| 13 | + * |
| 14 | + * The above copyright notice and this permission notice shall be |
| 15 | + * included in all copies or substantial portions of the Software. |
| 16 | + * |
| 17 | + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, |
| 18 | + * EXPRESS 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 AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY |
| 21 | + * CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, |
| 22 | + * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE |
| 23 | + * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. |
| 24 | + * |
| 25 | + ****************************************************************************/ |
| 26 | + |
| 27 | +/**************************************************************************** |
| 28 | + * Included Files |
| 29 | + ****************************************************************************/ |
| 30 | + |
| 31 | +#include <stdio.h> |
| 32 | +#include <wchar.h> |
| 33 | + |
| 34 | +#include "libc.h" |
| 35 | + |
| 36 | +#ifdef CONFIG_FILE_STREAM |
| 37 | + |
| 38 | +/**************************************************************************** |
| 39 | + * Public Functions |
| 40 | + ****************************************************************************/ |
| 41 | + |
| 42 | +/**************************************************************************** |
| 43 | + * Name: fputws_unlocked |
| 44 | + * |
| 45 | + * Description: |
| 46 | + * Write wide string to stream without lock the stream |
| 47 | + * |
| 48 | + * Input Parameters: |
| 49 | + * ws - the wide string to write to the stream |
| 50 | + * f - the FILE object that identifies an output stream |
| 51 | + * |
| 52 | + * Returned Value: |
| 53 | + * Return the wide character that written in to the stream on success, |
| 54 | + * return WEOF on fail write to the stream |
| 55 | + * |
| 56 | + ****************************************************************************/ |
| 57 | + |
| 58 | +int fputws_unlocked(FAR const wchar_t *ws, FAR FILE *f) |
| 59 | +{ |
| 60 | + char buf[BUFSIZ]; |
| 61 | + size_t l = 0; |
| 62 | + |
| 63 | + while (ws && |
| 64 | + (l = wcsrtombs(buf, &ws, sizeof(buf), NULL)) + 1 > 1) |
| 65 | + { |
| 66 | + if (lib_fwrite_unlocked(buf, l, f) < l) |
| 67 | + { |
| 68 | + funlockfile(f); |
| 69 | + return -1; |
| 70 | + } |
| 71 | + } |
| 72 | + |
| 73 | + return l; |
| 74 | +} |
| 75 | + |
| 76 | +/**************************************************************************** |
| 77 | + * Name: fputws |
| 78 | + * |
| 79 | + * Description: |
| 80 | + * Write wide string to stream |
| 81 | + * |
| 82 | + * Input Parameters: |
| 83 | + * ws - the wide string to write to the stream |
| 84 | + * f - the FILE object that identifies an output stream |
| 85 | + * |
| 86 | + * Returned Value: |
| 87 | + * Return the wide character that written in to the stream on success, |
| 88 | + * return WEOF on fail write to the stream |
| 89 | + * |
| 90 | + ****************************************************************************/ |
| 91 | + |
| 92 | +int fputws(FAR const wchar_t *ws, FAR FILE *f) |
| 93 | +{ |
| 94 | + int l; |
| 95 | + flockfile(f); |
| 96 | + l = fputws_unlocked(ws, f); |
| 97 | + funlockfile(f); |
| 98 | + return l; |
| 99 | +} |
| 100 | + |
| 101 | +#endif /* CONFIG_FILE_STREAM */ |
0 commit comments