about summary refs log tree commit diff stats
path: root/src/config
diff options
context:
space:
mode:
authorMichael Vetter <jubalh@iodoru.org>2020-06-12 16:12:21 +0200
committerMichael Vetter <jubalh@iodoru.org>2020-06-12 16:12:21 +0200
commit74e061165a808883c5b17ff356bde60fa335cbda (patch)
treef0cb35ac30ee9fb90a00ba0e93ec4e84326979bc /src/config
parentf1141932fc45fa4bcc87984241b524381c0ab2b3 (diff)
downloadprofani-tty-74e061165a808883c5b17ff356bde60fa335cbda.tar.gz
Define POSIX macro to have strdup
https://github.com/profanity-im/profanity/commit/98c38dc6d6d29333c63f80327774f094610d8602
sets C99 as standard.

strdup() is not part of C99.

For now set `-D_POSIX_C_SOURCE=200809L` macro to have strdup() in C99.
Using `gnu99` instead would be another option.

We should take more care to use glib functions whenever possible.

Regards https://github.com/profanity-im/profanity/issues/1357
Diffstat (limited to 'src/config')
-rw-r--r--src/config/files.c14
-rw-r--r--src/config/files.h8
-rw-r--r--src/config/preferences.c6
-rw-r--r--src/config/theme.c9
4 files changed, 19 insertions, 18 deletions
diff --git a/src/config/files.c b/src/config/files.c
index ff612d64..da2b66bb 100644
--- a/src/config/files.c
+++ b/src/config/files.c
@@ -91,7 +91,7 @@ files_create_directories(void)
     g_free(xdg_data);
 }
 
-char*
+gchar*
 files_get_inputrc_file(void)
 {
     gchar *xdg_config = _files_get_xdg_config_home();
@@ -101,7 +101,7 @@ files_get_inputrc_file(void)
     g_string_append(inputrc_file, "/profanity/inputrc");
 
     if (g_file_test(inputrc_file->str, G_FILE_TEST_IS_REGULAR)) {
-        char *result = strdup(inputrc_file->str);
+        gchar *result = g_strdup(inputrc_file->str);
         g_string_free(inputrc_file, TRUE);
 
         return result;
@@ -131,7 +131,7 @@ files_get_log_file(char *log_file)
 
     g_string_append(logfile, ".log");
 
-    char *result = strdup(logfile->str);
+    char *result = g_strdup(logfile->str);
 
     free(xdg_data);
     g_string_free(logfile, TRUE);
@@ -139,28 +139,28 @@ files_get_log_file(char *log_file)
     return result;
 }
 
-char*
+gchar*
 files_get_config_path(char *config_base)
 {
     gchar *xdg_config = _files_get_xdg_config_home();
     GString *file_str = g_string_new(xdg_config);
     g_string_append(file_str, "/profanity/");
     g_string_append(file_str, config_base);
-    char *result = strdup(file_str->str);
+    gchar *result = g_strdup(file_str->str);
     g_free(xdg_config);
     g_string_free(file_str, TRUE);
 
     return result;
 }
 
-char*
+gchar*
 files_get_data_path(char *data_base)
 {
     gchar *xdg_data = _files_get_xdg_data_home();
     GString *file_str = g_string_new(xdg_data);
     g_string_append(file_str, "/profanity/");
     g_string_append(file_str, data_base);
-    char *result = strdup(file_str->str);
+    gchar *result = g_strdup(file_str->str);
     g_free(xdg_data);
     g_string_free(file_str, TRUE);
 
diff --git a/src/config/files.h b/src/config/files.h
index 0abd7f6f..c87c4501 100644
--- a/src/config/files.h
+++ b/src/config/files.h
@@ -60,10 +60,10 @@
 
 void files_create_directories(void);
 
-char* files_get_config_path(char *config_base);
-char* files_get_data_path(char *data_base);
+gchar* files_get_config_path(char *config_base);
+gchar* files_get_data_path(char *data_base);
 
-char* files_get_log_file(char *log_file);
-char* files_get_inputrc_file(void);
+gchar* files_get_log_file(char *log_file);
+gchar* files_get_inputrc_file(void);
 
 #endif
diff --git a/src/config/preferences.c b/src/config/preferences.c
index 10e406b2..d1c1d900 100644
--- a/src/config/preferences.c
+++ b/src/config/preferences.c
@@ -67,7 +67,7 @@
 
 #define INPBLOCK_DEFAULT 1000
 
-static char *prefs_loc;
+static gchar *prefs_loc;
 static GKeyFile *prefs;
 gint log_maxsize = 0;
 
@@ -209,7 +209,7 @@ prefs_load(char *config_file)
     if (config_file == NULL) {
         prefs_loc = files_get_config_path(FILE_PROFRC);
     } else {
-        prefs_loc = strdup(config_file);
+        prefs_loc = g_strdup(config_file);
     }
 
     if (g_file_test(prefs_loc, G_FILE_TEST_EXISTS)) {
@@ -236,7 +236,7 @@ prefs_close(void)
     g_key_file_free(prefs);
     prefs = NULL;
 
-    free(prefs_loc);
+    g_free(prefs_loc);
     prefs_loc = NULL;
 }
 
diff --git a/src/config/theme.c b/src/config/theme.c
index 48fbd95b..e9726593 100644
--- a/src/config/theme.c
+++ b/src/config/theme.c
@@ -230,10 +230,11 @@ GSList*
 theme_list(void)
 {
     GSList *result = NULL;
-    char *themes_dir = files_get_config_path(DIR_THEMES);
+    gchar *themes_dir = files_get_config_path(DIR_THEMES);
 
     _theme_list_dir(themes_dir, &result);
-    free(themes_dir);
+    g_free(themes_dir);
+
 #ifdef THEMES_PATH
     _theme_list_dir(THEMES_PATH, &result);
 #endif
@@ -532,11 +533,11 @@ static GString*
 _theme_find(const char *const theme_name)
 {
     GString *path = NULL;
-    char *themes_dir = files_get_config_path(DIR_THEMES);
+    gchar *themes_dir = files_get_config_path(DIR_THEMES);
 
     if (themes_dir) {
         path = g_string_new(themes_dir);
-        free(themes_dir);
+        g_free(themes_dir);
         g_string_append(path, "/");
         g_string_append(path, theme_name);
         if (!g_file_test(path->str, G_FILE_TEST_EXISTS)) {