shorter fmt_ulong

Nikola Vladov <[email protected]>
Newsgroups gmane.linux.lib.dietlibc
Message-ID <[email protected]>
On my box DJB fmt_ulong is shorter than included in libowfat.
Here I suggest one fmt_ulong which is even shorter than DJB fmt_ulong.
I doesn't compare them for speed.  Which is better for fmt_ulong:
short or fast? 

Felix, I have send already one improvement for sysconf.  It uses
sysinfo(2) to get physical RAM instead of parsing /proc/... files.
Have you seen it already?

Nikola
#include <sys/types.h>

size_t fmt_ulong(char *s, unsigned long u) {
  size_t len; unsigned long q;
  len = 0; q = u;
  do { ++len; q /= 10; } while (q);
  if (s) {
    s += len;
    do { *--s = '0' + (u % 10); u /= 10; } while(u); /* handles u == 0 */
  }
  return len;
}
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.