]> sjero.net Git - wget/commitdiff
[svn] Rename long_to_string to number_to_string, and make it return a useful
authorhniksic <devnull@localhost>
Mon, 10 Dec 2001 02:29:12 +0000 (18:29 -0800)
committerhniksic <devnull@localhost>
Mon, 10 Dec 2001 02:29:12 +0000 (18:29 -0800)
value.

src/ChangeLog
src/cookies.c
src/ftp-basic.c
src/res.c
src/url.c
src/utils.c
src/utils.h

index 9227af030d47e77ac0021709b9f6d38bbc065658..74c44809e20b7bc5d193a5856e0f91184954b2fe 100644 (file)
@@ -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
index b4559600a2893c6b2dd0880d69d254390e6fab1b..411160ee8f27aef775941efc3f2604a206512c5a 100644 (file)
@@ -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.  */
index 096010c373f2d16da090b6dd961db5e589731123..69e94f022380292cbb4a1181c75c6abd55ac9b58 100644 (file)
@@ -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)
index c2f383c2a38a818fa6c571e6e8ca07e534e2063c..38ed7f96a50eedd6289951c3e68dfa417fa1ca34 100644 (file)
--- 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
index ecf94417574d71ecfb99cacb1fc915488030a78e..f2953c40c778aefa35e18323014e383eae9c5e47 100644 (file)
--- 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);
index a245b5c2fc7ee8dc326e4cead1b99c0adceeb02f..cf54f316ac86525a6ff3b104d00946a3521eb838 100644 (file)
@@ -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
index d8e4481c7c915e89186267f70e2a7d024e736e59..7d88c31139c3ed113792ae5be3f0de825d25d5a4 100644 (file)
@@ -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));