From: Fangrui Song <i@maskray.me>
To: musl@lists.openwall.com
Subject: [PATCH] simplify __procfdname by folding the 0 case
Date: Sun, 2 Sep 2018 00:51:37 -0700 [thread overview]
Message-ID: <5b8b9a8b.1c69fb81.ed159.bb37@mx.google.com> (raw)
---
src/internal/procfdname.c | 11 +++--------
1 file changed, 3 insertions(+), 8 deletions(-)
diff --git a/src/internal/procfdname.c b/src/internal/procfdname.c
index 697e0bdc..5046abaa 100644
--- a/src/internal/procfdname.c
+++ b/src/internal/procfdname.c
@@ -2,12 +2,7 @@ void __procfdname(char *buf, unsigned fd)
{
unsigned i, j;
for (i=0; (buf[i] = "/proc/self/fd/"[i]); i++);
- if (!fd) {
- buf[i] = '0';
- buf[i+1] = 0;
- return;
- }
- for (j=fd; j; j/=10, i++);
- buf[i] = 0;
- for (; fd; fd/=10) buf[--i] = '0' + fd%10;
+ for (j=fd; i++, j /= 10; );
+ buf[i] = '\0';
+ while (buf[--i] = '0' + fd%10, fd /= 10);
}
--
2.18.0
next reply other threads:[~2018-09-02 7:51 UTC|newest]
Thread overview: 4+ messages / expand[flat|nested] mbox.gz Atom feed top
2018-09-02 7:51 Fangrui Song [this message]
2018-09-02 11:14 ` Alexander Monakov
2018-09-09 19:04 ` Fāng-ruì Sòng
2018-09-09 21:30 ` Alexander Monakov
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=5b8b9a8b.1c69fb81.ed159.bb37@mx.google.com \
--to=i@maskray.me \
--cc=musl@lists.openwall.com \
/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.
Code repositories for project(s) associated with this public inbox
https://git.vuxu.org/mirror/musl/
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).