|
|
Message-ID: <5b8b9a8b.1c69fb81.ed159.bb37@mx.google.com>
Date: Sun, 2 Sep 2018 00:51:37 -0700
From: Fangrui Song <i@...kray.me>
To: musl@...ts.openwall.com
Subject: [PATCH] simplify __procfdname by folding the 0 case
---
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
Powered by blists - more mailing lists
Confused about mailing lists and their use? Read about mailing lists on Wikipedia and check out these guidelines on proper formatting of your messages.