summaryrefslogtreecommitdiff
path: root/examples/hello_compatlib/prog2/prog2.c
diff options
context:
space:
mode:
Diffstat (limited to 'examples/hello_compatlib/prog2/prog2.c')
-rw-r--r--examples/hello_compatlib/prog2/prog2.c24
1 files changed, 24 insertions, 0 deletions
diff --git a/examples/hello_compatlib/prog2/prog2.c b/examples/hello_compatlib/prog2/prog2.c
new file mode 100644
index 0000000..8a4f0fb
--- /dev/null
+++ b/examples/hello_compatlib/prog2/prog2.c
@@ -0,0 +1,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;
+}