1
0
mirror of https://github.com/moparisthebest/wget synced 2024-07-03 16:38:41 -04:00

[svn] Rename long_to_string to number_to_string, and make it return a useful

value.
This commit is contained in:
hniksic 2001-12-09 18:29:12 -08:00
parent 997a87548c
commit 943f657aa7
7 changed files with 38 additions and 25 deletions

View 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

View 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. */

View 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)

View File

@ -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

View File

@ -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);

View 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

View 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));