aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAndreas Schneider <asn@cryptomilk.org>2011-09-08 15:27:45 +0200
committerAndreas Schneider <asn@cryptomilk.org>2011-09-08 15:58:53 +0200
commit3076632657aabdf029c6dd637853ab6371bea6c2 (patch)
tree84ff3e23bc757367f60bedb2a7fd96a648224e2f
parent5581323c2c81bee79e34b7cfeac625c8eca344ce (diff)
downloadlibssh-3076632657aabdf029c6dd637853ab6371bea6c2.tar.gz
libssh-3076632657aabdf029c6dd637853ab6371bea6c2.tar.xz
libssh-3076632657aabdf029c6dd637853ab6371bea6c2.zip
string: Add ssh_string_get_char().
-rw-r--r--include/libssh/libssh.h1
-rw-r--r--src/string.c19
2 files changed, 20 insertions, 0 deletions
diff --git a/include/libssh/libssh.h b/include/libssh/libssh.h
index 52bfc178..4dd84e24 100644
--- a/include/libssh/libssh.h
+++ b/include/libssh/libssh.h
@@ -526,6 +526,7 @@ LIBSSH_API void ssh_string_free(ssh_string str);
LIBSSH_API ssh_string ssh_string_from_char(const char *what);
LIBSSH_API size_t ssh_string_len(ssh_string str);
LIBSSH_API ssh_string ssh_string_new(size_t size);
+LIBSSH_API const char *ssh_string_get_char(ssh_string str);
LIBSSH_API char *ssh_string_to_char(ssh_string str);
LIBSSH_API void ssh_string_free_char(char *s);
diff --git a/src/string.c b/src/string.c
index 70764a59..5ce2cfc8 100644
--- a/src/string.c
+++ b/src/string.c
@@ -131,6 +131,25 @@ size_t ssh_string_len(struct ssh_string_struct *s) {
}
/**
+ * @brief Get the the string as a C nul-terminated string.
+ *
+ * This is only available as long as the SSH string exists.
+ *
+ * @param[in] s The SSH string to get the C string from.
+ *
+ * @return The char pointer, NULL on error.
+ */
+const char *ssh_string_get_char(struct ssh_string_struct *s)
+{
+ if (s == NULL) {
+ return NULL;
+ }
+ s->data[ntohl(s->size)] = '\0';
+
+ return (const char *) s->data;
+}
+
+/**
* @brief Convert a SSH string to a C nul-terminated string.
*
* @param[in] s The SSH input string.