[hackers] [scc] [libc] Use a counter in strlen || Quentin Rameau

From: <git_AT_suckless.org>
Date: Fri, 17 Feb 2017 11:01:40 +0100 (CET)

commit 154b5717a3ebfb71ccb7fa130a64cf90eae0bf5b
Author: Quentin Rameau <quinq_AT_fifth.space>
AuthorDate: Fri Feb 17 01:16:53 2017 +0100
Commit: Quentin Rameau <quinq_AT_fifth.space>
CommitDate: Fri Feb 17 11:00:33 2017 +0100

    [libc] Use a counter in strlen

diff --git a/libc/src/strlen.c b/libc/src/strlen.c
index 685ac62..be6d4f3 100644
--- a/libc/src/strlen.c
+++ b/libc/src/strlen.c
_AT_@ -5,9 +5,9 @@
 size_t
 strlen(const char *s)
 {
- const char *t;
+ size_t n = 0;
 
- for (t = s; *t; ++t)
- /* nothing */;
- return t - s;
+ while (*s++)
+ ++n;
+ return n;
 }
Received on Fri Feb 17 2017 - 11:01:40 CET

This archive was generated by hypermail 2.3.0 : Fri Feb 17 2017 - 11:12:36 CET