summaryrefslogtreecommitdiffstats
path: root/src/wgt.c
diff options
context:
space:
mode:
authorJosé Bollo <jose.bollo@iot.bzh>2015-12-10 16:39:05 +0100
committerJosé Bollo <jose.bollo@iot.bzh>2015-12-10 16:39:05 +0100
commitf3d64b7c741677cd28e2a11deed67196cd02b46a (patch)
tree57b6ee3ca5a206d78a39dbcdae49cac5a75ae59a /src/wgt.c
parent63f8720a3e610c0dc37bda3138d2e8de98ec1a78 (diff)
added info retrieval
Change-Id: I6f91b15e87308cf01db4ddafa3c2715c251f5fe5
Diffstat (limited to 'src/wgt.c')
-rw-r--r--src/wgt.c26
1 files changed, 21 insertions, 5 deletions
diff --git a/src/wgt.c b/src/wgt.c
index dd889d5..db59091 100644
--- a/src/wgt.c
+++ b/src/wgt.c
@@ -30,6 +30,7 @@
#include "wgt.h"
struct wgt {
+ int refcount;
int rootfd;
int nrlocales;
char **locales;
@@ -73,7 +74,10 @@ static int validsubpath(const char *subpath)
struct wgt *wgt_create()
{
struct wgt *wgt = malloc(sizeof * wgt);
- if (wgt) {
+ if (!wgt)
+ errno = ENOMEM;
+ else {
+ wgt->refcount = 1;
wgt->rootfd = -1;
wgt->nrlocales = 0;
wgt->locales = NULL;
@@ -96,9 +100,16 @@ void wgt_locales_reset(struct wgt *wgt)
free(wgt->locales[--wgt->nrlocales]);
}
-void wgt_destroy(struct wgt *wgt)
+void wgt_addref(struct wgt *wgt)
+{
+ assert(wgt);
+ wgt->refcount++;
+}
+
+void wgt_unref(struct wgt *wgt)
{
- if (wgt) {
+ assert(wgt);
+ if (!--wgt->refcount) {
wgt_disconnect(wgt);
wgt_locales_reset(wgt);
free(wgt->locales);
@@ -106,13 +117,13 @@ void wgt_destroy(struct wgt *wgt)
}
}
-int wgt_connect(struct wgt *wgt, const char *pathname)
+int wgt_connectat(struct wgt *wgt, int dirfd, const char *pathname)
{
int rfd;
assert(wgt);
- rfd = AT_FDCWD;
+ rfd = dirfd;
if (pathname) {
rfd = openat(rfd, pathname, O_PATH|O_DIRECTORY);
if (rfd < 0)
@@ -124,6 +135,11 @@ int wgt_connect(struct wgt *wgt, const char *pathname)
return 0;
}
+int wgt_connect(struct wgt *wgt, const char *pathname)
+{
+ return wgt_connectat(wgt, AT_FDCWD, pathname);
+}
+
int wgt_is_connected(struct wgt *wgt)
{
assert(wgt);