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

* src/format.c (make_cstring_l): New function.

Rev: src/format.c:1.35
Rev: src/format.h:1.28
parent 14ff85c3
...@@ -603,7 +603,8 @@ static int write_decimal_length(UINT8 *buffer, UINT32 n) ...@@ -603,7 +603,8 @@ static int write_decimal_length(UINT8 *buffer, UINT32 n)
* (not included in the length), to make it possible to pass the * (not included in the length), to make it possible to pass the
* string directly to C library functions. */ * string directly to C library functions. */
struct lsh_string *format_cstring(const char *s) struct lsh_string *
format_cstring(const char *s)
{ {
if (s) if (s)
{ {
...@@ -614,22 +615,28 @@ struct lsh_string *format_cstring(const char *s) ...@@ -614,22 +615,28 @@ struct lsh_string *format_cstring(const char *s)
return NULL; return NULL;
} }
struct lsh_string *make_cstring(struct lsh_string *s, int free) struct lsh_string *
make_cstring_l(UINT32 length, UINT8 *data)
{ {
struct lsh_string *res; struct lsh_string *res;
if (memchr(s->data, '\0', s->length)) if (memchr(data, '\0', length))
{ return NULL;
if (free)
lsh_string_free(s);
return 0;
}
res = ssh_format("%lS%c", s, 0); res = ssh_format("%ls%c", length, data, 0);
res->length--; res->length--;
return res;
}
struct lsh_string *
make_cstring(struct lsh_string *s, int free)
{
struct lsh_string *res = make_cstring_l(s->length, s->data);
if (free) if (free)
lsh_string_free(s); lsh_string_free(s);
return res; return res;
} }
......
...@@ -87,8 +87,14 @@ void ssh_vformat_write(const char *format, UINT32 length, UINT8 *buffer, va_list ...@@ -87,8 +87,14 @@ void ssh_vformat_write(const char *format, UINT32 length, UINT8 *buffer, va_list
/* Short cut */ /* Short cut */
#define lsh_string_dup(s) (ssh_format("%lS", (s))) #define lsh_string_dup(s) (ssh_format("%lS", (s)))
struct lsh_string *format_cstring(const char *s); struct lsh_string *
struct lsh_string *make_cstring(struct lsh_string *s, int free); format_cstring(const char *s);
struct lsh_string *
make_cstring_l(UINT32 length, UINT8 *data);
struct lsh_string *
make_cstring(struct lsh_string *s, int free);
unsigned format_size_in_decimal(UINT32 n); unsigned format_size_in_decimal(UINT32 n);
void format_decimal(unsigned length, UINT8 *buffer, UINT32 n); void format_decimal(unsigned length, UINT8 *buffer, UINT32 n);
......
Supports Markdown
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