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

From: <git_AT_suckless.org>
Date: Fri, 17 Feb 2017 10:52:56 +0100 (CET)

commit 04ef2afb0c0fb832d5928e59ac5f5cac3ee42f1d
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 10:51:37 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 - 10:52:56 CET

This archive was generated by hypermail 2.3.0 : Fri Feb 17 2017 - 11:01:03 CET