mirror of
https://git.libssh.org/projects/libssh.git
synced 2025-11-29 01:03:57 +03:00
string: Add ssh_string_get_char().
This commit is contained in:
@@ -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 ssh_string ssh_string_from_char(const char *what);
|
||||||
LIBSSH_API size_t ssh_string_len(ssh_string str);
|
LIBSSH_API size_t ssh_string_len(ssh_string str);
|
||||||
LIBSSH_API ssh_string ssh_string_new(size_t size);
|
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 char *ssh_string_to_char(ssh_string str);
|
||||||
LIBSSH_API void ssh_string_free_char(char *s);
|
LIBSSH_API void ssh_string_free_char(char *s);
|
||||||
|
|
||||||
|
|||||||
19
src/string.c
19
src/string.c
@@ -130,6 +130,25 @@ size_t ssh_string_len(struct ssh_string_struct *s) {
|
|||||||
return ntohl(s->size);
|
return ntohl(s->size);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @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[ssh_string_len(s)] = '\0';
|
||||||
|
|
||||||
|
return (const char *) s->data;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief Convert a SSH string to a C nul-terminated string.
|
* @brief Convert a SSH string to a C nul-terminated string.
|
||||||
*
|
*
|
||||||
|
|||||||
Reference in New Issue
Block a user