2015-02-11 14:13:43 -05: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 15:14:28 -05:00
|
|
|
fgetrune(Rune *r, FILE *fp)
|
2015-02-11 14:13:43 -05:00
|
|
|
{
|
|
|
|
char buf[UTFmax];
|
|
|
|
int i;
|
|
|
|
|
|
|
|
for (i = 0; i < UTFmax && (buf[i] = fgetc(fp)) != EOF && ++i ;)
|
2015-02-11 15:14:28 -05:00
|
|
|
if (charntorune(r, buf, i) > 0)
|
2015-02-11 14:13:43 -05:00
|
|
|
break;
|
|
|
|
if (ferror(fp))
|
|
|
|
return -1;
|
|
|
|
|
|
|
|
return i;
|
|
|
|
}
|
|
|
|
|
|
|
|
int
|
2015-02-11 15:14:28 -05:00
|
|
|
efgetrune(Rune *r, FILE *fp, const char *file)
|
2015-02-11 14:13:43 -05:00
|
|
|
{
|
|
|
|
int ret;
|
|
|
|
|
2015-02-11 15:14:28 -05:00
|
|
|
if ((ret = fgetrune(r, fp)) < 0) {
|
2015-02-11 14:13:43 -05:00
|
|
|
fprintf(stderr, "fgetrune %s: %s\n", file, strerror(errno));
|
|
|
|
exit(1);
|
|
|
|
}
|
|
|
|
return ret;
|
|
|
|
}
|