File: btowc.c

package info (click to toggle)
picolibc 1.8.11-2
  • links: PTS, VCS
  • area: main
  • in suites: sid
  • size: 50,064 kB
  • sloc: ansic: 404,031; asm: 24,984; sh: 2,585; python: 2,289; perl: 680; pascal: 329; exp: 287; makefile: 222; cpp: 71; xml: 40
file content (30 lines) | stat: -rw-r--r-- 565 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
/* Copyright (c) 2002 Thomas Fitzsimmons <fitzsim@redhat.com> */
#include <wchar.h>
#include <stdlib.h>
#include <stdio.h>
#include <string.h>
#include "local.h"

wint_t
btowc(int c)
{
    mbstate_t     mbs;
    int           retval = 0;
    wchar_t       pwc;
    unsigned char b;

    if (c == EOF)
        return WEOF;

    b = (unsigned char)c;

    /* Put mbs in initial state. */
    memset(&mbs, '\0', sizeof(mbs));

    retval = __MBTOWC(&pwc, (const char *)&b, 1, &mbs);

    if (retval != 0 && retval != 1)
        return WEOF;

    return (wint_t)pwc;
}