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:
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);
|
||||
}
|
||||
|
||||
/**
|
||||
* @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.
|
||||
*
|
||||
|
||||
Reference in New Issue
Block a user