diff options
author | José Bollo <jose.bollo@iot.bzh> | 2015-12-11 14:57:32 +0100 |
---|---|---|
committer | José Bollo <jose.bollo@iot.bzh> | 2015-12-11 14:57:32 +0100 |
commit | 9ab266df6642c6e930e03b3024d7c3d53ef88bbc (patch) | |
tree | 95c7686ad33af3c012a02412938f9b2c0191dc7b /src/wgt.c | |
parent | 26d75de504d808191dbadc9a735009a214a789b0 (diff) |
don't change of directory anymore
Change-Id: I9f5906d3e053b3fa0f3000d07c4af3f666fe079a
Diffstat (limited to 'src/wgt.c')
-rw-r--r-- | src/wgt.c | 22 |
1 files changed, 16 insertions, 6 deletions
@@ -132,12 +132,10 @@ int wgt_connectat(struct wgt *wgt, int dirfd, const char *pathname) assert(wgt); - rfd = dirfd; - if (pathname) { - rfd = openat(rfd, pathname, O_PATH|O_DIRECTORY); - if (rfd < 0) - return rfd; - } + rfd = (pathname && *pathname) ? openat(dirfd, pathname, O_PATH|O_DIRECTORY) : dup(dirfd); + if (rfd < 0) + return rfd; + if (wgt->rootfd >= 0) close(wgt->rootfd); wgt->rootfd = rfd; @@ -149,6 +147,18 @@ int wgt_connect(struct wgt *wgt, const char *pathname) return wgt_connectat(wgt, AT_FDCWD, pathname); } +struct wgt *wgt_createat(int dirfd, const char *pathname) +{ + struct wgt *wgt = wgt_create(); + if (wgt) { + if (wgt_connectat(wgt, dirfd, pathname)) { + wgt_unref(wgt); + wgt = NULL; + } + } + return wgt; +} + int wgt_is_connected(struct wgt *wgt) { assert(wgt); |