From 91a9a6b3910df8be3936ed0a70b0ac6cbdc10079 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Stefan=20B=C3=BChler?= Date: Sun, 8 Feb 2015 19:10:46 +0000 Subject: [PATCH 20/29] rename buffer_append_long_hex to buffer_append_uint_hex MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * takes uintmax_t now * use in http_chunk_append_len From: Stefan Bühler git-svn-id: svn://svn.lighttpd.net/lighttpd/branches/lighttpd-1.4.x@2980 152afb58-edef-0310-8abb-c4023f1b3aa9 --- src/buffer.c | 4 ++-- src/buffer.h | 2 +- src/http_chunk.c | 22 +++------------------- src/log.c | 4 ++-- 4 files changed, 8 insertions(+), 24 deletions(-) diff --git a/src/buffer.c b/src/buffer.c index d343731..425d700 100644 --- a/src/buffer.c +++ b/src/buffer.c @@ -234,12 +234,12 @@ void buffer_append_string_buffer(buffer *b, const buffer *src) { } } -void buffer_append_long_hex(buffer *b, unsigned long value) { +void buffer_append_uint_hex(buffer *b, uintmax_t value) { char *buf; int shift = 0; { - unsigned long copy = value; + uintmax_t copy = value; do { copy >>= 8; shift += 2; /* counting nibbles (4 bits) */ diff --git a/src/buffer.h b/src/buffer.h index e2ac778..f5d0224 100644 --- a/src/buffer.h +++ b/src/buffer.h @@ -89,7 +89,7 @@ void buffer_append_string(buffer *b, const char *s); void buffer_append_string_len(buffer *b, const char *s, size_t s_len); void buffer_append_string_buffer(buffer *b, const buffer *src); -void buffer_append_long_hex(buffer *b, unsigned long len); +void buffer_append_uint_hex(buffer *b, uintmax_t len); void buffer_append_int(buffer *b, intmax_t val); void buffer_copy_int(buffer *b, intmax_t val); diff --git a/src/http_chunk.c b/src/http_chunk.c index 79e4586..45db56c 100644 --- a/src/http_chunk.c +++ b/src/http_chunk.c @@ -21,31 +21,15 @@ #include static void http_chunk_append_len(server *srv, connection *con, size_t len) { - size_t i, olen = len, j; buffer *b; force_assert(NULL != srv); b = srv->tmp_chunk_len; - if (len == 0) { - buffer_copy_string_len(b, CONST_STR_LEN("0\r\n")); - } else { - for (i = 0; i < 8 && len; i++) { - len >>= 4; - } - - /* i is the number of hex digits we have, + \r\n */ - buffer_string_prepare_copy(b, i + 2); - - for (j = i-1, len = olen; j+1 > 0; j--) { - b->ptr[j] = (len & 0xf) + (((len & 0xf) <= 9) ? '0' : 'a' - 10); - len >>= 4; - } - buffer_commit(b, i); - - buffer_append_string_len(b, CONST_STR_LEN("\r\n")); - } + buffer_string_set_length(b, 0); + buffer_append_uint_hex(b, len); + buffer_append_string_len(b, CONST_STR_LEN("\r\n")); chunkqueue_append_buffer(con->write_queue, b); } diff --git a/src/log.c b/src/log.c index 6c9c38d..9322d2c 100644 --- a/src/log.c +++ b/src/log.c @@ -288,7 +288,7 @@ static void log_buffer_append_printf(buffer *out, const char *fmt, va_list ap) { case 'x': /* int (hex) */ d = va_arg(ap, int); buffer_append_string_len(out, CONST_STR_LEN("0x")); - buffer_append_long_hex(out, d); + buffer_append_uint_hex(out, d); buffer_append_string_len(out, CONST_STR_LEN(" ")); break; case 'S': /* string */ @@ -310,7 +310,7 @@ static void log_buffer_append_printf(buffer *out, const char *fmt, va_list ap) { case 'X': /* int (hex) */ d = va_arg(ap, int); buffer_append_string_len(out, CONST_STR_LEN("0x")); - buffer_append_long_hex(out, d); + buffer_append_uint_hex(out, d); break; case '(': case ')': -- 2.4.5