[LTP] [PATCH] Use memset() to fill buffers in diotest

Sergey Ulanov sergeyu@google.com
Tue Feb 27 02:37:27 CET 2024


Previously fillbuf() was calling strncpy() for every byte in the buffer,
which is rather inefficient and was slowing down the tests.

Signed-off-by: Sergey Ulanov <sergeyu@google.com>
---
 testcases/kernel/io/direct_io/diotest_routines.c | 6 +-----
 1 file changed, 1 insertion(+), 5 deletions(-)

diff --git a/testcases/kernel/io/direct_io/diotest_routines.c b/testcases/kernel/io/direct_io/diotest_routines.c
index fe03630ef..793572c37 100644
--- a/testcases/kernel/io/direct_io/diotest_routines.c
+++ b/testcases/kernel/io/direct_io/diotest_routines.c
@@ -55,11 +55,7 @@
 */
 void fillbuf(char *buf, int count, char value)
 {
-	while (count > 0) {
-		strncpy(buf, &value, 1);
-		buf++;
-		count = count - 1;
-	}
+	memset(buf, value, count);
 }
 
 void vfillbuf(struct iovec *iv, int vcnt, char value)
-- 
2.44.0.rc1.240.g4c46232300-goog



More information about the ltp mailing list