Commit bd18d360 authored by Niels Möller's avatar Niels Möller
Browse files

New functions ssh_format_length and ssh_format_write.

Rev: src/format.c:1.16
Rev: src/format.h:1.13
parent 1fefca6a
......@@ -43,14 +43,34 @@ struct lsh_string *ssh_format(char *format, ...)
packet = lsh_string_alloc(length);
va_start(args, format);
length = ssh_vformat(format, packet->data, args);
ssh_vformat_write(format, length, packet->data, args);
va_end(args);
assert(length == packet->length);
return packet;
}
UINT32 ssh_format_length(char *format, ...)
{
va_list args;
UINT32 length;
va_start(args, format);
length = ssh_vformat_length(format, args);
va_end(args);
return length;
}
void ssh_format_write(char *format, UINT32 length, UINT8 *buffer, ...)
{
va_list args;
va_start(args, buffer);
assert(length == ssh_vformat_write(format, buffer, args));
va_end(args);
}
UINT32 ssh_vformat_length(char *f, va_list args)
{
UINT32 length = 0;
......@@ -190,7 +210,7 @@ UINT32 ssh_vformat_length(char *f, va_list args)
return length;
}
UINT32 ssh_vformat(char *f, UINT8 *buffer, va_list args)
void ssh_vformat_write(char *f, UINT32 size, UINT8 *buffer, va_list args)
{
UINT8 *start = buffer;
......@@ -218,7 +238,7 @@ UINT32 ssh_vformat(char *f, UINT8 *buffer, va_list args)
switch(*f)
{
default:
fatal("ssh_vformat: bad format string");
fatal("ssh_vformat_write: bad format string");
break;
case 'c':
......@@ -393,5 +413,6 @@ UINT32 ssh_vformat(char *f, UINT8 *buffer, va_list args)
*buffer++ = *f++;
}
}
return buffer - start;
assert(buffer == start + size);
}
......@@ -67,9 +67,12 @@
* "f" (as in free). Frees the input string after it has been copied.
* Applicable to %S only. */
UINT32 ssh_vformat_length(char *format, va_list args);
UINT32 ssh_vformat(char *format, UINT8 *buffer, va_list args);
struct lsh_string *ssh_format(char *format, ...);
UINT32 ssh_format_length(char *format, ...);
void ssh_format_write(char *format, UINT32 length, UINT8 *buffer, ...);
UINT32 ssh_vformat_length(char *format, va_list args);
void ssh_vformat_write(char *format, UINT32 length, UINT8 *buffer, va_list args);
/* Short cut */
#define lsh_string_dup(s) (ssh_format("%lS", (s)))
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment