+#ifdef HAVE_DYNAMIC_PLUGINS
+/*****************************************************************************
+ * HideModule: remove a module from memory but keep its structure.
+ *****************************************************************************
+ * This function can only be called if i_usage == 0. It will make a call
+ * to the module's inner DeactivateModule() symbol, and then unload it
+ * from memory. A call to module_Need() will automagically load it again.
+ *****************************************************************************/
+static int HideModule( module_t * p_module )
+{
+ if( p_module->b_builtin )
+ {
+ /* A built-in module should never be hidden. */
+ intf_ErrMsg( "module error: trying to hide built-in module `%s'",
+ p_module->psz_name );
+ return( -1 );
+ }
+
+ if( p_module->i_usage >= 1 )
+ {
+ intf_ErrMsg( "module error: trying to hide module `%s' which is still"
+ " in use", p_module->psz_name );
+ return( -1 );
+ }
+
+ if( p_module->i_usage <= -1 )
+ {
+ intf_ErrMsg( "module error: trying to hide module `%s' which is already"
+ " hidden", p_module->psz_name );
+ return( -1 );
+ }
+
+ /* Deactivate the module : free the capability structure, etc. */
+ if( CallSymbol( p_module, "DeactivateModule" ) != 0 )
+ {
+ /* We couldn't call DeactivateModule() -- looks nasty, but
+ * we can't do much about it. Just try to unload module anyway. */
+ module_unload( p_module->is.plugin.handle );
+ p_module->i_usage = -1;
+ return( -1 );
+ }
+
+ /* Everything worked fine, we can safely unload the module. */
+ module_unload( p_module->is.plugin.handle );
+ p_module->i_usage = -1;
+
+ return( 0 );
+}
+