repo.or.cz
/
minix.git
/
blob
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
log
|
graphiclog1
|
graphiclog2
|
commit
|
commitdiff
|
tree
|
refs
|
edit
|
fork
blame
|
history
|
raw
|
HEAD
packages: don't put oss on cd.
[minix.git]
/
commands
/
pax
/
fgetln.c
blob
f39aa9235806f92d0111fcd4ffffa3c69a33dedd
1
2
#include <stdio.h>
3
#include <stdlib.h>
4
#include <string.h>
5
6
char
*
7
fgetln
(
FILE
*
fp
,
size_t
*
lenp
)
8
{
9
#define EXTRA 80
10
char
*
buf
=
NULL
;
11
int
used
=
0
,
len
=
0
,
remain
=
0
,
final
=
0
;
12
while
(!
final
) {
13
char
*
b
;
14
int
r
;
15
if
(
remain
<
EXTRA
) {
16
int
newlen
;
17
char
*
newbuf
;
18
newlen
=
len
+
EXTRA
;
19
if
(!(
newbuf
=
realloc
(
buf
,
newlen
))) {
20
if
(
buf
)
free
(
buf
);
21
return
NULL
;
22
}
23
buf
=
newbuf
;
24
len
=
newlen
;
25
remain
+=
EXTRA
;
26
}
27
buf
[
used
] =
'\0'
;
28
if
(!
fgets
(
buf
+
used
,
remain
,
fp
))
29
break
;
30
r
=
strlen
(
buf
+
used
);
31
used
+=
r
;
32
remain
-=
r
;
33
len
+=
r
;
34
}
35
*
lenp
=
len
;
36
return
buf
;
37
}
38