diff options
author | Marco Trevisan (Treviño) <mail@3v1n0.net> | 2022-05-17 03:39:06 +0200 |
---|---|---|
committer | Marco Trevisan (Treviño) <mail@3v1n0.net> | 2022-06-07 03:18:38 +0200 |
commit | cc30d8b8ddf73cfb60f7ba5c4bea34ff732b7889 (patch) | |
tree | 2f081fe4b51f0ea4de161bd2844814b0f8378e7a | |
parent | e8ea0c39d04b6c127bbb4b1317f13e972850db72 (diff) | |
download | libnotify-cc30d8b8ddf73cfb60f7ba5c4bea34ff732b7889.tar.gz |
notify: Support passing a NULL application name to notify_init()
We can find its name in some scenarios, so make it clearer from in the API.
Also, ensure that notify_set_app_name() is not used with a NULL App
name.
-rw-r--r-- | libnotify/notify.c | 28 |
1 files changed, 21 insertions, 7 deletions
diff --git a/libnotify/notify.c b/libnotify/notify.c index ffe8d62..601f8bd 100644 --- a/libnotify/notify.c +++ b/libnotify/notify.c @@ -121,6 +121,18 @@ _notify_update_spec_version (GError **error) return TRUE; } +static gboolean +set_app_name (const char *app_name) +{ + g_return_val_if_fail (app_name != NULL, FALSE); + g_return_val_if_fail (*app_name != '\0', FALSE); + + g_free (_app_name); + _app_name = g_strdup (app_name); + + return TRUE; +} + /** * notify_set_app_name: @@ -132,24 +144,24 @@ _notify_update_spec_version (GError **error) void notify_set_app_name (const char *app_name) { - g_free (_app_name); - _app_name = g_strdup (app_name); + set_app_name (app_name); } /** * notify_init: - * @app_name: The name of the application initializing libnotify. + * @app_name: (nullable): The name of the application initializing libnotify. * * Initialized libnotify. This must be called before any other functions. * + * Starting from 0.8, if the provided @app_name is %NULL, libnotify will + * try to figure it out from the running application. + * Before it was not allowed, and was causing libnotify not to be initialized. + * * Returns: %TRUE if successful, or %FALSE on error. */ gboolean notify_init (const char *app_name) { - g_return_val_if_fail (app_name != NULL, FALSE); - g_return_val_if_fail (*app_name != '\0', FALSE); - if (_initted) return TRUE; @@ -168,7 +180,9 @@ notify_init (const char *app_name) #endif } - notify_set_app_name (app_name); + if (!set_app_name (app_name)) { + return FALSE; + } #ifndef GLIB_VERSION_2_36 g_type_init (); |