summaryrefslogtreecommitdiff
path: root/src/core
diff options
context:
space:
mode:
authorSebastien Helleu <flashcode@flashtux.org>2008-01-24 16:50:20 +0100
committerSebastien Helleu <flashcode@flashtux.org>2008-01-24 16:50:20 +0100
commited26a0389c06250f02329fa477d2cffe7df59b5e (patch)
treeecfade4a588ba8c8dcd31d0894afabe8fbad5aad /src/core
parent25c5bc64217bce570afc36e57b0e838f54f08465 (diff)
downloadweechat-ed26a0389c06250f02329fa477d2cffe7df59b5e.zip
Add of "modifier" hook, migration of charset plugin to new API, SIGHUP signal catched (reload all config files), better config files reloading
Diffstat (limited to 'src/core')
-rw-r--r--src/core/wee-command.c108
-rw-r--r--src/core/wee-command.h4
-rw-r--r--src/core/wee-config-file.c4
-rw-r--r--src/core/wee-config-file.h8
-rw-r--r--src/core/wee-config.c42
-rw-r--r--src/core/wee-hook.c196
-rw-r--r--src/core/wee-hook.h20
-rw-r--r--src/core/wee-string.c9
-rw-r--r--src/core/wee-string.h4
9 files changed, 275 insertions, 120 deletions
diff --git a/src/core/wee-command.c b/src/core/wee-command.c
index 52991c7b3..98bf6697f 100644
--- a/src/core/wee-command.c
+++ b/src/core/wee-command.c
@@ -31,6 +31,7 @@
#include "weechat.h"
#include "wee-command.h"
#include "wee-config.h"
+#include "wee-config-file.h"
#include "wee-hook.h"
#include "wee-input.h"
#include "wee-log.h"
@@ -818,7 +819,7 @@ command_key (void *data, struct t_gui_buffer *buffer,
else
{
gui_chat_printf (NULL,
- _("No key found."));
+ _("No key found"));
}
if (internal_code)
free (internal_code);
@@ -1034,13 +1035,30 @@ command_plugin_list (char *name, int full)
HOOK_COMPLETION(ptr_hook, completion));
}
}
+
+ /* modifier hooked */
+ hook_found = 0;
+ for (ptr_hook = weechat_hooks[HOOK_TYPE_MODIFIER]; ptr_hook;
+ ptr_hook = ptr_hook->next_hook)
+ {
+ if (!ptr_hook->deleted && (ptr_hook->plugin == ptr_plugin))
+ {
+ if (!hook_found)
+ gui_chat_printf (NULL,
+ _(" modifiers hooked:"));
+ hook_found = 1;
+ gui_chat_printf (NULL,
+ " %s",
+ HOOK_MODIFIER(ptr_hook, modifier));
+ }
+ }
}
}
}
if (plugins_found == 0)
{
if (name)
- gui_chat_printf (NULL, _("No plugin found."));
+ gui_chat_printf (NULL, _("No plugin found"));
else
gui_chat_printf (NULL, _(" (no plugin)"));
}
@@ -1142,6 +1160,8 @@ int
command_reload (void *data, struct t_gui_buffer *buffer,
int argc, char **argv, char **argv_eol)
{
+ struct t_config_file *ptr_config_file;
+
/* make C compiler happy */
(void) data;
(void) buffer;
@@ -1149,28 +1169,26 @@ command_reload (void *data, struct t_gui_buffer *buffer,
(void) argv;
(void) argv_eol;
- /* reload WeeChat configuration */
- if (config_weechat_reload () == 0)
- gui_chat_printf (NULL,
- _("%sWeeChat configuration file reloaded"),
- gui_chat_prefix[GUI_CHAT_PREFIX_INFO]);
- else
- gui_chat_printf (NULL,
- _("%sError: failed to reload WeeChat configuration "
- "file"),
- gui_chat_prefix[GUI_CHAT_PREFIX_ERROR]);
-
- /* reload plugins configuration */
- if (plugin_config_reload () == 0)
- gui_chat_printf (NULL, _("%sPlugins options reloaded"),
- gui_chat_prefix[GUI_CHAT_PREFIX_INFO]);
- else
- gui_chat_printf (NULL,
- _("%sError: failed to reload plugins options"),
- gui_chat_prefix[GUI_CHAT_PREFIX_ERROR]);
-
- /* tell to plugins to reload their configuration */
- hook_signal_send ("config_reload", WEECHAT_HOOK_SIGNAL_STRING, NULL);
+ for (ptr_config_file = config_files; ptr_config_file;
+ ptr_config_file = ptr_config_file->next_config)
+ {
+ if (ptr_config_file->callback_reload)
+ {
+ if ((int) (ptr_config_file->callback_reload) (ptr_config_file) == 0)
+ {
+ gui_chat_printf (NULL, _("%sOptions reloaded from %s"),
+ gui_chat_prefix[GUI_CHAT_PREFIX_INFO],
+ ptr_config_file->filename);
+ }
+ else
+ {
+ gui_chat_printf (NULL,
+ _("%sError: failed to reload options from %s"),
+ gui_chat_prefix[GUI_CHAT_PREFIX_ERROR],
+ ptr_config_file->filename);
+ }
+ }
+ }
return WEECHAT_RC_OK;
}
@@ -1183,32 +1201,32 @@ int
command_save (void *data, struct t_gui_buffer *buffer,
int argc, char **argv, char **argv_eol)
{
+ struct t_config_file *ptr_config_file;
+
/* make C compiler happy */
(void) data;
(void) buffer;
(void) argc;
(void) argv;
(void) argv_eol;
-
- /* save WeeChat configuration */
- if (config_weechat_write () == 0)
- gui_chat_printf (NULL,
- _("%sWeeChat configuration file saved"),
- gui_chat_prefix[GUI_CHAT_PREFIX_INFO]);
- else
- gui_chat_printf (NULL,
- _("%sError: failed to save WeeChat configuration "
- "file"),
- gui_chat_prefix[GUI_CHAT_PREFIX_ERROR]);
- /* save plugins configuration */
- if (plugin_config_write () == 0)
- gui_chat_printf (NULL, _("%sPlugins options saved"),
- gui_chat_prefix[GUI_CHAT_PREFIX_INFO]);
- else
- gui_chat_printf (NULL,
- _("%sError: failed to save plugins options"),
- gui_chat_prefix[GUI_CHAT_PREFIX_ERROR]);
+ for (ptr_config_file = config_files; ptr_config_file;
+ ptr_config_file = ptr_config_file->next_config)
+ {
+ if (config_file_write (ptr_config_file) == 0)
+ {
+ gui_chat_printf (NULL, _("%sOptions saved to %s"),
+ gui_chat_prefix[GUI_CHAT_PREFIX_INFO],
+ ptr_config_file->filename);
+ }
+ else
+ {
+ gui_chat_printf (NULL,
+ _("%sError: failed to save options to %s"),
+ gui_chat_prefix[GUI_CHAT_PREFIX_ERROR],
+ ptr_config_file->filename);
+ }
+ }
return WEECHAT_RC_OK;
}
@@ -1826,7 +1844,7 @@ command_window (void *data, struct t_gui_buffer *buffer,
gui_chat_printf (NULL,
_("%sError: can not merge windows, "
"there's no other window with same "
- "size near current one."),
+ "size near current one"),
gui_chat_prefix[GUI_CHAT_PREFIX_ERROR]);
return WEECHAT_RC_ERROR;
}
@@ -1972,7 +1990,7 @@ command_init ()
"all plugins, then autoload plugins)\n"
" unload: unload one or all plugins\n\n"
"Without argument, /plugin command lists loaded plugins."),
- "list|listfull|load|autoload|reload|unload %p",
+ "list|listfull|load|autoload|reload|unload %f|%p",
command_plugin, NULL);
hook_command (NULL, "quit",
N_("quit WeeChat"),
diff --git a/src/core/wee-command.h b/src/core/wee-command.h
index adffc3c8c..f73e06fc7 100644
--- a/src/core/wee-command.h
+++ b/src/core/wee-command.h
@@ -20,6 +20,10 @@
#ifndef __WEECHAT_COMMAND_H
#define __WEECHAT_COMMAND_H 1
+struct t_gui_buffer;
+
+extern int command_reload (void *data, struct t_gui_buffer *buffer,
+ int argc, char **argv, char **argv_eol);
extern void command_init ();
extern void command_print_stdout ();
diff --git a/src/core/wee-config-file.c b/src/core/wee-config-file.c
index ec7b5ce8f..7cc16fe4b 100644
--- a/src/core/wee-config-file.c
+++ b/src/core/wee-config-file.c
@@ -69,7 +69,8 @@ config_file_search (char *filename)
*/
struct t_config_file *
-config_file_new (struct t_weechat_plugin *plugin, char *filename)
+config_file_new (struct t_weechat_plugin *plugin, char *filename,
+ int (*callback_reload)(struct t_config_file *config_file))
{
struct t_config_file *new_config_file;
@@ -86,6 +87,7 @@ config_file_new (struct t_weechat_plugin *plugin, char *filename)
new_config_file->plugin = plugin;
new_config_file->filename = strdup (filename);
new_config_file->file = NULL;
+ new_config_file->callback_reload = callback_reload;
new_config_file->sections = NULL;
new_config_file->last_section = NULL;
diff --git a/src/core/wee-config-file.h b/src/core/wee-config-file.h
index 4468c406f..87e4743f2 100644
--- a/src/core/wee-config-file.h
+++ b/src/core/wee-config-file.h
@@ -40,6 +40,8 @@ struct t_config_file
struct t_weechat_plugin *plugin; /* plugin which created this cfg */
char *filename; /* config filename (without path)*/
FILE *file; /* file pointer */
+ int (*callback_reload) /* callback for reloading file */
+ (struct t_config_file *config_file);
struct t_config_section *sections; /* config sections */
struct t_config_section *last_section; /* last config section */
struct t_config_file *prev_config; /* link to previous config file */
@@ -87,8 +89,12 @@ struct t_config_option
struct t_config_option *next_option; /* link to next option */
};
+extern struct t_config_file *config_files;
+extern struct t_config_file *last_config_file;
+
extern struct t_config_file *config_file_new (struct t_weechat_plugin *plugin,
- char *filename);
+ char *filename,
+ int (*callback_reload)(struct t_config_file *config_file));
extern int config_file_valid_for_plugin (struct t_weechat_plugin *plugin,
struct t_config_file *config_file);
extern struct t_config_section *config_file_new_section (struct t_config_file *config_file,
diff --git a/src/core/wee-config.c b/src/core/wee-config.c
index 1643c2187..9058774b6 100644
--- a/src/core/wee-config.c
+++ b/src/core/wee-config.c
@@ -415,6 +415,25 @@ config_change_day_change ()
}
/*
+ * config_weechat_reload: reload WeeChat configuration file
+ * return: 0 = successful
+ * -1 = config file file not found
+ * -2 = error in config file
+ */
+
+int
+config_weechat_reload (struct t_config_file *config_file)
+{
+ /* make C compiler happy */
+ (void) config_file;
+
+ /* remove all keys */
+ gui_keyboard_free_all ();
+
+ return config_file_reload (weechat_config_file);
+}
+
+/*
* config_weechat_read_key: read a key in configuration file
*/
@@ -495,7 +514,8 @@ config_weechat_init ()
{
struct t_config_section *ptr_section;
- weechat_config_file = config_file_new (NULL, WEECHAT_CONFIG_FILENAME);
+ weechat_config_file = config_file_new (NULL, WEECHAT_CONFIG_FILENAME,
+ &config_weechat_reload);
if (!weechat_config_file)
return 0;
@@ -1160,23 +1180,6 @@ config_weechat_read ()
}
/*
- * config_weechat_reload: reload WeeChat configuration file
- * return: 0 = successful
- * -1 = configuration file file not found
- * -2 = error in configuration file
- */
-
-int
-config_weechat_reload ()
-{
- /* remove all keys */
- gui_keyboard_free_all ();
-
- /* reload configuration file */
- return config_file_reload (weechat_config_file);
-}
-
-/*
* config_weechat_write: write WeeChat configuration file
* return: 0 if ok
* < 0 if error
@@ -1185,6 +1188,7 @@ config_weechat_reload ()
int
config_weechat_write ()
{
- log_printf (_("Saving WeeChat configuration to disk"));
+ log_printf (_("Saving WeeChat configuration to disk (%s)"),
+ weechat_config_file->filename);
return config_file_write (weechat_config_file);
}
diff --git a/src/core/wee-hook.c b/src/core/wee-hook.c
index 02e92de78..fe57e98c2 100644
--- a/src/core/wee-hook.c
+++ b/src/core/wee-hook.c
@@ -257,6 +257,30 @@ hook_valid_for_plugin (struct t_weechat_plugin *plugin, struct t_hook *hook)
}
/*
+ * hook_exec_start: code executed before a hook exec
+ */
+
+void
+hook_exec_start ()
+{
+ hook_exec_recursion++;
+}
+
+/*
+ * hook_exec_end: code executed after a hook exec
+ */
+
+void
+hook_exec_end ()
+{
+ if (hook_exec_recursion > 0)
+ hook_exec_recursion--;
+
+ if (hook_exec_recursion == 0)
+ hook_remove_deleted ();
+}
+
+/*
* hook_search_command: search command hook in list
*/
@@ -362,7 +386,7 @@ hook_command_exec (struct t_gui_buffer *buffer, char *string, int only_builtin)
}
argv_eol = string_explode (string, " ", 1, 0, NULL);
- hook_exec_recursion++;
+ hook_exec_start ();
ptr_hook = weechat_hooks[HOOK_TYPE_COMMAND];
while (ptr_hook)
@@ -383,10 +407,9 @@ hook_command_exec (struct t_gui_buffer *buffer, char *string, int only_builtin)
rc = (int) (HOOK_COMMAND(ptr_hook, callback))
(ptr_hook->callback_data, buffer, argc, argv, argv_eol);
ptr_hook->running = 0;
- if (hook_exec_recursion > 0)
- hook_exec_recursion--;
- if (hook_exec_recursion == 0)
- hook_remove_deleted ();
+ string_free_exploded (argv);
+ string_free_exploded (argv_eol);
+ hook_exec_end ();
if (rc == WEECHAT_RC_ERROR)
return 0;
else
@@ -399,11 +422,7 @@ hook_command_exec (struct t_gui_buffer *buffer, char *string, int only_builtin)
string_free_exploded (argv);
string_free_exploded (argv_eol);
- if (hook_exec_recursion > 0)
- hook_exec_recursion--;
-
- if (hook_exec_recursion == 0)
- hook_remove_deleted ();
+ hook_exec_end ();
/* no hook found */
return -1;
@@ -530,7 +549,7 @@ hook_timer_exec ()
gettimeofday (&tv_time, NULL);
- hook_exec_recursion++;
+ hook_exec_start ();
ptr_hook = weechat_hooks[HOOK_TYPE_TIMER];
while (ptr_hook)
@@ -566,11 +585,7 @@ hook_timer_exec ()
ptr_hook = next_hook;
}
- if (hook_exec_recursion > 0)
- hook_exec_recursion--;
-
- if (hook_exec_recursion == 0)
- hook_remove_deleted ();
+ hook_exec_end ();
}
/*
@@ -686,7 +701,7 @@ hook_fd_exec (fd_set *read_fds, fd_set *write_fds, fd_set *exception_fds)
{
struct t_hook *ptr_hook, *next_hook;
- hook_exec_recursion++;
+ hook_exec_start ();
ptr_hook = weechat_hooks[HOOK_TYPE_FD];
while (ptr_hook)
@@ -710,11 +725,7 @@ hook_fd_exec (fd_set *read_fds, fd_set *write_fds, fd_set *exception_fds)
ptr_hook = next_hook;
}
- if (hook_exec_recursion > 0)
- hook_exec_recursion--;
-
- if (hook_exec_recursion == 0)
- hook_remove_deleted ();
+ hook_exec_end ();
}
/*
@@ -776,7 +787,7 @@ hook_print_exec (struct t_gui_buffer *buffer, time_t date, char *prefix,
return;
}
- hook_exec_recursion++;
+ hook_exec_start ();
ptr_hook = weechat_hooks[HOOK_TYPE_PRINT];
while (ptr_hook)
@@ -802,11 +813,7 @@ hook_print_exec (struct t_gui_buffer *buffer, time_t date, char *prefix,
ptr_hook = next_hook;
}
- if (hook_exec_recursion > 0)
- hook_exec_recursion--;
-
- if (hook_exec_recursion == 0)
- hook_remove_deleted ();
+ hook_exec_end ();
}
/*
@@ -853,7 +860,7 @@ hook_signal_send (char *signal, char *type_data, void *signal_data)
{
struct t_hook *ptr_hook, *next_hook;
- hook_exec_recursion++;
+ hook_exec_start ();
ptr_hook = weechat_hooks[HOOK_TYPE_SIGNAL];
while (ptr_hook)
@@ -874,11 +881,7 @@ hook_signal_send (char *signal, char *type_data, void *signal_data)
ptr_hook = next_hook;
}
- if (hook_exec_recursion > 0)
- hook_exec_recursion--;
-
- if (hook_exec_recursion == 0)
- hook_remove_deleted ();
+ hook_exec_end ();
}
/*
@@ -923,7 +926,7 @@ hook_config_exec (char *type, char *option, char *value)
{
struct t_hook *ptr_hook, *next_hook;
- hook_exec_recursion++;
+ hook_exec_start ();
ptr_hook = weechat_hooks[HOOK_TYPE_CONFIG];
while (ptr_hook)
@@ -948,11 +951,7 @@ hook_config_exec (char *type, char *option, char *value)
ptr_hook = next_hook;
}
- if (hook_exec_recursion > 0)
- hook_exec_recursion--;
-
- if (hook_exec_recursion == 0)
- hook_remove_deleted ();
+ hook_exec_end ();
}
/*
@@ -1003,7 +1002,7 @@ hook_completion_exec (struct t_weechat_plugin *plugin, char *completion,
/* make C compiler happy */
(void) plugin;
- hook_exec_recursion++;
+ hook_exec_start ();
ptr_hook = weechat_hooks[HOOK_TYPE_COMPLETION];
while (ptr_hook)
@@ -1024,11 +1023,103 @@ hook_completion_exec (struct t_weechat_plugin *plugin, char *completion,
ptr_hook = next_hook;
}
- if (hook_exec_recursion > 0)
- hook_exec_recursion--;
+ hook_exec_end ();
+}
+
+/*
+ * hook_modifier: hook a modifier
+ */
+
+struct t_hook *
+hook_modifier (struct t_weechat_plugin *plugin, char *modifier,
+ t_hook_callback_modifier *callback, void *callback_data)
+{
+ struct t_hook *new_hook;
+ struct t_hook_modifier *new_hook_modifier;
- if (hook_exec_recursion == 0)
- hook_remove_deleted ();
+ if (!modifier || !modifier[0])
+ return NULL;
+
+ new_hook = (struct t_hook *)malloc (sizeof (struct t_hook));
+ if (!new_hook)
+ return NULL;
+ new_hook_modifier = (struct t_hook_modifier *)malloc (sizeof (struct t_hook_modifier));
+ if (!new_hook_modifier)
+ {
+ free (new_hook);
+ return NULL;
+ }
+
+ hook_init_data (new_hook, plugin, HOOK_TYPE_MODIFIER, callback_data);
+
+ new_hook->hook_data = new_hook_modifier;
+ new_hook_modifier->callback = callback;
+ new_hook_modifier->modifier = strdup (modifier);
+
+ hook_add_to_list (new_hook);
+
+ return new_hook;
+}
+
+/*
+ * hook_modifier_exec: execute modifier hook
+ */
+
+char *
+hook_modifier_exec (struct t_weechat_plugin *plugin, char *modifier,
+ char *modifier_data, char *string)
+{
+ struct t_hook *ptr_hook, *next_hook;
+ char *new_msg, *message_modified;
+
+ /* make C compiler happy */
+ (void) plugin;
+
+ new_msg = NULL;
+ message_modified = strdup (string);
+ if (!message_modified)
+ return NULL;
+
+ hook_exec_start ();
+
+ ptr_hook = weechat_hooks[HOOK_TYPE_MODIFIER];
+ while (ptr_hook)
+ {
+ next_hook = ptr_hook->next_hook;
+
+ if (!ptr_hook->deleted
+ && !ptr_hook->running
+ && (string_strcasecmp (HOOK_MODIFIER(ptr_hook, modifier),
+ modifier) == 0))
+ {
+ ptr_hook->running = 1;
+ new_msg = (HOOK_MODIFIER(ptr_hook, callback))
+ (ptr_hook->callback_data, modifier, modifier_data,
+ message_modified);
+ ptr_hook->running = 0;
+
+ /* empty string returned => message dropped */
+ if (new_msg && !new_msg[0])
+ {
+ free (message_modified);
+ hook_exec_end ();
+ return new_msg;
+ }
+
+ /* new message => keep it as base for next modifier */
+ if (new_msg)
+ {
+ free (message_modified);
+ message_modified = new_msg;
+ }
+ }
+
+ ptr_hook = next_hook;
+ }
+
+ hook_exec_end ();
+
+ return message_modified;
}
/*
@@ -1104,6 +1195,11 @@ unhook (struct t_hook *hook)
free (HOOK_COMPLETION(hook, completion));
free ((struct t_hook_completion *)hook->hook_data);
break;
+ case HOOK_TYPE_MODIFIER:
+ if (HOOK_MODIFIER(hook, modifier))
+ free (HOOK_MODIFIER(hook, modifier));
+ free ((struct t_hook_modifier *)hook->hook_data);
+ break;
case HOOK_NUM_TYPES:
/* this constant is used to count types only,
it is never used as type */
@@ -1288,6 +1384,16 @@ hook_print_log ()
log_printf (" completion . . . . . : '%s'", HOOK_COMPLETION(ptr_hook, completion));
}
break;
+ case HOOK_TYPE_MODIFIER:
+ log_printf (" type . . . . . . . . . : %d (modifier)", ptr_hook->type);
+ log_printf (" callback_data. . . . . : 0x%x", ptr_hook->callback_data);
+ if (!ptr_hook->deleted)
+ {
+ log_printf (" modifier data:");
+ log_printf (" callback . . . . . . : 0x%x", HOOK_MODIFIER(ptr_hook, callback));
+ log_printf (" modifier . . . . . . : '%s'", HOOK_MODIFIER(ptr_hook, modifier));
+ }
+ break;
case HOOK_NUM_TYPES:
/* this constant is used to count types only,
it is never used as type */
diff --git a/src/core/wee-hook.h b/src/core/wee-hook.h
index 0975aef37..26f684b06 100644
--- a/src/core/wee-hook.h
+++ b/src/core/wee-hook.h
@@ -34,6 +34,7 @@ enum t_hook_type
HOOK_TYPE_SIGNAL, /* signal */
HOOK_TYPE_CONFIG, /* config option */
HOOK_TYPE_COMPLETION, /* custom completions */
+ HOOK_TYPE_MODIFIER, /* stirng modifier */
/* number of hook types */
HOOK_NUM_TYPES,
};
@@ -49,6 +50,7 @@ enum t_hook_type
#define HOOK_SIGNAL(hook, var) (((struct t_hook_signal *)hook->hook_data)->var)
#define HOOK_CONFIG(hook, var) (((struct t_hook_config *)hook->hook_data)->var)
#define HOOK_COMPLETION(hook, var) (((struct t_hook_completion *)hook->hook_data)->var)
+#define HOOK_MODIFIER(hook, var) (((struct t_hook_modifier *)hook->hook_data)->var)
struct t_hook
{
@@ -139,7 +141,16 @@ typedef int (t_hook_callback_completion)(void *data, char *completion,
struct t_hook_completion
{
t_hook_callback_completion *callback; /* completion callback */
- char *completion; /* name of completion */
+ char *completion; /* name of completion */
+};
+
+typedef char *(t_hook_callback_modifier)(void *data, char *modifier,
+ char *modifier_data, char *string);
+
+struct t_hook_modifier
+{
+ t_hook_callback_modifier *callback; /* modifier callback */
+ char *modifier; /* name of modifier */
};
/* hook variables */
@@ -203,6 +214,13 @@ extern void hook_completion_exec (struct t_weechat_plugin *plugin,
char *completion,
struct t_gui_buffer *buffer,
struct t_weelist *list);
+extern struct t_hook *hook_modifier (struct t_weechat_plugin *plugin,
+ char *modifier,
+ t_hook_callback_modifier *callback,
+ void *callback_data);
+extern char *hook_modifier_exec (struct t_weechat_plugin *plugin,
+ char *modifier, char *modifier_data,
+ char *string);
extern void unhook (struct t_hook *hook);
extern void unhook_all_plugin (struct t_weechat_plugin *plugin);
extern void unhook_all ();
diff --git a/src/core/wee-string.c b/src/core/wee-string.c
index 61aacd5ec..b1728d578 100644
--- a/src/core/wee-string.c
+++ b/src/core/wee-string.c
@@ -47,12 +47,12 @@
/*
- * strndup: define strndup function if not existing (FreeBSD and maybe other)
+ * string_strndup: define strndup function for systems where this function does
+ * not exist (FreeBSD and maybe other)
*/
-#ifndef HAVE_STRNDUP
char *
-strndup (char *string, int length)
+string_strndup (char *string, int length)
{
char *result;
@@ -68,7 +68,6 @@ strndup (char *string, int length)
return result;
}
-#endif
/*
* string_tolower: locale independant string conversion to lower case
@@ -337,7 +336,7 @@ string_remove_quotes (char *string, char *quotes)
{
if (pos_end == (pos_start + 1))
return strdup ("");
- return strndup (pos_start + 1, pos_end - pos_start - 1);
+ return string_strndup (pos_start + 1, pos_end - pos_start - 1);
}
return strdup (string);
diff --git a/src/core/wee-string.h b/src/core/wee-string.h
index bcf0efa96..66729f1d2 100644
--- a/src/core/wee-string.h
+++ b/src/core/wee-string.h
@@ -20,9 +20,7 @@
#ifndef __WEECHAT_STRING_H
#define __WEECHAT_STRING_H 1
-#ifndef HAVE_STRNDUP
-extern char *strndup (char *string, int length);
-#endif
+extern char *string_strndup (char *string, int length);
extern void string_tolower (char *string);
extern void string_toupper (char *string);
extern int string_strcasecmp (char *string1, char *string2);