| 70 | } |
| 71 | |
| 72 | struct path_pushd *path_pushd(const tal_t *ctx, const char *dir) |
| 73 | { |
| 74 | struct path_pushd *old = tal(ctx, struct path_pushd); |
| 75 | |
| 76 | if (!old) |
| 77 | return NULL; |
| 78 | |
| 79 | if (unlikely(!dir) && taken(dir)) |
| 80 | return tal_free(old); |
| 81 | |
| 82 | if (!tal_add_destructor(old, pushd_destroy)) |
| 83 | old = tal_free(old); |
| 84 | else { |
| 85 | old->fd = open(".", O_RDONLY); |
| 86 | if (old->fd < 0) |
| 87 | old = tal_free(old); |
| 88 | else if (chdir(dir) != 0) |
| 89 | old = tal_free(old); |
| 90 | } |
| 91 | |
| 92 | if (taken(dir)) |
| 93 | tal_free(dir); |
| 94 | return old; |
| 95 | } |
| 96 | |
| 97 | bool path_popd(struct path_pushd *olddir) |
| 98 | { |
no test coverage detected