1
1

string: Add ssh_string_get_char().

Этот коммит содержится в:
Andreas Schneider 2011-09-08 15:27:45 +02:00
родитель 5581323c2c
Коммит c1f8b38b78
2 изменённых файлов: 20 добавлений и 0 удалений

Просмотреть файл

@ -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);

Просмотреть файл

@ -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.
*