1
0
mirror of https://github.com/profanity-im/profanity.git synced 2024-06-16 21:35:24 +00:00

Define POSIX macro to have strdup

98c38dc6d6
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
This commit is contained in:
Michael Vetter 2020-06-12 16:12:21 +02:00
parent f1141932fc
commit 74e061165a
8 changed files with 28 additions and 25 deletions

View File

@ -354,7 +354,7 @@ AC_CHECK_HEADERS([ncursesw/ncurses.h], [], [])
AC_CHECK_HEADERS([ncurses.h], [], [])
### Default parameters
AM_CFLAGS="-Wall -Wno-deprecated-declarations -std=c99"
AM_CFLAGS="-Wall -Wno-deprecated-declarations -std=c99 -D_POSIX_C_SOURCE=200809L"
AS_IF([test "x$PACKAGE_STATUS" = xdevelopment],
[AM_CFLAGS="$AM_CFLAGS -Wunused -Werror"])
AS_IF([test "x$PLATFORM" = xosx],

View File

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

View File

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

View File

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

View File

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

View File

@ -149,13 +149,13 @@ log_init(log_level_t filter, char *log_file)
level_filter = filter;
tz = g_time_zone_new_local();
char *lf;
gchar *lf;
lf = files_get_log_file(log_file);
logp = fopen(lf, "a");
g_chmod(lf, S_IRUSR | S_IWUSR);
mainlogfile = g_string_new(lf);
free(lf);
g_free(lf);
}
void

View File

@ -503,10 +503,10 @@ _inp_rl_startup_hook(void)
rl_variable_bind("disable-completion", "on");
// check for and load ~/.config/profanity/inputrc
char *inputrc = files_get_inputrc_file();
gchar *inputrc = files_get_inputrc_file();
if (inputrc) {
rl_read_init_file(inputrc);
free(inputrc);
g_free(inputrc);
}
return 0;

View File

@ -79,13 +79,15 @@ _get_icons(void)
#endif /* ICONS_PATH */
char *icons_dir_s = files_get_config_path(DIR_ICONS);
gchar *icons_dir_s = files_get_config_path(DIR_ICONS);
icons_dir = g_string_new(icons_dir_s);
free(icons_dir_s);
g_free(icons_dir_s);
GError *err = NULL;
if (!g_file_test(icons_dir->str, G_FILE_TEST_IS_DIR)) {
return;
}
GDir *dir = g_dir_open(icons_dir->str, 0, &err);
if (dir) {
GString *name = g_string_new(g_dir_read_name(dir));