2015-02-11 19:13:43 +00:00
|
|
|
/* See LICENSE file for copyright and license details. */
|
|
|
|
#include <errno.h>
|
|
|
|
#include <stdio.h>
|
|
|
|
#include <stdlib.h>
|
|
|
|
#include <string.h>
|
|
|
|
|
|
|
|
#include "../utf.h"
|
|
|
|
|
|
|
|
int
|
2015-02-11 20:14:28 +00:00
|
|
|
fgetrune(Rune *r, FILE *fp)
|
2015-02-11 19:13:43 +00:00
|
|
|
{
|
|
|
|
char buf[UTFmax];
|
|
|
|
int i;
|
|
|
|
|
|
|
|
for (i = 0; i < UTFmax && (buf[i] = fgetc(fp)) != EOF && ++i ;)
|
2015-02-11 20:14:28 +00:00
|
|
|
if (charntorune(r, buf, i) > 0)
|
2015-02-11 19:13:43 +00:00
|
|
|
break;
|
|
|
|
if (ferror(fp))
|
|
|
|
return -1;
|
|
|
|
|
|
|
|
return i;
|
|
|
|
}
|
|
|
|
|
|
|
|
int
|
2015-02-11 20:14:28 +00:00
|
|
|
efgetrune(Rune *r, FILE *fp, const char *file)
|
2015-02-11 19:13:43 +00:00
|
|
|
{
|
|
|
|
int ret;
|
|
|
|
|
2015-02-11 20:14:28 +00:00
|
|
|
if ((ret = fgetrune(r, fp)) < 0) {
|
2015-02-11 19:13:43 +00:00
|
|
|
fprintf(stderr, "fgetrune %s: %s\n", file, strerror(errno));
|
|
|
|
exit(1);
|
|
|
|
}
|
|
|
|
return ret;
|
|
|
|
}
|