#include <error.h>
#include <stdio.h>
#include <locale.h>
#include <wchar.h>
int main(void)
{
    if (setlocale(LC_ALL, "en_US.UTF-8") == NULL)
	return 3;
    FILE *f = fopen("mytest", "w");
    if (f == NULL || fwrite("A303204343201202" "A343!", 1, 10, f) != 10)
	error(1, 0, "failure %d", 1);
    fclose(f);
    f = freopen("mytest", "r", stdin);
    if (f == NULL)
	error(2, 0, "failure %d", 2);
    if (getwchar() != L'A')
	error(4, 0, "failure %d", 4);
    if (getwchar() != 0xc4)
	error(5, 0, "failure %d", 5);
    if (getwchar() != 0x3042)
	error(6, 0, "failure %d", 6);
    f = freopen("mytest", "r", stdin);
    if (f == NULL)
	error(7, 0, "failure %d", 7);
    if (getwchar() != L'A')
	error(8, 0, "failure %d", 8);
    return 0;
}
