~ubuntu-branches/ubuntu/trusty/emscripten/trusty-proposed

« back to all changes in this revision

Viewing changes to system/lib/libc/musl/src/stdio/fputwc.c

  • Committer: Package Import Robot
  • Author(s): Sylvestre Ledru
  • Date: 2014-01-19 14:12:40 UTC
  • mfrom: (1.2.4)
  • Revision ID: package-import@ubuntu.com-20140119141240-jg1l42cc158j59tn
Tags: 1.9.0~20140119~7dc8c2f-1
* New snapshot release (Closes: #733714)
* Provide sources for javascript and flash. Done in orig-tar.sh
  Available in third_party/websockify/include/web-socket-js/src/
  (Closes: #735903)

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
#include "stdio_impl.h"
 
2
#include <wchar.h>
 
3
#include <limits.h>
 
4
#include <ctype.h>
 
5
 
 
6
wint_t __fputwc_unlocked(wchar_t c, FILE *f)
 
7
{
 
8
        char mbc[MB_LEN_MAX];
 
9
        int l;
 
10
 
 
11
#if 0 // XXX EMSCRIPTEN
 
12
        f->mode |= f->mode+1;
 
13
 
 
14
        if (isascii(c)) {
 
15
                c = putc_unlocked(c, f);
 
16
        } else if (f->wpos + MB_LEN_MAX < f->wend) {
 
17
                l = wctomb((void *)f->wpos, c);
 
18
                if (l < 0) c = WEOF;
 
19
                else f->wpos += l;
 
20
        } else {
 
21
                l = wctomb(mbc, c);
 
22
                if (l < 0 || __fwritex((void *)mbc, l, f) < l) c = WEOF;
 
23
        }
 
24
        return c;
 
25
#else
 
26
  if (isascii(c)) {
 
27
    c = fputc(c, f);
 
28
  } else {
 
29
    l = wctomb(mbc, c);
 
30
    if (l < 0) c = WEOF;
 
31
    else {
 
32
      for (int i = 0; i < l; i++) {
 
33
        if (fputc(mbc[i], f) == EOF) {
 
34
          c = WEOF;
 
35
          break;
 
36
        }
 
37
      }
 
38
    }
 
39
  }
 
40
#endif
 
41
        return c;
 
42
}
 
43
 
 
44
wint_t fputwc(wchar_t c, FILE *f)
 
45
{
 
46
        FLOCK(f);
 
47
        c = __fputwc_unlocked(c, f);
 
48
        FUNLOCK(f);
 
49
        return c;
 
50
}
 
51
 
 
52
weak_alias(__fputwc_unlocked, fputwc_unlocked);
 
53
weak_alias(__fputwc_unlocked, putwc_unlocked);