[gnome-photos/gnome-3-20] Add photos_utils_take_string
- From: Debarshi Ray <debarshir src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gnome-photos/gnome-3-20] Add photos_utils_take_string
- Date: Wed, 24 Aug 2016 15:54:49 +0000 (UTC)
commit 2a20013184f67583b5a5b642f8c9ec12cdbb0a1e
Author: Debarshi Ray <debarshir gnome org>
Date: Sat Jul 9 15:10:52 2016 +0200
Add photos_utils_take_string
This is a variant of photos_utils_set_string where string_ptr takes
ownership of new_string.
Based on an implementation by Emmanuele Bassi.
https://bugzilla.gnome.org/show_bug.cgi?id=768548
src/photos-utils.c | 28 ++++++++++++++++++++++++++++
src/photos-utils.h | 2 ++
2 files changed, 30 insertions(+), 0 deletions(-)
---
diff --git a/src/photos-utils.c b/src/photos-utils.c
index 1fc46d9..cb21e92 100644
--- a/src/photos-utils.c
+++ b/src/photos-utils.c
@@ -1473,3 +1473,31 @@ photos_utils_set_string (gchar **string_ptr, const gchar *new_string)
out:
return ret_val;
}
+
+
+gboolean
+photos_utils_take_string (gchar **string_ptr, gchar *new_string)
+{
+ gboolean ret_val = FALSE;
+
+ g_return_val_if_fail (string_ptr != NULL, FALSE);
+
+ if (*string_ptr == new_string)
+ {
+ new_string = NULL;
+ goto out;
+ }
+
+ if (g_strcmp0 (*string_ptr, new_string) == 0)
+ goto out;
+
+ g_free (*string_ptr);
+ *string_ptr = new_string;
+ new_string = NULL;
+
+ ret_val = TRUE;
+
+ out:
+ g_free (new_string);
+ return ret_val;
+}
diff --git a/src/photos-utils.h b/src/photos-utils.h
index 184ecff..1821811 100644
--- a/src/photos-utils.h
+++ b/src/photos-utils.h
@@ -178,6 +178,8 @@ void photos_utils_set_favorite (const gchar *urn, gbo
gboolean photos_utils_set_string (gchar **string_ptr, const gchar *new_string);
+gboolean photos_utils_take_string (gchar **string_ptr, gchar *new_string);
+
G_END_DECLS
#endif /* PHOTOS_UTILS_H */
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]