-
Notifications
You must be signed in to change notification settings - Fork 5
/
linein.c
48 lines (40 loc) · 1.17 KB
/
linein.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
/* VM/370 CMS and GCCLIB linein.c */
#include <stdio.h>
#include <errno.h>
#include <cmssys.h>
#include "lstring.h"
/* ---------------- Llinein ------------------- */
void __CDECL
Llinein(FILEP f, const PLstr line, long start, long length) {
int l, i;
char *c;
Context *context = (Context *) CMSGetPG();
/* initialise line */
LZEROSTR(*line);
/* find start line */
if (start >= 0) {
if (!fsetrec(f, start)) {
if (errno == ENOTBLK)
(context->lstring_Lerror)(ERR_NOT_RECORD_ACCESS, 0);
else (context->lstring_Lerror)(ERR_INCORRECT_CALL, 0);
}
}
if (length <= 0) return;
else if (length == 1) Lread(f, line, LREADLINE);
else {
Lfx(line, LREADINCSIZE);
l = 0;
while (length && (i = nextrecLen(f)) > 0) {
if (l + i > LMAXLEN(*line)) {
Lfx(line, (size_t) (l + i + LREADINCSIZE));
}
c = LSTR(*line) + l;
fgets(c, i + 1, f);
l += i;
length--;
}
Lfx(line, l); /* Give back unwanted memory */
LLEN(*line) = l;
LTYPE(*line) = LSTRING_TY;
}
} /* Llinein */