Commit 85ccf21a authored by Niels Möller's avatar Niels Möller

Added %z specifier.

Rev: src/format.c:1.6
Rev: src/format.h:1.6
parent 49d7f3d5
......@@ -2,23 +2,24 @@
*
*/
#include "format.h"
#include "werror.h"
#include <assert.h>
#include <string.h>
struct simple_packet *ssh_format(char *format, ...)
#include "format.h"
#include "werror.h"
#include "xalloc.h"
struct lsh_string *ssh_format(char *format, ...)
{
va_list args;
UINT32 length;
struct simple_packet *packet;
struct lsh_string *packet;
va_start(args, format);
length = ssh_vformat_length(format, args);
va_end(args);
packet = simple_packet_alloc(length);
packet = lsh_string_alloc(length);
va_start(args, format);
ssh_vformat(format, packet->data, args);
......@@ -82,6 +83,13 @@ UINT32 ssh_vformat_length(char *f, va_list args)
length += 4;
break;
case 'z':
length += strlen(va_arg(args, char*));
f++;
if (!literal)
length += 4;
break;
case 'r':
length += va_arg(args, struct lsh_string *)->length;
(void) va_arg(args, UINT8 **); /* pointer */
......@@ -208,6 +216,21 @@ void ssh_vformat(char *f, UINT8 *buffer, va_list args)
buffer += s->length;
f++;
}
case 'z':
{
char *s = va_arg(args, char *);
UINT32 length = strlen(s);
if (!literal)
{
WRITE_UINT32(buffer, length);
buffer += 4;
}
memcpy(buffer, s, length);
buffer += length;
f++;
break;
}
case 'r':
{
UINT32 length = va_arg(args, UINT32);
......
......@@ -24,6 +24,11 @@
*
* %S Insert a string, given as a struct lsh_string pointer.
*
* %z Insert a string, using a null-terminated argument.
*
* %r Reserves space in the string, and stores a pointer to this space
* into the given UINT8 ** argument.
*
* %a Insert a string containing one atom.
*
* %A Insert a string containing a list of atoms. The corresponding
......@@ -31,9 +36,6 @@
*
* %n Insert a string containing a bignum.
*
* %r Reserves space in the string, and stores a pointer to this space
* into the given UINT8 ** argument.
*
* There is one valid modifier:
*
* "l" (as in literal). It is applicable to the s, a, A, n and r
......
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