blob: 734755bca99de95537d46836a1e9f52144554941 [file] [log] [blame]
Viet-Trung Luu96b05c12016-01-11 11:26:36 -08001#include "shgetc.h"
2
George Kulakowski17e3b042016-02-18 15:59:50 -08003void __shlim(FILE* f, off_t lim) {
4 f->shlim = lim;
5 f->shcnt = f->rend - f->rpos;
6 if (lim && f->shcnt > lim)
7 f->shend = f->rpos + lim;
8 else
9 f->shend = f->rend;
Viet-Trung Luu96b05c12016-01-11 11:26:36 -080010}
11
George Kulakowski17e3b042016-02-18 15:59:50 -080012int __shgetc(FILE* f) {
13 int c;
14 if ((f->shlim && f->shcnt >= f->shlim) || (c = __uflow(f)) < 0) {
15 f->shend = 0;
16 return EOF;
17 }
18 if (f->shlim && f->rend - f->rpos > f->shlim - f->shcnt - 1)
19 f->shend = f->rpos + (f->shlim - f->shcnt - 1);
20 else
21 f->shend = f->rend;
22 if (f->rend)
23 f->shcnt += f->rend - f->rpos + 1;
24 if (f->rpos[-1] != c)
25 f->rpos[-1] = c;
26 return c;
Viet-Trung Luu96b05c12016-01-11 11:26:36 -080027}