blob: 8a4f0fbbb0e1d3ac05ac04d142cef276a26ade2a (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
|
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <mkc_fgetln.h>
#include <mkc_err.h>
int main (int argc, char ** argv)
{
char *buf, *lbuf;
size_t len;
while ((lbuf = buf = fgetln (stdin, &len)) != NULL) {
if (len > 0 && buf [len - 1] == '\n')
buf[len - 1] = '\0';
else if ((lbuf = strndup (buf, len + 1)) == NULL)
err (1, NULL);
printf ("%s\n", lbuf);
if (lbuf != buf)
free (lbuf);
}
return 0;
}
|