diff options
author | Sébastien Helleu <flashcode@flashtux.org> | 2024-04-02 19:32:13 +0200 |
---|---|---|
committer | Sébastien Helleu <flashcode@flashtux.org> | 2024-04-07 13:18:13 +0200 |
commit | 2cf66de4236ca05024917c183c24f4dede4aa6d9 (patch) | |
tree | 204d66805a8e955a7ba8f2319d551db4e7c0b9c3 /doc/en | |
parent | 08bc6404eb0d7d6fb276c33d9f4cd6499c63d624 (diff) | |
download | weechat-2cf66de4236ca05024917c183c24f4dede4aa6d9.zip |
api: add function "asprintf"
Diffstat (limited to 'doc/en')
-rw-r--r-- | doc/en/weechat_plugin_api.en.adoc | 49 |
1 files changed, 49 insertions, 0 deletions
diff --git a/doc/en/weechat_plugin_api.en.adoc b/doc/en/weechat_plugin_api.en.adoc index 3c72ae974..a5cdf5e84 100644 --- a/doc/en/weechat_plugin_api.en.adoc +++ b/doc/en/weechat_plugin_api.en.adoc @@ -537,6 +537,55 @@ num_files = 2 str = weechat.ngettext("file", "files", num_files) ---- +==== asprintf + +_WeeChat ≥ 4.3.0._ + +Format a message in a string allocated by the function. + +[NOTE] +This function is defined for systems where the GNU function `asprintf()` +is not available. + +The behavior is almost the same except that `*result` is set to NULL on error. + +Prototype: + +[source,c] +---- +int weechat_asprintf (char **result, const char *fmt, ...); +---- + +Arguments: + +* _result_: pointer to a string pointer +* _fmt_: format string + +Return value: + +* number of bytes written in `*result` (excluding the final null byte), + a negative value in case of error. + +C example: + +[source,c] +---- +char *str; + +if (weechat_asprintf (&str, "%s, %d", "test", 42) >= 0) +{ + /* *str == "test, 42" */ + /* ... */ + free (str); +} +else +{ + /* error: *str == NULL */ +} +---- + +[NOTE] +This function is not available in scripting API. + ==== strndup Return duplicated string, with a max number of bytes. |