value.
+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
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. */
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)
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
{
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 */
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);
{
char inbuf[24];
/* Print the number into the buffer. */
- long_to_string (inbuf, l);
+ number_to_string (inbuf, l);
return legible_1 (inbuf);
}
/* 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'
#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;
/* 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)
*p = '\0';
#endif /* (SIZEOF_LONG == 4) || (SIZEOF_LONG == 8) */
+
+ return p;
}
#undef ONE_DIGIT
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));