From: Bart Van Assche <bvanassche@acm.org>
To: christophe.varoqui@opensvc.com
Cc: device-mapper development <dm-devel@redhat.com>,
Sebastian Herbszt <herbszt@gmx.de>
Subject: [PATCH 2/5] libmultipath: Simplify read_line()
Date: Fri, 18 Jul 2014 14:53:11 +0200 [thread overview]
Message-ID: <53C918B7.3010704@acm.org> (raw)
In-Reply-To: <53C91871.9070402@acm.org>
Let read_line() zero-terminate the buffer it returns such that its
callers do not have to clear that buffer before calling read_line().
Signed-off-by: Bart Van Assche <bvanassche@acm.org>
---
libmultipath/parser.c | 22 ++++++----------------
1 file changed, 6 insertions(+), 16 deletions(-)
diff --git a/libmultipath/parser.c b/libmultipath/parser.c
index 0d4c870..b7bdfcc 100644
--- a/libmultipath/parser.c
+++ b/libmultipath/parser.c
@@ -282,18 +282,12 @@ out:
int
read_line(char *buf, int size)
{
- int ch;
- int count = 0;
-
- while ((ch = fgetc(stream)) != EOF && (int) ch != '\n'
- && (int) ch != '\r') {
- if (count < size)
- buf[count] = (int) ch;
- else
- break;
- count++;
- }
- return (ch == EOF) ? 0 : 1;
+ char *p;
+
+ if (fgets(buf, size, stream) == NULL)
+ return 0;
+ strtok_r(buf, "\n\r", &p);
+ return 1;
}
vector
@@ -341,7 +335,6 @@ read_value_block(void)
}
free_strvec(vec);
}
- memset(buf, 0, MAXBUF);
}
FREE(buf);
return elements;
@@ -379,7 +372,6 @@ alloc_value_block(vector strvec, void (*alloc_func) (vector))
free_strvec(vec);
}
- memset(buf, 0, MAXBUF);
}
FREE(buf);
return 0;
@@ -489,8 +481,6 @@ process_stream(vector keywords)
while (read_line(buf, MAXBUF)) {
line_nr++;
strvec = alloc_strvec(buf);
- memset(buf,0, MAXBUF);
-
if (!strvec)
continue;
--
1.8.4.5
next prev parent reply other threads:[~2014-07-18 12:53 UTC|newest]
Thread overview: 13+ messages / expand[flat|nested] mbox.gz Atom feed top
2014-07-18 12:52 [PATCH 0/5] Five small multipath-tools patches Bart Van Assche
2014-07-18 12:52 ` [PATCH 1/5] ALUA prioritizer: Remove an unused variable Bart Van Assche
2014-07-24 14:37 ` Sebastian Herbszt
2014-07-18 12:53 ` Bart Van Assche [this message]
2014-07-18 12:53 ` [PATCH 3/5] libmultipath: Zero-terminate sysfs_attr_get_value() result Bart Van Assche
2014-07-18 12:54 ` [PATCH 4/5] libmultipath: Print line number for which parsing failed Bart Van Assche
2014-07-24 14:44 ` Sebastian Herbszt
2014-07-25 9:15 ` Christophe Varoqui
2014-07-18 12:54 ` [PATCH 5/5] libmultipath: Accept "*" as a valid regular expression Bart Van Assche
2014-07-24 14:55 ` Sebastian Herbszt
2014-07-24 16:34 ` Bryn M. Reeves
2014-07-25 9:10 ` Christophe Varoqui
2014-07-24 8:29 ` [PATCH 0/5] Five small multipath-tools patches Christophe Varoqui
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=53C918B7.3010704@acm.org \
--to=bvanassche@acm.org \
--cc=christophe.varoqui@opensvc.com \
--cc=dm-devel@redhat.com \
--cc=herbszt@gmx.de \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox