changeset 33:23a3ebcbf08e

Return a module instead of an int
author David Demelier <markand@malikania.fr>
date Sun, 25 Sep 2011 19:16:21 +0200
parents ed6ae3b865c9
children 653bb22d3c0c
files module.c module.h
diffstat 2 files changed, 17 insertions(+), 8 deletions(-) [+]
line wrap: on
line diff
--- a/module.c	Sun Sep 25 19:15:55 2011 +0200
+++ b/module.c	Sun Sep 25 19:16:21 2011 +0200
@@ -21,9 +21,14 @@
 
 #include "module.h"
 
-int
-module_load(struct module *mod, const char *path, int flags)
+struct module *
+module_load(const char *path, int flags)
 {
+	struct module *mod;
+
+	if ((mod = malloc(sizeof (struct module))) == NULL)
+		return NULL;
+
 	/* Flags are not supported on Windows */
 #if defined(_WIN32) || defined(__WIN32__)
 	(void) flags;
@@ -32,10 +37,12 @@
 	mod->handler = dlopen(path, flags);
 #endif
 
-	if (!(mod->handler))
-		return -1;
+	if (!(mod->handler)) {
+		module_free(mod);
+		return NULL;
+	}
 
-	return 0;
+	return mod;
 }
 
 int
@@ -61,4 +68,6 @@
 #else
 	dlclose(mod->handler);
 #endif
+
+	free(mod);
 }
--- a/module.h	Sun Sep 25 19:15:55 2011 +0200
+++ b/module.h	Sun Sep 25 19:16:21 2011 +0200
@@ -44,8 +44,8 @@
 #endif
 };
 
-int	module_load(struct module *, const char *, int);
-int	module_find(struct module *, const char *);
-void	module_free(struct module *);
+struct module	*module_load(const char *, int);
+int		module_find(struct module *, const char *);
+void		module_free(struct module *);
 
 #endif /* _MODULE_H_ */