ignore trailing carriage returns in file parser
authorJo-Philipp Wich <jow@openwrt.org>
Tue, 5 Mar 2013 14:48:04 +0000 (15:48 +0100)
committerJo-Philipp Wich <jow@openwrt.org>
Tue, 5 Mar 2013 15:33:03 +0000 (16:33 +0100)
file.c

diff --git a/file.c b/file.c
index c2b0e721da417cbbf000252cca3c0d2d83e4e992..c69a297323132428c0ab16faf48a75a01d9a4981 100644 (file)
--- a/file.c
+++ b/file.c
@@ -60,7 +60,10 @@ __private void uci_getln(struct uci_context *ctx, int offset)
                ofs += strlen(p);
                if (pctx->buf[ofs - 1] == '\n') {
                        pctx->line++;
-                       pctx->buf[ofs - 1] = 0;
+                       if (ofs >= 2 && pctx->buf[ofs - 2] == '\r')
+                               pctx->buf[ofs - 2] = 0;
+                       else
+                               pctx->buf[ofs - 1] = 0;
                        return;
                }