@@ -0,0 +1,40 @@
1+#include <unicode/ustdio.h>
2+#include <stdio.h>
3+#include <stdlib.h>
4+#include <string.h>
5+
6+void text(const char *name)
7+{
8+ UFILE *ufp = u_fopen(name, "r", NULL, "UTF-8");
9+ FILE *fp = u_fgetfile(ufp);
10+ UChar *str;
11+ long fsize;
12+ int32_t n;
13+
14+ fseek(fp, 0, SEEK_END);
15+ fsize = ftell(fp);
16+ u_frewind(ufp);
17+
18+ str = malloc(sizeof(*str) * fsize);
19+
20+ n = u_file_read(str, fsize, ufp);
21+
22+ printf("%d\n", n);
23+}
24+
25+int main(int argc, char **argv)
26+{
27+ if (argc != 3) {
28+ fprintf(stderr, "Usage: fileread handler filename\n");
29+ exit(1);
30+ }
31+
32+ if (strcmp(argv[1], "text") == 0)
33+ text(argv[2]);
34+ else {
35+ fprintf(stderr, "no matching handler\n");
36+ return 1;
37+ }
38+
39+ return 0;
40+}