diff --git a/src/ChangeLog b/src/ChangeLog
index 9227af03..74c44809 100644
--- a/src/ChangeLog
+++ b/src/ChangeLog
@@ -1,3 +1,9 @@
+2001-12-10  Hrvoje Niksic  <hniksic@arsdigita.com>
+
+	* utils.c (long_to_string): Return a pointer after where the
+	number ends.
+	(long_to_string): Rename to number_to_string.
+
 2001-12-10  Hrvoje Niksic  <hniksic@arsdigita.com>
 
 	* utils.c (path_simplify): Correctly handle the unlikely case that
diff --git a/src/cookies.c b/src/cookies.c
index b4559600..411160ee 100644
--- a/src/cookies.c
+++ b/src/cookies.c
@@ -121,7 +121,7 @@ delete_cookie (struct cookie *cookie)
   result = alloca (HP_len + 1 + numdigit (port) + 1);	\
   memcpy (result, host, HP_len);			\
   result[HP_len] = ':';					\
-  long_to_string (result + HP_len + 1, port);		\
+  number_to_string (result + HP_len + 1, port);		\
 } while (0)
 
 /* Find cookie chain that corresponds to DOMAIN (exact) and PORT.  */
diff --git a/src/ftp-basic.c b/src/ftp-basic.c
index 096010c3..69e94f02 100644
--- a/src/ftp-basic.c
+++ b/src/ftp-basic.c
@@ -426,9 +426,9 @@ ftp_rest (struct rbuf *rbuf, long offset)
   char *request, *respline;
   int nwritten;
   uerr_t err;
-  static char numbuf[20]; /* Buffer for the number */
+  static char numbuf[24]; /* Buffer for the number */
 
-  long_to_string (numbuf, offset);
+  number_to_string (numbuf, offset);
   request = ftp_request ("REST", numbuf);
   nwritten = iwrite (RBUF_FD (rbuf), request, strlen (request));
   if (nwritten < 0)
diff --git a/src/res.c b/src/res.c
index c2f383c2..38ed7f96 100644
--- a/src/res.c
+++ b/src/res.c
@@ -478,7 +478,7 @@ static struct hash_table *registered_specs;
   result = alloca (HP_len + 1 + numdigit (port) + 1);	\
   memcpy (result, host, HP_len);			\
   result[HP_len] = ':';					\
-  long_to_string (result + HP_len + 1, port);		\
+  number_to_string (result + HP_len + 1, port);		\
 } while (0)
 
 /* Register RES specs that below to server on HOST:PORT.  They will
diff --git a/src/url.c b/src/url.c
index ecf94417..f2953c40 100644
--- a/src/url.c
+++ b/src/url.c
@@ -1206,7 +1206,7 @@ mkstruct (const struct url *u)
 	{
 	  int len = strlen (dirpref);
 	  dirpref[len] = ':';
-	  long_to_string (dirpref + len + 1, u->port);
+	  number_to_string (dirpref + len + 1, u->port);
 	}
     }
   else				/* not add_hostdir */
@@ -1654,8 +1654,7 @@ url_string (const struct url *url, int hide_password)
   if (url->port != scheme_port)
     {
       *p++ = ':';
-      long_to_string (p, url->port);
-      p += strlen (p);
+      p = number_to_string (p, url->port);
     }
 
   full_path_write (url, p);
diff --git a/src/utils.c b/src/utils.c
index a245b5c2..cf54f316 100644
--- a/src/utils.c
+++ b/src/utils.c
@@ -1343,7 +1343,7 @@ legible (long l)
 {
   char inbuf[24];
   /* Print the number into the buffer.  */
-  long_to_string (inbuf, l);
+  number_to_string (inbuf, l);
   return legible_1 (inbuf);
 }
 
@@ -1399,17 +1399,17 @@ legible_very_long (VERY_LONG_TYPE l)
 
 /* Count the digits in a (long) integer.  */
 int
-numdigit (long a)
+numdigit (long number)
 {
-  int res = 1;
-  if (a < 0)
+  int cnt = 1;
+  if (number < 0)
     {
-      a = -a;
-      ++res;
+      number = -number;
+      ++cnt;
     }
-  while ((a /= 10) != 0)
-    ++res;
-  return res;
+  while ((number /= 10) > 0)
+    ++cnt;
+  return cnt;
 }
 
 #define ONE_DIGIT(figure) *p++ = n / (figure) + '0'
@@ -1438,21 +1438,26 @@ numdigit (long a)
 #define DIGITS_18(figure) ONE_DIGIT_ADVANCE (figure); DIGITS_17 ((figure) / 10)
 #define DIGITS_19(figure) ONE_DIGIT_ADVANCE (figure); DIGITS_18 ((figure) / 10)
 
-/* Print NUMBER to BUFFER in base 10.  This is completely equivalent
-   to `sprintf(buffer, "%ld", number)', only much faster.
+/* Print NUMBER to BUFFER in base 10.  This should be completely
+   equivalent to `sprintf(buffer, "%ld", number)', only much faster.
 
    The speedup may make a difference in programs that frequently
    convert numbers to strings.  Some implementations of sprintf,
    particularly the one in GNU libc, have been known to be extremely
    slow compared to this function.
 
-   BUFFER should accept as many bytes as you expect the number to take
-   up.  On machines with 64-bit longs the maximum needed size is 24
-   bytes.  That includes the worst-case digits, the optional `-' sign,
-   and the trailing \0.  */
+   Return the pointer to the location where the terminating zero was
+   printed.  (Equivalent to calling buffer+strlen(buffer) after the
+   function is done.)
 
-void
-long_to_string (char *buffer, long number)
+   BUFFER should be big enough to accept as many bytes as you expect
+   the number to take up.  On machines with 64-bit longs the maximum
+   needed size is 24 bytes.  That includes the digits needed for the
+   largest 64-bit number, the `-' sign in case it's negative, and the
+   terminating '\0'.  */
+
+char *
+number_to_string (char *buffer, long number)
 {
   char *p = buffer;
   long n = number;
@@ -1461,6 +1466,7 @@ long_to_string (char *buffer, long number)
   /* We are running in a strange or misconfigured environment.  Let
      sprintf cope with it.  */
   sprintf (buffer, "%ld", n);
+  p += strlen (buffer);
 #else  /* (SIZEOF_LONG == 4) || (SIZEOF_LONG == 8) */
 
   if (n < 0)
@@ -1496,6 +1502,8 @@ long_to_string (char *buffer, long number)
 
   *p = '\0';
 #endif /* (SIZEOF_LONG == 4) || (SIZEOF_LONG == 8) */
+
+  return p;
 }
 
 #undef ONE_DIGIT
diff --git a/src/utils.h b/src/utils.h
index d8e4481c..7d88c311 100644
--- a/src/utils.h
+++ b/src/utils.h
@@ -91,7 +91,7 @@ void free_keys_and_values PARAMS ((struct hash_table *));
 char *legible PARAMS ((long));
 char *legible_very_long PARAMS ((VERY_LONG_TYPE));
 int numdigit PARAMS ((long));
-void long_to_string PARAMS ((char *, long));
+char *number_to_string PARAMS ((char *, long));
 
 struct wget_timer *wtimer_allocate PARAMS ((void));
 struct wget_timer *wtimer_new PARAMS ((void));